Climate Data Module
The clim module provides access to climatological data from AEMet,
including station metadata, normals, extremes, ephemerides, and threshold exceedances.
Station metadata
Two static dictionaries provide station information:
- STATIONS
Dictionary of ~80 climate stations. Each entry maps a station ID to a dict with:
lat(float): Latitudelon(float): Longitudealt(float): Altitude in metersid(str): Station identifierest(str): Station nameperiod(str): Data availability period
from aemetxfb.clim import STATIONS info = STATIONS["3129"] print(info["est"]) # "Madrid Aeropuerto"
- CLIM_EXTREMES_STATIONS
Dictionary of ~120 stations available for climate extreme data. Maps station ID to station name.
from aemetxfb.clim import CLIM_EXTREMES_STATIONS
print(len(CLIM_EXTREMES_STATIONS)) # ~120
- VALID_EXTREME_PARAMS
Dictionary with a extreme value threshold parameter name and its description. See “Thresholds exceedances” section below.
from aemetxfb.clim import VALID_EXTREME_PARAMS
print(VALID_EXTREME_PARAMS)
# {'pptSup40': 'Precipitation above 40 mm',
# 'vtoSup70': 'Wind above 70 km/h',
# 'vtoSup80': 'Wind above 80 km/h',
# 'vtoSup90': 'Wind above 90 km/h',
# 'vtoSup96': 'Wind above 96 km/h'}
Normals
get_normals() returns climatological normal values for a station:
from aemetxfb.clim import get_normals
df = get_normals("3129") # Madrid Aeropuerto
The returned pandas.DataFrame has month names (January-December + Year) as index
and the following columns:
Code |
Name |
Description |
|---|---|---|
T |
Temperatura |
Mean monthly/annual temperature (ºC) |
TM |
Maxima |
Mean of daily maximum temperatures (ºC) |
Tm |
Minima |
Mean of daily minimum temperatures (ºC) |
R |
Precipitación |
Mean monthly/annual precipitation (mm) |
H |
Humedad |
Mean relative humidity (%) |
DR |
Días precip. |
Mean days with precipitation >= 1mm |
DN |
Días nieve |
Mean days with snow |
DT |
Días tormenta |
Mean days with thunderstorms |
DF |
Días niebla |
Mean days with fog |
DH |
Días helada |
Mean days with frost |
DD |
Días despej. |
Mean clear days |
I |
Horas sol |
Mean sunshine hours |
Climate normals maps
get_normals_map() downloads a tar.gz archive of climate maps
for Spain (peninsular, Balearic Islands, and Canary Islands) covering 1981-2010:
from aemetxfb.clim import get_normals_map
path = get_normals_map("clima.tar.gz")
Extremes
get_clim_extremes() returns absolute extreme values since ~1920:
from aemetxfb.clim import get_clim_extremes
# Annual extremes
df = get_clim_extremes("3129")
# Monthly extremes
df_jan = get_clim_extremes("3129", when="january")
The returned pandas.DataFrame has variable names as index and two columns:
value(float): The extreme valuetimestamp(str): When it occurred (e.g."1963/12/29")
Variables include:
Max. num. de dias de lluvia en el mes— Maximum number of rainy days in the monthMax. num. de dias de nieve en el mes— Maximum number of snowy days in the monthMax. num. de dias de tormenta en el mes— Maximum number of stormy days in the monthPrec. max. en un dia (l/m2)— Maximum precipitation in a dayPrec. mensual mas alta (l/m2)— Highest monthly precipitationPrec. mensual mas baja (l/m2)— Lowest monthly precipitationRacha max. viento (velocidad, km/h)— Maximum wind gust (speed)Racha max. viento (direccion)— Maximum wind gust (direction)Tem. max. absoluta (ºC)— Absolute maximum temperatureTem. media de las max. mas alta (ºC)— Highest mean monthly of maximum temperaturesTem. media de las min. mas baja (ºC)— Lowest mean monthly of maximum temperaturesTem. media mas alta (ºC)— Highest mean monthly temperatureTem. media mas baja (ºC)— Lowest mean monthly temperatureTem. min. absoluta (ºC)— Absolute minimum temperature
Ephemerides
get_clim_ephem() returns meteorological ephemerides and commemorations:
from aemetxfb.clim import get_clim_ephem
# Events on a specific date
result = get_clim_ephem(day=1, month=1)
# Search by keyword
result = get_clim_ephem(keyword="tormenta")
# Filter by year
result = get_clim_ephem(year=2020)
The returned dict has keys:
"search_params"— The search parameters used"Efemérides"— List of(date, description)tuples"Conmemoraciones"— List of(date, description)tuples
Threshold exceedances
get_clim_threshold_day() returns stations that exceeded a threshold
on a specific day:
from aemetxfb.clim import get_clim_threshold_day
from datetime import date
# Stations with precipitation > 40mm
df = get_clim_threshold_day(date(2024, 7, 15), "pptSup40")
# Stations with wind gust > 96 km/h
df = get_clim_threshold_day(date(2024, 1, 15), "vtoSup96")
Available parameters:
"pptSup40"— Precipitation > 40mm"vtoSup70"— Wind gust > 70 km/h"vtoSup80"— Wind gust > 80 km/h"vtoSup90"— Wind gust > 90 km/h"vtoSup96"— Wind gust > 96 km/h
get_clim_threshold_month() returns monthly exceedance counts
for all stations:
from aemetxfb.clim import get_clim_threshold_month
df = get_clim_threshold_month(date(2024, 7, 1))
API reference
See aemetxfb.clim for the full API reference.