Exemplo n.º 1
0
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."
    ]
Exemplo n.º 2
0
def test_get_dimensions_no_band_dimension_with_eo_bands():
    logs = []
    dims = CollectionMetadata._parse_dimensions(
        {
            "cube:dimensions": {
                "x": {
                    "type": "spatial",
                    "extent": [-10, 10]
                },
            },
            "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]),
    ])
    assert logs == [
        "No 'bands' dimension in 'cube:dimensions' while having 'eo:bands'"
    ]
Exemplo n.º 3
0
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),
                      ])
    ])
Exemplo n.º 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),
        ])
    ])
Exemplo n.º 5
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'"]
Exemplo n.º 6
0
def test_get_dimensions_cube_dimensions_non_standard_type():
    logs = []
    dims = CollectionMetadata._parse_dimensions({
        "cube:dimensions": {
            "bar": {"type": "foo"},
        },
    }, complain=logs.append)
    assert_same_dimensions(dims, [
        Dimension(type="foo", name="bar")
    ])
    assert logs == ["Unknown dimension type 'foo'"]
Exemplo n.º 7
0
def test_get_dimensions_cube_dimensions_spatial_xyt():
    dims = CollectionMetadata._parse_dimensions({
        "cube:dimensions": {
            "xx": {"type": "spatial", "extent": [-10, 10]},
            "yy": {"type": "spatial", "extent": [-56, 83], "reference_system": 123},
            "tt": {"type": "temporal", "extent": ["2020-02-20", None]},
        }
    })
    assert_same_dimensions(dims, [
        SpatialDimension(name="xx", extent=[-10, 10]),
        SpatialDimension(name="yy", extent=[-56, 83], crs=123),
        TemporalDimension(name="tt", extent=["2020-02-20", None]),
    ])
Exemplo n.º 8
0
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'"]
Exemplo n.º 9
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']"]
Exemplo n.º 10
0
def test_get_dimensions_cube_dimensions_empty():
    dims = CollectionMetadata._parse_dimensions({})
    assert_same_dimensions(dims, [])