# Getting Weather Data

The [get_weather_data()](../reference/get_weather_data.md#weathervault.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:


``` python
import weathervault as wv

# Get all available data for a station
weather = wv.get_weather_data("725030-14732")
weather
```


shape: (660_415, 10)

| id | time | temp | dew_point | rh | wd | ws | atmos_pres | ceil_hgt | visibility |
|----|----|----|----|----|----|----|----|----|----|
| str | datetime\[μs, America/New_York\] | f64 | f64 | f64 | i32 | f64 | f64 | i32 | i32 |
| "725030-14732" | 1973-01-01 00:00:00 EST | 11.0 | 11.0 | 100.0 | 170 | 6.1 | 1016.6 | null | 9000 |
| "725030-14732" | 1973-01-01 01:00:00 EST | 12.2 | 11.1 | 93.0 | 180 | 6.7 | 1015.9 | 366 | 8000 |
| "725030-14732" | 1973-01-01 02:00:00 EST | 12.0 | 11.0 | 93.6 | 140 | 5.1 | 1015.6 | null | 6000 |
| "725030-14732" | 1973-01-01 03:00:00 EST | 12.0 | 11.0 | 93.6 | 200 | 3.0 | 1015.6 | null | 4800 |
| "725030-14732" | 1973-01-01 04:00:00 EST | 12.2 | 11.7 | 96.8 | 180 | 5.2 | 1014.2 | 427 | 4800 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2025-08-26 20:51:00 EDT | 23.3 | 10.0 | 42.9 | 330 | 3.6 | 1015.9 | 22000 | 16093 |
| "725030-14732" | 2025-08-26 21:51:00 EDT | 22.8 | 9.4 | 42.5 | 320 | 4.1 | 1016.3 | 3353 | 16093 |
| "725030-14732" | 2025-08-26 22:51:00 EDT | 21.7 | 8.9 | 44.0 | 310 | 6.7 | 1016.7 | 7620 | 16093 |
| "725030-14732" | 2025-08-26 23:51:00 EDT | 21.1 | 8.3 | 43.8 | 320 | 4.1 | 1016.8 | 7620 | 16093 |
| "725030-14732" | 2025-08-27 00:59:00 EDT | null | null | null | null | null | null | null | null |


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


# Specifying Years


## Single Year


``` python
# Get data for 2024
weather_2024 = wv.get_weather_data("725030-14732", years=2024)
weather_2024
```


shape: (13_420, 10)

| id | time | temp | dew_point | rh | wd | ws | atmos_pres | ceil_hgt | visibility |
|----|----|----|----|----|----|----|----|----|----|
| str | datetime\[μs, America/New_York\] | f64 | f64 | f64 | i32 | f64 | f64 | i32 | i32 |
| "725030-14732" | 2024-01-01 00:51:00 EST | 6.1 | -2.8 | 52.9 | 230 | 3.1 | 1015.7 | 1280 | 16093 |
| "725030-14732" | 2024-01-01 01:00:00 EST | 6.1 | -2.8 | 52.9 | 230 | 3.1 | 1015.7 | null | 16000 |
| "725030-14732" | 2024-01-01 01:51:00 EST | 6.1 | -2.8 | 52.9 | 270 | 4.1 | 1015.5 | 1829 | 16093 |
| "725030-14732" | 2024-01-01 02:51:00 EST | 5.6 | -2.2 | 57.2 | 270 | 4.1 | 1015.5 | 1097 | 16093 |
| "725030-14732" | 2024-01-01 03:51:00 EST | 5.6 | -1.7 | 59.4 | 280 | 3.1 | 1015.1 | 1219 | 16093 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2024-12-31 23:20:00 EST | 7.2 | 4.4 | 82.4 | 50 | 7.7 | null | 335 | 16093 |
| "725030-14732" | 2024-12-31 23:43:00 EST | 7.2 | 5.0 | 85.9 | 40 | 4.6 | null | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:51:00 EST | 7.2 | 5.0 | 85.9 | 40 | 5.7 | 998.9 | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


## Multiple Years


``` python
# Get data for specific years
weather_range = wv.get_weather_data("725030-14732", years=[2023, 2024])
weather_range
```


shape: (27_065, 10)

| id | time | temp | dew_point | rh | wd | ws | atmos_pres | ceil_hgt | visibility |
|----|----|----|----|----|----|----|----|----|----|
| str | datetime\[μs, America/New_York\] | f64 | f64 | f64 | i32 | f64 | f64 | i32 | i32 |
| "725030-14732" | 2023-01-01 00:19:00 EST | 11.7 | 10.6 | 93.0 | 280 | 1.5 | null | 518 | 16093 |
| "725030-14732" | 2023-01-01 00:51:00 EST | 11.7 | 10.0 | 89.3 | 220 | 3.1 | 1007.2 | 518 | 16093 |
| "725030-14732" | 2023-01-01 01:00:00 EST | 11.7 | 10.0 | 89.3 | 220 | 3.1 | 1007.2 | null | 16000 |
| "725030-14732" | 2023-01-01 01:24:00 EST | 12.2 | 10.0 | 86.4 | null | 1.5 | null | 2438 | 16093 |
| "725030-14732" | 2023-01-01 01:51:00 EST | 12.2 | 10.0 | 86.4 | 250 | 5.1 | 1006.7 | 2438 | 16093 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2024-12-31 23:20:00 EST | 7.2 | 4.4 | 82.4 | 50 | 7.7 | null | 335 | 16093 |
| "725030-14732" | 2024-12-31 23:43:00 EST | 7.2 | 5.0 | 85.9 | 40 | 4.6 | null | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:51:00 EST | 7.2 | 5.0 | 85.9 | 40 | 5.7 | 998.9 | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


``` python
# Get a range of years
years = [2023, 2024]
weather_multi = wv.get_weather_data("725030-14732", years=years)
weather_multi
```


shape: (27_065, 10)

| id | time | temp | dew_point | rh | wd | ws | atmos_pres | ceil_hgt | visibility |
|----|----|----|----|----|----|----|----|----|----|
| str | datetime\[μs, America/New_York\] | f64 | f64 | f64 | i32 | f64 | f64 | i32 | i32 |
| "725030-14732" | 2023-01-01 00:19:00 EST | 11.7 | 10.6 | 93.0 | 280 | 1.5 | null | 518 | 16093 |
| "725030-14732" | 2023-01-01 00:51:00 EST | 11.7 | 10.0 | 89.3 | 220 | 3.1 | 1007.2 | 518 | 16093 |
| "725030-14732" | 2023-01-01 01:00:00 EST | 11.7 | 10.0 | 89.3 | 220 | 3.1 | 1007.2 | null | 16000 |
| "725030-14732" | 2023-01-01 01:24:00 EST | 12.2 | 10.0 | 86.4 | null | 1.5 | null | 2438 | 16093 |
| "725030-14732" | 2023-01-01 01:51:00 EST | 12.2 | 10.0 | 86.4 | 250 | 5.1 | 1006.7 | 2438 | 16093 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2024-12-31 23:20:00 EST | 7.2 | 4.4 | 82.4 | 50 | 7.7 | null | 335 | 16093 |
| "725030-14732" | 2024-12-31 23:43:00 EST | 7.2 | 5.0 | 85.9 | 40 | 4.6 | null | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:51:00 EST | 7.2 | 5.0 | 85.9 | 40 | 5.7 | 998.9 | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


# Temperature Units

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


``` python
# Fahrenheit
weather_f = wv.get_weather_data("725030-14732", years=2024, temp_unit="fahrenheit")
```


``` python
# Kelvin
weather_k = wv.get_weather_data("725030-14732", years=2024, temp_unit="kelvin")
```


Short forms are also supported:


``` python
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)

| id | time | temp | dew_point | rh | wd | ws | atmos_pres | ceil_hgt | visibility |
|----|----|----|----|----|----|----|----|----|----|
| str | datetime\[μs, America/New_York\] | f64 | f64 | f64 | i32 | f64 | f64 | i32 | i32 |
| "725030-14732" | 2024-01-01 00:51:00 EST | 279.25 | 270.35 | 52.9 | 230 | 3.1 | 1015.7 | 1280 | 16093 |
| "725030-14732" | 2024-01-01 01:00:00 EST | 279.25 | 270.35 | 52.9 | 230 | 3.1 | 1015.7 | null | 16000 |
| "725030-14732" | 2024-01-01 01:51:00 EST | 279.25 | 270.35 | 52.9 | 270 | 4.1 | 1015.5 | 1829 | 16093 |
| "725030-14732" | 2024-01-01 02:51:00 EST | 278.75 | 270.95 | 57.2 | 270 | 4.1 | 1015.5 | 1097 | 16093 |
| "725030-14732" | 2024-01-01 03:51:00 EST | 278.75 | 271.45 | 59.4 | 280 | 3.1 | 1015.1 | 1219 | 16093 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2024-12-31 23:20:00 EST | 280.35 | 277.55 | 82.4 | 50 | 7.7 | null | 335 | 16093 |
| "725030-14732" | 2024-12-31 23:43:00 EST | 280.35 | 278.15 | 85.9 | 40 | 4.6 | null | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:51:00 EST | 280.35 | 278.15 | 85.9 | 40 | 5.7 | 998.9 | 671 | 16093 |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2024-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


# Time Conversion


## Local Time (Default)

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


``` python
# 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:


``` python
# 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:


``` python
# 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:


``` python
# 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)

| id             | name                 | lat    | lon    | elev |
|----------------|----------------------|--------|--------|------|
| str            | str                  | f64    | f64    | f64  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| …              | …                    | …      | …      | …    |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.0  |
| "725030-14732" | "LA GUARDIA AIRPORT" | 40.779 | -73.88 | 3.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:


``` python
# 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)

| year | month | day | hour | min |
|------|-------|-----|------|-----|
| i32  | i8    | i8  | i8   | i8  |
| 2024 | 1     | 1   | 0    | 51  |
| 2024 | 1     | 1   | 1    | 0   |
| 2024 | 1     | 1   | 1    | 51  |
| 2024 | 1     | 1   | 2    | 51  |
| 2024 | 1     | 1   | 3    | 51  |
| …    | …     | …   | …    | …   |
| 2024 | 12    | 31  | 23   | 20  |
| 2024 | 12    | 31  | 23   | 43  |
| 2024 | 12    | 31  | 23   | 51  |
| 2024 | 12    | 31  | 23   | 59  |
| 2024 | 12    | 31  | 23   | 59  |


# Local Caching

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


``` python
# 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:


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


# Quiet Mode

Suppress warnings about partial data:


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


# Error Handling


## Invalid Station


``` python
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


``` python
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:


``` python
# 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:


``` python
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](04-data-processing.md) with weathervault.
