Пример #1
0
def test_reproject_rule_layer():
    BM = BECModel(TESTCONFIG)
    BM.update_config(
        {
            "rulepolys_file": "tests/data/rulepolys_4326.geojson",
            "rulepolys_layer": None
        },
        reload=True)
    assert BM.data["rulepolys"].crs == "EPSG:3005"
Пример #2
0
def test_load_terraintile_elevation(tmpdir):
    BM = BECModel(TESTCONFIG)

    BM.update_config(
        {
            "temp_folder": str(tmpdir),
            "rulepolys_file": "tests/data/rulepolys_4326_usa.geojson",
            "rulepolys_layer": None
        },
        reload=True)
    BM.load()
    assert os.path.exists(tmpdir.join("src", "dem_bc.tif"))
    assert os.path.exists(tmpdir.join("src", "dem_exbc.tif"))
    assert os.path.exists(tmpdir.join("src", "dem.tif"))
Пример #3
0
def test_run_shp(tmpdir):
    """
    Check that shapefile outputs are created, properly structured and consistent
    (not necessarily correct!)
    """
    BM = BECModel(TESTCONFIG)
    BM.update_config({"temp_folder": str(tmpdir)})
    BM.update_config({"out_file": str(os.path.join(tmpdir, "bectest.shp"))})
    BM.update_config({"dem": "tests/data/dem_ok.tif"})
    BM.load()
    BM.model()
    BM.postfilter()
    BM.write()
    assert os.path.exists(tmpdir.join("00_dem.tif"))
    assert os.path.exists(tmpdir.join("02_aspect.tif"))
    assert os.path.exists(tmpdir.join("bectest.shp"))
    assert fiona.listlayers(os.path.join(tmpdir, "bectest.shp")) == ["bectest"]
    with fiona.open(os.path.join(tmpdir, "bectest.shp")) as output:
        assert list(output.schema["properties"].keys()) == [
            "BGC_LABEL",
            "AREA_HA",
        ]
    # check outputs
    df = gpd.read_file(str(os.path.join(tmpdir, "bectest.shp")))
    areas = df.groupby(["BGC_LABEL"])["AREA_HA"].sum().round()
    # note output areas are not quite the same as when using gpkg above!
    assert list(areas) == [5156.0, 553.0, 3619.0, 7550.0, 1510.0, 5049.0]
Пример #4
0
def test_nohigh(tmpdir):
    BM = BECModel(TESTCONFIG)
    BM.update_config({"temp_folder": str(tmpdir)})
    BM.update_config(
        {"out_file": str(os.path.join(tmpdir, "bectest_nohigh.gpkg"))})
    BM.update_config({"elevation": "tests/data/elevation_nohigh.csv"},
                     reload=True)
    BM.load()
    BM.model()
    BM.postfilter()
    BM.write()
Пример #5
0
def test_load_excel():
    BM = BECModel(TESTCONFIG)
    BM.update_config({"elevation": "tests/data/elevation.xlsx"})
    assert BM.data["elevation"].beclabel[0] == "BG  xh 1"
Пример #6
0
def test_load_becmaster_invalid_data():
    with pytest.raises(DataValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config(
            {"becmaster": "tests/data/becmaster_invalid_data.csv"},
            reload=True)
Пример #7
0
def test_load_becmaster():
    BM = BECModel(TESTCONFIG)
    BM.update_config({"becmaster": "tests/data/becmaster_test.csv"},
                     reload=True)
    assert BM.data["becmaster"].becvalue[0] == 4
Пример #8
0
def test_invalid_cell_size3():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"cell_size_metres": 26})
Пример #9
0
def test_invalid_rule_layer():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"rulepolys_layer": "nodata"})
Пример #10
0
def test_config_data_missing():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"rulepolys_file": "nodata.gdb"})
Пример #11
0
def test_local_dem(tmpdir):
    """Test loading dem from local file path
    """
    BM = BECModel(TESTCONFIG)
    BM.update_config({"dem": "tests/data/dem_ok.tif"})
    BM.load()
Пример #12
0
def test_invalid_dem_path():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"dem": "tests/data/dem_does_not_exit.tif"})
Пример #13
0
def test_load_invalid_beclabel():
    with pytest.raises(DataValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config(
            {"elevation": "tests/data/elevation_invalid_beclabel.csv"},
            reload=True)
Пример #14
0
def test_load_invalid_rulepolys():
    with pytest.raises(DataValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"rulepolys_file": "tests/data/invalid_data.gdb.zip"},
                         reload=True)