Exemplo n.º 1
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]
Exemplo n.º 2
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()
Exemplo n.º 3
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"))
Exemplo n.º 4
0
def cli(config_file, overwrite, discard_temp, dry_run, load, verbose, quiet):
    verbosity = verbose - quiet
    log_level = max(10, 20 - 10 * verbosity)  # default to INFO log level
    logging.basicConfig(
        stream=sys.stderr,
        level=log_level,
        format="%(asctime)s %(name)-12s %(levelname)-8s %(message)s",
    )

    BM = BECModel(config_file)
    if dry_run:
        click.echo("becmodel: Basic input data validation successful")
    elif load:
        BM.load(overwrite=overwrite)
    else:
        BM.load(overwrite=overwrite)
        BM.model()
        BM.postfilter()
        BM.write(discard_temp)
Exemplo n.º 5
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()