acia.tracking.formats#

Module to convert tracking formats

acia.tracking.formats.parse_simple_tracking(file_content)[source]#

Parse simple tracking format from file content string

Parameters:

file_content (str) – simple tracking format file content

Returns:

Tuple[Overlay, nx.DiGraph] – segmentation overlay and tracking graph

Return type:

tuple[Overlay, DiGraph]

acia.tracking.formats.gen_simple_tracking(overlay, tracking_graph)[source]#

Create a simple tracking format from overlay and tracking graph

Parameters:
  • overlay (Overlay) – segmentation overlay

  • tracking_graph (nx.Graph) – tracking graph

Returns:

str – simple tracking format string

Return type:

str

acia.tracking.formats.read_ctc_tracklet_graph(file)[source]#
Parameters:

file (Path)

acia.tracking.formats.read_ctc_tracking(input_path)[source]#

Read ctc tracking information

Parameters:

input_path (Path) – Path to the ctc tracking folder

Returns:

tuple[Overlay, nx.DiGraph, nx.DiGraph] – segmentation overlay, tracklet graph (every cell cycle is a node), tracking graph (every cell detection is a node)

Return type:

tuple[Overlay, DiGraph, DiGraph]

acia.tracking.formats.write_ctc_tracking(output_path, images, overlay, tracklet_graph)[source]#

Write ctc tracking to output folder

Parameters:
  • output_path (Path) – output folder for writing

  • images (ImageSequenceSource) – image time-lapse (only used to compute mask sizes)

  • overlay (Overlay) – segmentation overlay

  • tracklet_graph (nx.DiGraph) – tracklet graph (every cell cycle is a node)

acia.tracking.formats.save_tracking(path, images, overlay, tracklet_graph)[source]#

Store a tracking result as a CTC folder, guaranteeing full frame coverage.

The counterpart of load_tracking(), and the recommended way to persist a tracker’s (overlay, tracklet_graph) output. It wraps write_ctc_tracking() and adds the one guarantee that function cannot give on its own: the written mask stack is aligned with images.

write_ctc_tracking names its masks by enumerating timeIterator(), which starts at the overlay’s first populated frame when the overlay carries no explicit frame list. An overlay whose frame 0 happens to hold no detections would therefore write a stack shifted against the movie – every reloaded detection landing on the wrong frame, with no error anywhere. This function re-wraps such an overlay over range(images.size_t) first (the caller’s overlay is not mutated).

Parameters:
  • path (str | Path) – output directory (created if missing). It must be owned by this artifact: load_tracking() reads every *.tif in it.

  • images (ImageSequenceSource) – the image sequence the tracking was computed on – used for the mask size and the frame extent.

  • overlay (Overlay) – tracked overlay; label carries the tracklet id.

  • tracklet_graph (DiGraph) – one node per tracklet (start_frame/end_frame).

Returns:

The directory written.

Raises:

ValueError – if the overlay holds a frame beyond images.size_t, i.e. overlay and images do not belong to the same sequence.

Return type:

Path

acia.tracking.formats.load_tracking(path, source)[source]#

Load a tracking stored by save_tracking(), with time re-attached.

Returns the same (overlay, tracklet_graph, tracking_graph) triple, in the same order, that a tracking processor (e.g. TrackastraTracker) returns – so a step that loads is a drop-in for a step that tracked.

This is not equivalent to read_ctc_tracking(). That function builds the tracking graph while the reloaded overlay is still uncalibrated, and ctc_track_graph() reads each detection’s time to stamp its nodes – so re-attaching the time model afterwards leaves the graph timeless, and a lineage plotted over time_feature="time" silently has nothing to plot. Here the calibration is attached first and the tracking graph is built from the calibrated overlay.

Detection ids are not stable across this round-trip: the CTC mask format stores label images, so ids are renumbered on load (this is already true of the trackers themselves, which round-trip through the same format). After tracking, label – the tracklet id – is the stable key; do not join these ids against a property table exported before tracking.

Parameters:
  • path (str | Path) – the CTC directory written by save_tracking().

  • source (ImageSequenceSource) – the image sequence the tracking was computed on. Required: it is the only carrier of the time calibration.

Returns:

(overlay, tracklet_graph, tracking_graph). When source is uncalibrated, the graphs simply carry no time attributes.

Raises:

FileNotFoundError – if the directory or its man_track.txt is missing.

Return type:

tuple[Overlay, DiGraph, DiGraph]

acia.tracking.formats.ctc_track_graph(ov, tracklet_graph)[source]#

Computes the ctc track graph (every cell detection is a node) based on cell detections (overlay) and the tracklet graph (every tracklet is one node).

Hint: overlay labels and tracklet_graph node ids need to align.

Parameters:
  • ov (Overlay) – _description_

  • tracklet_graph (nx.DiGraph) – _description_

Returns:

_type_ – _description_

acia.tracking.formats.tracking_to_graph(data)[source]#

Populates a ctc tracking into a full tracking lineage where every detection has its own node with a unique id based on (ctc_id, frame)

Parameters:

data (list[dict]) – Output of read_ctc_tracking()

Returns:

nx.DiGraph – A lineage graph where every detection has its unique node (id, frame) and the edges represent the linking

Return type:

DiGraph