get_weather_data()

Get weather data for a meteorological station.

Usage

Source

get_weather_data(
    station_id,
    years=None,
    *,
    convert_to_local=True,
    temp_unit="celsius",
    make_hourly=False,
    cache_dir=None,
    incl_stn_info=False,
    time_as_columns=False,
    quiet=False
)

Downloads and parses weather observation data from NOAA’s Integrated Surface Database (ISD) for the specified station and years.

Parameters

station_id: str

Station identifier in USAF-WBAN format (e.g., “725030-14732”). Use search_stations() or get_station_metadata() to find station IDs.

years: int | list[int] | None = None

Year or list of years to retrieve data for. If None, retrieves all available years for the station.

convert_to_local: bool = True

Whether to convert times from UTC to the station’s local time. Default is True.

temp_unit: str = "celsius"

Temperature unit for output. Accepts "c"/"celsius", "f"/"fahrenheit", or "k"/"kelvin" (case-insensitive). Default is "c" (Celsius).

make_hourly: bool = False

If True, resample data to hourly intervals, taking the first observation of each hour and filling missing hours with None values. Default is False.

cache_dir: str | Path | None = None

Directory to cache downloaded data files. Options are: (1) None (default) for downloading data to memory without saving to disk (will check current working directory for existing cached files first), (2) "." saves to and loads from current working directory, and (3) a path string serving as a custom directory path for caching files. Cached files are named as "{station_id}-{year}.gz".

incl_stn_info: bool = False

Whether to include station metadata in the output. When True, adds columns for station name, country, state, ICAO code, latitude, longitude, and elevation. Default is False.

time_as_columns: bool = False

If True, output separate columns for time components (year, month, day, hour, min) instead of a single time column. Default is False.

quiet: bool = False
If True, suppress warning messages about partial data availability (when some requested years are not available). Default is False.

Returns

pl.DataFrame
A DataFrame with weather observations.

Columns

The returned DataFrame contains the following columns:

  • id: Station identifier
  • time: Observation time (local time if convert_to_local=True, else UTC); or if time_as_columns=True: year, month, day, hour, min columns instead
  • temp: Air temperature (Celsius, Fahrenheit, or Kelvin based on temp_unit=)
  • dew_point: Dew point temperature
  • rh: Relative humidity (percentage)
  • wd: Wind direction in degrees (0-360, direction wind is blowing from)
  • ws: Wind speed in meters per second
  • atmos_pres: Atmospheric pressure at sea level (hectopascals)
  • ceil_hgt: Ceiling height in meters (22000 is taken as unlimited)
  • visibility: Visibility in meters (max is 16000)

When incl_stn_info=True, the following station information columns are also included:

  • name: Station name
  • country: Country name
  • state: State/region code (if applicable)
  • icao: ICAO identifier
  • lat: Latitude in degrees
  • lon: Longitude in degrees
  • elev: Elevation in meters above sea level

Examples

Get weather data for JFK Airport (New York) for 2023:

import weathervault as wv

weather = wv.get_weather_data("744860-94789", years=2023)
weather.head()
shape: (5, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"744860-94789"2023-01-01 00:51:00 EST8.98.9100.02404.61007.661402
"744860-94789"2023-01-01 01:00:00 EST8.98.9100.02404.61007.6120400
"744860-94789"2023-01-01 01:49:00 EST8.08.0100.02304.1null30402
"744860-94789"2023-01-01 01:51:00 EST7.87.8100.02404.11007.361402
"744860-94789"2023-01-01 02:15:00 EST7.87.8100.02504.6null152402

Get data for multiple years with Fahrenheit temperatures:

weather = wv.get_weather_data(
    "725030-14732",  # LaGuardia Airport
    years=2023,
    temp_unit="fahrenheit"
)

weather
shape: (13_645, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"725030-14732"2023-01-01 00:19:00 EST53.151.193.02801.5null51816093
"725030-14732"2023-01-01 00:51:00 EST53.150.089.32203.11007.251816093
"725030-14732"2023-01-01 01:00:00 EST53.150.089.32203.11007.2null16000
"725030-14732"2023-01-01 01:24:00 EST54.050.086.4null1.5null243816093
"725030-14732"2023-01-01 01:51:00 EST54.050.086.42505.11006.7243816093
…………………………
"725030-14732"2023-12-31 22:00:00 EST43.026.151.02603.61015.7null16000
"725030-14732"2023-12-31 22:51:00 EST43.026.151.02503.61015.7146316093
"725030-14732"2023-12-31 23:51:00 EST44.126.148.92404.11015.8149416093
"725030-14732"2023-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2023-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull

Get hourly data (resampled):

weather = wv.get_weather_data(
    "724050-13743",  # Washington Reagan Airport
    years=2023,
    make_hourly=True
)

weather
shape: (8_760, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"724050-13743"2023-01-01 00:00:00 EST11.711.196.1null1.5null1833219
"724050-13743"2023-01-01 01:00:00 EST11.110.696.72202.11011.6null16000
"724050-13743"2023-01-01 02:00:00 EST10.09.496.12003.6null911207
"724050-13743"2023-01-01 03:00:00 EST10.610.6100.02702.6null612414
"724050-13743"2023-01-01 04:00:00 EST8.37.896.71703.11013.0120400
…………………………
"724050-13743"2023-12-31 19:00:00 EST7.2-0.657.71603.11016.3null16000
"724050-13743"2023-12-31 20:00:00 EST6.70.062.31903.61016.6167616093
"724050-13743"2023-12-31 21:00:00 EST6.70.665.11702.11016.6152416093
"724050-13743"2023-12-31 22:00:00 EST6.70.665.11702.11016.6null16000
"724050-13743"2023-12-31 23:00:00 EST5.60.067.2null0.01015.72200016093

Cache data to current directory for offline use:

weather = wv.get_weather_data(
    "725030-14732",
    years=2023,
    cache_dir="."  # Saves to current working directory
)

# Subsequent calls will automatically use the cached file
weather = wv.get_weather_data("725030-14732", years=2023)  # Loads from cache

weather
shape: (13_645, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"725030-14732"2023-01-01 00:19:00 EST11.710.693.02801.5null51816093
"725030-14732"2023-01-01 00:51:00 EST11.710.089.32203.11007.251816093
"725030-14732"2023-01-01 01:00:00 EST11.710.089.32203.11007.2null16000
"725030-14732"2023-01-01 01:24:00 EST12.210.086.4null1.5null243816093
"725030-14732"2023-01-01 01:51:00 EST12.210.086.42505.11006.7243816093
…………………………
"725030-14732"2023-12-31 22:00:00 EST6.1-3.351.02603.61015.7null16000
"725030-14732"2023-12-31 22:51:00 EST6.1-3.351.02503.61015.7146316093
"725030-14732"2023-12-31 23:51:00 EST6.7-3.348.92404.11015.8149416093
"725030-14732"2023-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2023-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull

Include station metadata in the output:

weather = wv.get_weather_data(
    "725030-14732",
    years=2023,
    incl_stn_info=True
)

weather[["name", "country", "lat", "lon"]].head(1)
shape: (1, 4)
namecountrylatlon
strstrf64f64
"LA GUARDIA AIRPORT""United States"40.779-73.88