TransWikia.com

Intake-STAC: KeyError: 'open_stac_item_collection'

Geographic Information Systems Asked by ScienceNoob on April 12, 2021

I downloaded the AWS Earth search notebook from the intake-stac examples and whithout changing anything. Just run the cells…

But I’ve got everytime the error: KeyError: 'open_stac_item_collection'

Here is my code:

%matplotlib inline
import intake
import satsearch

bbox = [35.48, -3.24, 35.58, -3.14] # (min lon, min lat, max lon, max lat)
dates = '2020-07-01/2020-08-15'

URL='https://earth-search.aws.element84.com/v0'
results = satsearch.Search.search(url=URL,
                                  collections=['sentinel-s2-l2a-cogs'], # note collection='sentinel-s2-l2a-cogs' doesn't work
                                  datetime=dates,
                                  bbox=bbox,    
                                  sort=['<datetime'])

items = results.items()

catalog = intake.open_stac_item_collection(items)

This is the result/error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/opt/anaconda3/envs/openspacedata_app/lib/python3.7/site-packages/intake/__init__.py in __getattr__(attr)
     60     try:
---> 61         return gl[attr]
     62     except KeyError:

KeyError: 'open_stac_item_collection'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-29-45f007afa1be> in <module>
----> 1 catalog = intake.open_stac_item_collection(items)

~/opt/anaconda3/envs/openspacedata_app/lib/python3.7/site-packages/intake/__init__.py in __getattr__(attr)
     61         return gl[attr]
     62     except KeyError:
---> 63         raise AttributeError(attr)
     64 
     65 

AttributeError: open_stac_item_collection

After the solution of Kadir and replace intake_stac.catalog.StacItemCollection with intake.open_stac_item_collection, I’ve got the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-61-0321aa237297> in <module>
----> 1 catalog = intake_stac.catalog.StacItemCollection(items)

~/opt/anaconda3/envs/openspacedata_app/lib/python3.7/site-packages/intake_stac/catalog.py in __init__(self, stac_obj, **kwargs)
     61             self._stac_obj = self._stac_cls.from_file(stac_obj)
     62         else:
---> 63             raise ValueError('Expected %s instance, got: %s' % (self._stac_cls, type(stac_obj)))
     64 
     65         metadata = self._get_metadata(**kwargs.pop('metadata', {}))

ValueError: Expected <class 'pystac.catalog.Catalog'> instance, got: <class 'satstac.itemcollection.ItemCollection'>

One Answer

It must be removed from the package. The error says: "there is no such a method in the package".

  • Install intake-stac.

    pip install intake-stac
    
  • Then, you can use intake_stac.catalog.StacItemCollection instead of intake.open_stac_item_collection (Reference).

    import intake_stac
    
    # ...
    
    catalog = intake_stac.catalog.StacItemCollection(items)
    

Result:

<class 'satstac.itemcollection.ItemCollection'>:
  args:
    stac_obj: !!python/object:satstac.itemcollection.ItemCollection
      _collections:
      - &id001 !!python/object:satstac.collection.Collection
        _data:
          description: Sentinel-2a and Sentinel-2b imagery, processed to Level 2A
            (Surface Reflectance) and converted to Cloud-Optimized GeoTIFFs
          extent:
            spatial:
              bbox:
              - - -180
                - -90
...
...

UPDATE:

The following line gives some results. Please try that:

catalog = intake_stac.catalog.Catalog(items)
null:
  args:
    entries: !!python/object:satstac.itemcollection.ItemCollection
      _collections:
      - &id001 !!python/object:satstac.collection.Collection
        _data:
          description: Sentinel-2a and Sentinel-2b imagery, processed to Level 2A
            (Surface Reflectance) and converted to Cloud-Optimized GeoTIFFs
          extent:
            spatial:
              bbox:
              - - -180
                - -90
...
...

Answered by Kadir Şahbaz on April 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP