SynopticPy
SynopticPy copied to clipboard
Metadata requests should use "obrange" instead of start/stop
I am running the code below to get station metadata for a given time range. My use case is that I want to avoid errors from querying too many hours, so I get the stations in the bbox and time range I need with stations_metadata and then run stations_timeseries on a smaller set of data so I don't query too much.
The start and stop parameters do not work properly with metadata, but obrange does. Here is a reproducible example where stations_metadata returns more STIDs than exist in that time range returned by stations_timeseries:
from datetime import datetime
from synoptic.services import stations_timeseries, stations_metadata
box = [-105, 37, -103, 39]
# Find all stations with fuel moisture
sts = stations_metadata(
bbox=box,
vars=["fuel_moisture"],
start=datetime(2024, 1, 1),
end=datetime(2024, 1, 31)
)
# Returns 12 stations
print(sts.columns)
# Returns 6 stations
data = stations_timeseries(
bbox=box,
vars=["fuel_moisture"],
start=datetime(2024, 1, 1),
end=datetime(2024, 3, 31)
)
I tested some Synoptic API commands by hand, and I found that the metadata requests work properly with obrange as a parameter. See "Optional Parameters" at: https://docs.synopticdata.com/services/metadata
I ran curl -X GET url with the urls below.
URL Constructed by SynopticPy: too many stations compared to stations_timeseries for time range
"https://api.synopticdata.com/v2/stations/metadata?bbox=-105,37,-103,39&vars=fuel_moisture&start=202401010000&end=202401310000&token=TOKEN"
URL with obrange: stations match stations_timeseries for time range
"https://api.synopticdata.com/v2/stations/metadata?bbox=-105,37,-103,39&vars=fuel_moisture&obrange=202401010000,202401310000&token=TOKEN"
I wanted to bring this to your attention to see if you know an easy fix. For now I think I will incorporate the manual command line calls into my workflow, but if I have time in the future I could try to help modify synoptic_api and submit a pull request.
Thanks, Jonathon Hirschi, CU Denver Math Department
Thanks for reporting this. I can't promise I'll get around to fixing it any time soon, but I'd like to get a fix in for this.