Beispiel #1
0
)
table = table.loc[table.Value > 0].copy()
table.Priority = table.Priority.astype("uint8")
table["category"] = table.Descrpt.str[0].astype("uint8")

remap_table = table[["Value", "Priority"]].values.astype("uint8")
priority_data = remap(data, remap_table, nodata=nodata)

write_raster(outfilename, priority_data, transform, DATA_CRS, nodata=nodata)

print("Adding overviews and masks...")
add_overviews(outfilename)

create_lowres_mask(
    outfilename,
    str(outfilename).replace(".tif", "_mask.tif"),
    factor=MASK_FACTOR,
    ignore_zero=False,
)

### Process indicators

# Extract cores from the categories
table["aquatic_cores"] = table.Descrpt.str.contains("Aquatic")
table["terrestrial_cores"] = table.Descrpt.str.contains("Terrestrial")
table["imperiled_cores"] = table.Descrpt.str.contains("Imperiled")

for core_type in ["aquatic_cores", "terrestrial_cores", "imperiled_cores"]:
    print(f"Processing {core_type}")
    cores_data = remap(data,
                       table[["Value", core_type]].values.astype("uint8"),
                       nodata=nodata)
        ix = (
            slice(row_off, row_off + data_height, None),
            slice(col_off, col_off + data_width, None),
        )

        out[ix] = np.where((data >= 0) & (data < 255), data.astype("uint8"),
                           out[ix])

    meta = {
        "driver": "GTiff",
        "crs": DATA_CRS,
        "transform": transform,
        "width": width,
        "height": height,
        "count": 1,
        "nodata": 255,
        "dtype": "uint8",
        "compress": "lzw",
    }

    with rasterio.open(out_dir / f"urban_{year}.tif", "w", **meta) as outfile:
        outfile.write(out, 1)

        outfile.build_overviews(OVERVIEW_FACTORS, Resampling.nearest)

create_lowres_mask(out_dir / "urban_2100.tif",
                   out_dir / "urban_mask.tif",
                   factor=8,
                   ignore_zero=True)