def test_merge_cubes(con100: Connection):
    a = con100.load_collection("S2")
    b = con100.load_collection("MASK")
    c = a.merge(b)
    assert c.graph["mergecubes1"] == {
        "process_id": "merge_cubes",
        "arguments": {
            "cube1": {"from_node": "loadcollection1"},
            "cube2": {"from_node": "loadcollection2"},
        },
        "result": True
    }
def test_resample_spatial(con100: Connection):
    data = con100.load_collection("S2")
    target = con100.load_collection("MASK")
    im = data.resample_cube_spatial(target,method='spline')
    print(im.graph)
    assert im.graph["resamplecubespatial1"] == {
        'arguments': {
           'data': {'from_node': 'loadcollection1'},
           'method': 'spline',
           'target': {'from_node': 'loadcollection2'}
        },
        'process_id': 'resample_cube_spatial',
        'result': True}
def test_mask_raster(con100: Connection):
    img = con100.load_collection("S2")
    mask = con100.load_collection("MASK")
    masked = img.mask(mask=mask, replacement=102)
    assert masked.graph["mask1"] == {
        "process_id": "mask",
        "arguments": {
            "data": {"from_node": "loadcollection1"},
            "mask": {"from_node": "loadcollection2"},
            "replacement": 102
        },
        "result": True
    }
def test_load_collection_arguments_100(requests_mock):
    requests_mock.get(API_URL, json={"api_version": "1.0.0"})
    conn = Connection(API_URL)
    requests_mock.get(API_URL + "collections/FOO",
                      json={
                          "summaries": {
                              "eo:bands": [{
                                  "name": "red"
                              }, {
                                  "name": "green"
                              }, {
                                  "name": "blue"
                              }]
                          }
                      })
    spatial_extent = {"west": 1, "south": 2, "east": 3, "north": 4}
    temporal_extent = ["2019-01-01", "2019-01-22"]
    im = conn.load_collection("FOO",
                              spatial_extent=spatial_extent,
                              temporal_extent=temporal_extent,
                              bands=["red", "green"])
    assert im._pg.process_id == "load_collection"
    assert im._pg.arguments == {
        "id": "FOO",
        "spatial_extent": spatial_extent,
        "temporal_extent": temporal_extent,
        "bands": ["red", "green"]
    }
def test_load_collection_arguments_040(requests_mock):
    requests_mock.get(API_URL, json={"api_version": "0.4.0"})
    conn = Connection(API_URL)
    requests_mock.get(API_URL + "collections/FOO",
                      json={
                          "properties": {
                              "eo:bands": [{
                                  "name": "red"
                              }, {
                                  "name": "green"
                              }, {
                                  "name": "blue"
                              }]
                          }
                      })
    spatial_extent = {"west": 1, "south": 2, "east": 3, "north": 4}
    temporal_extent = ["2019-01-01", "2019-01-22"]
    im = conn.load_collection("FOO",
                              spatial_extent=spatial_extent,
                              temporal_extent=temporal_extent,
                              bands=["red", "green"])
    node = im.graph[im.node_id]
    assert node["process_id"] == "load_collection"
    assert node["arguments"] == {
        "id": "FOO",
        "spatial_extent": spatial_extent,
        "temporal_extent": temporal_extent,
        "bands": ["red", "green"]
    }
def test_mask_polygon(con100: Connection):
    img = con100.load_collection("S2")
    polygon = shapely.geometry.box(0, 0, 1, 1)
    masked = img.mask_polygon(mask=polygon)
    assert sorted(masked.graph.keys()) == ["loadcollection1", "maskpolygon1"]
    assert masked.graph["maskpolygon1"] == {
        "process_id": "mask_polygon",
        "arguments": {
            "data": {
                "from_node": "loadcollection1"
            },
            'mask': {
                'coordinates': (((1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
                                 (0.0, 0.0), (1.0, 0.0)), ),
                'crs': {
                    'properties': {
                        'name': 'EPSG:4326'
                    },
                    'type': 'name'
                },
                'type':
                'Polygon'
            }
        },
        "result": True
    }
def test_filter_bbox_parameter(con100: Connection):
    expected = {
        "process_id": "filter_bbox",
        "arguments": {
            "data": {"from_node": "loadcollection1"},
            "extent": {"from_parameter": "my_bbox"}
        },
        "result": True
    }
    bbox_param = Parameter(name="my_bbox", schema={"type": "object"})

    cube = con100.load_collection("S2").filter_bbox(bbox_param)
    assert _get_leaf_node(cube) == expected

    cube = con100.load_collection("S2").filter_bbox(bbox=bbox_param)
    assert _get_leaf_node(cube) == expected
def test_custom_process_arguments_datacube_chained(con100: Connection):
    res = con100.load_collection("S2").process(process_id="foo",
                                               arguments={
                                                   "data": THIS,
                                                   "bar": 123
                                               })
    expected = load_json_resource('data/1.0.0/process_foo.json')
    assert res.graph == expected
def test_ndvi_args(con100: Connection):
    ndvi = con100.load_collection("S2").ndvi(nir="nirr", red="rred", target_band="ndvii")
    assert sorted(ndvi.graph.keys()) == ["loadcollection1", "ndvi1"]
    assert ndvi.graph["ndvi1"] == {
        "process_id": "ndvi",
        "arguments": {"data": {"from_node": "loadcollection1"}, "nir": "nirr", "red": "rred", "target_band": "ndvii"},
        "result": True,
    }
def test_ndvi_simple(con100: Connection):
    ndvi = con100.load_collection("S2").ndvi()
    assert sorted(ndvi.graph.keys()) == ["loadcollection1", "ndvi1"]
    assert ndvi.graph["ndvi1"] == {
        "process_id": "ndvi",
        "arguments": {"data": {"from_node": "loadcollection1"}},
        "result": True,
    }
def test_mask_polygon_path(con100: Connection):
    img = con100.load_collection("S2")
    masked = img.mask_polygon(mask="path/to/polygon.json")
    assert sorted(masked.graph.keys()) == ["loadcollection1", "maskpolygon1", "readvector1"]
    assert masked.graph["maskpolygon1"] == {
        "process_id": "mask_polygon",
        "arguments": {
            "data": {"from_node": "loadcollection1"},
            "mask": {"from_node": "readvector1"},
        },
        "result": True
    }
    assert masked.graph["readvector1"] == {
        "process_id": "read_vector",
        "arguments": {"filename": "path/to/polygon.json"},
    }
Пример #12
0
def test_custom_process_kwargs_datacube_chained(con100: Connection):
    res = con100.load_collection("S2").process(process_id="foo",
                                               data=THIS,
                                               bar=123)
    expected = load_json_resource('data/1.0.0/process_foo.json')
    assert res.graph == expected
Пример #13
0
def test_custom_process_kwargs_datacube_pg(con100: Connection):
    img = con100.load_collection("S2")
    res = img.process(process_id="foo", data=img._pg, bar=123)
    expected = load_json_resource('data/1.0.0/process_foo.json')
    assert res.graph == expected
def test_filter_bbox_legacy_positional_args(con100: Connection):
    with pytest.warns(UserWarning, match="Deprecated argument order"):
        cube = con100.load_collection("S2").filter_bbox(3, 4, 52, 51)
    node = _get_leaf_node(cube)
    assert node["process_id"] == "filter_bbox"
    assert node["arguments"]["extent"] == {"west": 3, "south": 51, "east": 4, "north": 52}
def test_filter_bbox_positional_args(con100: Connection, args, expected):
    cube = con100.load_collection("S2").filter_bbox(*args)
    node = _get_leaf_node(cube)
    assert node["process_id"] == "filter_bbox"
    assert node["arguments"]["extent"] == expected
def test_filter_bbox_args_and_kwargs_conflict(con100: Connection, args, kwargs, expected):
    with pytest.raises(ValueError, match=expected):
        con100.load_collection("S2").filter_bbox(*args, **kwargs)