# get_weather_data()


Get weather data for a meteorological station.


Usage

``` python
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()](search_stations.md#weathervault.search_stations) or [get_station_metadata()](get_station_metadata.md#weathervault.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.md#weathervault.country): Country name
- [state](state.md#weathervault.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:


``` python
import weathervault as wv

weather = wv.get_weather_data("744860-94789", years=2023)
weather.head()
```


shape: (5, 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 |
| "744860-94789" | 2023-01-01 00:51:00 EST | 8.9 | 8.9 | 100.0 | 240 | 4.6 | 1007.6 | 61 | 402 |
| "744860-94789" | 2023-01-01 01:00:00 EST | 8.9 | 8.9 | 100.0 | 240 | 4.6 | 1007.6 | 120 | 400 |
| "744860-94789" | 2023-01-01 01:49:00 EST | 8.0 | 8.0 | 100.0 | 230 | 4.1 | null | 30 | 402 |
| "744860-94789" | 2023-01-01 01:51:00 EST | 7.8 | 7.8 | 100.0 | 240 | 4.1 | 1007.3 | 61 | 402 |
| "744860-94789" | 2023-01-01 02:15:00 EST | 7.8 | 7.8 | 100.0 | 250 | 4.6 | null | 152 | 402 |


Get data for multiple years with Fahrenheit temperatures:


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

weather
```


shape: (13_645, 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 | 53.1 | 51.1 | 93.0 | 280 | 1.5 | null | 518 | 16093 |
| "725030-14732" | 2023-01-01 00:51:00 EST | 53.1 | 50.0 | 89.3 | 220 | 3.1 | 1007.2 | 518 | 16093 |
| "725030-14732" | 2023-01-01 01:00:00 EST | 53.1 | 50.0 | 89.3 | 220 | 3.1 | 1007.2 | null | 16000 |
| "725030-14732" | 2023-01-01 01:24:00 EST | 54.0 | 50.0 | 86.4 | null | 1.5 | null | 2438 | 16093 |
| "725030-14732" | 2023-01-01 01:51:00 EST | 54.0 | 50.0 | 86.4 | 250 | 5.1 | 1006.7 | 2438 | 16093 |
| … | … | … | … | … | … | … | … | … | … |
| "725030-14732" | 2023-12-31 22:00:00 EST | 43.0 | 26.1 | 51.0 | 260 | 3.6 | 1015.7 | null | 16000 |
| "725030-14732" | 2023-12-31 22:51:00 EST | 43.0 | 26.1 | 51.0 | 250 | 3.6 | 1015.7 | 1463 | 16093 |
| "725030-14732" | 2023-12-31 23:51:00 EST | 44.1 | 26.1 | 48.9 | 240 | 4.1 | 1015.8 | 1494 | 16093 |
| "725030-14732" | 2023-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2023-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


Get hourly data (resampled):


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

weather
```


shape: (8_760, 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 |
| "724050-13743" | 2023-01-01 00:00:00 EST | 11.7 | 11.1 | 96.1 | null | 1.5 | null | 183 | 3219 |
| "724050-13743" | 2023-01-01 01:00:00 EST | 11.1 | 10.6 | 96.7 | 220 | 2.1 | 1011.6 | null | 16000 |
| "724050-13743" | 2023-01-01 02:00:00 EST | 10.0 | 9.4 | 96.1 | 200 | 3.6 | null | 91 | 1207 |
| "724050-13743" | 2023-01-01 03:00:00 EST | 10.6 | 10.6 | 100.0 | 270 | 2.6 | null | 61 | 2414 |
| "724050-13743" | 2023-01-01 04:00:00 EST | 8.3 | 7.8 | 96.7 | 170 | 3.1 | 1013.0 | 120 | 400 |
| … | … | … | … | … | … | … | … | … | … |
| "724050-13743" | 2023-12-31 19:00:00 EST | 7.2 | -0.6 | 57.7 | 160 | 3.1 | 1016.3 | null | 16000 |
| "724050-13743" | 2023-12-31 20:00:00 EST | 6.7 | 0.0 | 62.3 | 190 | 3.6 | 1016.6 | 1676 | 16093 |
| "724050-13743" | 2023-12-31 21:00:00 EST | 6.7 | 0.6 | 65.1 | 170 | 2.1 | 1016.6 | 1524 | 16093 |
| "724050-13743" | 2023-12-31 22:00:00 EST | 6.7 | 0.6 | 65.1 | 170 | 2.1 | 1016.6 | null | 16000 |
| "724050-13743" | 2023-12-31 23:00:00 EST | 5.6 | 0.0 | 67.2 | null | 0.0 | 1015.7 | 22000 | 16093 |


Cache data to current directory for offline use:


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

| 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" | 2023-12-31 22:00:00 EST | 6.1 | -3.3 | 51.0 | 260 | 3.6 | 1015.7 | null | 16000 |
| "725030-14732" | 2023-12-31 22:51:00 EST | 6.1 | -3.3 | 51.0 | 250 | 3.6 | 1015.7 | 1463 | 16093 |
| "725030-14732" | 2023-12-31 23:51:00 EST | 6.7 | -3.3 | 48.9 | 240 | 4.1 | 1015.8 | 1494 | 16093 |
| "725030-14732" | 2023-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |
| "725030-14732" | 2023-12-31 23:59:00 EST | null | null | null | null | null | null | null | null |


Include station metadata in the output:


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

weather[["name", "country", "lat", "lon"]].head(1)
```


shape: (1, 4)

| name                 | country         | lat    | lon    |
|----------------------|-----------------|--------|--------|
| str                  | str             | f64    | f64    |
| "LA GUARDIA AIRPORT" | "United States" | 40.779 | -73.88 |
