playnano.processing.stack_edit module

Functions for editing AFM image stacks by removing or selecting frames.

These functions are designed to be called by the ProcessingPipeline, which handles provenance tracking and updates to the AFMImageStack object. The functions here operate purely on data arrays or frame index lists.

Only ‘drop_frames’ performs actual stack edits. Other registered stack_edit functions return indices to drop, which are then passed to ‘drop_frames’ to ensure consistent provenance tracking.

Functions

  • drop_frames : Remove specific frames from a 3D array.

  • drop_frame_range : Generate a list of frame indices to drop within a given range.

  • select_frames : Generate a list of frame indices to drop, keeping only the selected frames.

  • drop_final_frames : Generate a list of frame indices to drop from the end of the stack. Default is to drop the last frame (n_frames_to_drop=1).

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

Generate a list of frame indices to drop from the end of the stack.

Parameters:
  • data (np.ndarray) – 3D array of shape (n_frames, height, width) representing the image stack.

  • n_frames_to_drop (int) – Number of frames to drop from the end of the stack.

Returns:

List of frame indices that should be dropped. By default, this will drop the last frame (n_frames_to_drop=1).

Return type:

list of int

Raises:

ValueError – If n_frames_to_drop is negative or exceeds the number of frames.

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

Generate indices to drop within a given range of frames.

Parameters:
  • data (np.ndarray) – 3D array of shape (n_frames, height, width) representing the image stack.

  • start (int) – Starting index of the range (inclusive).

  • end (int) – Ending index of the range (exclusive).

Returns:

List of indices that should be dropped.

Return type:

list of int

Raises:

ValueError – If the range is invalid or out of bounds.

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

Remove specific frames from a 3D array.

Parameters:
  • data (np.ndarray) – 3D array of shape (n_frames, height, width) representing the image stack.

  • indices_to_drop (list of int) – List of frame indices to remove from the stack.

Returns:

New array with the specified frames removed.

Return type:

np.ndarray

Raises:

ValueError – If any provided indices are out of bounds or if data is not 3D.

Notes

  • The function does not modify the input array in place.

  • The ProcessingPipeline is responsible for updating metadata and provenance.

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

Return a dictionary of registered stack editing processing filters.

Keys are names of the operations, values are the functions themselves. drop_frames is the operational function takes a 3D stack (n_frames, H, W) and a list of indices and returns a ndarray. drop_frame_range, select_frames and drop_final_frames are helper functions that return lists of indices to drop which can be passed to drop_frames.

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

Generate a list of frame indices to drop, keeping only the selected frames.

Parameters:
  • data (np.ndarray) – 3D array of shape (n_frames, height, width) representing the image stack.

  • keep_indices (list of int) – Indices of frames to retain in the stack.

Returns:

List of frame indices that should be dropped.

Return type:

list of int

Raises:

ValueError – If keep_indices contains out-of-range values.