Station¶
riweather.Station
¶
ISD Station object.
Examples:
>>> s = Station("720534")
>>> s
Station("720534")
>>> print(s.name, s.latitude, s.longitude)
ERIE MUNICIPAL AIRPORT 40.017 -105.05
Parameters:
-
usaf_id
(str
) –USAF identifier
-
load_metadata_on_init
(bool
, default:True
) –If
True
, station metadata will be retrieved from the local data store and loaded into the object as properties.
Source code in src/riweather/stations.py
name
property
¶
state
property
¶
get_filenames
¶
Construct the names of ISD files corresponding to this station.
Parameters:
-
year
(int | None
, default:None
) –Limit the filenames to the one corresponding to the given year. If
None
, filenames for all years are returned.
Returns:
Examples:
>>> s = Station("720534")
>>> print(s.get_filenames(2022))
['/pub/data/noaa/2022/720534-00161-2022.gz']
Source code in src/riweather/stations.py
quality_report
¶
Retrieve information on data quality.
Parameters:
-
year
(int | None
, default:None
) –Limit the report to information concerning the given year. If
None
, all years are included.
Returns:
Source code in src/riweather/stations.py
fetch_raw_data
¶
Fetch data from ISD.
Parameters:
-
year
(int | list[int]
) –Year or years of data to fetch.
-
use_http
(bool
, default:False
) –Use NOAA’s HTTP server instead of their FTP server. Set this to
True
if you are running into issues with FTP.
Returns:
Source code in src/riweather/stations.py
fetch_data
¶
fetch_data(
year,
datum=None,
*,
period=None,
rollup="ending",
upsample_first=True,
tz="UTC",
include_control=False,
include_quality_codes=True,
temp_scale=None,
model_dump_include=None,
model_dump_exclude=None,
use_http=False,
)
Fetch data from ISD and return it as a DataFrame.
Parameters:
-
year
(int | list[int]
) –Year or years of data to fetch.
-
datum
(str | list[str] | None
, default:None
) –Data elements to include in the results. Must be one or more of the mandatory data fields:
'wind'
'ceiling'
'visibility'
'air_temperature'
'dew_point'
'sea_level_pressure'
If not specified, all data are returned.
-
period
(str | None
, default:None
) –The time step at which the data will be returned. If
None
, the default, the data is returned at the original times they were observed. If specified, it must be a frequency string recognized by Pandas such as'h'
for hourly and'15min'
for every 15 minutes (see the docs on frequency strings). The data will be resampled to the given frequency. -
rollup
(str
, default:'ending'
) –How to align values to the
period
. Defaults to'ending'
, meaning that values over the previous time period are averaged. Can also be'starting'
,'midpoint'
, or'instant'
. Ifperiod=None
, this value is ignored. -
upsample_first
(bool
, default:True
) –Whether to upsample the data to the minute level prior to resampling. Upsampling is recommended because it gives more accurate representations of the weather observations, so it defaults to
True
. -
tz
(str
, default:'UTC'
) –The timestamps of each observation are returned from the ISD in UTC. If this parameter is set, the data will be converted to the specified timezone. The timezone string should match one of the standard TZ identifiers, e.g.
'US/Eastern'
,'US/Central'
,'US/Mountain'
,'US/Pacific'
, etc. -
include_control
(bool
, default:False
) –If
True
, include the control data fields in the results. -
include_quality_codes
(bool
, default:True
) –If
False
, filter out all the quality code fields from the results. These are columns that end in the string'quality_code'
. -
temp_scale
(str | None
, default:None
) –By default, when
'air_temperature'
or'dew_point'
are specified as a datum, temperatures are returned in both degrees Celsius and degrees Fahrenheit. To only include one or the other, settemp_scale
to'C'
or'F'
. Ignored if no temperature values are meant to be retrieved. -
model_dump_include
(IncEx | None
, default:None
) –Fine-grained control over the fields that are returned. Passed directly to
pydantic.BaseModel.model_dump
as theinclude
parameter; see the docs for details. Takes precendence overdatum
. -
model_dump_exclude
(IncEx | None
, default:None
) –Fine-grained control over the fields that are returned. Passed directly to
pydantic.BaseModel.model_dump
as theexclude
parameter; see the docs for details. Takes precendence overdatum
. -
use_http
(bool
, default:False
) –Use NOAA’s HTTP server instead of their FTP server. Set this to
True
if you are running into issues with FTP.
Returns:
-
DataFrame
–Weather observations from the station.
Source code in src/riweather/stations.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
|
fetch_raw_temp_data
¶
Retrieve raw weather data from the ISD.
Warning
This has been deprecated and will be removed in a future release. Please consider using
riweather.Station.fetch_data
instead.
Parameters:
-
year
(int | list[int] | None
, default:None
) –Returned data will be limited to the year(s) specified. If
None
, data for all years is returned. -
scale
(str
, default:'C'
) –Return the temperature in Celsius (
"C"
, the default) or Fahrenheit ("F"
). -
use_http
(bool
, default:False
) –Use NOAA’s HTTP server instead of their FTP server. Set this to
True
if you are running into issues with FTP.
Returns:
-
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))
wind_dir wind_speed tempC dewC
2022-01-01 00:15:00+00:00 80.0 4.6 -2.8 -4.0
2022-01-01 00:35:00+00:00 60.0 4.1 -4.2 -5.5
Source code in src/riweather/stations.py
fetch_temp_data
¶
fetch_temp_data(
year=None,
value=None,
scale="C",
period="h",
rollup="ending",
*,
upsample_first=True,
use_http=False,
)
Retrieve temperature data from the ISD.
Warning
This has been deprecated and will be removed in a future release. Please consider using
riweather.Station.fetch_data
instead.
Parameters:
-
year
(int | list[int] | None
, default:None
) –Returned data will be limited to the year specified. If
None
, data for all years is returned. -
value
(str | None
, default:None
) –"temperature"
to retrieve the air temperature only, or"dew_point"
to retrieve the dew point temperature only.None
returns both temperatures in a DataFrame. -
scale
(str
, default:'C'
) –Return the value(s) in Celsius (
"C"
, the default) or Fahrenheit ("F"
). -
period
(str
, default:'h'
) –The time step at which the data will be returned. Defaults to
"h"
, which corresponds to hourly data. Other possible values are"30min"
for half-hourly data,"15min"
for quarter-hourly data, and so on. See the Pandas documentation on frequency strings for more details on possible values. -
rollup
(str
, default:'ending'
) –How to align values to the
period
. Defaults to"ending"
, meaning that values over the previous time period are averaged. -
upsample_first
(bool
, default:True
) –Whether to upsample the data to the minute level prior to resampling. Usually results in more accurate representations of the true weather data.
-
use_http
(bool
, default:False
) –Use NOAA’s HTTP server instead of their FTP server. Set this to
True
if you are running into issues with FTP.
Returns:
Examples:
>>> s = Station("720534")
>>> print(s.fetch_temp_data(2022).head(2))
wind_dir wind_speed tempC dewC
2022-01-01 01:00:00+00:00 63.913043 4.197826 -4.328261 -5.539674
2022-01-01 02:00:00+00:00 17.583333 3.656250 -6.585833 -7.717917
Source code in src/riweather/stations.py
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
|
riweather.plot_stations
¶
Plot stations relative to a location.
Raises:
-
ImportError
–If matplotlib and folium are not installed.
Parameters:
-
lat
(float
) –Site latitude
-
lon
(float
) –Site longitude
-
ranked_stations
(DataFrame
) –Ranked stations
-
n
(int | None
, default:None
) –The
n
top-ranked stations ofranked_stations
will be plotted -
distance_unit
(str
, default:'m'
) –Distance unit to use on the plot. Must be meters (
m
), kilometers (km
), or miles (mi
)
Source code in src/riweather/viz.py
riweather.rank_stations
¶
Rank stations by distance to a point.
Parameters:
-
lat
(float | None
, default:None
) –Site latitude
-
lon
(float | None
, default:None
) –Site longitude
-
year
(int | None
, default:None
) –If specified, only include stations with data for the given year(s).
-
max_distance_m
(int | None
, default:None
) –If specified, only include stations within this distance (in meters) from the site.
-
zipcode
(str | None
, default:None
) –Site zip code. If
lat
and/orlon
are not given andzipcode
is, then stations will be ranked according to the distance from the center point of the zip code.
Returns:
Source code in src/riweather/stations.py
riweather.select_station
¶
Return a Station object out of a ranked set of stations.
Parameters:
-
ranked_stations
(DataFrame
) –A DataFrame returned by
riweather.rank_stations
. -
rank
(int
, default:0
) –Which station to return. Defaults to
rank=0
, which corresponds to the first (i.e. nearest) station.
Returns:
Source code in src/riweather/stations.py
riweather.zcta_to_lat_lon
¶
Convert zip code to lat/lon.
Parameters:
-
zcta
(str
) –Five-digit zip code
Returns: