Station API¶
Weather station index, search, and geocoding.
StationIndex¶
idfkit.weather.index.StationIndex
¶
Searchable index of weather stations from climate.onebuilding.org.
Use load to load the bundled (or user-refreshed) station index. No network access or third-party dependencies are required for load.
Use check_for_updates to see if upstream data has changed, and refresh to re-download and rebuild the index.
Examples:
index = StationIndex.load()
results = index.search("chicago ohare", limit=3)
for r in results:
print(r.station.display_name, r.score)
Source code in idfkit/weather/index.py
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 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 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 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | |
countries
property
¶
Sorted list of unique country codes in the index.
stations
property
¶
All stations in the index.
check_for_updates()
¶
Check if upstream KML files have changed since this index was built.
Sends lightweight HEAD requests to climate.onebuilding.org.
Returns True if any file has a newer Last-Modified date.
Returns False if all files match or if the check fails (offline,
timeout, etc.).
Source code in idfkit/weather/index.py
filter(*, country=None, state=None, wmo_region=None, climate_zone=None, climate_zone_determined=None)
¶
Filter stations by metadata criteria.
All specified criteria must match (logical AND).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country
|
str | None
|
ISO 3166 country code. Case-insensitive. |
None
|
state
|
str | None
|
State or province abbreviation. Case-insensitive. |
None
|
wmo_region
|
int | None
|
WMO region number, inferred from the download URL. |
None
|
climate_zone
|
str | None
|
ASHRAE climate zone code, e.g. |
None
|
climate_zone_determined
|
bool | None
|
Whether the station's zone was determined
upstream. |
None
|
Source code in idfkit/weather/index.py
from_stations(stations)
classmethod
¶
Create an index from an explicit list of stations (useful for tests).
get_by_filename(filename)
¶
Look up stations by EPW filename.
The filename can include or omit the extension (.zip,
.epw, .ddy). Matching is case-insensitive.
When the exact filename matches an indexed entry, those stations are returned. Otherwise the method extracts the WMO number from the filename and falls back to get_by_wmo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
An EPW filename or stem, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
list[WeatherStation]
|
Matching stations (may be empty). |
Source code in idfkit/weather/index.py
get_by_wmo(wmo)
¶
Look up stations by WMO number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wmo
|
str
|
WMO station number as a string (e.g. |
required |
Returns a list because a single WMO number can correspond to multiple stations or dataset variants.
Source code in idfkit/weather/index.py
load(*, cache_dir=None)
classmethod
¶
Load the station index from a local compressed file.
Checks for a user-refreshed cache first, then falls back to the bundled index shipped with the package. No network access is required.
If the cached file is from an older idfkit version and fails to
deserialise (e.g. missing schema fields after a format migration),
it is quarantined to stations.json.gz.stale and the bundled
index is used instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path | None
|
Override the default cache directory. |
None
|
Source code in idfkit/weather/index.py
nearest(latitude, longitude, *, limit=5, max_distance_km=None, country=None)
¶
Find stations nearest to a geographic coordinate.
Uses the Haversine formula for great-circle distance. A bounding-box pre-filter is applied when max_distance_km is specified to avoid computing distances for stations that are obviously too far.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
Decimal degrees, north positive. |
required |
longitude
|
float
|
Decimal degrees, east positive. |
required |
limit
|
int
|
Maximum results to return. |
5
|
max_distance_km
|
float | None
|
Exclude stations farther than this. |
None
|
country
|
str | None
|
If given, restrict to this country code. |
None
|
Source code in idfkit/weather/index.py
refresh(*, cache_dir=None)
classmethod
¶
Re-download the regional KML indexes from climate.onebuilding.org and rebuild the cache.
Uses the Python standard library only — no third-party dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path | None
|
Override the default cache directory. |
None
|
Source code in idfkit/weather/index.py
search(query, *, limit=10, country=None)
¶
Fuzzy-search stations by name, city, state, WMO number, or EPW filename.
Matching is case-insensitive and uses substring / token-prefix
heuristics (no external NLP dependencies). Canonical EPW
filenames (e.g.
"USA_IL_Chicago.Ohare.Intl.AP.725300_TMYx.2009-2023") are
detected automatically and resolved via
get_by_filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search query or EPW filename. |
required |
limit
|
int
|
Maximum number of results to return. |
10
|
country
|
str | None
|
If given, restrict to stations in this country code. |
None
|
Source code in idfkit/weather/index.py
WeatherStation¶
idfkit.weather.station.WeatherStation
dataclass
¶
Metadata for a single weather file entry from climate.onebuilding.org.
Each instance represents one downloadable weather dataset. The same physical
station may appear multiple times with different source or year-range
variants (e.g. TMYx.2007-2021 vs TMYx.2009-2023).
Attributes:
| Name | Type | Description |
|---|---|---|
country |
str
|
ISO 3166 country code (e.g. |
state |
str
|
State or province abbreviation (e.g. |
city |
str
|
City or station name as it appears in the index
(e.g. |
wmo |
str
|
WMO station number as a string to preserve leading zeros
(e.g. |
source |
str
|
Dataset source identifier (e.g. |
latitude |
float
|
Decimal degrees, north positive. |
longitude |
float
|
Decimal degrees, east positive. |
timezone |
float
|
Hours offset from GMT (e.g. |
elevation |
float
|
Meters above sea level. |
url |
str
|
Full download URL for the ZIP archive. |
ashrae_climate_zone |
str
|
ASHRAE HOF climate zone label
(e.g. |
heating_design_db_c |
float
|
99% heating design dry-bulb temperature in °C. |
cooling_design_db_c |
float
|
1% cooling design dry-bulb temperature in °C. |
hdd18 |
int
|
Heating degree-days base 18 °C. |
cdd10 |
int
|
Cooling degree-days base 10 °C. |
design_conditions_source_wmo |
str | None
|
When the station inherits design
conditions from a neighbouring station, this holds that
station's WMO number; otherwise |
Source code in idfkit/weather/station.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
ashrae_climate_zone
instance-attribute
¶
cdd10
instance-attribute
¶
city
instance-attribute
¶
cooling_design_db_c
instance-attribute
¶
cooling_design_db_f
property
¶
1% cooling design dry-bulb temperature in °F.
country
instance-attribute
¶
dataset_variant
property
¶
Extract the TMYx dataset variant from the download URL.
Returns a string like "TMYx", "TMYx.2007-2021", or
"TMYx.2009-2023".
design_conditions_source_wmo = None
class-attribute
instance-attribute
¶
display_name
property
¶
Human-readable station name with location context.
Dots in the city name are replaced with spaces for readability.
elevation
instance-attribute
¶
filename_stem
property
¶
The canonical EPW filename stem derived from the download URL.
Returns the ZIP filename without the .zip extension, e.g.
"USA_IL_Chicago.Ohare.Intl.AP.725300_TMYx.2009-2023".
hdd18
instance-attribute
¶
heating_design_db_c
instance-attribute
¶
heating_design_db_f
property
¶
99% heating design dry-bulb temperature in °F.
latitude
instance-attribute
¶
longitude
instance-attribute
¶
source
instance-attribute
¶
state
instance-attribute
¶
timezone
instance-attribute
¶
url
instance-attribute
¶
wmo
instance-attribute
¶
from_dict(data)
classmethod
¶
Deserialize from a plain dictionary.
The required climate fields use data[key] so a stale or
corrupt payload fails loudly. design_conditions_source_wmo
is genuinely optional.
Source code in idfkit/weather/station.py
to_dict()
¶
Serialize to a plain dictionary for JSON storage.
Source code in idfkit/weather/station.py
SearchResult¶
idfkit.weather.station.SearchResult
dataclass
¶
A text search result with relevance score.
Source code in idfkit/weather/station.py
SpatialResult¶
idfkit.weather.station.SpatialResult
dataclass
¶
A spatial proximity result with great-circle distance.
Source code in idfkit/weather/station.py
geocode¶
idfkit.weather.geocode.geocode(address)
¶
Convert a street address to (latitude, longitude) via Nominatim.
Uses the free OpenStreetMap Nominatim geocoding service. No API key is required. Requests are rate-limited to one per second in compliance with Nominatim usage policy.
This function is thread-safe. Concurrent calls from multiple threads will be serialized to respect the rate limit.
Composable with spatial search: Use the splat operator to combine with nearest for address-based weather station lookup:
```python
from idfkit.weather import StationIndex, geocode
# Find weather stations near an address (one line!)
results = StationIndex.load().nearest(*geocode("350 Fifth Avenue, New York, NY"))
for r in results[:3]:
print(f"{r.station.display_name}: {r.distance_km:.0f} km")
```
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
A free-form address string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A |
Raises:
| Type | Description |
|---|---|
GeocodingError
|
If the address cannot be resolved or the service is unreachable. |
Example
lat, lon = geocode("Empire State Building, NYC") print(f"{lat:.4f}, {lon:.4f}") 40.7484, -73.9857