API Reference¶
riweather ¶
riweather.
Grab publicly available weather data.
plot_stations ¶
Plot stations relative to a location.
Raises:
Type | Description |
---|---|
ImportError
|
If matplotlib and folium are not installed. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
float
|
Site latitude |
required |
lon |
float
|
Site longitude |
required |
ranked_stations |
pd.DataFrame
|
Ranked stations |
required |
n |
int
|
The |
None
|
distance_unit |
str
|
Distance unit to use on the plot. Must be meters ( |
'm'
|
Source code in riweather/viz.py
rank_stations ¶
Rank stations by distance to a point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
float
|
Site latitude |
required |
lon |
float
|
Site longitude |
required |
year |
int
|
If specified, only include stations with data for the given year(s). |
None
|
max_distance_m |
int
|
If specified, only include stations within this distance (in meters) from the site. |
None
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
A DataFrame of station information. |
Source code in riweather/stations.py
select_station ¶
Return a Station object out of a ranked set of stations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ranked_stations |
pd.DataFrame
|
A DataFrame returned by
[ |
required |
rank |
int
|
Which station to return. Defaults to |
0
|
Returns:
Type | Description |
---|---|
Station
|
A |
Source code in riweather/stations.py
zcta_to_lat_lon ¶
Convert zip code to lat/lon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zcta |
str
|
Five-digit zip code |
required |
Returns:
Type | Description |
---|---|
float, float
|
The center point of the ZCTA (Zip Code Tabulation Area). |
Source code in riweather/stations.py
Station ¶
ISD Station object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
usaf_id |
str
|
USAF identifier |
required |
load_metadata_on_init |
bool
|
If |
True
|
Examples:
>>> s = Station("720534")
>>> print(s.name, s.latitude, s.longitude)
ERIE MUNICIPAL AIRPORT 40.017 -105.05
Source code in riweather/stations.py
recent_wban_id
property
¶
Most recent WBAN (Weather Bureau Army Navy) identifier.
__repr__ ¶
fetch_raw_temp_data ¶
Retrieve raw weather data from the ISD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year |
int
|
Returned data will be limited to the year specified. If
|
None
|
scale |
str
|
Return the temperature in Celsius ( |
'C'
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
A DataFrame, indexed on the timestamp, with two columns: air temperature and dew point temperature. |
Examples:
>>> s = Station("720534")
>>> print(s.fetch_raw_temp_data(2022).head(2))
tempC dewC
2022-01-01 00:15:00+00:00 -2.8 -4.0
2022-01-01 00:35:00+00:00 -4.2 -5.5
Source code in riweather/stations.py
fetch_temp_data ¶
fetch_temp_data(
year=None,
value=None,
scale="C",
period="H",
rollup="ending",
upsample_first=True,
)
Retrieve temperature data from the ISD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year |
int
|
Returned data will be limited to the year specified. If
|
None
|
value |
int
|
|
None
|
scale |
str
|
Return the value(s) in Celsius ( |
'C'
|
period |
str
|
The time step at which the data will be returned. Defaults
to |
'H'
|
rollup |
str
|
How to align values to the |
'ending'
|
upsample_first |
bool
|
Whether to upsample the data to the minute level prior to resampling. Usually results in more accurate representations of the true weather data. |
True
|
Returns:
Type | Description |
---|---|
pd.DataFrame | pd.Series
|
Either a DataFrame containing both air temperature
and dew point temperature, or, if |
Examples:
>>> s = Station("720534")
>>> print(s.fetch_temp_data(2022).head(2))
tempC dewC
2022-01-01 00:00:00+00:00 -4.298889 -5.512222
2022-01-01 01:00:00+00:00 -6.555833 -7.688333
Source code in riweather/stations.py
get_filenames ¶
Construct the names of ISD files corresponding to this station.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year |
int
|
Limit the filenames to the one corresponding to the given year.
If |
None
|
Returns:
Type | Description |
---|---|
list[str]
|
List of filenames |
Examples:
>>> s = Station("720534")
>>> print(s.get_filenames(2022))
['/pub/data/noaa/2022/720534-00161-2022.gz']
Source code in riweather/stations.py
quality_report ¶
Retrieve information on data quality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
year |
int
|
Limit the report to information concerning the given year.
If |
None
|
Returns:
Type | Description |
---|---|
pd.DataFrame | pd.Series
|
Data quality report |