playnano.analysis.modules.particle_region_media_export module¶
Analysis module that saves tracked particle regions as GIFs, videos or image sequences.
It uses the crops made by particle_region_extraction. For each track, the
crops are padded to the size of the track’s largest crop and stacked, then
written with the same rendering as the whole-stack exports:
playnano.io.gif_export.create_gif_with_scale_and_timestamp(),playnano.io.video_export.create_video_with_scale_and_timestamp(),
Any combination of the three can be written in one step.
- class playnano.analysis.modules.particle_region_media_export.ParticleRegionMediaExportModule[source]¶
Bases:
AnalysisModuleSave each tracked particle’s crops as a GIF, video and/or image sequence.
Pipeline name:
"particle_region_media_export". It needs the output ofparticle_region_extraction, run withinclude_image=True(the default). Files are written tooutput_folder, overwriting any with the same name:GIF:
<name>_track_<id>.gif;video:
<name>_track_<id>.<video_fmt>;image sequence: a folder
<name>_track_<id>/offrame_0000.png,frame_0001.pngand so on.
Frames where the particle was not detected are filled with
fill_value. Seerun()for the parameters and outputs.Examples
After detection, tracking and region extraction, write a GIF of the ten tracks with the most detections:
>>> pipeline.add( ... "particle_region_media_export", ... export_gif=True, ... export_video=False, ... sort_by="n_detections", ... max_tracks=10, ... )
- requires = ['particle_region_extraction']¶
- run(stack: Any, previous_results: Dict[str, Any] | None = None, *, extraction_module: str = 'particle_region_extraction', output_folder: str | None = None, output_name: str | None = None, track_ids: List[int] | None = None, max_tracks: int | None = None, sort_by: str = 'track_id', export_gif: bool = False, export_video: bool = True, video_fmt: str = 'mp4', export_sequence: bool = False, sequence_fmt: str = 'png', fps: float = 5.0, cmap_name: str = 'afm_brown', zmin: float | str | None = None, zmax: float | str | None = None, draw_ts: bool = True, draw_scale: bool = True, scale_bar_length_nm: int = 100, font_scale: float = 2.0, fill_value: float = 0.0) Dict[str, Any][source]¶
Write the GIFs, videos and image sequences for the selected tracks.
- Parameters:
stack (AFMImageStack) – The stack: its
pixel_size_nmsets the scale bar and its file name the default output name.previous_results (dict) – Outputs of earlier steps. Must hold the output of
extraction_module.extraction_module (str, optional) – Name of the region extraction step. Default is
"particle_region_extraction".output_folder (str, optional) – Folder for the output; created if missing. If None,
./output.output_name (str, optional) – Start of each file name. If None, the name of the file the stack was loaded from.
track_ids (list of int, optional) – Export only these tracks. IDs not found are ignored. If None, all tracks. Default is None.
max_tracks (int, optional) – Export at most this many tracks, after
track_idsandsort_by. Default is None (no limit).sort_by ({"track_id", "n_frames", "n_detections"}, optional) – Order of the tracks before
max_tracksis applied: by ID (ascending), by number of frames spanned, or by number of frames with a detection (both descending). Default is"track_id".export_gif (bool, optional) – Write a GIF per track. Default is False.
export_video (bool, optional) – Write a video per track. Default is True.
video_fmt ({"mp4", "avi", "mov", "mkv"}, optional) – Video format. Default is
"mp4".export_sequence (bool, optional) – Write a folder of images per track. Default is False.
sequence_fmt ({"png", "jpg", "jpeg"}, optional) – Image format of the sequences. Default is
"png".fps (float, optional) – Frames per second of the GIFs and videos. Default is 5.0.
cmap_name (str, optional) – Name of a registered matplotlib colormap. Default is
"afm_brown".zmin (float or str, optional) – Colour scale limits, as for
playnano.io.gif_export.export_gif(): both None scales each frame separately;"auto"uses the 1st or 99th percentile of the track. Padding and missing frames (fill_value) count towards both, so they can change the colours. Default is None.zmax (float or str, optional) – Colour scale limits, as for
playnano.io.gif_export.export_gif(): both None scales each frame separately;"auto"uses the 1st or 99th percentile of the track. Padding and missing frames (fill_value) count towards both, so they can change the colours. Default is None.draw_ts (bool, optional) – Draw each frame’s time. Default is True.
draw_scale (bool, optional) – Draw a scale bar. Default is True.
scale_bar_length_nm (int, optional) – Length of the scale bar, in nm; 0 hides it. Default is 100.
font_scale (float, optional) – Size of the annotation text for a frame 512 pixels high. Default is 2.0.
fill_value (float, optional) – Value used for padding and for frames where the particle was not detected. Default is 0.0.
- Returns:
"gif_paths","video_paths","sequence_folders"Absolute paths of what was written, as str.
"per_track"One dict per track written, with
track_id,n_frames,frame_size(height, width, in pixels) and itsgif_path,video_pathandsequence_folder."summary"Counts of tracks found, selected, written, skipped (no crops) and filtered out, and the settings used.
- Return type:
- Raises:
RuntimeError – If no export is enabled,
previous_resultsis None or lacks the extraction output, or the extraction ran withinclude_image=False.ValueError – If
sort_byis not recognised,sequence_fmtis not supported, orzminis greater thanzmax.
Notes
Formats are not checked before writing starts, so with an unsupported format some files may already be written when the error is raised. An unsupported
video_fmtraisesFileNotFoundErrorrather thanValueError. The scale bar uses the stack’s pixel size, not each frame’s.
- version = '0.1.0'¶