Getting Weather Data

The get_weather_data() function is the main interface for downloading weather observations from the ISD database.

Basic Usage

At minimum, you need a station ID:

import weathervault as wv

# Get all available data for a station
weather = wv.get_weather_data("725030-14732")
weather
shape: (660_415, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"725030-14732"1973-01-01 00:00:00 EST11.011.0100.01706.11016.6null9000
"725030-14732"1973-01-01 01:00:00 EST12.211.193.01806.71015.93668000
"725030-14732"1973-01-01 02:00:00 EST12.011.093.61405.11015.6null6000
"725030-14732"1973-01-01 03:00:00 EST12.011.093.62003.01015.6null4800
"725030-14732"1973-01-01 04:00:00 EST12.211.796.81805.21014.24274800
…………………………
"725030-14732"2025-08-26 20:51:00 EDT23.310.042.93303.61015.92200016093
"725030-14732"2025-08-26 21:51:00 EDT22.89.442.53204.11016.3335316093
"725030-14732"2025-08-26 22:51:00 EDT21.78.944.03106.71016.7762016093
"725030-14732"2025-08-26 23:51:00 EDT21.18.343.83204.11016.8762016093
"725030-14732"2025-08-27 00:59:00 EDTnullnullnullnullnullnullnullnull

By default, this downloads all available years for the station.

Specifying Years

Single Year

# Get data for 2024
weather_2024 = wv.get_weather_data("725030-14732", years=2024)
weather_2024
shape: (13_420, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"725030-14732"2024-01-01 00:51:00 EST6.1-2.852.92303.11015.7128016093
"725030-14732"2024-01-01 01:00:00 EST6.1-2.852.92303.11015.7null16000
"725030-14732"2024-01-01 01:51:00 EST6.1-2.852.92704.11015.5182916093
"725030-14732"2024-01-01 02:51:00 EST5.6-2.257.22704.11015.5109716093
"725030-14732"2024-01-01 03:51:00 EST5.6-1.759.42803.11015.1121916093
…………………………
"725030-14732"2024-12-31 23:20:00 EST7.24.482.4507.7null33516093
"725030-14732"2024-12-31 23:43:00 EST7.25.085.9404.6null67116093
"725030-14732"2024-12-31 23:51:00 EST7.25.085.9405.7998.967116093
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull

Multiple Years

# Get data for specific years
weather_range = wv.get_weather_data("725030-14732", years=[2023, 2024])
weather_range
shape: (27_065, 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"2024-12-31 23:20:00 EST7.24.482.4507.7null33516093
"725030-14732"2024-12-31 23:43:00 EST7.25.085.9404.6null67116093
"725030-14732"2024-12-31 23:51:00 EST7.25.085.9405.7998.967116093
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
# Get a range of years
years = [2023, 2024]
weather_multi = wv.get_weather_data("725030-14732", years=years)
weather_multi
shape: (27_065, 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"2024-12-31 23:20:00 EST7.24.482.4507.7null33516093
"725030-14732"2024-12-31 23:43:00 EST7.25.085.9404.6null67116093
"725030-14732"2024-12-31 23:51:00 EST7.25.085.9405.7998.967116093
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull

Temperature Units

By default, temperatures are in Celsius. You can change this with the temp_unit parameter:

# Fahrenheit
weather_f = wv.get_weather_data("725030-14732", years=2024, temp_unit="fahrenheit")
# Kelvin
weather_k = wv.get_weather_data("725030-14732", years=2024, temp_unit="kelvin")

Short forms are also supported:

wv.get_weather_data("725030-14732", years=2024, temp_unit="f")  # Fahrenheit
wv.get_weather_data("725030-14732", years=2024, temp_unit="c")  # Celsius
wv.get_weather_data("725030-14732", years=2024, temp_unit="k")  # Kelvin
shape: (13_420, 10)
idtimetempdew_pointrhwdwsatmos_presceil_hgtvisibility
strdatetime[μs, America/New_York]f64f64f64i32f64f64i32i32
"725030-14732"2024-01-01 00:51:00 EST279.25270.3552.92303.11015.7128016093
"725030-14732"2024-01-01 01:00:00 EST279.25270.3552.92303.11015.7null16000
"725030-14732"2024-01-01 01:51:00 EST279.25270.3552.92704.11015.5182916093
"725030-14732"2024-01-01 02:51:00 EST278.75270.9557.22704.11015.5109716093
"725030-14732"2024-01-01 03:51:00 EST278.75271.4559.42803.11015.1121916093
…………………………
"725030-14732"2024-12-31 23:20:00 EST280.35277.5582.4507.7null33516093
"725030-14732"2024-12-31 23:43:00 EST280.35278.1585.9404.6null67116093
"725030-14732"2024-12-31 23:51:00 EST280.35278.1585.9405.7998.967116093
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull
"725030-14732"2024-12-31 23:59:00 ESTnullnullnullnullnullnullnullnull

Time Conversion

Local Time (Default)

By default, timestamps are converted from UTC to the station’s local timezone:

# Times in America/New_York timezone
weather_local = wv.get_weather_data("725030-14732", years=2024)
print(weather_local["time"].dtype)  # datetime[μs, America/New_York]
Datetime(time_unit='us', time_zone='America/New_York')

This handles:

  • daylight saving time transitions
  • timezone offsets
  • year boundaries (buffer years are automatically fetched)

UTC Time

To keep timestamps in UTC:

# Times in UTC
weather_utc = wv.get_weather_data(
    "725030-14732",
    years=2024,
    convert_to_local=False
)
print(weather_utc["time"].dtype)  # datetime[μs, UTC]
Datetime(time_unit='us', time_zone='UTC')

Hourly Resampling

Weather observations are typically irregular (every hour, but sometimes more or less frequent). Use make_hourly=True to resample to exact hourly intervals:

# Resample to hourly data
weather_hourly = wv.get_weather_data(
    "725030-14732",
    years=2024,
    make_hourly=True
)

# All observations at exact hours
print(weather_hourly["time"].dt.minute().unique())  # [0]
shape: (1,)
Series: 'time' [i8]
[
    0
]

This creates a complete hourly time series, with missing hours filled in as null values.

Including Station Metadata

Add station information columns to each row:

# Include station name, location, etc.
weather_with_info = wv.get_weather_data(
    "725030-14732",
    years=2024,
    incl_stn_info=True
)

# Additional columns: name, country, state, icao, lat, lon, elev
weather_with_info[["id", "name", "lat", "lon", "elev"]]
shape: (13_420, 5)
idnamelatlonelev
strstrf64f64f64
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
……………
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0
"725030-14732""LA GUARDIA AIRPORT"40.779-73.883.0

This is useful when combining data from multiple stations.

Time as Separate Columns

For some analyses, you may want time broken into year/month/day/hour/minute columns:

# Split datetime into components
weather_split = wv.get_weather_data(
    "725030-14732",
    years=2024,
    time_as_columns=True
)

# Columns: id, year, month, day, hour, min, temp, ...
weather_split[["year", "month", "day", "hour", "min"]]
shape: (13_420, 5)
yearmonthdayhourmin
i32i8i8i8i8
202411051
20241110
202411151
202411251
202411351
……………
202412312320
202412312343
202412312351
202412312359
202412312359

Local Caching

To avoid re-downloading data, use local file caching:

# Cache files in a specific directory
weather = wv.get_weather_data(
    "725030-14732",
    years=2024,
    cache_dir="./weather_cache"
)

Subsequent calls will use cached files if available. To use the current directory:

# Cache in current working directory
weather = wv.get_weather_data("725030-14732", years=2024, cache_dir=".")

Quiet Mode

Suppress warnings about partial data:

# No warnings about unavailable years
weather = wv.get_weather_data(
    "725030-14732",
    years=[2020, 2021, 2022, 2023, 2024],
    quiet=True
)

Error Handling

Invalid Station

try:
    weather = wv.get_weather_data("000000-00000", years=2024)
except ValueError as e:
    print(f"Error: {e}")
    # Error: Station '000000-00000' not found in station metadata
Error: Station '000000-00000' not found in metadata. Use search_stations() to find valid station IDs.

Unavailable Years

try:
    weather = wv.get_weather_data("725030-14732", years=1800)
except ValueError as e:
    print(f"Error: {e}")
    # Error includes available year range
Error: No data available for station '725030-14732' for year(s) 1800. Available years: 1973-2025 (53 years total). Use get_years_for_station('725030-14732') to see all available years.

Partial Data

If some requested years are unavailable, weathervault warns you and returns the available years:

# Request years that don't have data - raises ValueError
try:
    weather = wv.get_weather_data("725030-14732", years=list(range(1900, 1951)))
except ValueError as e:
    print(f"Error: {str(e)[:150]}...")
Error: No data available for station '725030-14732' for year(s) 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 191...

Complete Example

Here’s a typical workflow combining multiple options:

import weathervault as wv
import polars as pl

# Get weather data with custom options
weather = wv.get_weather_data(
    "725030-14732",  # LaGuardia Airport
    years=2024,
    temp_unit="celsius",
    make_hourly=True,
    incl_stn_info=True,
    cache_dir="./cache"
)

# Quick analysis
temp_stats = weather.select([
    pl.col("temp").mean().alias("mean_temp"),
    pl.col("temp").min().alias("min_temp"),
    pl.col("temp").max().alias("max_temp"),
])

print(temp_stats)
shape: (1, 3)
┌───────────┬──────────┬──────────┐
│ mean_temp ┆ min_temp ┆ max_temp │
│ ---       ┆ ---      ┆ ---      │
│ f64       ┆ f64      ┆ f64      │
╞═══════════╪══════════╪══════════╡
│ 14.333037 ┆ -11.1    ┆ 35.6     │
└───────────┴──────────┴──────────┘

Performance Tips

For best performance, always use caching by specifying cache_dir= for repeated downloads (this avoids re-downloading the same data). Request specific years rather than downloading all available years if you only need recent data. When working with multiple years, batch your requests by downloading them in one call rather than making separate calls. Finally, if you don’t need timezone conversion, set convert_to_local=False to avoid the local time overhead associated with timezone calculations.

Next Steps

Learn about data processing and analysis with weathervault.