print("Reclassifying data...") # Remap the raw values to priorities and categories table = read_dataframe( src_dir / "NaturesNetwork_conservdesign_180625.tif.vat.dbf", columns=["Value", "Priority", "Descrpt"], read_geometry=False, ) 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")
print("Reclassifying TNC data...") table = read_dataframe( src_dir / "Resilient_and_Connected20180308.tif.vat.dbf", read_geometry=False, columns=["Value"], ) for i, row in table.iterrows(): if i == row.Value: continue data[data == row.Value] = i write_raster(tnc_outfilename, data, transform=transform, crs=DATA_CRS, nodata=255) # Reclassify to merge with below print("Reclassifying TNC data for merge...") # map TNC values to merged NatureScape / TNC values tnc_values = { # 0:0, # noop 2: 4, 3: 0, # 4: 4, # noop 11: 4, 12: 2, 13: 4, 14: 4,
# if masks are all false for this window, we can skip this step if not np.asarray(masks).sum(): continue # stack mask bits and layer_bits along inner dimension so that we have a shape of # (height, width, total_bits) data_bits = np.dstack(masks + layer_bits) # packbits must be in little order to read the whole array properly in JS packed = np.squeeze(np.packbits(data_bits, axis=-1, bitorder="little")) window_shape = (window.height, window.width) # fill remaining bytes up to dtype bytes fill = np.zeros(shape=window_shape, dtype="uint8") encoded = np.dstack([packed] + ([fill] * (num_bytes - packed.shape[-1]))) out[window.toslices()] = encoded.view(dtype).reshape(window_shape) # determine the window where data are available, and write out a smaller output print("Calculating data window...") data_window = get_data_window(out, nodata=0) out = out[data_window.toslices()] transform = blueprint.window_transform(data_window) print("Writing GeoTIFF...") outfilename = out_dir / f"indicators_{i}.tif" write_raster(outfilename, out, transform=transform, crs=blueprint.crs, nodata=0) add_overviews(outfilename)
print("Extracting Florida inland input area mask...") mask, transform, window = get_input_area_mask("fl") ### Extract FL Blueprint print("Reading and warping Florida Blueprint...") with rasterio.open(src_dir / "HubsData&Blueprint/Blueprint_V_1_3.tif") as src: nodata = int(src.nodata) data = extract_window(src, window, transform, nodata=nodata) # fill with 0 where not 1 or 2 data[data == nodata] = 0 # apply mask data = np.where(mask == 1, data, nodata).astype("uint8") write_raster(outfilename, data, transform=transform, crs=DATA_CRS, nodata=nodata) add_overviews(outfilename) create_lowres_mask( outfilename, str(outfilename).replace(".tif", "_mask.tif"), factor=MASK_FACTOR, ignore_zero=False, ) ### Extract FL indicators from CLIP v4 indicators = { "clip4_aggregate": "Priority_CLIP4.tif", "clip4_fnai_habitat": "fhab_clip41.tif", "clip4_landscape_resource": "landscape_rp_CLIP4.tif",
width=window.width, height=window.height, nodata=nodata, transform=transform, crs=DATA_CRS, resampling=Resampling.nearest, ) raw_data = vrt.read()[0] raw_data = raw_data.astype("uint16") write_raster( src_dir / "midse_raw.tif", raw_data, transform=transform, crs=DATA_CRS, nodata=nodata, ) print("Reclassifying data...") table = read_dataframe(src_dir / "MidSE_2020_CVI.img.vat.dbf") table["priority"] = table.M_SEBcode.astype("uint8") remap_table = table[["Value", "priority"]].values.astype("uint16") data = remap(raw_data, remap_table, nodata=nodata) print("Done reclassifying values") # coerce down to uint8, set nodata to smaller value data[data == nodata] = 255