paidiverpy.images_layer#

Module to handle images and metadata for each step in the pipeline.

Classes#

ImagesLayer

Class to handle images and metadata for each step in the pipeline.

Module Contents#

class paidiverpy.images_layer.ImagesLayer(output_path: str | pathlib.Path | None = None)[source]#

Class to handle images and metadata for each step in the pipeline.

Parameters:

output_path (str | Path | None) – Path to save the images. Default is None.

add_step(step: str, images: xarray.Dataset, step_metadata: dict[str, object], metadata: pandas.DataFrame | None = None, track_changes: bool = True) None[source]#

Add a step to the pipeline.

Parameters:
  • step (str) – The step to add

  • images (xr.Dataset) – The images for the step.

  • step_metadata (dict) – The metadata for the step.

  • metadata (pd.DataFrame | None, optional) – The metadata to set. Defaults to None.

  • track_changes (bool, optional) – Whether to track changes. Defaults to True.

replace_step(images: xarray.Dataset) None[source]#

Add a step to the pipeline.

Parameters:

images (xr.Dataset) – The images for the step.

set_images(images: xarray.Dataset) None[source]#

Set the images for the layer.

Parameters:

images (xr.Dataset) – The images to set.

remove_steps_by_order(step_order: int) None[source]#

Remove steps by order.

Parameters:

step_order (int) – The step order to remove

get_step(step: str | int | None = None, last: bool = False, flag: None | int = None) xarray.Dataset[source]#

Get a step by name or order.

Parameters:
  • step (str | int, optional) – The step to get. Defaults to None.

  • last (bool, optional) – If True, get the last step. Defaults to False.

  • flag (None | int, optional) – The flag to filter the images. Defaults to None.

Returns:

The images for the step or None if the step does not exist.

Return type:

xr.Dataset | None

show(image_number: int = 0) IPython.display.HTML[source]#

Show the images in the pipeline.

Parameters:

image_number (int, optional) – The index of the image to show. Defaults to 0.

Returns:

The HTML representation of the images

Return type:

HTML

save(config: paidiverpy.config.configuration.Configuration, step: str | int | None = None, last: bool = True, output_path: str | pathlib.Path | None = None, image_format: str = 'png', client: dask.distributed.Client | None = None, n_jobs: int = 1, use_dask: bool = False) None[source]#

Save the images in the pipeline.

Parameters:
  • step (str| int, optional) – The step to save. Defaults to None.

  • last (bool, optional) – If True, save the last step. Defaults to False.

  • output_path (str, optional) – The output path to save the images. Defaults to None.

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

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

  • client (Client, optional) – The Dask client. Defaults to None.

  • n_jobs (int, optional) – The number of jobs to use. Defaults to 1.

  • use_dask (bool, optional) – Whether to use Dask. Defaults to False.

process_and_upload(image: numpy.ndarray[Any, Any] | dask.array.core.Array, img_path: str | pathlib.Path, image_format: str, s3_client: dask.distributed.Client | None = None) None[source]#

Process and upload the images.

Parameters:
  • image (np.ndarray | da.core.Array) – The image to process and upload.

  • img_path (str | Path) – The image path to save.

  • image_format (str) – The image format to save.

  • s3_client (boto3.client, optional) – The S3 client. Defaults to None.

calculate_image(image: numpy.ndarray[Any, Any] | dask.array.core.Array) numpy.ndarray[Any, Any][source]#

Calculate the image.

Parameters:

image (np.ndarray | da.core.Array) – The image to calculate.

Returns:

The calculated image.

Return type:

np.ndarray

remove(output_path: str | pathlib.Path | None = None) None[source]#

Remove the images from the output path.

Parameters:

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

__call__(max_images: int | None = None) IPython.display.HTML[source]#

Call the object.

Parameters:

max_images (int, optional) – The maximum number of images to show.

Defaults to None.

Returns:

The HTML representation of the object

Return type:

HTML

static process_single_image(img: numpy.ndarray[Any, Any], height: numpy.ndarray[Any, Any], width: numpy.ndarray[Any, Any], filename: numpy.ndarray[Any, Any], output_path: pathlib.Path, image_format: str, s3_client: dask.distributed.Client | None, processor: collections.abc.Callable) int[source]#

Process a single image and save it.

Parameters:
  • img (np.ndarray) – The image to process.

  • height (np.ndarray) – The height of the image.

  • width (np.ndarray) – The width of the image.

  • filename (np.ndarray) – The filename of the image.

  • output_path (Path) – The path to save the output.

  • image_format (str) – The format to save the image.

  • s3_client (Client | None) – The S3 client to use for uploading.

  • processor (Callable) – The processing function to use.

Returns:

The status code (0 for success).

Return type:

int