Skip to content

Commit

Permalink
Merge pull request #145 from yfukai/major_update_for_algorithm
Browse files Browse the repository at this point in the history
Major update for algorithm
  • Loading branch information
yfukai authored Jul 4, 2022
2 parents 9c7684b + 796a6e2 commit ec4d4f5
Show file tree
Hide file tree
Showing 13 changed files with 868 additions and 321 deletions.
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Example usage: tracking pre-detected spots

.. literalinclude:: ../examples/lap_tracking_example.py
:language: python
:emphasize-lines: 29-35
:emphasize-lines: 29-37
5 changes: 3 additions & 2 deletions examples/brownian_motion_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from matplotlib import pyplot as plt

from laptrack import laptrack
from laptrack import LapTrack

track_length = 100
track_count = 10
Expand Down Expand Up @@ -41,7 +41,8 @@
plt.legend()

spots = [np.array([pos[t] for pos in brownian_poss]) for t in range(track_length)]
tree = laptrack(spots)
lt = LapTrack()
tree = lt.predict(spots)
#%% # noqa:
for edge in tree.edges():
if (edge[0][0] + 1 != edge[1][0]) or (edge[0][1] != edge[1][1]):
Expand Down
8 changes: 5 additions & 3 deletions examples/lap_tracking_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from laptrack import laptrack
from laptrack import LapTrack

script_path = path.dirname(path.realpath(__file__))
filename = "../tests/data/trackmate_tracks_with_splitting_spots.csv"
Expand All @@ -26,13 +26,15 @@
# ]

max_distance = 15
track_tree = laptrack(
coords,
lt = LapTrack(
track_dist_metric="sqeuclidean",
splitting_dist_metric="sqeuclidean",
track_cost_cutoff=max_distance**2,
splitting_cost_cutoff=max_distance**2,
)
track_tree = lt.predict(
coords,
)

for edge in track_tree.edges():
print(edge)
Expand Down
7 changes: 4 additions & 3 deletions examples/napari_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib import pyplot as plt
from skimage.feature import blob_log

from laptrack import laptrack
from laptrack import LapTrack

#%% # noqa:
viewer = napari.Viewer()
Expand Down Expand Up @@ -65,7 +65,8 @@

# %%
spots_for_tracking = [spots[spots[:, 0] == j][:, 1:] for j in range(track_length)]
track_tree = laptrack(spots_for_tracking)
lt = LapTrack()
track_tree = lt.predict(spots_for_tracking)

tracks = []
for i, segment in enumerate(nx.connected_components(track_tree)):
Expand Down Expand Up @@ -105,7 +106,7 @@
for j in np.sort(np.unique(extracted_spots[:, 0]))
]

test_track = laptrack(extracted_spots_for_tracking, gap_closing_cost_cutoff=False)
test_track = lt.predict(extracted_spots_for_tracking, gap_closing_cost_cutoff=False)
for edge in test_track.edges():
_e = np.array(edge)
pos = [extracted_spots_for_tracking[frame][ind] for frame, ind in edge]
Expand Down
54 changes: 53 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "laptrack"
version = "0.1.6"
version = "0.1.7-alpha.2"
description = "LapTrack"
authors = ["Yohsuke Fukai <[email protected]>"]
license = "BSD-3-Clause"
Expand Down Expand Up @@ -32,6 +32,7 @@ scipy = "^1.7.0"
networkx = "^2.6.1"
pandas = "^1.3.1"
typing-extensions = "^3.10.0"
pydantic = "^1.9.1"

[tool.poetry.dev-dependencies]
pytest = "^6.2.4"
Expand Down
4 changes: 2 additions & 2 deletions src/laptrack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
__author__ = """Yohsuke T. Fukai"""
__email__ = "[email protected]"

from ._tracking import laptrack
from ._tracking import laptrack, LapTrack, LapTrackMulti

__all__ = ["laptrack"]
__all__ = ["laptrack", "LapTrack", "LapTrackMulti"]
6 changes: 3 additions & 3 deletions src/laptrack/_cost_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union

import numpy as np
from scipy.sparse.coo import coo_matrix
from scipy.sparse import coo_matrix

from ._typing_utils import Float
from ._typing_utils import Matrix
Expand Down Expand Up @@ -67,7 +67,7 @@ def build_segment_cost_matrix(
alternative_cost_factor: Float = 1.05,
alternative_cost_percentile: Float = 90,
alternative_cost_percentile_interpolation: str = "lower",
) -> coo_matrix:
) -> Optional[coo_matrix]:
"""Build sparce array for segment-linking cost matrix.
Parameters
Expand Down Expand Up @@ -141,7 +141,7 @@ def build_segment_cost_matrix(
# XXX seems numpy / mypy is over-strict here. Will fix later.
C.data, # type: ignore
alternative_cost_percentile,
interpolation=alternative_cost_percentile_interpolation,
method=alternative_cost_percentile_interpolation,
)
* alternative_cost_factor
)
Expand Down
2 changes: 1 addition & 1 deletion src/laptrack/_optimization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple

import lap
from scipy.sparse.csr import csr_matrix
from scipy.sparse import csr_matrix

from ._typing_utils import FloatArray
from ._typing_utils import Int
Expand Down
Loading

0 comments on commit ec4d4f5

Please sign in to comment.