示例#1
0
def test_band_dimension_filter_bands():
    b02 = Band("B02", "blue", 0.490)
    b03 = Band("B03", "green", 0.560)
    b04 = Band("B04", "red", 0.665)
    bdim = BandDimension(name="bs", bands=[b02, b03, b04])
    assert bdim.filter_bands(["B03", "B04"]) == BandDimension(name="bs", bands=[b03, b04])
    assert bdim.filter_bands(["B04", "blue"]) == BandDimension(name="bs", bands=[b04, b02])
    assert bdim.filter_bands(["green", 2]) == BandDimension(name="bs", bands=[b03, b04])
def test_get_dimensions_eo_bands_only():
    logs = []
    dims = CollectionMetadata._parse_dimensions(
        {
            "summaries": {
                "eo:bands": [
                    {
                        "name": "y",
                        "common_name": "yellow",
                        "center_wavelength": 5
                    },
                    {
                        "name": "c",
                        "center_wavelength": 8
                    },
                    {
                        "name": "m",
                        "common_name": "magenta"
                    },
                ]
            }
        },
        complain=logs.append)
    assert_same_dimensions(dims, [
        BandDimension(name="bands",
                      bands=[
                          Band("y", "yellow", 5),
                          Band("c", None, 8),
                          Band("m", "magenta", None),
                      ])
    ])
    assert logs == [
        'No cube:dimensions metadata',
        "Assuming name 'bands' for anonymous band dimension."
    ]
def test_get_dimensions_cube_dimensions_spatial_xyt_bands():
    dims = CollectionMetadata._parse_dimensions({
        "cube:dimensions": {
            "x": {
                "type": "spatial",
                "extent": [-10, 10]
            },
            "y": {
                "type": "spatial",
                "extent": [-56, 83],
                "reference_system": 123
            },
            "t": {
                "type": "temporal",
                "extent": ["2020-02-20", None]
            },
            "spectral": {
                "type": "bands",
                "values": ["red", "green", "blue"]
            },
        }
    })
    assert_same_dimensions(dims, [
        SpatialDimension(name="x", extent=[-10, 10]),
        SpatialDimension(name="y", extent=[-56, 83], crs=123),
        TemporalDimension(name="t", extent=["2020-02-20", None]),
        BandDimension(name="spectral",
                      bands=[
                          Band("red", None, None),
                          Band("green", None, None),
                          Band("blue", None, None),
                      ])
    ])
示例#4
0
def test_get_dimensions_cube_dimensions_eo_bands():
    dims = CollectionMetadata._parse_dimensions({
        "cube:dimensions": {
            "x": {"type": "spatial", "extent": [-10, 10]},
            "y": {"type": "spatial", "extent": [-56, 83], "reference_system": 123},
            "t": {"type": "temporal", "extent": ["2020-02-20", None]},
            "spectral": {"type": "bands", "values": ["r", "g", "b"]},
        },
        "summaries": {
            "eo:bands": [
                {"name": "r", "common_name": "red", "center_wavelength": 5},
                {"name": "g", "center_wavelength": 8},
                {"name": "b", "common_name": "blue"},
            ]
        }
    })
    assert_same_dimensions(dims, [
        SpatialDimension(name="x", extent=[-10, 10]),
        SpatialDimension(name="y", extent=[-56, 83], crs=123),
        TemporalDimension(name="t", extent=["2020-02-20", None]),
        BandDimension(name="spectral", bands=[
            Band("r", "red", 5),
            Band("g", None, 8),
            Band("b", "blue", None),
        ])
    ])
示例#5
0
def test_band_dimension_rename_labels_with_source_mismatch():
    b02 = Band("B02", "blue", 0.490)
    b03 = Band("B03", "green", 0.560)
    bdim = BandDimension(name="bs", bands=[b02, b03])
    metadata = CollectionMetadata({}, dimensions=[bdim])
    with pytest.raises(ValueError,
                       match="should have same number of labels, but got"):
        _ = metadata.rename_labels("bs", target=['2', "3"], source=['B03'])
示例#6
0
def test_band_dimension():
    bdim = BandDimension(name="spectral", bands=[
        Band("B02", "blue", 0.490),
        Band("B03", "green", 0.560),
        Band("B04", "red", 0.665),
    ])
    assert bdim.band_names == ["B02", "B03", "B04"]
    assert bdim.common_names == ["blue", "green", "red"]
def test_band_dimension_set_labels():

    bdim = BandDimension(name="bs", bands=[Band('some_name',None,None)])
    metadata = CollectionMetadata({},dimensions=[bdim])
    newdim = metadata.rename_labels("bs",target=['1','2','3']).band_dimension

    assert metadata.band_dimension.band_names == ['some_name']
    assert newdim.band_names == ['1','2','3']
def test_get_dimensions_multiple_band_dimensions_with_eo_bands():
    logs = []
    dims = CollectionMetadata._parse_dimensions(
        {
            "cube:dimensions": {
                "x": {
                    "type": "spatial",
                    "extent": [-10, 10]
                },
                "spectral": {
                    "type": "bands",
                    "values": ["alpha", "beta"]
                },
                "bands": {
                    "type": "bands",
                    "values": ["r", "g", "b"]
                },
            },
            "summaries": {
                "eo:bands": [
                    {
                        "name": "zu",
                        "common_name": "foo"
                    },
                ]
            },
        },
        complain=logs.append)
    assert_same_dimensions(dims, [
        SpatialDimension(name="x", extent=[-10, 10]),
        BandDimension(name="spectral",
                      bands=[
                          Band("alpha", None, None),
                          Band("beta", None, None),
                      ]),
        BandDimension(name="bands",
                      bands=[
                          Band("r", None, None),
                          Band("g", None, None),
                          Band("b", None, None),
                      ]),
    ])
    assert logs == ["Multiple dimensions of type 'bands'"]
def test_band_dimension_rename_labels():
    b02 = Band("B02", "blue", 0.490)
    b03 = Band("B03", "green", 0.560)
    b04 = Band("B04", "red", 0.665)
    bdim = BandDimension(name="bs", bands=[b02, b03, b04])
    metadata = CollectionMetadata({},dimensions=[bdim])
    newdim = metadata.rename_labels("bs",target=['1','2','3']).band_dimension

    assert metadata.band_dimension.band_names == ['B02','B03','B04']
    assert newdim.band_names == ['1','2','3']
示例#10
0
def test_get_dimensions_cube_dimensions_no_band_names():
    logs = []
    dims = CollectionMetadata._parse_dimensions({
        "cube:dimensions": {
            "spectral": {"type": "bands"},
        },
    }, complain=logs.append)
    assert_same_dimensions(dims, [
        BandDimension(name="spectral", bands=[])
    ])
    assert logs == ["No band names in dimension 'spectral'"]
示例#11
0
def test_get_dimensions_cube_dimensions_eo_bands_mismatch():
    logs = []
    dims = CollectionMetadata._parse_dimensions(
        {
            "cube:dimensions": {
                "x": {
                    "type": "spatial",
                    "extent": [-10, 10]
                },
                "spectral": {
                    "type": "bands",
                    "values": ["r", "g", "b"]
                },
            },
            "summaries": {
                "eo:bands": [
                    {
                        "name": "y",
                        "common_name": "yellow",
                        "center_wavelength": 5
                    },
                    {
                        "name": "c",
                        "center_wavelength": 8
                    },
                    {
                        "name": "m",
                        "common_name": "magenta"
                    },
                ]
            }
        },
        complain=logs.append)
    assert_same_dimensions(dims, [
        SpatialDimension(name="x", extent=[-10, 10]),
        BandDimension(name="spectral",
                      bands=[
                          Band("r", None, None),
                          Band("g", None, None),
                          Band("b", None, None),
                      ])
    ])
    assert logs == ["Band name mismatch: ['r', 'g', 'b'] != ['y', 'c', 'm']"]
示例#12
0
def test_band_dimension_band_name():
    bdim = BandDimension(name="spectral",
                         bands=[
                             Band("B02", "blue", 0.490),
                             Band("B03", "green", 0.560),
                         ])
    assert bdim.band_name("B02") == "B02"
    assert bdim.band_name("B03") == "B03"
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_name("B04")
    assert bdim.band_name("blue") == "blue"
    assert bdim.band_name("green") == "green"
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_name("red")
    assert bdim.band_name(0) == "B02"
    assert bdim.band_name(1) == "B03"
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_name(2)
示例#13
0
def test_band_dimension_band_index():
    bdim = BandDimension(name="spectral",
                         bands=[
                             Band("B02", "blue", 0.490),
                             Band("B03", "green", 0.560),
                             Band("B04", "red", 0.665),
                             Band("B08", "nir", 0.842),
                         ])
    assert bdim.band_index(0) == 0
    assert bdim.band_index(2) == 2
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_index(-1)
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_index(4)
    assert bdim.band_index("B02") == 0
    assert bdim.band_index("B03") == 1
    assert bdim.band_index("B08") == 3
    assert bdim.band_index("blue") == 0
    assert bdim.band_index("green") == 1
    assert bdim.band_index("red") == 2
    assert bdim.band_index("nir") == 3
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_index("B05")
    with pytest.raises(ValueError, match="Invalid band name/index"):
        bdim.band_index("yellow")