def test_apply_if(): input = create_spacetime_layer_singleband() input = gps.Pyramid({0: input}) imagecollection = GeopysparkDataCube(pyramid=input) graph = { "6": { "arguments": { "reject": { "from_parameter": "x" }, "value": { "from_node": "10" }, "accept": 2.0 }, "process_id": "if", "result": True }, "10": { "process_id": "gt", "arguments": { "x": { "from_parameter": "x" }, "y": 7.0 } } } stitched = imagecollection.apply( graph).pyramid.levels[0].to_spatial_layer().stitch() print(stitched) assert 2.0 == stitched.cells[0][0][0]
def test_apply_cos(): input = create_spacetime_layer() cube = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) res = cube.apply("cos") data = res.pyramid.levels[0].to_spatial_layer().stitch().cells np.testing.assert_array_almost_equal(data[0, 2:6, 2:6], np.cos(first[0])) np.testing.assert_array_almost_equal(data[1, 2:6, 2:6], np.cos(second[0]))
def test_apply_complex_graph(): graph = { "sin": { "arguments": { "x": { "from_argument": "data" } }, "process_id": "sin", "result": False }, "multiply": { "arguments": { "x": { "from_node": "sin" }, "y": 5.0 }, "process_id": "multiply", "result": True } } input = create_spacetime_layer() cube = GeopysparkDataCube(gps.Pyramid({0: input}), InMemoryServiceRegistry()) res = cube.apply(graph) data = res.pyramid.levels[0].to_spatial_layer().stitch().cells np.testing.assert_array_almost_equal(data[0, 2:6, 2:6], 5.0 * np.sin(first[0])) np.testing.assert_array_almost_equal(data[1, 2:6, 2:6], 5.0 * np.sin(second[0]))
def test_point_series(): input = create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) transformed_collection = imagecollection.apply("cos") for p in points[0:3]: result = transformed_collection.timeseries(p.x, p.y) print(result) value = result.popitem() assert math.cos(10) == value[1][0] assert math.cos(5) == value[1][1]