semantique.QueryRecipe.execute

semantique.QueryRecipe.execute#

QueryRecipe.execute(datacube, mapping, space, time, run_preview=False, cache_data=False, **config)[source]#

Execute a query recipe.

This function initializes a processor.core.QueryProcessor instance and uses it to process the query. It runs through all distinct phases of query processing: parsing, optimization and execution.

Parameters:
  • datacube (Datacube) – The datacube instance to process the query against.

  • mapping (Mapping) – The mapping instance to process the query against.

  • space (SpatialExtent) – The spatial extent in which the query should be processed.

  • time (TemporalExtent) – The temporal extent in which the query should be processed.

  • run_preview (bool) – Should a preview run be performed before executing the query recipe as specified? A preview run calls the query processor with reduced resolution to test if the recipe execution succeeds.

  • cache_data (bool) – Should the query processor cache the data references as provided by the mapped concepts? Enabling caching increases the memory footprint while reducing the I/O time to retrieve data. Will be used only if the same data layer is referenced multiple times. Caching requires a preview run and will automatically set the preview parameter to True.

  • **config – Additional configuration parameters forwarded to QueryProcessor.parse.

Returns:

dict of xarray.DataArray – The response of the query processor as a dictionary containing result names as keys and result arrays as values.

Examples

>>> import semantique as sq
>>> import geopandas as pd
>>> recipe = sq.QueryRecipe()
>>> recipe["map"] = sq.entity("water").reduce("time", "count")
>>> recipe["series"] = sq.entity("water").reduce("space", "count")
>>> dc = sq.datacube.GeotiffArchive("files/layout_gtiff.json", src = "layers_gtiff.zip")
>>> mapping = sq.mapping.Semantique("files/mapping.json")
>>> space = sq.SpatialExtent(gpd.read_file("files/footprint.geojson"))
>>> time = sq.TemporalExtent("2019-01-01", "2020-12-31")
>>> config = {"crs": 3035, "tz": "UTC", "spatial_resolution": [-1800, 1800]}
>>> recipe.execute(dc, mapping, space, time, **config)