Skip to content

meteostat

meteostat #

Historical weather from Meteostat station observations.

Backfills a cg.Weather for captures that did not record one: the day's hourly observations are interpolated to the capture point, the hour nearest the capture is picked, and its raw station units (km/h wind, % humidity, okta cloud cover) convert to the canonical weather. Meteostat omits apparent temperature, visibility, and UV entirely.

COCO_CONDITIONS = {1: ('Clear', 'sun.max.fill'), 2: ('Mostly Clear', 'sun.max.fill'), 3: ('Partly Cloudy', 'cloud.sun.fill'), 4: ('Cloudy', 'cloud.fill'), 5: ('Fog', 'cloud.fog.fill'), 6: ('Freezing Fog', 'cloud.fog.fill'), 7: ('Light Rain', 'cloud.drizzle.fill'), 8: ('Rain', 'cloud.rain.fill'), 9: ('Heavy Rain', 'cloud.heavyrain.fill'), 10: ('Freezing Rain', 'cloud.sleet.fill'), 11: ('Heavy Freezing Rain', 'cloud.sleet.fill'), 12: ('Sleet', 'cloud.sleet.fill'), 13: ('Heavy Sleet', 'cloud.sleet.fill'), 14: ('Light Snow', 'cloud.snow.fill'), 15: ('Snow', 'cloud.snow.fill'), 16: ('Heavy Snow', 'cloud.snow.fill'), 17: ('Rain Shower', 'cloud.rain.fill'), 18: ('Heavy Rain Shower', 'cloud.heavyrain.fill'), 19: ('Sleet Shower', 'cloud.sleet.fill'), 20: ('Heavy Sleet Shower', 'cloud.sleet.fill'), 21: ('Snow Shower', 'cloud.snow.fill'), 22: ('Heavy Snow Shower', 'cloud.snow.fill'), 23: ('Lightning', 'cloud.bolt.fill'), 24: ('Hail', 'cloud.hail.fill'), 25: ('Thunderstorm', 'cloud.bolt.rain.fill'), 26: ('Heavy Thunderstorm', 'cloud.bolt.rain.fill'), 27: ('Storm', 'wind')} module-attribute #

Each Meteostat condition code as its condition name and SF Symbol.

NEARBY_STATIONS = 4 module-attribute #

How many stations around the point the observations interpolate between.

OKTAS = 8.0 module-attribute #

The full-sky cloud cover Meteostat's cldc counts eighths of.

UNKNOWN_CONDITION = ('Unknown', 'cloud.fill') module-attribute #

What a condition code outside the table reports.

fetch_past_weather(location, when) #

Fetch the historical weather at a location and time.

Parameters:

Name Type Description Default
location Location

The place to fetch for, including its altitude.

required
when datetime

The moment to fetch for (naive is treated as local).

required

Returns:

Type Description
Weather

A cg.Weather with the available observations; the fields Meteostat

Weather

does not report come back as nan.

Raises:

Type Description
ValueError

If no observations cover the location and time.

Example
import capturegraph as cg
import capturegraph_recipes as cgr
from datetime import datetime

loc = cg.Location(latitude=42.445, longitude=-76.480, altitude_meters=261.5)
weather = cgr.scheduling.forecast.fetch_past_weather(loc, datetime(2024, 6, 15, 12, 0))
weather.temperature_celsius  # 22.5
Source code in capturegraph-recipes/capturegraph_recipes/scheduling/forecast/meteostat.py
def fetch_past_weather(location: cg.Location, when: datetime) -> cg.Weather:
    """Fetch the historical weather at a location and time.

    Args:
        location: The place to fetch for, including its altitude.
        when: The moment to fetch for (naive is treated as local).

    Returns:
        A ``cg.Weather`` with the available observations; the fields Meteostat
        does not report come back as ``nan``.

    Raises:
        ValueError: If no observations cover the location and time.

    Example:
        ```python
        import capturegraph as cg
        import capturegraph_recipes as cgr
        from datetime import datetime

        loc = cg.Location(latitude=42.445, longitude=-76.480, altitude_meters=261.5)
        weather = cgr.scheduling.forecast.fetch_past_weather(loc, datetime(2024, 6, 15, 12, 0))
        weather.temperature_celsius  # 22.5
        ```
    """
    observations = _station_day(location, when)
    return _as_weather(_nearest_hour(observations, when), when)