forked from Open-EO/openeo-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue Open-EO#567/Open-EO#591 Finetune detection of actual temporal d…
…imension name in `load_stac` - move logic to _StacMetadataParser (less logic nesting) - improve test coverage (and add DummyStacDictBuilder utility)
- Loading branch information
Showing
6 changed files
with
262 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from typing import List, Optional, Union | ||
|
||
|
||
class DummyStacDictBuilder: | ||
""" | ||
Helper to compactly produce STAC Item/Collection/Catalog/... dicts for test purposes | ||
""" | ||
|
||
# TODO: move this to more generic test utilities module | ||
_EXT_DATACUBE = "https://stac-extensions.github.io/datacube/v2.2.0/schema.json" | ||
|
||
@classmethod | ||
def item( | ||
cls, | ||
*, | ||
id: str = "item123", | ||
stac_version="1.0.0", | ||
datetime: str = "2024-03-08", | ||
properties: Optional[dict] = None, | ||
cube_dimensions: Optional[dict] = None, | ||
stac_extensions: Optional[List[str]] = None, | ||
**kwargs, | ||
) -> dict: | ||
properties = properties or {} | ||
properties.setdefault("datetime", datetime) | ||
|
||
if cube_dimensions is not None: | ||
properties["cube:dimensions"] = cube_dimensions | ||
stac_extensions = cls._add_stac_extension(stac_extensions, cls._EXT_DATACUBE) | ||
|
||
d = { | ||
"type": "Feature", | ||
"stac_version": stac_version, | ||
"id": id, | ||
"geometry": None, | ||
"properties": properties, | ||
**kwargs, | ||
} | ||
|
||
if stac_extensions is not None: | ||
d["stac_extensions"] = stac_extensions | ||
return d | ||
|
||
@classmethod | ||
def _add_stac_extension(cls, stac_extensions: Union[List[str], None], stac_extension: str) -> List[str]: | ||
stac_extensions = list(stac_extensions or []) | ||
if stac_extension not in stac_extensions: | ||
stac_extensions.append(stac_extension) | ||
return stac_extensions | ||
|
||
@classmethod | ||
def collection( | ||
cls, | ||
*, | ||
id: str = "collection123", | ||
description: str = "Collection 123", | ||
stac_version: str = "1.0.0", | ||
stac_extensions: Optional[List[str]] = None, | ||
license: str = "proprietary", | ||
extent: Optional[dict] = None, | ||
cube_dimensions: Optional[dict] = None, | ||
summaries: Optional[dict] = None, | ||
) -> dict: | ||
if extent is None: | ||
extent = {"spatial": {"bbox": [[3, 4, 5, 6]]}, "temporal": {"interval": [["2024-01-01", "2024-05-05"]]}} | ||
|
||
d = { | ||
"type": "Collection", | ||
"stac_version": stac_version, | ||
"id": id, | ||
"description": description, | ||
"license": license, | ||
"extent": extent, | ||
"links": [], | ||
} | ||
if cube_dimensions is not None: | ||
d["cube:dimensions"] = cube_dimensions | ||
stac_extensions = cls._add_stac_extension(stac_extensions, cls._EXT_DATACUBE) | ||
if summaries is not None: | ||
d["summaries"] = summaries | ||
if stac_extensions is not None: | ||
d["stac_extensions"] = stac_extensions | ||
return d | ||
|
||
@classmethod | ||
def catalog(cls, *, id: str = "catalog123", stac_version: str = "1.0.0", description: str = "Catalog 123"): | ||
d = { | ||
"type": "Catalog", | ||
"stac_version": stac_version, | ||
"id": id, | ||
"description": description, | ||
"links": [], | ||
} | ||
return d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.