Skip to content

Commit cfcfc94

Browse files
authored
fix replacement value (#158)
1 parent 5f997c5 commit cfcfc94

File tree

2 files changed

+72
-75
lines changed

2 files changed

+72
-75
lines changed

src/openeo_grass_gis_driver/actinia_processing/mask_polygon_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_process_description():
4848
)
4949
p_value = Parameter(
5050
description="The value used to replace non-zero and `true` values with",
51-
schema={"type": "object", "subtype": "string"},
51+
schema={"type": ["number", "boolean", "string", "null"]},
5252
optional=True,
5353
)
5454
p_inside = Parameter(

src/openeo_grass_gis_driver/actinia_processing/mask_process.py

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
from random import randint
44
from typing import Tuple
55

6-
from openeo_grass_gis_driver.models.process_graph_schemas import \
7-
ProcessGraphNode, ProcessGraph
8-
9-
from openeo_grass_gis_driver.actinia_processing.base import \
10-
check_node_parents, DataObject, GrassDataType, \
11-
create_output_name
12-
from openeo_grass_gis_driver.models.process_schemas import \
13-
Parameter, ProcessDescription, ReturnValue, ProcessExample
6+
from openeo_grass_gis_driver.models.process_graph_schemas import (
7+
ProcessGraphNode,
8+
ProcessGraph,
9+
)
10+
11+
from openeo_grass_gis_driver.actinia_processing.base import (
12+
check_node_parents,
13+
DataObject,
14+
GrassDataType,
15+
create_output_name,
16+
)
17+
from openeo_grass_gis_driver.models.process_schemas import (
18+
Parameter,
19+
ProcessDescription,
20+
ReturnValue,
21+
ProcessExample,
22+
)
1423
from .base import PROCESS_DICT, PROCESS_DESCRIPTION_DICT, Node
1524

1625
__license__ = "Apache License, Version 2.0"
@@ -26,26 +35,25 @@ def create_process_description():
2635
p_data = Parameter(
2736
description="Any openEO process object that returns raster datasets "
2837
"or space-time raster dataset",
29-
schema={
30-
"type": "object",
31-
"subtype": "raster-cube"},
32-
optional=False)
38+
schema={"type": "object", "subtype": "raster-cube"},
39+
optional=False,
40+
)
3341
p_mask = Parameter(
3442
description="Any openEO process object that returns raster datasets "
3543
"or space-time raster dataset",
36-
schema={
37-
"type": "object",
38-
"subtype": "raster-cube"},
39-
optional=False)
44+
schema={"type": "object", "subtype": "raster-cube"},
45+
optional=False,
46+
)
4047
p_value = Parameter(
4148
description="The value used to replace non-zero and `true` values with",
42-
schema={
43-
"type": "object",
44-
"subtype": "string"},
45-
optional=True)
49+
schema={"type": ["number", "boolean", "string", "null"]},
50+
optional=True,
51+
)
4652

47-
rv = ReturnValue(description="Processed EO data.",
48-
schema={"type": "object", "subtype": "raster-cube"})
53+
rv = ReturnValue(
54+
description="Processed EO data.",
55+
schema={"type": "object", "subtype": "raster-cube"},
56+
)
4957

5058
# Example
5159
arguments = {
@@ -55,27 +63,23 @@ def create_process_description():
5563
}
5664
node = ProcessGraphNode(process_id=PROCESS_NAME, arguments=arguments)
5765
graph = ProcessGraph(
58-
title="title",
59-
description="description",
60-
process_graph={
61-
"mask_1": node})
66+
title="title", description="description", process_graph={"mask_1": node}
67+
)
6268
examples = [
6369
ProcessExample(
64-
title="Simple example",
65-
description="Simple example",
66-
process_graph=graph)]
70+
title="Simple example", description="Simple example", process_graph=graph
71+
)
72+
]
6773

6874
pd = ProcessDescription(
6975
id=PROCESS_NAME,
7076
description="Applies a mask to a raster data cube "
7177
" replacing pixels in data that are not null in mask with the new value.",
7278
summary="Applies a mask to a raster data cube",
73-
parameters={
74-
"data": p_data,
75-
"mask": p_mask,
76-
"replacement": p_value},
79+
parameters={"data": p_data, "mask": p_mask, "replacement": p_value},
7780
returns=rv,
78-
examples=[examples])
81+
examples=[examples],
82+
)
7983

8084
return json.loads(pd.to_json())
8185

@@ -84,10 +88,11 @@ def create_process_description():
8488

8589

8690
def create_process_chain_entry(
87-
input_object: DataObject,
88-
mask_object: DataObject,
89-
mask_value: str,
90-
output_object: DataObject):
91+
input_object: DataObject,
92+
mask_object: DataObject,
93+
mask_value: str,
94+
output_object: DataObject,
95+
):
9196
"""Create a Actinia command of the process chain that uses t.rast.mapcalc
9297
to mask raster values based on a mask dataset and a replacement value
9398
@@ -105,27 +110,30 @@ def create_process_chain_entry(
105110

106111
pc = []
107112

108-
p = {"id": "t_rast_mask_%i" % rn,
109-
"module": "t.rast.mask",
110-
"inputs": [{"param": "input",
111-
"value": input_object.grass_name()},
112-
{"param": "mask",
113-
"value": mask_object.grass_name()},
114-
{"param": "basename",
115-
"value": output_object.name},
116-
{"param": "output",
117-
"value": output_object.grass_name()},
118-
{"param": "value",
119-
"value": mask_value}],
120-
"flags": "i"}
113+
p = {
114+
"id": "t_rast_mask_%i" % rn,
115+
"module": "t.rast.mask",
116+
"inputs": [
117+
{"param": "input", "value": input_object.grass_name()},
118+
{"param": "mask", "value": mask_object.grass_name()},
119+
{"param": "basename", "value": output_object.name},
120+
{"param": "output", "value": output_object.grass_name()},
121+
{"param": "value", "value": mask_value},
122+
],
123+
"flags": "i",
124+
}
121125

122126
pc.append(p)
123127

124-
p = {"id": "t_info_%i" % rn,
125-
"module": "t.info",
126-
"inputs": [{"param": "input", "value": output_object.grass_name()},
127-
{"param": "type", "value": "strds"}],
128-
"flags": 'g'}
128+
p = {
129+
"id": "t_info_%i" % rn,
130+
"module": "t.info",
131+
"inputs": [
132+
{"param": "input", "value": output_object.grass_name()},
133+
{"param": "type", "value": "strds"},
134+
],
135+
"flags": "g",
136+
}
129137

130138
pc.append(p)
131139

@@ -142,36 +150,25 @@ def get_process_list(node: Node) -> Tuple[list, list]:
142150
input_objects, process_list = check_node_parents(node=node)
143151
output_objects = []
144152

145-
if "data" not in node.arguments or \
146-
"mask" not in node.arguments:
147-
raise Exception(
148-
"Process %s requires parameter data, mask" %
149-
PROCESS_NAME)
153+
if "data" not in node.arguments or "mask" not in node.arguments:
154+
raise Exception("Process %s requires parameter data, mask" % PROCESS_NAME)
150155

151156
if "replacement" in node.arguments:
152157
mask_value = node.arguments["replacement"]
153158
else:
154159
mask_value = "null"
155160

156161
# Get the input and mask data separately
157-
data_object = list(
158-
node.get_parent_by_name(
159-
parent_name="data").output_objects)[0]
160-
mask_object = list(
161-
node.get_parent_by_name(
162-
parent_name="mask").output_objects)[0]
162+
data_object = list(node.get_parent_by_name(parent_name="data").output_objects)[0]
163+
mask_object = list(node.get_parent_by_name(parent_name="mask").output_objects)[0]
163164

164165
output_object = DataObject(
165-
name=create_output_name(data_object.name, node),
166-
datatype=GrassDataType.STRDS)
166+
name=create_output_name(data_object.name, node), datatype=GrassDataType.STRDS
167+
)
167168
output_objects.append(output_object)
168169
node.add_output(output_object=output_object)
169170

170-
pc = create_process_chain_entry(
171-
data_object,
172-
mask_object,
173-
mask_value,
174-
output_object)
171+
pc = create_process_chain_entry(data_object, mask_object, mask_value, output_object)
175172
process_list.extend(pc)
176173

177174
return output_objects, process_list

0 commit comments

Comments
 (0)