Is there a csv for all weather station metadata? #721
-
The endpoint /stations maxes out at a 500 limit. So if I wanted metadata about all the weather stations I would have to send a lot of requests because I presume there is several thousand total weather stations. Is there a csv or xml file hosted somewhere that gives all metadata (lat, long, name, ...etc) for each station? For example NDBC has something like this with the buoy stations https://www.ndbc.noaa.gov/activestations.xml What I'm trying to do is find a list of metadata of wind stations Thanks for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You might try the list of METAR stations from https://aviationweather.gov/data/cache/stations.cache.xml.gz as a list you can use. I do note that their server seems to have an invalid GZ format when obtained by PHP so I use code
to fix the 'pull' and successfully gzdecode() the result. See the full code I use in https://github.com/ktrue/metar-placefile in the get-aviation-metadata.php script. |
Beta Was this translation helpful? Give feedback.
-
What I ended up doing is using the /stations endpoint with pagination, although the pagination cursor seems bugged to me but maybe I'm missing something. The loop would go on infinitely and the cursor would never run out/change to null Ultimately I just hacked around it with using a counter. There are 45832 stations, if we can get 500 every time then we need 91 iterations to get all stations. I then loaded them into a pandas dataframe which then allows me to do some of the analysis I wanted to do with the metadata. Would be great if there was a csv or xml file somewhere so one does not have to make 91 individual requests to get all the data but not a huge deal import requests
import pandas as pd
def get_geojson_data(url):
try:
response = requests.get(url)
response.raise_for_status()
if response.headers.get('content-type') == 'application/geo+json':
geojson_data = response.json()
return geojson_data
else:
print("Response is not in GeoJSON format")
return None
except requests.exceptions.RequestException as e:
print("Error fetching data:", e)
return None
all_data = []
next_url = "https://api.weather.gov/stations"
count = 0
while next_url:
print(next_url)
data = get_geojson_data(next_url)
for item in data["features"]:
coords = item["geometry"]["coordinates"]
all_data.append([item["id"], coords[0], coords[1]])
pagination = data.get('pagination')
if pagination and 'next' in pagination:
next_url = pagination['next']
count+=1
else:
next_url = None
if count > 91:
break
df = pd.DataFrame(all_data, columns=["id", "lat", "long"])
print(df)
print(len(df))
df.to_csv("testing.csv")
print(count) result:
|
Beta Was this translation helpful? Give feedback.
-
This page provides access to observed current weather conditions for about 1,800 locations across the United States and US Territories. https://forecast.weather.gov/xml/index.xml I wish the API would provide a list like this. |
Beta Was this translation helpful? Give feedback.
What I ended up doing is using the /stations endpoint with pagination, although the pagination cursor seems bugged to me but maybe I'm missing something. The loop would go on infinitely and the cursor would never run out/change to null
Ultimately I just hacked around it with using a counter. There are 45832 stations, if we can get 500 every time then we need 91 iterations to get all stations. I then loaded them into a pandas dataframe which then allows me to do some of the analysis I wanted to do with the metadata. Would be great if there was a csv or xml file somewhere so one does not have to make 91 individual requests to get all the data but not a huge deal