Exemple #1
0
def test_run_scene(safe_file):
    """
    This method test the functionality of the run method with one scene.
    """

    # Copy two_data.json to tmp/input/data.json
    _location_ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
    shutil.copyfile(
        os.path.join(_location_, "mock_data/data.json"), Path("/tmp/input/data.json")
    )

    _ = safe_file

    os.environ["UP42_TASK_PARAMETERS"] = '{"mask": null, "tcorrection": false}'
    # params = load_params()
    SNAPPolarimetry.run()

    with open(Path("/tmp/output/data.json"), "rb") as f_p:
        test_featurecollection = geojson.load(f_p)

    assert Path(
        "/tmp/output/"
        + test_featurecollection.features[0]["properties"]["up42.data_path"]
    ).is_file()

    # Clean up if exists
    if os.path.exists("/tmp/output/"):
        shutil.rmtree("/tmp/output/")
    if os.path.exists("/tmp/input/data.json"):
        os.remove("/tmp/input/data.json")
Exemple #2
0
def test_create_substitutions_dict(safe_file):
    params = {
        "intersects": {
            "type": "Polygon",
            "coordinates": [
                [
                    [13.365898, 52.491561],
                    [13.385296, 52.491561],
                    [13.385296, 52.506191],
                    [13.365898, 52.506191],
                    [13.365898, 52.491561],
                ]
            ],
        },
        "mask": ["sea"],
        "tcorrection": "false",
    }

    test_feature = safe_file.feature
    dict_default = SNAPPolarimetry(params).create_substitutions_dict(
        test_feature, "VV", "vv"
    )
    assert (
        dict_default["polygon"] == "POLYGON ((13.365898 52.491561, 13.385296 52.491561,"
        " 13.385296 52.506191, 13.365898 52.506191, 13.365898 52.491561))"
    )
def fixture_mainclass():
    """
    This method initiates the SNAPPolarimetry( class from snap_polarimetry to be
    used to testing.
    """
    params = {'mask': ['sea'], 'tcorrection': 'false'}
    return SNAPPolarimetry(params)
Exemple #4
0
def test_create_substitutions_dict_add_beta_band(safe_file):
    params = {"mask": ["sea"], "tcorrection": "false", "calibration_band": "beta"}

    test_feature = safe_file.feature
    dict_default = SNAPPolarimetry(params).create_substitutions_dict(
        test_feature, "VV", "vv"
    )
    assert dict_default["beta_band"]
Exemple #5
0
def fixture_mainclass():
    """
    This method initiates the SNAPPolarimetry( class from snap_polarimetry to be
    used to testing.
    """
    params = {
        "mask": ["sea"],
        "tcorrection": "false",
    }
    return SNAPPolarimetry(params)
Exemple #6
0
def test_assert_input_params():
    params = {"mask": ["sea"], "tcorrection": "false", "clip_to_aoi": "true"}

    # assert "polygon" not in dict_default
    with pytest.raises(ValueError) as e:
        SNAPPolarimetry(params).assert_input_params()
    assert (
        str(e.value)
        == "When clip_to_aoi set to True, you MUST define the same coordinates in bbox, contains"
        " or intersect for both the S1 and SNAP blocks."
    )
Exemple #7
0
def test_create_substitutions_dict_no_subseting(safe_file):
    params = {
        "mask": ["sea"],
        "tcorrection": "false",
    }

    test_feature = safe_file.feature
    dict_default = SNAPPolarimetry(params).create_substitutions_dict(
        test_feature, "VV", "vv")
    assert "polygon" not in dict_default
    assert dict_default["sigma_band"]
    assert dict_default["gamma_band"] == "false"
Exemple #8
0
def test_generate_snap_graph_no_speckle_filter(safe_file):
    params = {"mask": ["sea"], "tcorrection": False, "speckle_filter": False}

    SNAPPolarimetry(params).generate_snap_graph(
        safe_file.feature,
        "VV",
        "/tmp/input/S1B_IW_GRDH_1SDV_"
        "20190220T050359_20190220T050424_015025_01C12F_4EA4.SAFE_vv",
    )
    graph_xml_file = PosixPath(
        "/tmp/S1B_IW_GRDH_1SDV_"
        "20190220T050359_20190220T050424_015025_01C12F_4EA4.SAFE_VV.xml")
    tree = ET.parse(str(graph_xml_file))
    all_nodes = tree.findall("node")

    node_id_list = [graph_node.attrib["id"] for graph_node in all_nodes]

    assert "Speckle-Filter" not in node_id_list
    assert "LinearToFromdB" in node_id_list
Exemple #9
0
def test_assert_input_params_full():
    params = {
        "mask": ["sea"],
        "tcorrection":
        "false",
        "bbox": [
            14.558086395263674,
            53.4138293218823,
            14.584178924560549,
            53.433673900512616,
        ],
        "contains":
        None,
        "intersects":
        None,
    }

    # assert "polygon" not in dict_default
    with pytest.raises(UP42Error, match=r".*['WRONG_INPUT_ERROR'].*"):
        SNAPPolarimetry(params).assert_input_params()
Exemple #10
0
def test_assert_input_params_full():
    params = {
        "mask": ["sea"],
        "tcorrection": "false",
        "bbox": [
            14.558086395263674,
            53.4138293218823,
            14.584178924560549,
            53.433673900512616,
        ],
        "contains": None,
        "intersects": None,
    }

    # assert "polygon" not in dict_default
    with pytest.raises(ValueError) as e:
        SNAPPolarimetry(params).assert_input_params()
    assert (
        str(e.value)
        == "When clip_to_aoi is set to False, bbox, contains and intersects must be set to null."
    )
Exemple #11
0
def test_assert_input_params():
    params = {"mask": ["sea"], "tcorrection": "false", "clip_to_aoi": "true"}

    # assert "polygon" not in dict_default
    with pytest.raises(UP42Error, match=r".*['WRONG_INPUT_ERROR'].*"):
        SNAPPolarimetry(params).assert_input_params()