### Basic Tracking Example in Python Source: https://github.com/royerlab/tracksdata/blob/main/docs/examples.md Demonstrates the core workflow of TracksData. This example requires the TracksData library to be installed. ```python from pathlib import Path from iohub.reader import build_reader from tracksdata import TracksData def main(): # Load data from a CSV file data_path = Path("../data/tracks.csv") reader = build_reader(data_path) tracks = TracksData(reader) # Print basic information about the tracks print(f"Loaded {len(tracks)} tracks.") print(f"Number of frames: {tracks.max_frame + 1}") print(f"Number of objects: {tracks.max_object_id + 1}") # Access a specific track track_id = 0 track = tracks[track_id] print(f"Track {track_id}: {len(track)} points") # Iterate over frames and objects for frame in range(tracks.max_frame + 1): if frame in tracks: objects_in_frame = tracks[frame] print(f"Frame {frame}: {len(objects_in_frame)} objects") if __name__ == "__main__": main() ``` -------------------------------- ### Verify TracksData Installation Source: https://github.com/royerlab/tracksdata/blob/main/docs/installation.md Import the library and print its version to confirm a successful installation. This is a quick check after installation. ```python import tracksdata as td print(td.__version__) ``` -------------------------------- ### Install TracksData from Source (Development) Source: https://github.com/royerlab/tracksdata/blob/main/docs/installation.md Clone the repository and install the latest development version locally. This is useful for contributing to the project. ```bash git clone https://github.com/royerlab/tracksdata.git cd tracksdata pip install . ``` -------------------------------- ### Install TracksData from PyPI Source: https://github.com/royerlab/tracksdata/blob/main/docs/installation.md Use this command to install the latest stable release of TracksData from the Python Package Index. ```bash pip install tracksdata ``` -------------------------------- ### Install TracksData with Documentation Dependencies Source: https://github.com/royerlab/tracksdata/blob/main/docs/installation.md Install TracksData with dependencies required for building the documentation. This is typically used by developers working on the documentation. ```bash pip install .[docs] ``` -------------------------------- ### Install TracksData with Testing Dependencies Source: https://github.com/royerlab/tracksdata/blob/main/docs/installation.md Install TracksData along with the necessary dependencies for running tests. Use this if you plan to contribute or verify the library's functionality. ```bash pip install .[test] ``` -------------------------------- ### Manage Documentation Versions with Mike Source: https://github.com/royerlab/tracksdata/blob/main/docs/contributing.md Install dependencies, deploy new versions, set the default version, list all versions, or delete a specific version using the 'mike' tool. ```bash uv sync --extra docs ``` ```bash uv run mike deploy --push --update-aliases v1.0.0 latest ``` ```bash uv run mike set-default --push latest ``` ```bash uv run mike list ``` ```bash uv run mike delete --push v0.9.0 ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/royerlab/tracksdata/blob/main/docs/contributing.md Build and serve the documentation locally with live reload enabled for development. ```bash uv run mkdocs serve ``` -------------------------------- ### Build Static Documentation Site Source: https://github.com/royerlab/tracksdata/blob/main/docs/contributing.md Generate a static build of the documentation site for deployment. ```bash uv run mkdocs build ``` -------------------------------- ### Create and Solve a Simple Tracking Graph Source: https://github.com/royerlab/tracksdata/blob/main/docs/getting_started.md This snippet demonstrates the basic workflow of creating an in-memory graph, generating random nodes, adding edges based on distance, and solving the tracking problem using the NearestNeighborsSolver. It's useful for initial testing and understanding the core API. ```python import numpy as np import tracksdata as td # Create a graph graph = td.graph.InMemoryGraph() # Generate random nodes for testing node_generator = td.nodes.RandomNodes( n_time_points=5, n_nodes_per_tp=(10, 15), n_dim=2 ) node_generator.add_nodes(graph) # Connect nearby nodes across time edge_generator = td.edges.DistanceEdges( distance_threshold=0.3, n_neighbors=3 ) edge_generator.add_edges(graph) # Solve the tracking problem solver = td.solvers.NearestNeighborsSolver(edge_weight="distance") solution = solver.solve(graph) print(f"Original graph has {graph.num_nodes()} nodes and {graph.num_edges()} edges") print(f"Solution has {solution.num_nodes()} nodes and {solution.num_edges()} edges") ``` -------------------------------- ### Add Custom Node and Edge Attributes Source: https://github.com/royerlab/tracksdata/blob/main/docs/faq.md Demonstrates how to add new attribute keys to the graph and use them when adding nodes or edges. ```python # Add new attribute keys to the graph graph.add_node_attr_key("my_feature", 0.0) graph.add_edge_attr_key("confidence", 1.0) # Use them when adding nodes/edges graph.add_node({"t": 0, "x": 10, "my_feature": 42.0}) graph.add_edge(source_id, target_id, {"confidence": 0.95}) ``` -------------------------------- ### Convert TracksData to Napari Format Source: https://github.com/royerlab/tracksdata/blob/main/docs/faq.md Illustrates how to convert TracksData results into a format compatible with napari for visualization, including labels, tracks data, and graph information. ```python import tracksdata as td labels = ... tracks_df, track_graph, track_labels = td.functional.to_napari_format( solution_graph, shape=labels.shape, mask_key="mask", ) viewer = napari.Viewer() viewer.add_labels(track_labels) viewer.add_tracks(tracks_df, graph=track_graph) napari.run() ``` -------------------------------- ### Create Custom Nodes Operator Source: https://github.com/royerlab/tracksdata/blob/main/docs/faq.md Shows how to create a custom operator for adding nodes by inheriting from BaseNodesOperator and implementing the add_nodes method. ```python import tracksdata as td class CustomNodes(td.nodes.BaseNodesOperator): def add_nodes( self, graph: td.graph.BaseGraph, *, t: int | None = None, **kwargs: Any, ) -> None: # Your custom logic here to add nodes to the graph pass ``` -------------------------------- ### Create SQLGraph Attribute Indexes Source: https://github.com/royerlab/tracksdata/blob/main/docs/concepts.md Create composite or unique indexes on node or edge attributes in SQLGraph for faster filtering. This is particularly useful for large datasets. ```python graph.create_node_attr_index(["t", "label"]) graph.create_edge_attr_index("score", unique=True) ``` -------------------------------- ### Access and Manipulate Node and Edge Attributes Source: https://github.com/royerlab/tracksdata/blob/main/docs/concepts.md Demonstrates how to access node and edge attributes using TracksData's attribute system. Supports direct access, mathematical expressions, and comparison operations for filtering. ```python import tracksdata as td x_coords = td.NodeAttr("x") distance_cost = td.EdgeAttr("distance") + 0.1 * td.EdgeAttr("angle_change") recent_nodes = td.NodeAttr("t") >= 10 large_objects = td.NodeAttr("area") > 100 ``` -------------------------------- ### Extract Nodes from Labeled Images and Filter by Time Source: https://github.com/royerlab/tracksdata/blob/main/docs/getting_started.md This snippet shows how to extract nodes from segmented images using RegionPropsNodes, including custom properties, and then filter the graph to retrieve node data at a specific time point. This is useful for processing real-world detection data. ```python import tracksdata as td # Extract nodes from labeled images node_op = td.nodes.RegionPropsNodes(extra_properties=["area", "eccentricity"]) node_op.add_nodes(graph, labels=labels) # Filter nodes by time graph_filter = graph.filter(td.NodeAttr("t") == 0) node_data = graph_filter.node_attrs() print(node_data) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.