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] allow load from static Collection #203

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions openeo_processes_dask/process_implementations/cubes/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import planetary_computer as pc
import pyproj
import pystac
import pystac_client
import stackstac
import xarray as xr
Expand Down Expand Up @@ -80,6 +81,23 @@
return catalog_url, collection_id


def _get_items_from_static_collection(url):
stac_api = pystac_client.stac_api_io.StacApiIO()
stac_dict = json.loads(stac_api.read_text(url))
collection = stac_api.stac_object_from_dict(stac_dict)

Check warning on line 87 in openeo_processes_dask/process_implementations/cubes/load.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/cubes/load.py#L85-L87

Added lines #L85 - L87 were not covered by tests

items_list = None
items = []
if "items" in stac_dict:
items_list = stac_dict.pop("items")
elif "features" in stac_dict:
items_list = stac_dict.pop("features")
if items_list is None:
raise Exception("No Items/Features found in the provided STAC Collection!")
items = [pystac.Item.from_dict(it) for it in items_list]
return items

Check warning on line 98 in openeo_processes_dask/process_implementations/cubes/load.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/cubes/load.py#L89-L98

Added lines #L89 - L98 were not covered by tests


def load_stac(
url: str,
spatial_extent: Optional[BoundingBox] = None,
Expand All @@ -90,10 +108,20 @@
asset_type = _validate_stac(url)

if asset_type == "COLLECTION":
# We need to distinguish if we are trying to load from a STAC API or from a static Collection
is_static_collection = False
try:
catalog_url, collection_id = _search_for_parent_catalog(url)
except Exception as e:
is_static_collection = True
pass

Check warning on line 117 in openeo_processes_dask/process_implementations/cubes/load.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/cubes/load.py#L112-L117

Added lines #L112 - L117 were not covered by tests

# If query parameters are passed, try to get the parent Catalog if possible/exists, to use the /search endpoint
if spatial_extent or temporal_extent or bands or properties:
if is_static_collection:
items = _get_items_from_static_collection(url)

Check warning on line 121 in openeo_processes_dask/process_implementations/cubes/load.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/cubes/load.py#L120-L121

Added lines #L120 - L121 were not covered by tests

elif spatial_extent or temporal_extent or bands or properties:

Check warning on line 123 in openeo_processes_dask/process_implementations/cubes/load.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/cubes/load.py#L123

Added line #L123 was not covered by tests
# If query parameters are passed, try to get the parent Catalog if possible/exists, to use the /search endpoint
catalog_url, collection_id = _search_for_parent_catalog(url)

# Check if we are connecting to Microsoft Planetary Computer, where we need to sign the connection
modifier = pc.sign_inplace if "planetarycomputer" in catalog_url else None
Expand Down