playnano.analysis.utils.particles module¶
Turn tracks or clusters of detected features into a table, plot or CSV file.
- playnano.analysis.utils.particles.export_particle_csv(df: DataFrame, out_path: Path) None[source]¶
Write a table from
flatten_particle_features()to a CSV file.- Parameters:
df (pandas.DataFrame) – The table to write; the index is not written.
out_path (pathlib.Path) – The CSV file. Missing folders are created. Must be a Path, not a str.
- playnano.analysis.utils.particles.flatten_particle_features(grouping_output: Mapping[str, Any], detection_output: Mapping[str, Any], *, object_key: str | None = None, object_id_field: str = 'cluster_id', frame_key: str = 'frames', index_key: str = 'point_indices') DataFrame[source]¶
Make a table with one row per feature in each track or cluster.
Each object (a track or cluster) lists the frame and index of each of its features. These are looked up in the detection output to get each feature’s measurements.
- Parameters:
grouping_output (dict) – Output of a tracking or clustering module, for example
ParticleTrackingModule. Each object must have an"id"and the lists named byframe_keyandindex_key.detection_output (dict) – Output of a detection module, with
"features_per_frame": a list, for each frame, of feature dicts with at least"centroid".object_key (str, optional) – Key of the list of objects in
grouping_output. If None,"tracks"is used if present (and the ID column is called"track_id"), otherwise"clusters"("cluster_id"), overridingobject_id_field. Default is None.object_id_field (str, optional) – Name of the ID column. Used only if
object_keyis given. Default is"cluster_id".frame_key (str, optional) – Key of each object’s list of frame indices. Default is
"frames".index_key (str, optional) – Key of each object’s list of feature indices within those frames. Entries that are None (frames where a track has no feature) are skipped. Default is
"point_indices".
- Returns:
One row per feature, with the columns
object_id_field,frame,timestamp(s),label,centroid_xandcentroid_y(pixels),area(pixels), andmean,minandmax(height, usually in nm). Missing measurements are NaN. Frame or feature indices out of range are skipped.- Return type:
- Raises:
ValueError – If
object_keyis None andgrouping_outputhas neither"tracks"nor"clusters".KeyError – If an object lacks the
frame_keyorindex_keylist.
- playnano.analysis.utils.particles.plot_particle_labels_3d(df: DataFrame, object_id_field: str = 'track_id', ax: Axes | None = None, save_to: Path | None = None, cmap: str = 'tab10') Axes[source]¶
Plot each feature’s position against time in 3D, coloured by track or cluster.
- Parameters:
df (pandas.DataFrame) – A table from
flatten_particle_features(), with the columnscentroid_x,centroid_y,timestampandobject_id_field.object_id_field (str, optional) – Column that identifies each track or cluster. Default is
"track_id".ax (mpl_toolkits.mplot3d.axes3d.Axes3D, optional) – 3D axes to draw on. If None, a new figure is created. Default is None.
save_to (str or pathlib.Path, optional) – If given, save the figure to this file at 150 dpi. Default is None.
cmap (str, optional) – Name of the matplotlib colormap for the objects. Default is
"tab10".
- Returns:
The axes drawn on, with x and y in pixels and time in seconds.
- Return type: