Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncomment dist_func parameter to enable PBCs with predictive tracking #376

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tobac/tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,74 @@ def test_time_cell_min(
np.sum(all_feats_tracked_drop_no_cells["orig_cell_num"] == i)
== expected_val
)


def test_trackpy_predict_PBC():
"""Test if predictive tracking with PBCs works correctly"""

test_features = pd.DataFrame(
{
"feature": [1, 2, 3, 4, 5, 6, 7, 8],
"hdim_1": [85, 15, 95, 5, 5, 95, 15, 85],
"hdim_2": [50, 45, 50, 45, 50, 45, 50, 45],
"frame": [0, 0, 1, 1, 2, 2, 3, 3],
"time": [
datetime.datetime(2000, 1, 1),
datetime.datetime(2000, 1, 1),
datetime.datetime(2000, 1, 1, 0, 5),
datetime.datetime(2000, 1, 1, 0, 5),
datetime.datetime(2000, 1, 1, 0, 10),
datetime.datetime(2000, 1, 1, 0, 10),
datetime.datetime(2000, 1, 1, 0, 15),
datetime.datetime(2000, 1, 1, 0, 15),
],
}
)

output_random_no_pbc = tobac.linking_trackpy(
test_features, None, 1, 1, d_max=10, method_linking="random"
)

# Assert cell does not cross border
assert output_random_no_pbc["cell"].tolist() == [1, 2, 1, 2, 2, 1, 2, 1]

output_random_pbc = tobac.linking_trackpy(
test_features,
None,
1,
1,
d_max=10,
method_linking="random",
PBC_flag="hdim_1",
min_h1=0,
max_h1=100,
min_h2=0,
max_h2=100,
)

# Assert cell does not cross border even with PBC because of random tracking
assert output_random_pbc["cell"].tolist() == [1, 2, 1, 2, 2, 1, 2, 1]

output_predict_no_pbc = tobac.linking_trackpy(
test_features, None, 1, 1, d_max=10, method_linking="predict"
)

# Assert that without PBCs predictive tracking creates 4 cells because the d_max criteria is too small
assert output_predict_no_pbc["cell"].tolist() == [1, 2, 1, 2, 3, 4, 3, 4]

output_predict_pbc = tobac.linking_trackpy(
test_features,
None,
1,
1,
d_max=10,
method_linking="predict",
PBC_flag="hdim_1",
min_h1=0,
max_h1=100,
min_h2=0,
max_h2=100,
)

# Assert with PBCs and prdictive tracking the cells should cross the border
assert output_predict_pbc["cell"].tolist() == [1, 2, 1, 2, 1, 2, 1, 2]
2 changes: 1 addition & 1 deletion tobac/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def linking_trackpy(
link_strategy="auto",
adaptive_step=adaptive_step,
adaptive_stop=adaptive_stop,
# dist_func=dist_func
dist_func=dist_func
# copy_features=False, diagnostics=False,
# hash_size=None, box_size=None, verify_integrity=True,
# retain_index=False
Expand Down
Loading