@stopuhr.funkuhr("Exporting tile", logger.debug, print_kwargs=["bands", "ensemble_subsets"])
def export_tile( # noqa: C901
tile: xr.Dataset,
out_dir: Path,
bands: list[str] = ["probabilities", "binarized", "polygonized", "extent", "thumbnail"],
ensemble_subsets: list[str] = [],
):
"""Export a tile to a file.
Args:
tile (xr.Dataset): The tile to export.
out_dir (Path): The path where to export to.
bands (list[str], optional): The bands to export. Defaults to ["probabilities"].
ensemble_subsets (list[str], optional): The ensemble subsets to export. Defaults to [].
Raises:
ValueError: If the band is not found in the tile.
"""
out_dir.mkdir(parents=True, exist_ok=True)
for band in bands:
match band:
case "polygonized":
_export_polygonized(tile, out_dir, ensemble_subsets)
case "binarized":
_export_binarized(tile, out_dir, ensemble_subsets)
case "probabilities":
_export_probabilities(tile, out_dir, ensemble_subsets)
case "extent":
_export_vector(tile, "extent", out_dir, fname="prediction_extent")
case "thumbnail":
_export_thumbnail(tile, out_dir)
case "optical":
_export_raster(tile, ["red", "green", "blue", "nir"], out_dir, fname="optical")
case "dem":
_export_raster(tile, ["slope", "relative_elevation"], out_dir, fname="dem")
case "tcvis":
_export_raster(tile, ["tc_brightness", "tc_greenness", "tc_wetness"], out_dir, fname="tcvis")
case _:
if band not in tile.data_vars:
raise ValueError(
f"Band {band} not found in tile for export. Available bands are: {list(tile.data_vars.keys())}"
)
# Export the band as a raster
_export_raster(tile, band, out_dir)