Exemplo n.º 1
0
def test_merge_cubes_exception_if_levels_do_not_match():
    red_ramp, nir_ramp = np.mgrid[0:4, 0:4]
    layer1 = _create_spacetime_layer(cells=np.array([[red_ramp]]))
    layer2 = _create_spacetime_layer(cells=np.array([[nir_ramp]]))
    metadata = _build_metadata(bands=["the_band"])
    cube1 = GeopysparkDataCube(pyramid=gps.Pyramid({0: layer1}),
                               metadata=metadata)
    cube2 = GeopysparkDataCube(pyramid=gps.Pyramid({14: layer2}),
                               metadata=metadata)
    with pytest.raises(OpenEOApiException) as excinfo:
        res = cube1.merge_cubes(cube2, 'sum')
Exemplo n.º 2
0
def test_merge_cubes_into_single_band():
    red_ramp, nir_ramp = np.mgrid[0:4, 0:4]
    layer1 = _create_spacetime_layer(cells=np.array([[red_ramp]]))
    layer2 = _create_spacetime_layer(cells=np.array([[nir_ramp]]))
    metadata = _build_metadata(bands=["the_band"])
    cube1 = GeopysparkDataCube(pyramid=gps.Pyramid({0: layer1}),
                               metadata=metadata)
    cube2 = GeopysparkDataCube(pyramid=gps.Pyramid({0: layer2}),
                               metadata=metadata)
    res = cube1.merge_cubes(cube2, 'sum')
    stitched = res.pyramid.levels[0].to_spatial_layer().stitch()
    assert stitched.cells.shape[0] == 1
    np.testing.assert_array_equal(red_ramp + nir_ramp, stitched.cells[0, 0:4,
                                                                      0:4])
Exemplo n.º 3
0
def _test_merge_cubes_subtract_spatial(left_spatial=False,
                                       right_spatial=False):
    # TODO: this would be cleaner with @pytest.mark.parameterize but that's not supported on TestCase methods
    red_ramp, nir_ramp = np.mgrid[0:4, 0:4]
    layer1 = _create_spacetime_layer(cells=np.array([[red_ramp]]))
    if left_spatial:
        layer1 = layer1.to_spatial_layer()
    layer2 = _create_spacetime_layer(cells=np.array([[nir_ramp]]))
    if right_spatial:
        layer2 = layer2.to_spatial_layer()
    metadata = _build_metadata()
    cube1 = GeopysparkDataCube(pyramid=gps.Pyramid({0: layer1}),
                               metadata=metadata)
    cube2 = GeopysparkDataCube(pyramid=gps.Pyramid({0: layer2}),
                               metadata=metadata)

    res = cube1.merge_cubes(cube2, 'subtract')
    layer = res.pyramid.levels[0]
    if layer.layer_type != LayerType.SPATIAL:
        layer = layer.to_spatial_layer()
    actual = layer.stitch().cells[0, 0:4, 0:4]
    expected = red_ramp - nir_ramp
    np.testing.assert_array_equal(expected, actual)