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

load_stac: "Invalid band name/index" warning for https://stac.terrascope.be/collections/sentinel-2-l2a #692

Open
bossie opened this issue Dec 19, 2024 · 3 comments

Comments

@bossie
Copy link
Collaborator

bossie commented Dec 19, 2024

The client is unable to detect the bands for this STAC Collection; why? The error message (actually: a warning) is apparently intimidating so could be improved as well.

The job finishes successfully so the back-end is able to cope.

connection = openeo.connect(url="openeo-dev.vito.be").authenticate_oidc()

df = pd.DataFrame({ "west" : 528140, "south" : 4497440, "east" : 529420, "north" : 4498720, "epsg" : 32629, 'tile' : '29TNE'}, index=[0])
row = df.iloc[0]

spatial_extent = {
        "west": int(row.west),
        "south": int(row.south),
        "east": int(row.east),
        "north": int(row.north),
        "crs": "EPSG:" + str(row.epsg),
    }

s2_datacube = connection.load_stac(
    "https://stac.terrascope.be/collections/sentinel-2-l2a",
    spatial_extent=spatial_extent,
    temporal_extent=["2020-06-01", "2020-06-30"],
    bands=["B02", "B04", "B08", "SCL_20m"],
    properties={"eo:cloud_cover": lambda v: v <= 90,
                "s2:processing_baseline": lambda pb: pb == "05.00",
                "mgrs:utm_zone": lambda utm: utm == int(row.tile[0:2]), #.lstrip('0'),
                "mgrs:latitude_band": lambda lat_band: lat_band == row.tile[2:3],
                "mgrs:grid_square": lambda square: square == row.tile[3:],
            }
    )

Client error:

Failed to extract cube metadata from STAC URL https://stac.terrascope.be/collections/sentinel-2-l2a
Traceback (most recent call last):
  File "/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/rest/datacube.py", line 393, in load_stac
    metadata = metadata.filter_bands(band_names=bands)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py", line 313](https://notebooks.terrascope.be/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py#line=312), in filter_bands
    dimensions=[d.filter_bands(band_names) if isinstance(d, BandDimension) else d for d in self._dimensions]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py", line 313](https://notebooks.terrascope.be/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py#line=312), in <listcomp>
    dimensions=[d.filter_bands(band_names) if isinstance(d, BandDimension) else d for d in self._dimensions]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py", line 178](https://notebooks.terrascope.be/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py#line=177), in filter_bands
    bands=[self.bands[self.band_index(b)] for b in bands]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py", line 178](https://notebooks.terrascope.be/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py#line=177), in <listcomp>
    bands=[self.bands[self.band_index(b)] for b in bands]
                      ^^^^^^^^^^^^^^^^^^
  File "[/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py", line 153](https://notebooks.terrascope.be/opt/conda/envs/python3/lib/python3.11/site-packages/openeo/metadata.py#line=152), in band_index
    raise ValueError("Invalid band name[/index](https://notebooks.terrascope.be/index) {b!r}. Valid names: {n!r}".format(b=band, n=band_names))
ValueError: Invalid band name[/index](https://notebooks.terrascope.be/index) 'B02'. Valid names: []
@EmileSonneveld
Copy link
Contributor

@soxofaan
Copy link
Member

soxofaan commented Dec 20, 2024

I can not reproduce that original error. At the moment I get (snippet slimmed down to essential parts):

connection = openeo.connect(url="openeo-dev.vito.be")

s2_datacube = connection.load_stac(
    "https://stac.terrascope.be/collections/sentinel-2-l2a",
    bands=["B02", "B04", "B08", "SCL_20m"],
    )

->

  File ".../openeo-python-client/openeo/rest/datacube.py", line 393, in load_stac
    metadata = metadata.filter_bands(band_names=bands)
  File ".../openeo-python-client/openeo/metadata.py", line 313, in filter_bands
    dimensions=[d.filter_bands(band_names) if isinstance(d, BandDimension) else d for d in self._dimensions]
  File ".../openeo-python-client/openeo/metadata.py", line 313, in <listcomp>
    dimensions=[d.filter_bands(band_names) if isinstance(d, BandDimension) else d for d in self._dimensions]
  File ".../openeo-python-client/openeo/metadata.py", line 178, in filter_bands
    bands=[self.bands[self.band_index(b)] for b in bands]
  File ".../openeo-python-client/openeo/metadata.py", line 178, in <listcomp>
    bands=[self.bands[self.band_index(b)] for b in bands]
  File ".../openeo-python-client/openeo/metadata.py", line 153, in band_index
    raise ValueError("Invalid band name/index {b!r}. Valid names: {n!r}".format(b=band, n=band_names))
ValueError: Invalid band name/index 'SCL_20m'. Valid names: ['B09', 'B8A', 'B02', 'B01', 'B12', 'B05', 'B06', 'B04', 'B07', 'B11', 'B03', 'B08']

so here it complains about SCL_20m, while B02 is present

(FYI: I'm using current master branch of client here, which is after 0.36.0)

@soxofaan
Copy link
Member

FYI to simplify reproducing/debugging: you just have to do this to see how client extracts band list from stac:

import openeo.metadata
metadata = openeo.metadata.metadata_from_stac(
    "https://stac.terrascope.be/collections/sentinel-2-l2a"
)
# print(metadata.band_dimension)
print(metadata.band_names)

-> ['B09', 'B8A', 'B02', 'B01', 'B12', 'B05', 'B06', 'B04', 'B07', 'B11', 'B03', 'B08']

Comparable issue reported by Joris C:

metadata = openeo.metadata.metadata_from_stac(
    "https://stac.dataspace.copernicus.eu/v1/collections/sentinel-2-l2a"
)
# print(metadata.band_dimension)
print(metadata.band_names)

-> []

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

No branches or pull requests

3 participants