Skip to content

Commit

Permalink
EP-3251 Open-EO#117 Open-EO#124 Open-EO#125 further fixes for `reduce…
Browse files Browse the repository at this point in the history
…_dimension`/`reduce_dimension_binary` handling
  • Loading branch information
soxofaan committed Mar 11, 2020
1 parent 8670c99 commit 2193952
Show file tree
Hide file tree
Showing 17 changed files with 792 additions and 359 deletions.
15 changes: 3 additions & 12 deletions openeo/internal/graphbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ def __init__(self, graph=None):
self.result_node = graph.result_node
# TODO: what is result_node in "else" case?

def shallow_copy(self):
def shallow_copy(self) -> 'GraphBuilder':
"""
Copy, but don't update keys
:return:
"""
# TODO can we avoid copies and work with immutable structures?
the_copy = GraphBuilder()
# TODO: this "shallow copy" method does a "deep copy"
the_copy.result_node = copy.deepcopy(self.result_node)
return the_copy

@classmethod
def from_process_graph(cls, graph: Dict):
# TODO Can't this just be part of default constructor?
# TODO: remove this method?
# TODO: can we avoid the deepcopy?
# TODO is this a nested or flat graph?
builder = GraphBuilder()
Expand All @@ -59,17 +61,6 @@ def add_process(self, process_id: str, arguments: dict = None, **kwargs):
}
self.result_node = new_process

@classmethod
def combine(cls, operator: str, first: Union['GraphBuilder', dict], second: Union['GraphBuilder', dict], arg_name='data'):
"""Combine two GraphBuilders to a new merged one using the given operator"""
merged = cls()

args = {
arg_name:[{'from_node':first.result_node}, {'from_node':second.result_node}]
}

merged.add_process(operator, **args)
return merged

def flatten(self):
return GraphFlattener().flatten(graph=self.result_node)
Expand Down
11 changes: 11 additions & 0 deletions openeo/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ class JobFailedException(OpenEoClientException):
"""A synchronous batch job failed. This exception references its corresponding job so the client can e.g.
retrieve its logs.
"""

def __init__(self, message, job):
super().__init__(message)
self.job = job


class OperatorException(OpenEoClientException):
"""Invalid (mathematical) operator usage."""
pass


class BandMathException(OperatorException):
"""Invalid "band math" usage."""
pass
377 changes: 134 additions & 243 deletions openeo/rest/datacube.py

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions tests/data/0.4.0/bm_add_bands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"spatial_extent": null,
"id": "S2",
"temporal_extent": null
},
"result": false
},
"reduce1": {
"process_id": "reduce",
"arguments": {
"dimension": "spectral_bands",
"data": {
"from_node": "loadcollection1"
},
"reducer": {
"callback": {
"arrayelement1": {
"process_id": "array_element",
"arguments": {
"index": 2,
"data": {
"from_argument": "data"
}
},
"result": false
},
"arrayelement2": {
"process_id": "array_element",
"arguments": {
"index": 1,
"data": {
"from_argument": "data"
}
},
"result": false
},
"sum1": {
"process_id": "sum",
"arguments": {
"data": [
{
"from_node": "arrayelement1"
},
{
"from_node": "arrayelement2"
}
]
},
"result": true
}
}
}
},
"result": false
}
}
83 changes: 83 additions & 0 deletions tests/data/0.4.0/bm_add_sub_mul_div_scalar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"spatial_extent": null,
"id": "S2",
"temporal_extent": null
},
"result": false
},
"reduce1": {
"process_id": "reduce",
"arguments": {
"dimension": "spectral_bands",
"data": {
"from_node": "loadcollection1"
},
"reducer": {
"callback": {
"r1": {
"process_id": "array_element",
"arguments": {
"index": 2,
"data": {
"from_argument": "data"
}
},
"result": false
},
"sum1": {
"process_id": "sum",
"arguments": {
"data": [
{
"from_node": "r1"
},
42
]
},
"result": false
},
"subtract1": {
"process_id": "subtract",
"arguments": {
"data": [
{
"from_node": "sum1"
},
10
]
},
"result": false
},
"product1": {
"process_id": "product",
"arguments": {
"data": [
{
"from_node": "subtract1"
},
3
]
},
"result": false
},
"divide1": {
"process_id": "divide",
"arguments": {
"data": [
{
"from_node": "product1"
},
2
]
},
"result": true
}
}
}
},
"result": false
}
}
45 changes: 45 additions & 0 deletions tests/data/0.4.0/bm_eq_scalar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"spatial_extent": null,
"id": "S2",
"temporal_extent": null
},
"result": false
},
"reduce1": {
"process_id": "reduce",
"arguments": {
"dimension": "spectral_bands",
"data": {
"from_node": "loadcollection1"
},
"reducer": {
"callback": {
"r1": {
"process_id": "array_element",
"arguments": {
"index": 2,
"data": {
"from_argument": "data"
}
},
"result": false
},
"eq1": {
"process_id": "eq",
"arguments": {
"x": {
"from_node": "r1"
},
"y": 42
},
"result": true
}
}
}
},
"result": false
}
}
45 changes: 45 additions & 0 deletions tests/data/0.4.0/bm_gt_scalar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"spatial_extent": null,
"id": "S2",
"temporal_extent": null
},
"result": false
},
"reduce1": {
"process_id": "reduce",
"arguments": {
"dimension": "spectral_bands",
"data": {
"from_node": "loadcollection1"
},
"reducer": {
"callback": {
"r1": {
"process_id": "array_element",
"arguments": {
"index": 2,
"data": {
"from_argument": "data"
}
},
"result": false
},
"gt1": {
"process_id": "gt",
"arguments": {
"x": {
"from_node": "r1"
},
"y": 42
},
"result": true
}
}
}
},
"result": false
}
}
44 changes: 44 additions & 0 deletions tests/data/0.4.0/bm_invert_band.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"spatial_extent": null,
"id": "S2",
"temporal_extent": null
},
"result": false
},
"reduce1": {
"process_id": "reduce",
"arguments": {
"dimension": "spectral_bands",
"data": {
"from_node": "loadcollection1"
},
"reducer": {
"callback": {
"arrayelement1": {
"process_id": "array_element",
"arguments": {
"index": 2,
"data": {
"from_argument": "data"
}
},
"result": false
},
"not1": {
"process_id": "not",
"arguments": {
"expression": {
"from_node": "arrayelement1"
}
},
"result": true
}
}
}
},
"result": false
}
}
Loading

0 comments on commit 2193952

Please sign in to comment.