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

stac2ds product_cache does not accept odc product #167

Open
jmettes opened this issue Sep 2, 2024 · 0 comments
Open

stac2ds product_cache does not accept odc product #167

jmettes opened this issue Sep 2, 2024 · 0 comments

Comments

@jmettes
Copy link

jmettes commented Sep 2, 2024

I'd like to construct an odc ds doc from stac, with an existing odc product definition. But it looks like it requires some _md attributes with RasterCollectionMetadata

>>> import datacube
>>> dc = datacube.Datacube()

>>> product_cache={"sentinel-2-c1-l2a": dc.index.products.get_by_name("s2_l2a")}
>>> product_cache
{'sentinel-2-c1-l2a': Product(name='s2_l2a', id_=1)}
>>> from odc.stac.eo3 import stac2ds
>>> from pystac import Item

>>> item = Item.from_file("https://earth-search.aws.element84.com/v1/collections/sentinel-2-c1-l2a/items/S2A_T01KAA_20240825T221936_L2A")
>>> next(stac2ds([item], product_cache=product_cache))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[134], line 7
      3 from odc.stac.eo3._eo3converter import infer_dc_product_from_item
      5 item = Item.from_file("https://earth-search.aws.element84.com/v1/collections/sentinel-2-c1-l2a/items/S2A_T01KAA_20240825T221936_L2A")
----> 7 next(stac2ds([item], product_cache=product_cache))

File ~/micromamba/envs/generic-mamba/envs/cubeenv/lib/python3.11/site-packages/odc/stac/eo3/_eo3converter.py:325, in stac2ds(items, cfg, product_cache)
    322     product = infer_dc_product(item, cfg)
    323     products[collection_id] = product
--> 325 yield _item_to_ds(item, product, cfg)

File [~/micromamba/envs/generic-mamba/envs/cubeenv/lib/python3.11/site-packages/odc/stac/eo3/_eo3converter.py:241](http://localhost:8888/home/jonathan/micromamba/envs/generic-mamba/envs/cubeenv/lib/python3.11/site-packages/odc/stac/eo3/_eo3converter.py#line=240), in _item_to_ds(item, product, cfg)
    238 if cfg is None:
    239     cfg = {}
--> 241 md: RasterCollectionMetadata = getattr(product, "_md")
    242 uuid_cfg = cfg.get("uuid", {})
    243 ds_uuid = _compute_uuid(
    244     item, mode=uuid_cfg.get("mode", "auto"), extras=uuid_cfg.get("extras", [])
    245 )

AttributeError: 'Product' object has no attribute '_md'

One way to get around this is:

>>> dataset = next(stac2ds([item]))
>>> dataset.product
Product(name='sentinel-2-c1-l2a', id_=None)
>>> dataset.product = dc.index.products.get_by_name("s2_l2a")
>>> dataset.product
Product(name='s2_l2a', id_=1)

but would be nice to pass it in from the start.

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