def test_bidx_p_unready(minimal_prod):
    bidx = BandIndex(minimal_prod, {"foo": ["foo"]})
    with pytest.raises(OWSConfigNotReady) as excinfo:
        x = bidx.native_bands
    assert "native_bands" in str(excinfo.value)
    with pytest.raises(OWSConfigNotReady) as excinfo:
        x = bidx.nodata_val("foo")
    assert "_nodata_vals" in str(excinfo.value)
def test_bidx_p_duplicates(minimal_prod):
    with pytest.raises(ConfigException) as excinfo:
        bidx = BandIndex(minimal_prod, {"foo": ["bar"], "bar": ["baz"]})
    assert "Duplicate band name/alias" in str(excinfo.value)
    assert "bar" in str(excinfo.value)
    with pytest.raises(ConfigException) as excinfo:
        bidx = BandIndex(minimal_prod, {"foo": ["bar"], "boo": ["bar"]})
    assert "Duplicate band name/alias" in str(excinfo.value)
    assert "bar" in str(excinfo.value)
def test_bidx_p_band_labels(minimal_prod):
    bidx = BandIndex(minimal_prod, {
        "foo": ["bar", "foo", "baz"],
        "zing": ["pow", "splat"],
        "oof": [],
    })
    bls = bidx.band_labels()
    assert "bar" in bls
    assert "pow" in bls
    assert "oof" in bls
    assert len(bls) == 3
예제 #4
0
def product_layer():
    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer.name = "test_product"
    product_layer.pq_band = "test_band"
    product_layer.product_names = ["test_odc_product"]
    product_layer.always_fetch_bands = ["red", "green", "blue"]
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx.band_cfg = {
        "red": [
            "crimson",
            "foo",
        ],
        "green": [],
        "blue": ["azure"],
        "fake": []
    }
    product_layer.band_idx._idx = {
        "red": "red",
        "crimson": "red",
        "foo": "red",
        "green": "green",
        "blue": "blue",
        "azure": "red",
        "fake": "fake",
    }
    return product_layer
예제 #5
0
def product_layer():
    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer._unready_attributes = []
    product_layer.global_cfg = MagicMock()
    product_layer.name = "test_product"
    product_layer.pq_band = "test_band"
    product_layer.product_names = ["test_odc_product"]
    product_layer.always_fetch_bands = ["red", "green", "blue"]
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx._unready_attributes = []
    product_layer.band_idx.product = product_layer
    product_layer.band_idx.band_cfg = {
        "red": [
            "crimson",
            "foo",
        ],
        "green": [],
        "blue": ["azure", "bar"],
        "fake": []
    }
    product_layer.band_idx._idx = {
        "red": "red",
        "crimson": "red",
        "foo": "red",
        "bar": "blue",
        "green": "green",
        "blue": "blue",
        "azure": "red",
        "fake": "fake",
    }
    product_layer.global_cfg.product_index = {"test_product": product_layer}
    product_layer.style_index = {}
    return product_layer
예제 #6
0
def dummy_layer():
    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer.name = "test_product"
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx._idx = {"b1": "b1", "b2": "b2"}
    product_layer.style_index = {}
    return product_layer
def test_bidx_makeready_default(minimal_prod, minimal_dc):
    bidx = BandIndex(minimal_prod, {})
    bidx.make_ready(minimal_dc)
    assert bidx.ready
    assert bidx.band("band1") == "band1"
    assert bidx.band("band2") == "band2"
    assert bidx.band("band3") == "band3"
    assert bidx.band("band4") == "band4"
    assert bidx.nodata_val("band1") == -999
    assert isinstance(bidx.nodata_val("band4"), float)
예제 #8
0
def product_layer_mask_map():
    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer.name = "test_product"
    product_layer.pq_band = None
    product_layer.always_fetch_bands = ["foo"]
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx.band_cfg = {"foo": ["foo"]}
    product_layer.band_idx._idx = {"foo": "foo"}
    return product_layer
예제 #9
0
def product_layer_alpha_map():
    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer.global_cfg = None
    product_layer.name = "test_product"
    product_layer.pq_band = "test_band"
    product_layer.product_names = ["test_odc_product"]
    product_layer.always_fetch_bands = ["foo"]
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx.band_cfg = {"foo": ["foo"]}
    product_layer.band_idx._idx = {"foo": "foo"}
    return product_layer
예제 #10
0
def test_bidx_makeready(minimal_prod, minimal_dc):
    bidx = BandIndex(
        minimal_prod, {
            "band1": [],
            "band2": ["alias2"],
            "band3": ["alias3", "band3"],
            "band4": ["band4", "alias4"]
        })
    bidx.make_ready(minimal_dc)
    assert bidx.ready
    assert bidx.band("band1") == "band1"
    assert bidx.band("alias2") == "band2"
    assert bidx.band("band3") == "band3"
    assert bidx.band("alias4") == "band4"
예제 #11
0
def test_bidx_p_label(minimal_prod):
    bidx = BandIndex(minimal_prod, {
        "foo": ["bar", "baz"],
    })
    assert bidx.band_label("foo") == "bar"
    assert bidx.band_label("bar") == "bar"
    assert bidx.band_label("baz") == "bar"
    with pytest.raises(ConfigException) as excinfo:
        bidx.band_label("splat")
    assert "Unknown band name/alias" in str(excinfo.value)
    assert "splat" in str(excinfo.value)
예제 #12
0
def test_bidx_makeready_invalid_band(minimal_prod, minimal_dc):
    bidx = BandIndex(minimal_prod, {
        "band1": ["band1", "valid"],
        "bandx": ["invalid"]
    })
    assert bidx.band("valid") == "band1"
    assert bidx.band("invalid") == "bandx"
    with pytest.raises(ConfigException) as excinfo:
        bidx.make_ready(minimal_dc)
    assert "Unknown band" in str(excinfo.value)
    assert "bandx" in str(excinfo.value)
예제 #13
0
def test_band_index():
    dc = MagicMock()
    prod = MagicMock()
    prod.name = "prod_name"
    nb = MagicMock()
    nb.index = ['band1', 'band2', 'band3', 'band4']
    nb.get.return_val = {
        "band1": -999,
        "band2": -999,
        "band3": -999,
        "band4": -999,
    }
    dc.list_measurements().loc = {"prod_name": nb}

    foo = dc.list_measurements().loc["prod_name"]

    cfg = {
        "band1": [],
        "band2": ["alias1"],
        "band3": ["alias2", "alias3"],
        "band4": ["band4", "alias4"],
    }

    bidx = BandIndex(prod, cfg, dc)
예제 #14
0
def test_bidx_p_minimal(minimal_prod):
    bidx = BandIndex(minimal_prod, None)
    assert bidx.product_name == "foo"
    assert bidx.band_cfg == {}
    assert bidx._idx == {}
    assert not bidx.ready
예제 #15
0
def product_layer():
    class FakeODCProduct:
        def __init__(self, name):
            self.name = name
            self.id = 7

        def __str__(self):
            return self.name

        def __repr__(self):
            return f"FakeODCProduct({self.name})"

    class FakeProductBand:
        bands = set(["pq", "wongle"])
        products = [FakeODCProduct("test_masking_product")]
        manual_merge = False
        ignore_time = False
        fuse_func = None

        def products_match(self, name):
            return False

    product_layer = OWSProductLayer.__new__(OWSProductLayer)
    product_layer._unready_attributes = []
    product_layer.global_cfg = MagicMock()
    product_layer.name = "test_product"
    product_layer.pq_band = "test_band"
    product_layer.product_names = ["test_odc_product"]
    product_layer.products = [FakeODCProduct('test_odc_product')]
    product_layer.low_res_product_names = ["test_odc_summary_product"]
    product_layer.low_res_products = [
        FakeODCProduct('test_odc_summary_product')
    ]
    product_layer.always_fetch_bands = ["red", "green", "blue"]
    product_layer.band_idx = BandIndex.__new__(BandIndex)
    product_layer.band_idx._unready_attributes = []
    product_layer.band_idx.product = product_layer
    product_layer.band_idx.band_cfg = {
        "red": [
            "crimson",
            "foo",
        ],
        "green": [],
        "blue": ["azure", "bar"],
        "fake": []
    }
    product_layer.band_idx._idx = {
        "red": "red",
        "crimson": "red",
        "foo": "red",
        "bar": "blue",
        "green": "green",
        "blue": "blue",
        "azure": "red",
        "fake": "fake",
    }
    product_layer.global_cfg.product_index = {"test_product": product_layer}
    product_layer.data_manual_merge = False
    product_layer.fuse_func = None
    product_layer.allflag_productbands = [FakeProductBand()]
    product_layer.style_index = {}
    return product_layer