load_stac: "Invalid band name/index" warning for https://stac.terrascope.be/collections/sentinel-2-l2a
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: []
Url shows valid with radiant earth viewer:
https://radiantearth.github.io/stac-browser/#/external/stac.dataspace.copernicus.eu/v1/collections/sentinel-2-l2a?.language=en
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)
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)
-> []