Skip to content

Commit 28d4a11

Browse files
committed
Issue #298 add "bands" metadata in collection summaries
in addition to existing "eo:bands" to align better with STAC 1.1
1 parent 221873b commit 28d4a11

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and start a new "In Progress" section above it.
2929
- Fix compatibility with Shapely2 ([#158](https://github.com/Open-EO/openeo-python-driver/issues/158))
3030
- Allow `overlap` in `apply_neighborhood` to be not specified ([#401](https://github.com/Open-EO/openeo-python-driver/issues/401))
3131
- Start including STAC-1.1.0-style "bands" metadata in assets in batch job results ([#298](https://github.com/Open-EO/openeo-python-driver/issues/298))
32+
- Start including STAC-1.1.0-style "bands" summaries in collection metadata ([#298](https://github.com/Open-EO/openeo-python-driver/issues/298))
3233

3334

3435
## 0.133.0

openeo_driver/views.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,9 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18491849
# Version dependent metadata conversions
18501850
cube_dims_100 = deep_get(metadata, "cube:dimensions", default=None)
18511851
cube_dims_040 = deep_get(metadata, "properties", "cube:dimensions", default=None)
1852+
bands_110 = deep_get(metadata, "summaries", "bands", default=None)
18521853
eo_bands_100 = deep_get(metadata, "summaries", "eo:bands", default=None)
1854+
# TODO do we still need normalization of openEO 0.4 style eo:bands?
18531855
eo_bands_040 = deep_get(metadata, "properties", "eo:bands", default=None)
18541856
extent_spatial_100 = deep_get(metadata, "extent", "spatial", "bbox", default=None)
18551857
extent_spatial_040 = deep_get(metadata, "extent", "spatial", default=None)
@@ -1859,6 +1861,19 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18591861
if full and not cube_dims_100 and cube_dims_040:
18601862
_log.warning("Collection metadata 'cube:dimensions' in API 0.4 style instead of 1.0 style")
18611863
metadata["cube:dimensions"] = cube_dims_040
1864+
if full and not bands_110 and eo_bands_100:
1865+
_log.warning("_normalize_collection_metadata: converting eo:bands to bands metadata")
1866+
# TODO #298/#363: "bands" is a STAC>=1.1 feature, but here we don't know what version we are in.
1867+
metadata["summaries"]["bands"] = [
1868+
dict_no_none(
1869+
{
1870+
"name": b.get("name"),
1871+
"eo:common_name": b.get("common_name"),
1872+
"eo:center_wavelength": b.get("center_wavelength"),
1873+
}
1874+
)
1875+
for b in eo_bands_100
1876+
]
18621877
if full and not eo_bands_100 and eo_bands_040:
18631878
_log.warning("Collection metadata 'eo:bands' in API 0.4 style instead of 1.0 style")
18641879
metadata.setdefault("summaries", {})
@@ -1886,13 +1901,14 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18861901
dim["extent"] = interval
18871902

18881903
# Make sure some required fields are set.
1904+
# TODO #363 bump stac_version default to 1.0.0 or even 1.1.0?
18891905
metadata.setdefault("stac_version", "0.9.0")
18901906
metadata.setdefault(
18911907
"stac_extensions",
18921908
[
18931909
# TODO: enable these extensions only when necessary?
18941910
STAC_EXTENSION.DATACUBE,
1895-
STAC_EXTENSION.EO,
1911+
STAC_EXTENSION.EO_V110,
18961912
],
18971913
)
18981914

tests/test_views.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,36 @@ def test_normalize_collection_metadata_dimensions_and_bands_100(self, caplog):
10661066
assert res["cube:dimensions"] == {"x": {"type": "spatial"}, "b": {"type": "bands", "values": ["B02", "B03"]}}
10671067
assert res["summaries"]["eo:bands"] == [{"name": "B02"}, {"name": "B03"}]
10681068

1069+
def test_normalize_collection_metadata_bands_stac110(self, caplog):
1070+
"""Test normalization of legacy "eo:bands" metadata to common "bands" metadata"""
1071+
metadata = {
1072+
"id": "foobar",
1073+
"summaries": {
1074+
"eo:bands": [
1075+
{"name": "B02", "common_name": "blue", "center_wavelength": 0.47},
1076+
{"name": "B03", "common_name": "green", "center_wavelength": 0.56},
1077+
],
1078+
},
1079+
}
1080+
res = _normalize_collection_metadata(metadata, api_version=ComparableVersion("1.0.0"), full=True)
1081+
assert res == dirty_equals.IsPartialDict(
1082+
id="foobar",
1083+
stac_version="0.9.0", # TODO #363
1084+
stac_extensions=dirty_equals.Contains(
1085+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
1086+
),
1087+
summaries={
1088+
"eo:bands": [
1089+
{"name": "B02", "common_name": "blue", "center_wavelength": 0.47},
1090+
{"name": "B03", "common_name": "green", "center_wavelength": 0.56},
1091+
],
1092+
"bands": [
1093+
{"name": "B02", "eo:common_name": "blue", "eo:center_wavelength": 0.47},
1094+
{"name": "B03", "eo:common_name": "green", "eo:center_wavelength": 0.56},
1095+
],
1096+
},
1097+
)
1098+
10691099
def test_normalize_collection_metadata_datetime(self, caplog):
10701100
metadata = {
10711101
"id": "foobar",

0 commit comments

Comments
 (0)