Skip to content

Commit 2b3df52

Browse files
committed
Issue #699/#780 final documentation tweaks
1 parent 68c4b6b commit 2b3df52

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- More extensive band detection for `load_stac` use cases, including the common `bands` metadata from STAC 1.1 ([#699](https://github.com/Open-EO/openeo-python-client/issues/699), [#692](https://github.com/Open-EO/openeo-python-client/issues/692))
12+
- More extensive band detection for `load_stac` use cases, including the common `bands` metadata introduced with STAC 1.1 ([#699](https://github.com/Open-EO/openeo-python-client/issues/699), [#692](https://github.com/Open-EO/openeo-python-client/issues/692), [#586](https://github.com/Open-EO/openeo-python-client/issues/586)).
1313

1414
### Changed
1515

openeo/metadata.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,13 @@ def metadata_from_stac(url: str) -> CubeMetadata:
686686

687687

688688
class _BandList(list):
689-
"""Internal wrapper for list of ``Band`` objects"""
689+
"""
690+
Internal wrapper for list of ``Band`` objects.
691+
692+
.. warning::
693+
This is an internal, experimental helper, with an API that is subject to change.
694+
Do not use/expose it directly in user (facing) code
695+
"""
690696

691697
def __init__(self, bands: Iterable[Band]):
692698
super().__init__(bands)
@@ -707,10 +713,15 @@ def merge(cls, band_lists: Iterable[_BandList]) -> _BandList:
707713

708714
class _StacMetadataParser:
709715
"""
710-
Helper to extract openEO metadata from STAC metadata resource
716+
Helper to extract openEO metadata from STAC metadata resources (Collection, Item, Asset, etc.).
717+
718+
.. warning::
719+
This is an internal, experimental helper, with an API that is subject to change.
720+
Do not use/expose it directly in user (facing) code
711721
"""
712722

713723
def __init__(self, *, logger=_log, log_level=logging.DEBUG, supress_duplicate_warnings: bool = True):
724+
# TODO: argument to set some kind of reference to a root document to improve logging messages?
714725
self._logger = logger
715726
self._log_level = log_level
716727
self._log = lambda msg, **kwargs: self._logger.log(msg=msg, level=self._log_level, **kwargs)
@@ -781,7 +792,7 @@ def _band_from_common_bands_metadata(self, data: dict) -> Band:
781792

782793
def bands_from_stac_object(self, obj: Union[pystac.STACObject, pystac.Asset]) -> _BandList:
783794
"""
784-
Extract band metadata from a STAC object (Collection, Catalog, Item or Asset).
795+
Extract band listing from a STAC object (Collection, Catalog, Item or Asset).
785796
"""
786797
# Note: first check for Collection, as it is a subclass of Catalog
787798
if isinstance(obj, pystac.Collection):
@@ -793,9 +804,13 @@ def bands_from_stac_object(self, obj: Union[pystac.STACObject, pystac.Asset]) ->
793804
elif isinstance(obj, pystac.Asset):
794805
return self.bands_from_stac_asset(asset=obj)
795806
else:
807+
# TODO: also support dictionary with raw STAC metadata?
796808
raise ValueError(f"Unsupported STAC object: {obj!r}")
797809

798810
def bands_from_stac_catalog(self, catalog: pystac.Catalog, *, on_empty: str = _ON_EMPTY_WARN) -> _BandList:
811+
"""
812+
Extract band listing from a STAC Catalog.
813+
"""
799814
# TODO: "eo:bands" vs "bands" priority based on STAC and EO extension version information
800815
summaries = catalog.extra_fields.get("summaries", {})
801816
if "eo:bands" in summaries:
@@ -817,6 +832,9 @@ def bands_from_stac_collection(
817832
consult_assets: bool = True,
818833
on_empty: str = _ON_EMPTY_WARN,
819834
) -> _BandList:
835+
"""
836+
Extract band listing from a STAC Collection.
837+
"""
820838
# TODO: "eo:bands" vs "bands" priority based on STAC and EO extension version information
821839
self._log(f"bands_from_stac_collection with {collection.summaries.lists.keys()=}")
822840
# Look for band metadata in collection summaries
@@ -865,6 +883,9 @@ def bands_from_stac_item(
865883
consult_assets: bool = True,
866884
on_empty: str = _ON_EMPTY_WARN,
867885
) -> _BandList:
886+
"""
887+
Extract band listing from a STAC Item.
888+
"""
868889
# TODO: "eo:bands" vs "bands" priority based on STAC and EO extension version information
869890
self._log(f"bands_from_stac_item with {item.properties.keys()=}")
870891
if "eo:bands" in item.properties:
@@ -890,7 +911,11 @@ def _warn_undeclared_metadata(self, *, field: str, ext: str):
890911
self._warn(f"Using {field!r} metadata, but STAC extension {ext} was not declared.")
891912

892913
def bands_from_stac_asset(self, asset: pystac.Asset, *, on_empty: str = _ON_EMPTY_WARN) -> _BandList:
914+
"""
915+
Extract band listing from a STAC Asset.
916+
"""
893917
# TODO: "eo:bands" vs "bands" priority based on STAC and EO extension version information
918+
# TODO: filter on asset roles?
894919
if _PYSTAC_1_9_EXTENSION_INTERFACE and asset.owner and asset.ext.has("eo") and asset.ext.eo.bands is not None:
895920
return _BandList(self._band_from_eo_bands_metadata(b) for b in asset.ext.eo.bands)
896921
elif "eo:bands" in asset.extra_fields:
@@ -912,6 +937,10 @@ def _bands_from_item_asset_definition(
912937
"pystac.ItemAssetDefinition", # TODO: non-string type hint once pystac dependency is bumped to at least 1.12
913938
],
914939
) -> _BandList:
940+
"""
941+
Extract band listing from a STAC Asset definition
942+
(as used in the item-assets extension, or STAC 1.1 item-assets).
943+
"""
915944
if isinstance(asset, pystac.extensions.item_assets.AssetDefinition):
916945
if "eo:bands" in asset.properties:
917946
if _PYSTAC_1_9_EXTENSION_INTERFACE and asset.owner and not asset.ext.has("eo"):

0 commit comments

Comments
 (0)