- query(*, fields=None, fire=None, version=None, start_date=None, assessment_date=None, publication_date=None, extent=None, extent_type=None, extent_relation='intersects', bbox=None, point=None, geometry=None, geometry_relation='intersects', geometry_layer=None, geometry_driver=None, geometry_encoding=None, max=None, offset=None, timeout=15, session=None)¶
Performs a single low-level query of the PWFDF collection and returns the ScienceBase API response as a dict.
Query API
query(...) query(..., *, fields)
Performs a single low-level query of the PWFDF collection via the ScienceBase API and returns the response as a dict. In most cases, the output will include a
totalkey, which reports the number of matching product records. The output will also usually include anitemskey, which is a list of sbJSON dicts for the assessment products included in the response. Usefieldsto indicate the sbJSON fields that should be included in the items.Important
The
totalwill exceed the number of elements initemsif the total number of search results exceed themaxpaging parameter. In such cases, multiple queries may be required to load all the search results.Fire Event
query(..., *, fire)
Searches for assessments whose fire matches the given name. Note that the provided fire name must exactly match an assessment’s fire name (case-insensitive). Partial matches are not supported.
Version Number
query(..., *, version)
Searches for assessments matching the provided version number.
Caution
The
versionmust be a full 2-part version number. Major version numbers are not supported.Date Range
query(..., *, start_date) query(..., *, assessment_date) query(..., *, publication_date)
Searches for assessments matching a given date range. Use
start_dateto filter by the fire start date,assessment_dateto filter by the date the assessment was run, andpublication_dateto filter by the date that the assessment was published to ScienceBase.In general, a date input may be a (1) integer year, (2) datetime.date object, (3) datetime.datetime object, (4) YYYY, YYYY-MM, or YYYY-MM-DD date string, or (5) a tuple of two such inputs. If the input is a year or a month, matches all assessments that fall within that interval. If the input is a 2-tuple, then it is interpreted as a date range and the search matches assessments that fall between the two dates. If the first date is a year or month, then the date range will begin on the first day of that interval. If the last date is a year or month, then the range will end on the final day of that interval.
Extent
query(..., *, extent) query(..., *, extent_type) query(..., *, extent_relation)
Searches for assessments in a spatial area with well-known coordinates, such as a country or state. The
extentmay be the name of a supported extent, or an integer extent ID. Useextent_relationto set the spatial relationship between the extent and the search results. Options are:Relation
Description
intersects(default) Matches assessments that intersect the extent at any point
withinOnly matches assessments that are fully contained within the extent
disjointMatches assessments that do not intersect the extent at any point
Use
extent_typeto specify the type of extent being searched. This option is usually not necessary, but can be useful for guarding against extents with similar names.Geometry
query(..., *, bbox) query(..., *, point) query(..., *, geometry) query(..., *, geometry_relation)
Searches for assessments in a custom geospatial area. You may use one of the following search types at a time:
Search Type
Description
bboxSearches a custom bounding box. The input may be either (1) a WGS-84 [xmin, ymin, xmax, ymax] coordinate sequence, or (2) a GIS file path. If a file, then the bounding box is calculated from the contained geometries.
pointSearches a custom geospatial point. The input may be either (1) a [lon, lat] sequence, or (2) a GIS file path. If a file, then the point is determined as the center of the bounding box of the contained geometries.
geometrySearches a custom geospatial geometry. The input may be either (1) a WGS-84 GeoJSON-like dict (with
typeandcoordinateskeys), or (2) a GIS file path. In practice, only coarse geometries are supported (fewer than 100 coordinate points).Note
GIS files may use any CRS. Unlike explicit coordinate points, they are not limited to WGS-84.
Use
geometry_relationto set the spatial relationship between the geometry and the search results. Options are:Relation
Description
intersects(default) Matches assessments that intersect the geometry at any point
withinOnly matches assessments that are fully contained within the geometry
disjointMatches assessments that do not intersect the geometry at any point
Geometry File IO
query(..., *, geometry_layer) query(..., *, geometry_driver) query(..., *, geometry_encoding)
Advanced options for reading a geometry from a GIS file. Use
geometry_layerwhen the file has multiple data layers. The layer may either be a layer name, or an integer index. Reads the first layer if not otherwise specified. Usegeometry_driverto specify the file format when the file uses a non-standard extension. Most drivers will automatically detect the file encoding, but you can usegeometry_encodingto explicitly specify the encoding if detection fails.Paging
query(..., *, max) query(..., *, offset)
Paging options for the ScienceBase API. Use
maxto set the maximum number of ScienceBase product records that should be retrieved. Defaults to 500 and cannot exceed 1000. Useoffsetto specify the number of ScienceBase products to skip before retrieving search results.Web Request
query(..., *, timeout) query(..., *, session)
Advanced web request options. Use
timeoutto specify a maximum time in seconds for connecting to the ScienceBase server (default is 15 seconds). This option is typically a scalar, but may also use a vector with two elements. In this case, the first value is the timeout to connect with the server, and the second value is the time for the server to return the first byte. You can also settimeout=None, in which case server queries will never time out. This may be useful for some slow connections, but is generally not recommended as your code may hang indefinitely if the server fails to respond.Use the
sessionoption to provide a pre-instantiated requests.Session object for querying the ScienceBase API. If not provided, the command creates (and then closes) a new Session for the request. If you provide a Session object as input, then the session is used to implement the query, but is not closed afterwards. This can be useful when calling pwfdf_api multiple times, as the Session object will preserve the underlying TCP connection, which can improve performance.- Inputs:
fire (str) – The name of a fire event
version (str) – A version number
start_date (str | int | datetime.date | datetime.datetime | tuple) – A date range in which matching fire events began
assessment_date (str | int | datetime.date | datetime.datetime | tuple) – A date range in which matching assessment were performed
publication_date (str | int | datetime.date | datetime.datetime | tuple) – A date range in which matching assessments were published to ScienceBase
extent (str | int) – An extent name or integer ID
extent_type (str) – The type of extent being searched
extent_relation (str) – The spatial relationship between the extent and the search results
bbox (str | Path | [float, float, float, float]) – A custom bounding box to search. Either a file path, or a WGS-84 [xmin, ymin, xmax, ymax] coordinate sequence
point (str | Path | [float, float]) – A custom geospatial point to search. Either a file path, or a [lon, lat] point.
geometry (str | Path | dict) – A custom geospatial geometry to search. Either a file path or a WGS-84 GeoJSON geometry-like dict
geometry_relation (str) – The spatial relationship between the geometry and the search results
geometry_layer (str | int) – The name or index of a data layer in a geometry file
geometry_driver (str) – The file format driver to use to read a geometry file
geometry_encoding (str) – The file encoding to use to read a geometry file
max (int) – The maximum number of ScienceBase records to retrieve per API query
offset (int) – The number of ScienceBase records to skip before retrieving results
fields (list[str]) – A list of sbJSON fields that should be included in the
itemsresponsetimeout (float | (float, float)) – The maximum allowed number of seconds to connect with the ScienceBase server
session (requests.Session) – A pre-existing requests.Session object that should be used to connect with the ScienceBase API
- Outputs:
dict – The ScienceBase API response for the query