playnano.cli.actions module¶
Core logic for CLI actions in playNano.
- playnano.cli.actions.DEFAULT_PLAYBACK_FPS = 5.0¶
Playback rate used when a stack has no usable frame timing, or when its real-time rate is below
MIN_REALTIME_FPS.
- class playnano.cli.actions.IO[source]¶
Bases:
objectSimple I/O adapter used by Wizard for testability and swapping UI later.
- playnano.cli.actions.MIN_REALTIME_FPS = 1.0¶
Slowest real-time rate that is played back as recorded. Slower series (e.g. slow-scan AFM with seconds or minutes per frame) play at
DEFAULT_PLAYBACK_FPSinstead, which is watchable.
- class playnano.cli.actions.Wizard(input_file: str, channel: str, output_folder: str | None, output_name: str | None, scale_bar_nm: int | None, io: IO | None = None, cmap: str = 'afm_brown')[source]¶
Bases:
objectInteractive processing + analysis wizard.
This class provides a REPL interface for building and running processing and analysis pipelines on AFM data. Users can add, remove, reorder, save, and load both processing and analysis steps. Processing steps operate on 2D image data and are applied in sequence to a stack, while analysis steps are executed on the processed data or raw data if no processing is specified.
The wizard can be driven interactively through text commands. It supports saving and loading pipelines from YAML or JSON files, exporting processed stacks in multiple formats, and creating animated GIFs.
Examples
>>> wiz = Wizard("data.afm", "height", ".", "output", 100) >>> wiz.run()
- Parameters:
input_file (str) – Path to the AFM input file.
channel (str) – Channel name to load from the AFM file (e.g. “height_trace”).
output_folder (Optional[str]) – Directory to write exported analysis/processing outputs. If None, the output directory defaults to the current working directory when an export is performed (see _run_analysis_and_export).
output_name (Optional[str]) – Base filename (no extension) for exported files. If None, the stem of input_file will be used at export time.
scale_bar_nm (Optional[int]) – Default scale bar size in nm used when creating GIFs. Use 0 to explicitly disable the scale bar. This value is passed to export_gif as given; that function determines how to interpret 0.
io (IO or None, optional) – I/O abstraction used for reading commands and printing output. If None, standard input/output will be used. Mainly for testing and automation.
cmap (str, optional) – Name of the colormap to use for GIF exports(default=DEFAULT_CMAP).
- processed_stack¶
Cached processed AFM stack produced by running the processing steps.
- Type:
Optional[AFMImageStack]
- processed_steps_snapshot¶
Snapshot of process_steps at time processed_stack was produced.
- afm_stack¶
Raw loaded AFM stack.
- Type:
- input_path¶
Path object for input_file.
- Type:
- Raises:
FileNotFoundError – If input_file does not exist.
LoadError – If the AFM stack cannot be loaded from the given file.
- handle_add(parts: List[str]) None[source]¶
Add a processing step interactively or from the command line.
- handle_aload(parts: List[str]) None[source]¶
Load analysis steps from a YAML/JSON file, restoring Python types.
- handle_arun(parts: List[str]) None[source]¶
Execute the analysis pipeline, running processing if needed and export results.
The function supports two modes:
If the wizard has processing steps configured (self.process_steps), it will ensure the processed stack is available and up-to-date and then run analysis in-memory on that processed stack.
If there are no processing steps, analysis runs directly on the loaded AFM stack.
Results are exported as JSON and HDF5 into self.output_folder (or
./output). The JSON is created with make_json_safe and both JSON/HDF5 are written atomically.- Parameters:
parts (List[str]) – Tokenized CLI command (unused).
- handle_load(parts: List[str]) None[source]¶
Load processing steps from a YAML file exported by save.
- handle_move(parts: List[str]) None[source]¶
Reorder processing steps by moving one from old_index to new_index.
- handle_run(parts: List[str]) None[source]¶
Execute the currently queued processing steps and optionally export outputs.
Behavior¶
Runs processing and caches the result.
Prompts the user whether to export (tif/npz/h5) and/or create a GIF.
- param parts:
Tokenized user command (not currently used).
- type parts:
List[str]
- prompt_for_processing_params(step_name: str) Dict[str, Any][source]¶
Prompt user for a processing step’s parameters (simple fallback).
This method provides a small set of built-in prompts for commonly-used processing filters. It is a fallback — the module-level ask_for_processing_params (which introspects/loads processing callables) may provide a richer interactive experience and is used in handle_add.
- run_processing_and_cache()[source]¶
Run the current processing steps and cache the processed AFM stack.
The method calls into process_stack with the accumulated process_steps and stores the returned AFMImageStack in self.processed_stack for subsequent in-memory analysis.
- Returns:
The processed AFM stack object.
- Return type:
- Raises:
LoadError – If loading/processing fails.
- playnano.cli.actions.analyze_pipeline_mode(input_file: str, channel: str, analysis_str: str | None, analysis_file: str | None, output_folder: str | None, output_name: str | None) None[source]¶
Run an analysis pipeline on an AFM stack and export both JSON and HDF5.
Steps¶
Load the AFMImageStack from disk using input_file and channel.
Parse analysis modules from analysis_file or analysis_str.
Build and execute an AnalysisPipeline over the stack.
Sanitize the full record (make_json_safe) and write it to <output>.json.
Export the raw record to HDF5 via export_to_hdf5.
- param input_file:
Path to the AFM input file.
- type input_file:
str
- param channel:
Name of the data channel to analyze (e.g., “height_trace”).
- type channel:
str
- param analysis_str:
Semicolon-delimited inline analysis string, e.g. “feature_detection:threshold=5;particle_tracking”.
- type analysis_str:
str or None
- param analysis_file:
Path to a YAML/JSON file defining the analysis pipeline.
- type analysis_file:
str or None
- param output_folder:
Directory in which to write JSON + HDF5 exports; defaults to
./output.- type output_folder:
str or None
- param output_name:
Base filename (no extension) for both <output>.json and <output>.h5; defaults to the stem of input_file.
- type output_name:
str or None
- rtype:
None
- raises ValueError:
If either output file would overwrite input_file. This is checked before the data is loaded.
- playnano.cli.actions.play_pipeline_mode(input_file: str, channel: str, processing_str: str | None, processing_file: str | None, output_folder: str | None, output_name: str | None, scale_bar_nm: int | None, fps: float | None, zmin: str = 'auto', zmax: str = 'auto', cmap: str = 'afm_brown') None[source]¶
Launch an interactive GUI to browse an AFM stack with optional filters.
Steps¶
Load the AFM stack from input_file and channel.
Optionally apply a processing pipeline (inline or YAML/JSON).
Display frames in a QT-based viewer with live filtering controls.
Allow on-the-fly export to bundles or GIF via GUI.
- param input_file:
Path to the AFM input file.
- type input_file:
str
- param channel:
Data channel to display (e.g., “height_trace”).
- type channel:
str
- param processing_str:
Inline processing string as for process_pipeline_mode.
- type processing_str:
str or None
- param processing_file:
Path to a YAML/JSON file specifying processing steps.
- type processing_file:
str or None
- param output_folder:
Directory for any GUI-triggered exports.
- type output_folder:
str or None
- param output_name:
Base filename (no extension) for GUI exports.
- type output_name:
str or None
- param scale_bar_nm:
Scale bar length (in nm) displayed on frames.
- type scale_bar_nm:
int or None
- param zmin:
Minimum Z-value mapping (float or “auto”).
- type zmin:
str
- param zmax:
Maximum Z-value mapping (float or “auto”).
- type zmax:
str
- param cmap:
Name of the colormap to use for visualisation on launch (default=DEFAULT_CMAP).
- type cmap:
str
- param fps:
Initial frame rate for the GIF in frames per second (default=5.0).
- type fps:
float
- rtype:
None
- playnano.cli.actions.print_env_info()[source]¶
Print the current playNano environment metadata.
- Return type:
None
- playnano.cli.actions.process_pipeline_mode(input_file: str, channel: str, processing_str: str | None, processing_file: str | None, export: str | None, make_gif: bool, make_video: str | None, make_sequence: bool, output_folder: str | None, output_name: str | None, scale_bar_nm: int | None, zmin: str = 'auto', zmax: str = 'auto', draw_ts: bool = False, cmap: str = 'afm_brown', fps: float = 5.0) None[source]¶
Apply a processing pipeline to an AFM file, then optionally export data and GIF.
Steps¶
Parse processing steps from either processing_file (YAML/JSON) or processing_str.
Run the ProcessingPipeline on the AFM stack to apply all filters.
Export the processed stack to TIFF/NPZ/HDF5 formats (export_bundles).
Generate an animated GIF of the filtered data (export_gif).
- param input_file:
Path to the AFM input file.
- type input_file:
str
- param channel:
Name of the data channel to extract (e.g., “height_trace”).
- type channel:
str
- param processing_str:
Semicolon-delimited inline pipeline string, e.g. “remove_plane;gaussian_filter:sigma=2”.
- type processing_str:
str or None
- param processing_file:
Path to a YAML/JSON file defining the processing steps.
- type processing_file:
str or None
- param export:
Comma-separated output formats for bundles (e.g. “tif,npz,h5”).
- type export:
str or None
- param make_gif:
Whether to create an animated GIF of the filtered stack.
- type make_gif:
bool
- param output_folder:
Directory in which to write any export files.
- type output_folder:
str or None
- param output_name:
Base filename (no extension) for bundles/GIF; defaults to the stem of input_file.
- type output_name:
str or None
- param scale_bar_nm:
Length (in nm) of the scale bar overlaid on each GIF frame.
- type scale_bar_nm:
int or None
- param zmin:
Minimum Z-value for GIF color normalization (float string or “auto”).
- type zmin:
str
- param zmax:
Maximum Z-value for GIF color normalization (float string or “auto”).
- type zmax:
str
- param cmap:
Name of the colormap to use for GIF export (default=DEFAULT_CMAP).
- type cmap:
str
- param fps:
Frame rate for the GIF in frames per second (default=5.0).
- type fps:
float
- rtype:
None
- playnano.cli.actions.warn_if_unprocessed(stack: AFMImageStack) None[source]¶
Warn if the AFMImageStack has not been processed using the playNano pipeline.
Emits a warning if .processed is missing or does not contain a ‘raw’ key.