Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robmarkcole opened this issue Nov 7, 2024 · 0 comments

Comments

@robmarkcole
Copy link
Collaborator

robmarkcole commented Nov 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant