Skip to content

funtracks.data_model.solution_tracks

Classes:

  • SolutionTracks

    Difference from Tracks: every node must have a track_id

SolutionTracks

SolutionTracks(graph: nx.DiGraph, segmentation: np.ndarray | None = None, time_attr: str = NodeAttr.TIME.value, pos_attr: str | tuple[str] | list[str] = NodeAttr.POS.value, scale: list[float] | None = None, ndim: int | None = None)

Bases: Tracks

Difference from Tracks: every node must have a track_id

Methods:

  • export_tracks

    Export the tracks from this run to a csv with the following columns:

  • get_next_track_id

    Return the next available track_id and update self.max_track_id

Source code in src/funtracks/data_model/solution_tracks.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(
    self,
    graph: nx.DiGraph,
    segmentation: np.ndarray | None = None,
    time_attr: str = NodeAttr.TIME.value,
    pos_attr: str | tuple[str] | list[str] = NodeAttr.POS.value,
    scale: list[float] | None = None,
    ndim: int | None = None,
):
    super().__init__(
        graph,
        segmentation=segmentation,
        time_attr=time_attr,
        pos_attr=pos_attr,
        scale=scale,
        ndim=ndim,
    )
    self.max_track_id: int
    self._initialize_track_ids()

export_tracks

export_tracks(outfile: Path | str)

Export the tracks from this run to a csv with the following columns: t,[z],y,x,id,parent_id,track_id Cells without a parent_id will have an empty string for the parent_id. Whether or not to include z is inferred from self.ndim

Source code in src/funtracks/data_model/solution_tracks.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def export_tracks(self, outfile: Path | str):
    """Export the tracks from this run to a csv with the following columns:
    t,[z],y,x,id,parent_id,track_id
    Cells without a parent_id will have an empty string for the parent_id.
    Whether or not to include z is inferred from self.ndim
    """
    header = ["t", "z", "y", "x", "id", "parent_id", "track_id"]
    if self.ndim == 3:
        header = [header[0]] + header[2:]  # remove z
    with open(outfile, "w") as f:
        f.write(",".join(header))
        for node_id in self.graph.nodes():
            parents = list(self.graph.predecessors(node_id))
            parent_id = "" if len(parents) == 0 else parents[0]
            track_id = self.get_track_id(node_id)
            time = self.get_time(node_id)
            position = self.get_position(node_id)
            row = [
                time,
                *position,
                node_id,
                parent_id,
                track_id,
            ]
            f.write("\n")
            f.write(",".join(map(str, row)))

get_next_track_id

get_next_track_id() -> int

Return the next available track_id and update self.max_track_id

Source code in src/funtracks/data_model/solution_tracks.py
57
58
59
60
61
62
63
def get_next_track_id(self) -> int:
    """Return the next available track_id and update self.max_track_id"""
    computed_max = max(self.node_id_to_track_id.values())
    if self.max_track_id < computed_max:
        self.max_track_id = computed_max
    self.max_track_id = self.max_track_id + 1
    return self.max_track_id