Subscribe to a Cecil dataset and load it
Subscribe to a Cecil dataset over an Area of Interest and load the result as an xarray.Dataset (raster) or pandas.DataFrame (vector) for analysis in Python.
Use this skill when the user wants to fetch a remote-sensing or geospatial dataset for an Area of Interest (AOI) from Cecil and analyse it in Python.
Prerequisites
- A Cecil API key — see docs.cecil.earth/quickstart to obtain one.
pip install cecil— the Cecil Python SDK.- The key exported as
CECIL_API_KEYin the environment.
Steps
Construct the client. It reads
CECIL_API_KEYlazily on the first request, so importing it is free.from cecil import Client client = Client()Define an AOI as a GeoJSON polygon and create it.
create_aoitakes onlygeometryand an optionalexternal_ref— there is nonameparameter.aoi = client.create_aoi( external_ref="my-aoi", geometry={ "type": "Polygon", "coordinates": [[ [-60.53, -20.81], [-60.53, -21.17], [-59.99, -21.17], [-59.99, -20.81], [-60.53, -20.81], ]], }, )To reuse an existing AOI instead, look it up:
client.list_aois()orclient.get_aoi(aoi_id).Pick a dataset. Browse docs.cecil.earth/datasets or call
client.list_datasets(). Note theidof the dataset you want.Create a subscription for that dataset over the AOI.
subscription = client.create_subscription( aoi_id=aoi.id, dataset_id="<dataset-uuid>", )Wait for staging. Subscriptions are processed asynchronously. While files are being staged,
load_xarraymay either raisececil.errors.HTTPErroror return an emptyxarray.Dataset. Poll until variables are available, with a hard ceiling so a stuck subscription raises rather than hangs.import time from cecil.errors import HTTPError for attempt in range(60): try: ds = client.load_xarray(subscription.id) if ds.data_vars: break except HTTPError: pass time.sleep(10) else: raise TimeoutError(f"Subscription {subscription.id} not ready after 10 min")Use the data.
dsis anxarray.Datasetbacked by lazy dask arrays. Variables, dimensions, and CRS depend on the dataset.For vector datasets, swap step 5 for
client.load_dataframe(subscription.id), which returns apandas.DataFrame.
Important constraints
Subscriptiondoes not expose astatusfield — readiness is determined by attempting to load.- AOIs and subscriptions are billable resources. To clean up after exploration:
client.archive_aoi(aoi.id)andclient.archive_subscription(subscription.id). - Each dataset has its own AOI size / vertex / latitude constraints (see
Dataset.constraints). Check before subscribing if the AOI is large or unusual.
References
- Cecil quickstart
- SDK reference
- Dataset catalogue
- Worked example:
tutorials/quickstart.ipynb