playnano.processing.stack_edit module

Functions for removing or selecting frames of an AFM image stack.

Only drop_frames() changes a stack. The other functions return the indices of the frames to drop; in a ProcessingPipeline these indices are passed to drop_frames(), so every edit is recorded the same way in the provenance. The pipeline also removes the matching entries from the stack’s frame metadata and keeps a copy of the metadata from before the first edit.

playnano.processing.stack_edit.drop_final_frames(data: ndarray, n_frames_to_drop: int = 1) → list[int][source]

Return the indices of the last frames of a stack, to drop.

Parameters:
  • data (numpy.ndarray) – 3D image stack of shape (n_frames, height, width).

  • n_frames_to_drop (int, optional) – Number of frames to drop from the end. Default is 1.

Returns:

Indices of the last n_frames_to_drop frames (empty if it is 0).

Return type:

list of int

Raises:

ValueError – If data is not 3D, or n_frames_to_drop is negative or larger than the number of frames.

playnano.processing.stack_edit.drop_frame_range(data: ndarray, start: int, end: int) → list[int][source]

Return the indices of a range of frames to drop.

Parameters:
  • data (numpy.ndarray) – 3D image stack of shape (n_frames, height, width).

  • start (int) – First frame to drop (inclusive).

  • end (int) – Frame after the last one to drop (exclusive).

Returns:

[start, start + 1, ..., end - 1].

Return type:

list of int

Raises:

ValueError – If data is not 3D, start < 0, end > n_frames or start >= end.

playnano.processing.stack_edit.drop_frames(data: ndarray, indices_to_drop: list[int]) → ndarray[source]

Remove the given frames from a stack.

Parameters:
  • data (numpy.ndarray) – 3D image stack of shape (n_frames, height, width).

  • indices_to_drop (list of int) – Indices of the frames to remove. Duplicates are ignored; negative indices are not allowed.

Returns:

A new array without the given frames. data is not changed.

Return type:

numpy.ndarray

Raises:

ValueError – If data is not 3D or an index is outside 0 .. n_frames - 1.

playnano.processing.stack_edit.register_stack_edit_processing() → dict[str, Callable][source]

Return the built-in stack edit functions.

Returns:

Maps each step name (str) to its function, for example "drop_frames" to drop_frames().

Return type:

dict

playnano.processing.stack_edit.select_frames(data: ndarray, keep_indices: list[int]) → list[int][source]

Return the indices of the frames to drop so that only the given frames are kept.

Parameters:
  • data (numpy.ndarray) – 3D image stack of shape (n_frames, height, width).

  • keep_indices (list of int) – Indices of the frames to keep. Duplicates are ignored.

Returns:

Sorted indices of every other frame.

Return type:

list of int

Raises:

ValueError – If data is not 3D or an index is outside 0 .. n_frames - 1.