earthdaily / earthdaily-python-client

EarthDaily python client
https://earthdaily.github.io/earthdaily-python-client/
MIT License
13 stars 7 forks source link

AttributeError: 'ItemCollection' object has no attribute 'collection_id' #119

Open robmarkcole opened 3 weeks ago

robmarkcole commented 3 weeks ago

I make a query:

my_item = eds.search(
    collections=["my-collection"],
    ids=[my_item_id],
    limit=1  # Since we're searching for a specific item
)

assert type(my_item) == pystac.item_collection.ItemCollection

When creating a datacube:

mask_datacube = earthdaily.earthdatastore.datacube(
    [my_item], 
    intersects=gdf, 
    assets=["B5"],
    resolution=RESOLUTION,
    crs="EPSG:3857",
).load()

An exception is raised:

File ~/earthdaily-python-client/earthdaily/earthdatastore/cube_utils/__init__.py:212, in datacube(items_collection, bbox, intersects, assets, engine, rescale, groupby_date, common_band_names, cross_calibration_items, properties, **kwargs)
    210 if common_band_names and not isinstance(assets, dict):
    211     aM = AssetMapper()
--> 212     assets = aM.map_collection_assets(items_collection[0].collection_id, assets)
    213 if isinstance(assets, dict):
    214     assets_keys = list(assets.keys())

AttributeError: 'ItemCollection' object has no attribute 'collection_id'

Resolved by

mask_datacube = earthdaily.earthdatastore.datacube(
    [my_item.items[0]], # creates a list of pystac.item.Item
    intersects=gdf, 
    assets=["cloud-mask"],
    resolution=RESOLUTION,
    crs="EPSG:3857",
).load()

Proposal: if an ItemCollection is received, it is automatically converted to a list of items Alternative: catch the AttributeError and raise an instructive warning?

This is really user error, so the question is how much we support misuse