Ejemplo n.º 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"
Ejemplo n.º 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"))
Ejemplo n.º 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]
Ejemplo n.º 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()
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 8
0
def test_invalid_cell_size3():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"cell_size_metres": 26})
Ejemplo n.º 9
0
def test_invalid_rule_layer():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"rulepolys_layer": "nodata"})
Ejemplo n.º 10
0
def test_config_data_missing():
    with pytest.raises(ConfigValueError):
        BM = BECModel(TESTCONFIG)
        BM.update_config({"rulepolys_file": "nodata.gdb"})
Ejemplo n.º 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()
Ejemplo n.º 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"})
Ejemplo n.º 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)
Ejemplo n.º 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)