Skip to content

Commit

Permalink
Consistent null particle addition and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Apr 12, 2018
1 parent c33c3c9 commit c61a162
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
6 changes: 4 additions & 2 deletions trackpy/linking/find_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ def assign_links(self):
else:
new_cands = set()

for sp in source_set:
sp.forward_cands.sort(key=lambda x: x[1])
# sort candidates and add in penalty for not linking
for _s in source_set:
_s.forward_cands.sort(key=lambda x: x[1])
_s.forward_cands.append((None, self.search_range))

# link
sn_spl, sn_dpl = self.subnet_linker(source_set, dest_set,
Expand Down
7 changes: 5 additions & 2 deletions trackpy/linking/linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,11 @@ def next_level(self, coords, t, extra_data=None):
def assign_links(self):
spl, dpl = [], []
for source_set, dest_set in self.subnets:
for sp in source_set:
sp.forward_cands.sort(key=lambda x: x[1])
# sort candidates and add in penalty for not linking before the
# subnetlinker, preventing repeats occuring during adaptive linking
for _s in source_set:
_s.forward_cands.sort(key=lambda x: x[1])
_s.forward_cands.append((None, self.search_range))

sn_spl, sn_dpl = self.subnet_linker(source_set, dest_set,
self.search_range)
Expand Down
3 changes: 3 additions & 0 deletions trackpy/linking/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ def split_subnet(source, dest, new_range):
# if dp is None:
# continue
assign_subnet(sp, dp, subnets=subnets)

# the null particle was removed: re-add it here
sp.forward_cands.append((None, new_range))
return (subnets[key] for key in subnets)


Expand Down
14 changes: 0 additions & 14 deletions trackpy/linking/subnetlinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,6 @@ def subnet_linker_recursive(source_set, dest_set, search_range, **kwargs):
# particle is lost. Not possible with default Linker implementation.
return [source_set.pop()], [None]

# sort candidates and add in penalty for not linking
for _s in source_set:
_s.forward_cands.sort(key=lambda x: x[1])
_s.forward_cands.append((None, search_range))

snl = SubnetLinker(source_set, len(dest_set), search_range, **kwargs)
sn_spl, sn_dpl = [list(particles) for particles in zip(*snl.best_pairs)]

Expand All @@ -413,11 +408,6 @@ def subnet_linker_nonrecursive(source_set, dest_set, search_range, **kwargs):
# particle is lost. Not possible with default Linker implementation.
return [source_set.pop()], [None]

# sort candidates and add in penalty for not linking
for _s in source_set:
_s.forward_cands.sort(key=lambda x: x[1])
_s.forward_cands.append((None, search_range))

sn_spl, sn_dpl = nonrecursive_link(source_set, len(dest_set), search_range, **kwargs)

for dp in dest_set - set(sn_dpl):
Expand Down Expand Up @@ -453,10 +443,6 @@ def subnet_linker_numba(source_set, dest_set, search_range,
# particle is lost. Not possible with default Linker implementation.
return [source_set.pop()], [None]

# Forward candidates were already sorted by Linker.assign_links()
for _s in source_set:
_s.forward_cands.append((None, search_range))

# Shortcut for small subnets, because the numba linker has significant overhead
if (lds == 1 or lss == 1 or (lds <= 3 and lss <= 3)) and hybrid:
sn_spl, sn_dpl = recursive_linker_obj(source_set, lds, search_range, **kwargs)
Expand Down

0 comments on commit c61a162

Please sign in to comment.