Skip to content

Commit 6409f0a

Browse files
committed
Issue #425 load_stac: support lambda based property filtering
1 parent febdeca commit 6409f0a

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Processes that take a CRS as argument now try harder to convert your input into a proper EPSG code, to avoid unexpected results when an invalid argument gets sent to the backend.
1414
- Initial `load_geojson` support with `Connection.load_geojson()` ([#424](https://github.com/Open-EO/openeo-python-client/issues/424))
1515
- Initial `load_url` (for vector cubes) support with `Connection.load_url()` ([#424](https://github.com/Open-EO/openeo-python-client/issues/424))
16+
- Support lambda based property filtering in `Connection.load_stac()` ([#425](https://github.com/Open-EO/openeo-python-client/issues/425))
1617

1718

1819
### Changed
@@ -105,7 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
105106
including special mode for in Jupyter notebooks.
106107
([#237](https://github.com/Open-EO/openeo-python-client/issues/237))
107108
- Basic support for `load_stac` process with `Connection.load_stac()`
108-
([#425](https://github.com/Open-EO/openeo-python-client/issues/))
109+
([#425](https://github.com/Open-EO/openeo-python-client/issues/425))
109110
- Add `DataCube.aggregate_spatial_window()`
110111

111112
### Fixed

openeo/rest/_datacube.py

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def build_child_callback(
279279
:param parent_parameters: list of parameter names defined for child process
280280
:return:
281281
"""
282+
# TODO: move this to more generic process graph building utility module
282283
# TODO: autodetect the parameters defined by parent process?
283284
if isinstance(process, PGNode):
284285
# Assume this is already a valid callback process

openeo/rest/connection.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from openeo.internal.warnings import legacy_alias, deprecated
2828
from openeo.metadata import CollectionMetadata, SpatialDimension, TemporalDimension, BandDimension, Band
2929
from openeo.rest import OpenEoClientException, OpenEoApiError, OpenEoRestError
30+
from openeo.rest._datacube import build_child_callback
3031
from openeo.rest.auth.auth import NullAuth, BearerAuth, BasicBearerAuth, OidcBearerAuth
3132
from openeo.rest.auth.config import RefreshTokenStore, AuthConfig
3233
from openeo.rest.auth.oidc import OidcClientCredentialsAuthenticator, OidcAuthCodePkceAuthenticator, \
@@ -1280,7 +1281,8 @@ def load_stac(
12801281
12811282
.. versionadded:: 0.17.0
12821283
"""
1283-
# TODO: detect actual metadata from URL
1284+
# TODO #425 move this implementation to `DataCube` and just forward here (like with `load_collection`)
1285+
# TODO #425 detect actual metadata from URL
12841286
metadata = CollectionMetadata(
12851287
{},
12861288
dimensions=[
@@ -1291,15 +1293,17 @@ def load_stac(
12911293
],
12921294
)
12931295
arguments = {"url": url}
1294-
# TODO: more normalization/validation of extent/band parameters and `properties`
1296+
# TODO #425 more normalization/validation of extent/band parameters
12951297
if spatial_extent:
12961298
arguments["spatial_extent"] = spatial_extent
12971299
if temporal_extent:
12981300
arguments["temporal_extent"] = DataCube._get_temporal_extent(temporal_extent)
12991301
if bands:
13001302
arguments["bands"] = bands
13011303
if properties:
1302-
arguments["properties"] = properties
1304+
arguments["properties"] = {
1305+
prop: build_child_callback(pred, parent_parameters=["value"]) for prop, pred in properties.items()
1306+
}
13031307
cube = self.datacube_from_process(process_id="load_stac", **arguments)
13041308
cube.metadata = metadata
13051309
return cube

tests/rest/test_connection.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -2331,18 +2331,18 @@ def test_load_result_filters(requests_mock):
23312331

23322332
class TestLoadStac:
23332333
def test_basic(self, con120):
2334-
cube = con120.load_stac("https://provide.test/dataset")
2334+
cube = con120.load_stac("https://provider.test/dataset")
23352335
assert cube.flat_graph() == {
23362336
"loadstac1": {
23372337
"process_id": "load_stac",
2338-
"arguments": {"url": "https://provide.test/dataset"},
2338+
"arguments": {"url": "https://provider.test/dataset"},
23392339
"result": True,
23402340
}
23412341
}
23422342

23432343
def test_extents(self, con120):
23442344
cube = con120.load_stac(
2345-
"https://provide.test/dataset",
2345+
"https://provider.test/dataset",
23462346
spatial_extent={"west": 1, "south": 2, "east": 3, "north": 4},
23472347
temporal_extent=["2023-05-10", "2023-06-01"],
23482348
bands=["B02", "B03"],
@@ -2351,7 +2351,7 @@ def test_extents(self, con120):
23512351
"loadstac1": {
23522352
"process_id": "load_stac",
23532353
"arguments": {
2354-
"url": "https://provide.test/dataset",
2354+
"url": "https://provider.test/dataset",
23552355
"spatial_extent": {"east": 3, "north": 4, "south": 2, "west": 1},
23562356
"temporal_extent": ["2023-05-10", "2023-06-01"],
23572357
"bands": ["B02", "B03"],
@@ -2360,6 +2360,29 @@ def test_extents(self, con120):
23602360
}
23612361
}
23622362

2363+
def test_properties(self, con120):
2364+
cube = con120.load_stac("https://provider.test/dataset", properties={"platform": lambda p: p == "S2A"})
2365+
assert cube.flat_graph() == {
2366+
"loadstac1": {
2367+
"process_id": "load_stac",
2368+
"arguments": {
2369+
"url": "https://provider.test/dataset",
2370+
"properties": {
2371+
"platform": {
2372+
"process_graph": {
2373+
"eq1": {
2374+
"arguments": {"x": {"from_parameter": "value"}, "y": "S2A"},
2375+
"process_id": "eq",
2376+
"result": True,
2377+
}
2378+
}
2379+
}
2380+
},
2381+
},
2382+
"result": True,
2383+
}
2384+
}
2385+
23632386

23642387
@pytest.mark.parametrize(
23652388
"data",

0 commit comments

Comments
 (0)