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 DataQuery.

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 (one or more strings passed as keyword arguments) – Names and values of parameters to add to the query
Returns:self – Returns self for chaining calls
Return type:DataQuery
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:DataQuery
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:

DataQuery

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.

Parameters:
  • lon (float) – The longitude to request
  • lat (float) – The latitude to request
Returns:

self – Returns self for chaining calls

Return type:

DataQuery

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 (one or more strings) – One or more names of variables to request
Returns:self – Returns self for chaining calls
Return type:RadarQuery
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:DataQuery
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:
Returns:

self – Returns self for chaining calls

Return type:

DataQuery

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.

Parameters:var_names (one or more strings) – One or more names of variables to request. Use ‘all’ to request all.
Returns:self – Returns self for chaining calls
Return type:DataQuery
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

TDSCatalogMetadata – 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.

variables

set(str) – Names of all variables available in this dataset

stations

dict[str, Station] – 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:
  • path (str) – The URL to request
  • params (DataQuery, optional) – The query to pass when making the request
Returns:

resp – The server’s response to the request

Return type:

requests.Response

Raises:

HTTPError – If the server returns anything other than a 200 (OK) code

See also

get_query(), get()

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 a TDSCatalog instance.

Parameters:query (RadarQuery) – The parameters to send to the radar server
Returns:catalog – The catalog of matching data files
Return type:TDSCatalog
Raises:BadQueryError – When the query cannot be handled by the server
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:bytes

See also

get_catalog()

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:
  • path (str) – The path to request, relative to the endpoint
  • query (DataQuery, optional) – The query to pass when making the request
Returns:

resp – The server’s response to the request

Return type:

requests.Response

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:requests.Response

See also

get_path(), get()

query()[source]

Return a new query for the radar server.

Returns:The new query
Return type:RadarQuery
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:str

See also

get_path()

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:bool
class siphon.radarserver.Station(id, elevation, latitude, longitude, name)
__init__

Initialize self. See help(type(self)) for accurate signature.

count(value) → integer -- return number of occurrences of value
elevation

Alias for field number 1

id

Alias for field number 0

index(value[, start[, stop]]) → integer -- 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 (string) – The base URL to the THREDDS server
Returns:datasets – Mapping of dataset name to the catalog reference
Return type:dict[str, CatalogRef]
siphon.radarserver.parse_station_table(root)[source]

Parse station list XML file.

siphon.radarserver.parse_xml_station(elem)[source]

Create a Station instance from an XML tag.