paidiverpy#

Paidiverpy base package.

Submodules#

Classes#

Paidiverpy

Main class for the paidiverpy package.

Functions#

show_versions(→ None)

Print the versions of paidiverpy and its dependencies.

Package Contents#

class paidiverpy.Paidiverpy(config_params: dict[str, Any] | paidiverpy.config.config_params.ConfigParams | None = None, config_file_path: str | None = None, config: paidiverpy.config.configuration.Configuration | None = None, metadata: paidiverpy.metadata_parser.MetadataParser | None = None, images: paidiverpy.images_layer.ImagesLayer | None = None, client: dask.distributed.Client | None = None, paidiverpy: Paidiverpy | None = None, track_changes: bool | None = None, logger: logging.Logger | None = None, raise_error: bool = False, verbose: int = 2)[source]#

Main class for the paidiverpy package.

Parameters:
  • config_params (dict | ConfigParams, optional) – The configuration parameters. It can contain the following keys / attributes: - input_path (str): The path to the input files. - output_path (str): The path to the output files. - image_open_args (str): The type of the images. - metadata_path (str): The path to the metadata file. - metadata_type (str): The type of the metadata file. - track_changes (bool): Whether to track changes. - n_jobs (int): The number of n_jobs.

  • config_file_path (str, optional) – The path to the configuration file.

  • config (Configuration, optional) – The configuration object.

  • metadata (MetadataParser, optional) – The metadata object.

  • images (ImagesLayer, optional) – The images object.

  • client (Client, optional) – The Dask client object.

  • paidiverpy (Paidiverpy, optional) – The paidiverpy object.

  • track_changes (bool) – Whether to track changes. Defaults to None, which means it will be set to the value of the configuration file.

  • logger (logging.Logger, optional) – The logger object.

  • raise_error (bool, optional) – Whether to raise an error.

  • verbose (int, optional) – verbose level (0 = none, 1 = errors/warnings, 2 = info).

run(add_new_step: bool = True) paidiverpy.images_layer.ImagesLayer | None[source]#

Run the paidiverpy pipeline.

Parameters:

add_new_step (bool, optional) – Whether to add a new step. Defaults to True.

Returns:

The images object.

Return type:

ImagesLayer | None

process_images(method: collections.abc.Callable, params: dict[str, Any] | paidiverpy.utils.base_model.BaseModel) xarray.Dataset[source]#

Process the images sequentially.

Method to process the images sequentially.

Parameters:
  • method (Callable) – The method to apply to the images.

  • params (dict | BaseModel) – The parameters for the method.

Returns:

A dataset containing the processed images and the metadata.

Return type:

xr.Dataset

calculate_output_image(images: xarray.Dataset, func: collections.abc.Callable) tuple[dict[str, Any], numpy.dtype[Any]][source]#

Calculate the output image dimensions and data type.

Parameters:
  • images (xr.Dataset) – The input images.

  • func (Callable) – The processing function.

Returns:

A tuple containing the dask_gufunc_kwargs and the output data type.

Return type:

tuple

process_dataset(images: xarray.Dataset, method: collections.abc.Callable, params: paidiverpy.utils.base_model.BaseModel) xarray.Dataset[source]#

Process the images as a dataset.

Parameters:
  • images (xr.Dataset) – The dataset of images to process.

  • method (Callable) – The method to apply to the images.

  • params (BaseModel) – The parameters for the method.

Returns:

A dataset containing the processed images

Return type:

xr.Dataset

get_metadata(flag: int | str | None = None) pandas.DataFrame[source]#

Get the metadata object.

Parameters:

flag (int | str | None, optional) – The flag to filter the metadata. If None, return all metadata. If “all”, return all metadata sorted by image-datetime. Defaults to None.

Returns:

The metadata object.

Return type:

pd.DataFrame

set_metadata(metadata: pandas.DataFrame | None = None, dataset_metadata: dict[str, Any] | None = None) None[source]#

Set the metadata.

Parameters:
  • metadata (pd.DataFrame | None) – The metadata to set.

  • dataset_metadata (dict | None) – The dataset metadata to set.

save_images(step: str | int | None = None, image_format: str = 'png', output_path: str | pathlib.Path | None = None) None[source]#

Save the images.

Parameters:
  • step (int, optional) – The step order. Defaults to None.

  • image_format (str, optional) – The image format. Defaults to “png”.

  • output_path (str | Path, optional) – The output path. Defaults to None.

remove_images() None[source]#

Remove output images from the output path.

load_custom_algorithm(file_path: str, class_name: str, algorithm_name: str) collections.abc.Callable[source]#

Load a custom algorithm class.

Parameters:
  • file_path (str) – The file path of the custom algorithm.

  • class_name (str) – The class name.

  • algorithm_name (str) – The algorithm name.

Returns:

The custom algorithm class.

Return type:

class

static process_single(img: numpy.ndarray[Any, Any], flag: int, height: int, width: int, filename: str, output_bands: int | None, func: collections.abc.Callable, metadata: pandas.DataFrame) tuple[numpy.ndarray[Any, Any], int, int][source]#

Wrapper to process a single image with its metadata.

Parameters:
  • img (np.ndarray) – The padded image (H, W, bands).

  • flag (int) – The flag indicating the processing step.

  • height (int) – The height of the valid image area.

  • width (int) – The width of the valid image area.

  • filename (str) – The filename of the image.

  • output_bands (int) – The number of output bands.

  • func (Callable) – The processing function.

  • metadata (pd.DataFrame) – The metadata DataFrame.

Returns:

A tuple containing the processed image, height, and width.

Return type:

tuple

paidiverpy.show_versions(file: TextIO = sys.stdout, conda: bool = False) None[source]#

Print the versions of paidiverpy and its dependencies.

Parameters:
  • file (TextIO, optional) – The file to write the versions to. Defaults to sys.stdout.

  • conda (bool, optional) – Whether to format the output for conda. Defaults to False.