Skip to content

Commit cbcbe85

Browse files
authored
Fix: fixed parsing of non-dict arguments for resolution (#85)
1 parent 50e7109 commit cbcbe85

File tree

7 files changed

+293
-5
lines changed

7 files changed

+293
-5
lines changed

openeo_pg_parser_networkx/resolving_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,14 @@ def _adjust_parameters(process_graph, process_replacement_id, arguments):
231231
for node_key, node in process_graph[process_replacement_id].items():
232232
for arg_key, from_param in node['arguments'].items():
233233
# Find from_parameter value in arguments list and replace with arguments[from_parameter value] value
234-
if "from_parameter" in from_param:
234+
if isinstance(from_param, dict) and "from_parameter" in from_param:
235235
process_graph[process_replacement_id][node_key]['arguments'][
236236
arg_key
237237
] = arguments[from_param['from_parameter']]
238+
else:
239+
process_graph[process_replacement_id][node_key]['arguments'][
240+
arg_key
241+
] = from_param
238242

239243

240244
def _adjust_references(input_graph):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openeo-pg-parser-networkx"
3-
version = "2024.3.1"
3+
version = "2024.4.0"
44

55
description = "Parse OpenEO process graphs from JSON to traversible Python objects."
66
authors = ["Lukas Weidenholzer <[email protected]>", "Sean Hoyal <[email protected]>", "Valentina Hutter <[email protected]>", "Gerald Irsiegler <[email protected]>"]

resolved_gfm_graph.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"sen2like_original_outputs_load1": {
3+
"process_id": "load_collection",
4+
"arguments": {
5+
"id": "SENTINEL2_L1C",
6+
"spatial_extent": {
7+
"west": -4.919340483677538,
8+
"east": 36.248628266322456,
9+
"south": 41.43373541041478,
10+
"north": 53.27118132212786
11+
},
12+
"temporal_extent": [
13+
"2024-04-01T00:00:00Z",
14+
"2024-04-09T00:00:00Z"
15+
],
16+
"bands": [
17+
"bo1"
18+
],
19+
"properties": {}
20+
}
21+
},
22+
"sen2like_original_outputs_sen2": {
23+
"process_id": "sen2like",
24+
"arguments": {
25+
"data": {
26+
"from_node": "sen2like_original_outputs_load1"
27+
},
28+
"export_original_files": true
29+
},
30+
"result": true
31+
}
32+
}
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
{
2+
"id": "sen2like_original_outputs",
3+
"summary": "Create Sentinel 2 - like .SAFE outputs from Sentinel 2 L1C and Landsat 8 and 9 datasets. ",
4+
"description": "Process sen2like and create Sentinel 2 - like .SAFE outputs from Sentinel 2 L1C and Landsat 8 and 9 datasets for all bands. Area of interest and time need to be specified. ",
5+
"parameters": [
6+
{
7+
"schema": {
8+
"type": "object",
9+
"subtype": "bounding-box",
10+
"title": "Bounding Box",
11+
"description": "A bounding box with the required fields `west`, `south`, `east`, `north` and optionally `base`, `height`, `crs`. The `crs` is a EPSG code, a WKT2:2018 string or a PROJ definition (deprecated).",
12+
"required": [
13+
"west",
14+
"south",
15+
"east",
16+
"north"
17+
],
18+
"properties": {
19+
"west": {
20+
"description": "West (lower left corner, coordinate axis 1).",
21+
"type": "number"
22+
},
23+
"south": {
24+
"description": "South (lower left corner, coordinate axis 2).",
25+
"type": "number"
26+
},
27+
"east": {
28+
"description": "East (upper right corner, coordinate axis 1).",
29+
"type": "number"
30+
},
31+
"north": {
32+
"description": "North (upper right corner, coordinate axis 2).",
33+
"type": "number"
34+
},
35+
"base": {
36+
"description": "Base (optional, lower left corner, coordinate axis 3).",
37+
"type": [
38+
"number",
39+
"null"
40+
]
41+
},
42+
"height": {
43+
"description": "Height (optional, upper right corner, coordinate axis 3).",
44+
"type": [
45+
"number",
46+
"null"
47+
]
48+
},
49+
"crs": {
50+
"description": "Coordinate reference system of the extent, specified as as [EPSG code](http://www.epsg-registry.org/), [WKT2 (ISO 19162) string](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html) or [PROJ definition (deprecated)](https://proj.org/usage/quickstart.html). Defaults to `4326` (EPSG code 4326) unless the client explicitly requests a different coordinate reference system.",
51+
"anyOf": [
52+
{
53+
"type": "integer",
54+
"subtype": "epsg-code",
55+
"title": "EPSG Code",
56+
"description": "Specifies details about cartographic projections as [EPSG](http://www.epsg.org) code.",
57+
"minimum": 1000,
58+
"examples": [
59+
3857
60+
]
61+
},
62+
{
63+
"type": "string",
64+
"subtype": "wkt2-definition",
65+
"title": "WKT2 definition",
66+
"description": "Specifies details about cartographic projections as WKT2 string. Refers to the latest WKT2 version (currently [WKT2:2018](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html) / ISO 19162:2018) unless otherwise stated by the process."
67+
},
68+
{
69+
"type": "string",
70+
"subtype": "proj-definition",
71+
"title": "PROJ definition",
72+
"description": "**DEPRECATED.** Specifies details about cartographic projections as [PROJ](https://proj.org/usage/quickstart.html) definition."
73+
}
74+
],
75+
"default": 4326
76+
}
77+
}
78+
},
79+
"name": "spatial_extent",
80+
"description": "Bounding box for the area of interest"
81+
},
82+
{
83+
"schema": {
84+
"type": "array",
85+
"subtype": "temporal-interval",
86+
"title": "Single temporal interval",
87+
"description": "Left-closed temporal interval, represented as two-element array with the following elements:\n\n1. The first element is the start of the temporal interval. The specified instance in time is **included** in the interval.\n2. The second element is the end of the temporal interval. The specified instance in time is **excluded** from the interval.\n\nThe specified temporal strings follow [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html). Although [RFC 3339 prohibits the hour to be '24'](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.7), **this process allows the value '24' for the hour** of an end time in order to make it possible that left-closed time intervals can fully cover the day. `null` can be used to specify open intervals.",
88+
"minItems": 2,
89+
"maxItems": 2,
90+
"items": {
91+
"description": "Processes and implementations may choose to only implement a subset of the subtypes specified here. Clients must check what back-ends / processes actually support.",
92+
"anyOf": [
93+
{
94+
"type": "string",
95+
"subtype": "date-time",
96+
"format": "date-time",
97+
"title": "Date with Time",
98+
"description": "Date and time representation, as defined for `date-time` by [RFC 3339 in section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6)."
99+
},
100+
{
101+
"type": "string",
102+
"subtype": "date",
103+
"format": "date",
104+
"title": "Date only",
105+
"description": "Date only representation, as defined for `full-date` by [RFC 3339 in section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6). The time zone is UTC."
106+
},
107+
{
108+
"type": "string",
109+
"subtype": "time",
110+
"format": "time",
111+
"title": "Time only",
112+
"description": "Time only representation, as defined for `full-time` by [RFC 3339 in section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6). Although [RFC 3339 prohibits the hour to be '24'](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.7), this definition allows the value '24' for the hour as end time in an interval in order to make it possible that left-closed time intervals can fully cover the day."
113+
},
114+
{
115+
"type": "string",
116+
"subtype": "year",
117+
"minLength": 4,
118+
"maxLength": 4,
119+
"pattern": "^\\d{4}$",
120+
"title": "Year only",
121+
"description": "Year representation, as defined for `date-fullyear` by [RFC 3339 in section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6)."
122+
},
123+
{
124+
"type": "null"
125+
}
126+
]
127+
},
128+
"examples": [
129+
[
130+
"2015-01-01T00:00:00Z",
131+
"2016-01-01T00:00:00Z"
132+
],
133+
[
134+
"2015-01-01",
135+
"2016-01-01"
136+
],
137+
[
138+
"00:00:00Z",
139+
"12:00:00Z"
140+
],
141+
[
142+
"2015-01-01",
143+
null
144+
]
145+
]
146+
},
147+
"name": "temporal_extent",
148+
"description": "Time span of interest"
149+
},
150+
{
151+
"schema": [
152+
{
153+
"type": "array",
154+
"minItems": 1,
155+
"items": {
156+
"type": "string",
157+
"subtype": "band-name"
158+
}
159+
},
160+
{
161+
"title": "No filter",
162+
"description": "Don't filter bands. All bands are included in the data cube.",
163+
"type": "null"
164+
}
165+
],
166+
"name": "bands",
167+
"description": "Bands to load and process. Note: sen2like does not process `B09`, `B10`. ",
168+
"optional": true
169+
}
170+
],
171+
"returns": {
172+
"description": "A list of .zip files containing the Sentinel 2 - like .SAFE folders. ",
173+
"schema": {
174+
"type": "list"
175+
}
176+
},
177+
"process_graph": {
178+
"load1": {
179+
"process_id": "load_collection",
180+
"arguments": {
181+
"id": "SENTINEL2_L1C",
182+
"spatial_extent": {
183+
"from_parameter": "spatial_extent"
184+
},
185+
"temporal_extent": {
186+
"from_parameter": "temporal_extent"
187+
},
188+
"bands": {
189+
"from_parameter": "bands"
190+
},
191+
"properties": {}
192+
}
193+
},
194+
"sen2": {
195+
"process_id": "sen2like",
196+
"arguments": {
197+
"data": {
198+
"from_node": "load1"
199+
},
200+
"export_original_files": true
201+
},
202+
"result": true
203+
}
204+
}
205+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"sen2like_original_outputs": {
3+
"process_id": "sen2like_original_outputs",
4+
"arguments": {
5+
"bands": [
6+
"bo1"
7+
],
8+
"spatial_extent": {
9+
"west": -4.919340483677538,
10+
"east": 36.248628266322456,
11+
"south": 41.43373541041478,
12+
"north": 53.27118132212786
13+
},
14+
"temporal_extent": [
15+
"2024-04-01T00:00:00Z",
16+
"2024-04-09T00:00:00Z"
17+
]
18+
},
19+
"result": true,
20+
"namespace": "user",
21+
"description": "Create Sentinel 2 - like .SAFE outputs from Sentinel 2 L1C and Landsat 8 and 9 datasets. "
22+
}
23+
}

tests/test_pg_resolving.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def get_predefined_process_registry():
2020
predefined_process_registry = ProcessRegistry()
2121

2222
predefined_processes_specs = [
23+
('sen2like', {}),
2324
('add', {}),
2425
('apply', {}),
2526
('load_collection', {}),
@@ -67,6 +68,12 @@ def unresolved_gfm_pg() -> dict:
6768
return dict(json.loads(f.read()))
6869

6970

71+
@pytest.fixture
72+
def unresolved_sen2like_pg() -> dict:
73+
with open('tests/data/res_tests/unresolved/unresolved_sen2like.json') as f:
74+
return dict(json.loads(f.read()))
75+
76+
7077
@pytest.fixture
7178
def correctly_resolved_pg() -> dict:
7279
with open('tests/data/res_tests/resolved/resolved_complex.json') as f:
@@ -79,6 +86,12 @@ def correctly_resolved_gfm_pg() -> dict:
7986
return dict(json.loads(f.read()))
8087

8188

89+
@pytest.fixture
90+
def correctly_resolved_sen2like_pg() -> dict:
91+
with open('tests/data/res_tests/resolved/resolved_sen2like.json') as f:
92+
return dict(json.loads(f.read()))
93+
94+
8295
def test_resolve_graph_with_predefined_process_registry(
8396
predefined_process_registry: ProcessRegistry,
8497
unresolved_pg: dict,
@@ -160,6 +173,18 @@ def test_resolve_gfm_graph_with_predefined_process_registry(
160173
get_udp_spec=get_udp,
161174
)
162175

163-
with open('resolved_gfm_graph.json', 'w') as f:
164-
json.dump(resolved_pg, f)
165176
assert correctly_resolved_gfm_pg == resolved_pg
177+
178+
179+
def test_resolve_sen2like_graph_with_predefined_process_registry(
180+
predefined_process_registry: ProcessRegistry,
181+
unresolved_sen2like_pg: dict,
182+
correctly_resolved_sen2like_pg: dict,
183+
):
184+
resolved_pg = resolving_utils.resolve_process_graph(
185+
process_graph=unresolved_sen2like_pg,
186+
process_registry=predefined_process_registry,
187+
get_udp_spec=get_udp,
188+
)
189+
190+
assert correctly_resolved_sen2like_pg == resolved_pg

0 commit comments

Comments
 (0)