Utilities#

The satrain.utils module provides utility functions used throughout the SatRain package.

satrain.utils#

Defines helper functions used throught the satrain package.

cleanup_files(path: Path, no_action: bool = False) None[source]#

Removes all files that do not have matching files in all input and target files.

Parameters:
  • path – A Path object pointing to the folder containing the SatRain training scenes.

  • no_action – Just print filename, don’t remove any files.

extract_samples(dataset: Dataset, mask: DataArray)[source]#

Extract tabular data from spatial scenes based on reference data availability.

Parameters:
  • dataset – The spatial input data.

  • mask – A mask identifying the pixels with valid reference data.

Returns:

A new dataset containing only samples with valid reference data.

get_median_time(path: Path | str) datetime[source]#

Extract median time from filename.

open_if_required(path_or_dataset: str | Path | Dataset) Dataset[source]#

Open and close an xarray.Dataset or do nothing if data is already loaded.

Parameters:

path_or_dataset – A Path pointing to a NetCDF4 to open of an already loaded dataset.

Returns:

An xarray.Dataset providing access to the loaded data.