3
3
from random import randint
4
4
from typing import Tuple
5
5
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
+ )
14
23
from .base import PROCESS_DICT , PROCESS_DESCRIPTION_DICT , Node
15
24
16
25
__license__ = "Apache License, Version 2.0"
@@ -26,26 +35,25 @@ def create_process_description():
26
35
p_data = Parameter (
27
36
description = "Any openEO process object that returns raster datasets "
28
37
"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
+ )
33
41
p_mask = Parameter (
34
42
description = "Any openEO process object that returns raster datasets "
35
43
"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
+ )
40
47
p_value = Parameter (
41
48
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
+ )
46
52
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
+ )
49
57
50
58
# Example
51
59
arguments = {
@@ -55,27 +63,23 @@ def create_process_description():
55
63
}
56
64
node = ProcessGraphNode (process_id = PROCESS_NAME , arguments = arguments )
57
65
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
+ )
62
68
examples = [
63
69
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
+ ]
67
73
68
74
pd = ProcessDescription (
69
75
id = PROCESS_NAME ,
70
76
description = "Applies a mask to a raster data cube "
71
77
" replacing pixels in data that are not null in mask with the new value." ,
72
78
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 },
77
80
returns = rv ,
78
- examples = [examples ])
81
+ examples = [examples ],
82
+ )
79
83
80
84
return json .loads (pd .to_json ())
81
85
@@ -84,10 +88,11 @@ def create_process_description():
84
88
85
89
86
90
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
+ ):
91
96
"""Create a Actinia command of the process chain that uses t.rast.mapcalc
92
97
to mask raster values based on a mask dataset and a replacement value
93
98
@@ -105,27 +110,30 @@ def create_process_chain_entry(
105
110
106
111
pc = []
107
112
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
+ }
121
125
122
126
pc .append (p )
123
127
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
+ }
129
137
130
138
pc .append (p )
131
139
@@ -142,36 +150,25 @@ def get_process_list(node: Node) -> Tuple[list, list]:
142
150
input_objects , process_list = check_node_parents (node = node )
143
151
output_objects = []
144
152
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 )
150
155
151
156
if "replacement" in node .arguments :
152
157
mask_value = node .arguments ["replacement" ]
153
158
else :
154
159
mask_value = "null"
155
160
156
161
# 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 ]
163
164
164
165
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
+ )
167
168
output_objects .append (output_object )
168
169
node .add_output (output_object = output_object )
169
170
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 )
175
172
process_list .extend (pc )
176
173
177
174
return output_objects , process_list
0 commit comments