Open-EO / openeo-python-client

Python client API for OpenEO
https://open-eo.github.io/openeo-python-client/
Apache License 2.0
156 stars 42 forks source link

Support parameterized `bands` argument in `load_collection` #471

Closed Pratichhya closed 1 year ago

Pratichhya commented 1 year ago

Doesn't accept a band as a parameter. In the following example, band parameter is defined:


band_list = Parameter(
            name = "bands",
            description = "The openEO bands. ",
            schema= {
                "type": "array",
                "minItems": 1,
                "items": { "type": "string", "subtype":"band-name" }
            }
)

Yet, when trying to specify it within a datacube :

cube = conn.load_collection(
                collection_id = collection_param,
                bands=band_list,
)

Type error is encountered TypeError: 'Parameter' object is not iterable

The full log is as shown below:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 4
      1 # specify the collection with input as parameter variables that will be used in the process
      2 
      3 # band = ["B04", "B08"]
----> 4 cube = conn.load_collection(
      5                 collection_id = collection_param,
      6                 bands=band_list,
      7 )

File /opt/conda/envs/openeo/lib/python3.11/site-packages/openeo/rest/connection.py:1131, in Connection.load_collection(self, collection_id, spatial_extent, temporal_extent, bands, properties, max_cloud_cover, fetch_metadata)
   1106 @openeo_process
   1107 def load_collection(
   1108         self,
   (...)
   1115         fetch_metadata=True,
   1116 ) -> DataCube:
   1117     """
   1118     Load a DataCube by collection id.
   1119 
   (...)
   1129         added the ``max_cloud_cover`` argument.
   1130     """
-> 1131     return DataCube.load_collection(
   1132             collection_id=collection_id, connection=self,
   1133             spatial_extent=spatial_extent, temporal_extent=temporal_extent, bands=bands, properties=properties,
   1134             max_cloud_cover=max_cloud_cover,
   1135             fetch_metadata=fetch_metadata,
   1136         )

File /opt/conda/envs/openeo/lib/python3.11/site-packages/openeo/rest/datacube.py:152, in DataCube.load_collection(cls, collection_id, connection, spatial_extent, temporal_extent, bands, fetch_metadata, properties, max_cloud_cover)
    149     metadata = metadata.filter_bands(bands)
    150 else:
    151     # Ensure minimal metadata with best effort band dimension guess (based on `bands` argument).
--> 152     band_dimension = BandDimension("bands", bands=[Band(b, None, None) for b in bands])
    153     metadata = CollectionMetadata({}, dimensions=[band_dimension])
    154 arguments['bands'] = bands

TypeError: 'Parameter' object is not iterable
soxofaan commented 1 year ago

shouldn't be too hard to add, a good starter issue.

@Pratichhya can you give indication of how urgent a fix is? Cooking up a workaround is also pretty straight-forward

Pratichhya commented 1 year ago

@soxofaan, I won't say it is very urgent. I got this issue when testing out some examples for UDP documentation. I can figure out some other examples in the meantime. It's ok.

soxofaan commented 1 year ago

fixed