-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
collection_property
helper to simplify building property filter…
…s for load_collection
- Loading branch information
Showing
6 changed files
with
107 additions
and
5 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
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,59 @@ | ||
""" | ||
Public openEO process graph building utilities | ||
''''''''''''''''''''''''''''''''''''''''''''''' | ||
""" | ||
|
||
from typing import Optional | ||
|
||
from openeo.internal.graph_building import PGNode, _FromNodeMixin | ||
from openeo.processes import ProcessBuilder | ||
|
||
|
||
class CollectionProperty(_FromNodeMixin): | ||
def __init__(self, name: str, _builder: Optional[ProcessBuilder] = None): | ||
self.name = name | ||
self._builder = _builder or ProcessBuilder(pgnode={"from_parameter": "value"}) | ||
|
||
def from_node(self) -> PGNode: | ||
return self._builder.from_node() | ||
|
||
def __eq__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder == other) | ||
|
||
def __ne__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder != other) | ||
|
||
def __gt__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder > other) | ||
|
||
def __ge__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder >= other) | ||
|
||
def __lt__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder < other) | ||
|
||
def __le__(self, other): | ||
return CollectionProperty(self.name, _builder=self._builder <= other) | ||
|
||
|
||
def collection_property(name: str) -> CollectionProperty: | ||
""" | ||
Helper to easily create simple a `load_collection` property filter. | ||
Usage example: | ||
.. code-block:: python | ||
connection.load_collection( | ||
... | ||
properties=[ | ||
collection_property("eo:cloud_cover") <= 75, | ||
collection_property("platform") == "Sentinel-2B", | ||
] | ||
) | ||
:param name: name of the property to filter on | ||
:return: an object which supports operators like ``<=``, ``==`` to build a simple property filter. | ||
""" | ||
return CollectionProperty(name=name) |
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