Skip to content

darts_export.missing_outputs

Check for missing output files in the given directory.

Parameters:

  • out_dir (pathlib.Path) –

    The directory to check for missing files.

  • bands (list[str], default: ['probabilities', 'binarized', 'polygonized', 'extent', 'thumbnail'] ) –

    The bands to export. Defaults to ["probabilities"].

  • ensemble_subsets (list[str], default: [] ) –

    The ensemble subsets to export. Defaults to [].

Returns:

  • typing.Literal['all', 'some', 'none']

    Literal["all", "some", "none"]: A string indicating the status of missing files: - "none": No files are missing. - "some": Some files are missing, which one will be logged to debug. - "all": All files are missing.

Raises:

  • ValueError

    If the output path is not a directory.

Source code in darts-export/src/darts_export/check.py
def missing_outputs(  # noqa: C901
    out_dir: Path,
    bands: list[str] = ["probabilities", "binarized", "polygonized", "extent", "thumbnail"],
    ensemble_subsets: list[str] = [],
) -> Literal["all", "some", "none"]:
    """Check for missing output files in the given directory.

    Args:
        out_dir (Path): The directory to check for missing files.
        bands (list[str], optional): The bands to export. Defaults to ["probabilities"].
        ensemble_subsets (list[str], optional): The ensemble subsets to export. Defaults to [].

    Returns:
        Literal["all", "some", "none"]: A string indicating the status of missing files:
            - "none": No files are missing.
            - "some": Some files are missing, which one will be logged to debug.
            - "all": All files are missing.

    Raises:
        ValueError: If the output path is not a directory.

    """
    if not out_dir.exists():
        return []
    if not out_dir.is_dir():
        raise ValueError(f"Output path {out_dir} is not a directory.")
    expected_files = []
    for band in bands:
        match band:
            case "polygonized":
                expected_files += ["prediction_segments.gpkg"] + [
                    f"prediction_segments-{es}.gpkg" for es in ensemble_subsets
                ]
                expected_files += ["prediction_segments.parquet"] + [
                    f"prediction_segments-{es}.parquet" for es in ensemble_subsets
                ]
            case "binarized":
                expected_files += ["binarized.tif"] + [f"binarized-{es}.tif" for es in ensemble_subsets]
            case "probabilities":
                expected_files += ["probabilities.tif"] + [f"probabilities-{es}.tif" for es in ensemble_subsets]
            case "extent":
                expected_files += ["extent.gpkg", "extent.parquet"]
            case "thumbnail":
                expected_files += ["thumbnail.jpg"]
            case _:
                expected_files += [f"{band}.tif"]

    missing_files = _missing_files(out_dir, expected_files)
    if len(missing_files) == 0:
        return "none"
    elif len(missing_files) == len(expected_files):
        return "all"
    else:
        logger.debug(
            f"Missing files in {out_dir}: {', '.join(missing_files)}. Expected files: {', '.join(expected_files)}."
        )
        return "some"