siphon.radarserver
Support making data requests to the radar data query service (radar server) on a TDS.
This includes forming proper queries as well as parsing the returned catalog.
- class siphon.radarserver.RadarQuery[source]
Represent a query to the THREDDS radar server.
Expands on the queries supported by
DataQuery
to add queries specific to the radar data query service.- __init__()
Construct an empty class representing a query for data.
- add_query_parameter(**kwargs)
Add arbitrary query element (name=value) to the request.
This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
- Parameters:
kwargs – Names and values of parameters to add to the query
- Returns:
self – Returns self for chaining calls
- Return type:
- all_times()
Add a request for all times to the query.
This adds a request for all times (temporal=all). This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing temporal queries that have been set.
- Returns:
self – Returns self for chaining calls
- Return type:
- items()
Return the various name=value pairs that compose the query.
- Returns:
items – Sequence of tuples of name, value representing the query.
- Return type:
iterator
- lonlat_box(west, east, south, north)
Add a latitude/longitude bounding box to the query.
This adds a request for a spatial bounding box, bounded by (‘north’, ‘south’) for latitude and (‘east’, ‘west’) for the longitude. This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing spatial queries that have been set.
- Parameters:
west (float) – The bounding longitude to the west, in degrees east of the prime meridian
east (float) – The bounding longitude to the east, in degrees east of the prime meridian
south (float) – The bounding latitude to the south, in degrees north of the equator
north (float) – The bounding latitude to the north, in degrees north of the equator
- Returns:
self – Returns self for chaining calls
- Return type:
- lonlat_point(lon, lat)
Add a latitude/longitude point to the query.
This adds a request for a (lon, lat) point. This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing spatial queries that have been set.
- stations(*stns)[source]
Specify one or more stations for the query.
This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing spatial queries that have been set.
- Parameters:
stns (str) – One or more names of variables to request
- Returns:
self – Returns self for chaining calls
- Return type:
- time(time)
Add a request for a specific time to the query.
This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing temporal queries that have been set.
- Parameters:
time (datetime.datetime) – The time to request
- Returns:
self – Returns self for chaining calls
- Return type:
- time_range(start, end)
Add a request for a time range to the query.
This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
This replaces any existing temporal queries that have been set.
- Parameters:
start (datetime.datetime) – The start of the requested time range
end (datetime.datetime) – The end of the requested time range
- Returns:
self – Returns self for chaining calls
- Return type:
- variables(*var_names)
Specify one or more variables for the query.
This function ensures that variable names are not repeated.
This modifies the query in-place, but returns self so that multiple queries can be chained together on one line.
- class siphon.radarserver.RadarServer(url)[source]
Wrap access to the THREDDS radar query service (radar server).
Simplifies access via HTTP to the radar server endpoint. Parses the metadata, provides query catalog results download and parsing based on the appropriate query.
- metadata
Contains the result of parsing the radar server endpoint’s dataset.xml. This has information about the time and space coverage, as well as full information about all of the variables.
- Type:
- stations
Mapping of station ID to a
Station
, which is a namedtuple containing the station’s id, name, latitude, longitude, and elevation.
- __init__(url)[source]
Create a RadarServer instance.
- Parameters:
url (str) – The base URL for the endpoint
- get(path, params=None)
Make a GET request, optionally including a parameters, to a path.
The path of the request is the full URL.
- Parameters:
- Returns:
resp – The server’s response to the request
- Return type:
- Raises:
HTTPError – If the server returns anything other than a 200 (OK) code
- get_catalog(query)[source]
Fetch a parsed THREDDS catalog from the radar server.
Requests a catalog of radar data files data from the radar server given the parameters in
query
and returns aTDSCatalog
instance.- Parameters:
query (RadarQuery) – The parameters to send to the radar server
- Returns:
catalog – The catalog of matching data files
- Return type:
- Raises:
BadQueryError – When the query cannot be handled by the server
See also
- get_catalog_raw(query)[source]
Fetch THREDDS catalog XML from the radar server.
Requests a catalog of radar data files data from the radar server given the parameters in
query
and returns the raw XML.- Parameters:
query (RadarQuery) – The parameters to send to the radar server
- Returns:
catalog – The XML of the catalog of matching data files
- Return type:
See also
- get_path(path, query=None)
Make a GET request, optionally including a query, to a relative path.
The path of the request includes a path on top of the base URL assigned to the endpoint.
- Parameters:
- Returns:
resp – The server’s response to the request
- Return type:
- get_query(query)
Make a GET request, including a query, to the endpoint.
The path of the request is to the base URL assigned to the endpoint.
- Parameters:
query (DataQuery) – The query to pass when making the request
- Returns:
resp – The server’s response to the request
- Return type:
- url_path(path)
Assemble the full url to a path.
Given a path relative to the base URL, assemble the full URL.
- Parameters:
path (str) – The path, relative to the endpoint
- Returns:
url – The full URL to path
- Return type:
See also
- validate_query(query)[source]
Validate a query.
Determines whether
query
is well-formed. This includes checking for all required parameters, as well as checking parameters for valid values.- Parameters:
query (RadarQuery) – The query to validate
- Returns:
valid – Whether
query
is valid.- Return type:
- class siphon.radarserver.Station(id, elevation, latitude, longitude, name)
- count(value, /)
Return number of occurrences of value.
- elevation
Alias for field number 1
- id
Alias for field number 0
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- latitude
Alias for field number 2
- longitude
Alias for field number 3
- name
Alias for field number 4
- siphon.radarserver.get_radarserver_datasets(server)[source]
Get datasets from a THREDDS radar server’s top-level catalog.
This is a helper function to construct the appropriate catalog URL from the server URL, fetch the catalog, and return the contained catalog references.
- Parameters:
server (str) – The base URL to the THREDDS server
- Returns:
datasets – Mapping of dataset name to the catalog reference
- Return type:
dict[str,
CatalogRef
]