Quick Start

Installation

Install with pip or uv:

pip install aemetxfb

# or with uv
uv add aemetxfb

The library requires Python 3.12+ and has only two runtime dependencies: pandas and numpy.

Basic Usage

Climate normals

Get climatological normal values for a station:

from aemetxfb.clim import get_normals

df = get_normals("3129")  # Madrid Aeropuerto
print(df.loc["Year", "T"])  # Annual mean temperature

# Monthly breakdown
print(df.loc["January", ["T", "R", "H"]])
# T    5.5   Mean temperature (ºC)
# R   29.0   Mean precipitation (mm)
# H   74.0   Mean humidity (%)

Climate extremes

Get absolute extreme values (since ~1920) for a station:

from aemetxfb.clim import get_clim_extremes

df = get_clim_extremes("3129")  # Madrid Aeropuerto
print(df.loc["Tem. max. absoluta (ºC)", "value"])  # e.g. 42.7

# Monthly extremes
df_jan = get_clim_extremes("3129", when="january")

Observations

Get the last 24 hours of hourly data:

from aemetxfb.obs import get_last_24h

df = get_last_24h("3129")
print(df.head())

Get today’s daily summary:

from aemetxfb.obs import get_daily_summary

df = get_daily_summary("3129")
print(df)

UV Index for today

Get hourly UV Index values for all stations:

from aemetxfb.obs import get_UVI_previous_day

df = get_UVI_previous_day()
print(df.head())

Satellite imagery

Download the latest IR satellite images:

from aemetxfb.obs import get_satellite_IR_24h

paths = get_satellite_IR_24h("satellite/")
print(f"Downloaded {len(paths)} images")

Radar data

Download regional radar reflectivity:

from aemetxfb.obs import get_radar_regional_reflectivity_4h

result = get_radar_regional_reflectivity_4h("CCD", "radar/")
print(f"PNGs: {len(result['png'])}, JSONs: {len(result['json'])}")

Station lists

Each module exposes tuples of available station identifiers:

from aemetxfb.clim import STATIONS
from aemetxfb.obs import met_masts, rad_stations, ozone_stations
from aemetxfb.pred import get_predicted_stations

print(f"Climate stations: {len(STATIONS)}")
print(f"Observation masts: {len(met_masts)}")
print(f"Radiation stations: {len(rad_stations)}")
print(f"Ozone stations: {len(ozone_stations)}")
print(f"Forecast stations: {len(get_predicted_stations())}")  # ~8000

Hourly forecasts

Get the hourly forecast for a municipality by name:

from aemetxfb.pred import get_forecast

forecast = get_forecast("Madrid")
print(forecast.get_metadata("name"))  # "Madrid"

# Temperature curve
df = forecast.get_hourly("temperature")
print(df.head())

# Probability of rain
df = forecast.get_probability("precipitation")
print(df)

Or by coordinates:

forecast = get_forecast(40.4168, -3.7038)  # Madrid
print(forecast.get_metadata("name"))

Next steps