From 610bc690e3f92ca5a6b166e1fc7b631eaefc3530 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Wed, 13 Dec 2023 13:53:57 +0100 Subject: [PATCH] Add more datacube tests, add int datacube example --- tests/README.md | 6 +- tests/apply.json5 | 157 +++++++++++++++++- tests/apply_dimension.json5 | 69 +++++++- tests/assets/xyb-minimal-int.json5 | 42 +++++ ...-minimal.json5 => xyt-minimal-float.json5} | 0 tests/reduce_dimension.json5 | 77 ++++++++- 6 files changed, 345 insertions(+), 6 deletions(-) create mode 100644 tests/assets/xyb-minimal-int.json5 rename tests/assets/{xyt-minimal.json5 => xyt-minimal-float.json5} (100%) diff --git a/tests/README.md b/tests/README.md index e8cab80b..a7218e7f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,8 +15,8 @@ This folder contains test cases for the openEO processes. - [x] and - [ ] anomaly - [x] any -- [ ] apply -- [ ] apply_dimension +- [x] apply* +- [x] apply_dimension* - [ ] apply_kernel - [ ] apply_neighborhood - [ ] apply_polygon (experimental) @@ -107,7 +107,7 @@ This folder contains test cases for the openEO processes. - [x] product - [x] quantiles - [x] rearrange* -- [ ] reduce_dimension +- [x] reduce_dimension* - [ ] reduce_spatial (experimental) - [ ] rename_dimension - [ ] rename_labels diff --git a/tests/apply.json5 b/tests/apply.json5 index 488e8eaa..ffa7940d 100644 --- a/tests/apply.json5 +++ b/tests/apply.json5 @@ -3,12 +3,13 @@ "level": "L1", "tests": [ { + // single math process "required": [ "add" ], "arguments": { "data": { - "$ref": "assets/xyt-minimal.json5" + "$ref": "assets/xyt-minimal-float.json5" }, "process": { "process_graph": { @@ -62,6 +63,160 @@ ] ] } + }, + { + // multiple processes with a data type change + "required": [ + "lt", + "gt", + "or" + ], + "arguments": { + "data": { + "$ref": "assets/xyt-minimal-float.json5" + }, + "process": { + "process_graph": { + "lt": { + "process_id": "lt", + "arguments": { + "x": { + "from_argument": "x" + }, + "y": -50 + } + }, + "gt": { + "process_id": "gt", + "arguments": { + "x": { + "from_argument": "x" + }, + "y": 50 + } + }, + "or": { + "process_id": "or", + "arguments": { + "x": { + "from_node": "lt" + }, + "y": { + "from_node": "gt" + } + }, + "result": true + } + } + } + }, + "returns": { + "type": "datacube", + "nodata": NaN, + "dimensions": [ + { + "name": "t", + "type": "temporal", + "values": ["2020-06-01T00:00:00Z", "2020-06-03T00:00:00Z"] + }, + { + "name": "y", + "type": "spatial", + "axis": "y", + "values": [5757495.0, 5757485.0, 5757475.0], + "reference_system": "EPSG:25832" + }, + { + "name": "x", + "type": "spatial", + "axis": "x", + "values": [404835.0, 404845.0, 404855.0, 404865.0], + "reference_system": "EPSG:25832" + } + ], + "data": [ + [ + [false, true, false, true], + [false, false, false, false], + [true, false, false, true] + ], + [ + [true, false, true, false], + [false, true, true, true], + [false, false, NaN, false] + ] + ] + } + }, + { + // math on integers + "required": [ + "multiply" + ], + "arguments": { + "data": { + "$ref": "assets/xyb-minimal-int.json5" + }, + "process": { + "process_graph": { + "add": { + "process_id": "multiply", + "arguments": { + "x": { + "from_parameter": "x" + }, + "y": { + "from_parameter": "context" + } + }, + "result": true + } + } + }, + "context": 10 + }, + "returns": { + "type": "datacube", + "nodata": 0, + "dimensions": [ + { + "name": "bands", + "type": "bands", + "values": ["red", "green", "blue"] + }, + { + "name": "y", + "type": "spatial", + "axis": "y", + "values": [5757495.0, 5757485.0, 5757475.0], + "reference_system": "EPSG:25832" + }, + { + "name": "x", + "type": "spatial", + "axis": "x", + "values": [404835.0, 404845.0, 404855.0, 404865.0], + "reference_system": "EPSG:25832" + } + ], + "data": [ + [ + [1720, 470, 1170, 1920], + [670, 2510, 1950, 1030], + [90, 2110, 0, 2420] + ], + [ + [360, 870, 700, 2160], + [880, 1400, 580, 1930], + [2300, 390, 0, 870] + ], + [ + [1740, 880, 810, 1650], + [250, 770, 720, 90], + [1480, 1150, 0, 2080] + ] + ] + } } ] } diff --git a/tests/apply_dimension.json5 b/tests/apply_dimension.json5 index a981d77f..2dd259e6 100644 --- a/tests/apply_dimension.json5 +++ b/tests/apply_dimension.json5 @@ -8,7 +8,7 @@ ], "arguments": { "data": { - "$ref": "assets/xyt-minimal.json5" + "$ref": "assets/xyt-minimal-float.json5" }, "process": { "process_graph": { @@ -62,6 +62,73 @@ ] ] } + }, + { + "required": [ + "quantiles" + ], + "arguments": { + "data": { + "$ref": "assets/xyb-minimal-int.json5" + }, + "process": { + "process_graph": { + "quantiles": { + "process_id": "quantiles", + "arguments": { + "data": { + "from_parameter": "data" + } + }, + "result": true + } + } + }, + "dimension": "bands", + "target_dimension": "quantiles", + }, + "returns": { + "type": "datacube", + "nodata": NaN, + "dimensions": [ + { + "name": "quantiles", + "type": "other", + "values": [0, 1, 2] + }, + { + "name": "y", + "type": "spatial", + "axis": "y", + "values": [5757495.0, 5757485.0, 5757475.0], + "reference_system": "EPSG:25832" + }, + { + "name": "x", + "type": "spatial", + "axis": "x", + "values": [404835.0, 404845.0, 404855.0, 404865.0], + "reference_system": "EPSG:25832" + } + ], + "data": [ + [ + [172.0, 87.0, 81.0, 192.0], + [67.0, 140.0, 72.0, 103.0], + [148.0, 115.0, NaN, 208.0] + ], + [ + [173.0, 87.5, 99.0, 204.0], + [77.5, 195.5, 133.5, 148.0], + [189.0, 163.0, NaN, 225.0] + ], + [ + [173.6, 87.8, 109.8, 211.2], + [83.8, 228.8, 170.4, 175.0], + [213.6, 191.8, NaN, 235.2] + ] + ] + } } ] } diff --git a/tests/assets/xyb-minimal-int.json5 b/tests/assets/xyb-minimal-int.json5 new file mode 100644 index 00000000..6ed0d6f5 --- /dev/null +++ b/tests/assets/xyb-minimal-int.json5 @@ -0,0 +1,42 @@ +{ + "type": "datacube", + "nodata": 0, + "dimensions": [ + { + "name": "bands", + "type": "bands", + "values": ["red", "green", "blue"] + }, + { + "name": "y", + "type": "spatial", + "axis": "y", + "values": [5757495.0, 5757485.0, 5757475.0], + "reference_system": "EPSG:25832" + }, + { + "name": "x", + "type": "spatial", + "axis": "x", + "values": [404835.0, 404845.0, 404855.0, 404865.0], + "reference_system": "EPSG:25832" + } + ], + "data": [ + [ + [172, 47, 117, 192], + [67, 251, 195, 103], + [9, 211, 0, 242] + ], + [ + [36, 87, 70, 216], + [88, 140, 58, 193], + [230, 39, 0, 87] + ], + [ + [174, 88, 81, 165], + [25, 77, 72, 9], + [148, 115, 0, 208] + ] + ] +} diff --git a/tests/assets/xyt-minimal.json5 b/tests/assets/xyt-minimal-float.json5 similarity index 100% rename from tests/assets/xyt-minimal.json5 rename to tests/assets/xyt-minimal-float.json5 diff --git a/tests/reduce_dimension.json5 b/tests/reduce_dimension.json5 index 896add44..d4a3cc08 100644 --- a/tests/reduce_dimension.json5 +++ b/tests/reduce_dimension.json5 @@ -3,12 +3,13 @@ "level": "L1", "tests": [ { + // single process "required": [ "sum" ], "arguments": { "data": { - "$ref": "assets/xyt-minimal.json5" + "$ref": "assets/xyt-minimal-float.json5" }, "reducer": { "process_graph": { @@ -50,6 +51,80 @@ [ 98.26, 27.94, 25.16, -35.45] ] } + }, + { + // multiple processes with labels + "required": [ + "array_element", + "divide" + ], + "arguments": { + "data": { + "$ref": "assets/xyb-minimal-int.json5" + }, + "reducer": { + "process_graph": { + "red": { + "process_id": "array_element", + "arguments": { + "data": { + "from_parameter": "data" + }, + "label": "red" + }, + "result": true + }, + "blue": { + "process_id": "array_element", + "arguments": { + "data": { + "from_parameter": "data" + }, + "label": "blue" + }, + "result": true + }, + "divide": { + "process_id": "divide", + "arguments": { + "x": { + "from_argument": "red" + }, + "y": { + "from_argument": "blue" + } + }, + "result": true + } + } + }, + "dimension": "bands" + }, + "returns": { + "type": "datacube", + "nodata": NaN, + "dimensions": [ + { + "name": "y", + "type": "spatial", + "axis": "y", + "values": [5757495.0, 5757485.0, 5757475.0], + "reference_system": "EPSG:25832" + }, + { + "name": "x", + "type": "spatial", + "axis": "x", + "values": [404835.0, 404845.0, 404855.0, 404865.0], + "reference_system": "EPSG:25832" + } + ], + "data": [ + [0.98850574712, 0.53409090909, 1.44444444444, 1.16363636363], + [2.68, 3.2597402597, 2.708333333333, 11.44444444444], + [0.06081081081081, 1.834782608695, NaN, 1.163461538461] + ] + } } ] }