earthdaily / earthdaily/earthdaily-python-client

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

Open
#119 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
31
Forks
10
PR merge metrics
No merged PRs in 30d

Description

I make a query:
```python
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:
```python
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
```python
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

Contributor guide

Open the contributing guide

Research direction

Start with earthdaily/earthdatastore/cube_utils/__init__.py around line 212 and reproduce the call using a pystac ItemCollection returned by eds.search. Check the datacube input handling and determine whether the completed behavior should convert the collection or provide an instructive warning; verify the original datacube example afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.