def link(self, f, search_range, *args, **kwargs): if 'pos_columns' in kwargs: raise nose.SkipTest( 'Skipping find_link tests with custom pos_columns.') # the minimal spacing between features in f is assumed to be 1. # from scipy.spatial import cKDTree # mindist = 1e7 # for _, _f in f.groupby('frame'): # dists, _ = cKDTree(_f[['y', 'x']].values).query(_f[['y', 'x']].values, k=2) # mindist = min(mindist, dists[:, 1].min()) # print("Minimal dist is {0:.3f}".format(mindist)) kwargs = dict(self.linker_opts, **kwargs) size = 3 separation = kwargs['separation'] f = f.copy() f[['y', 'x']] *= separation topleft = (f[['y', 'x']].min().values - 4 * separation).astype(np.int) f[['y', 'x']] -= topleft shape = (f[['y', 'x']].max().values + 4 * separation).astype(np.int) reader = CoordinateReader(f, shape, size) if kwargs.get('adaptive_stop', None) is not None: kwargs['adaptive_stop'] *= separation result = find_link(reader, search_range=search_range * separation, *args, **kwargs) result = pandas_sort(result, ['particle', 'frame']).reset_index(drop=True) result[['y', 'x']] += topleft result[['y', 'x']] /= separation return result
def link(self, f, search_range, *args, **kwargs): if 'pos_columns' in kwargs: raise nose.SkipTest('Skipping find_link tests with custom pos_columns.') # the minimal spacing between features in f is assumed to be 1. # from scipy.spatial import cKDTree # mindist = 1e7 # for _, _f in f.groupby('frame'): # dists, _ = cKDTree(_f[['y', 'x']].values).query(_f[['y', 'x']].values, k=2) # mindist = min(mindist, dists[:, 1].min()) # print("Minimal dist is {0:.3f}".format(mindist)) kwargs = dict(self.linker_opts, **kwargs) size = 3 separation = kwargs['separation'] f = f.copy() f[['y', 'x']] *= separation topleft = (f[['y', 'x']].min().values - 4 * separation).astype(np.int) f[['y', 'x']] -= topleft shape = (f[['y', 'x']].max().values + 4 * separation).astype(np.int) reader = CoordinateReader(f, shape, size) if kwargs.get('adaptive_stop', None) is not None: kwargs['adaptive_stop'] *= separation result = find_link(reader, search_range=search_range*separation, *args, **kwargs) result = pandas_sort(result, ['particle', 'frame']).reset_index(drop=True) result[['y', 'x']] += topleft result[['y', 'x']] /= separation return result
def link(self, f, shape, remove=None, **kwargs): _kwargs = dict(diameter=self.diameter, search_range=self.search_range, separation=self.separation) _kwargs.update(kwargs) if remove is not None: callback_coords = f.loc[f['frame'] == 1, ['y', 'x']].values remove = np.array(remove, dtype=np.int) if np.any(remove < 0) or np.any(remove > len(callback_coords)): raise RuntimeError('Invalid test: `remove` is out of bounds.') callback_coords = np.delete(callback_coords, remove, axis=0) def callback(image, coords, **unused_kwargs): if image.frame_no == 1: return callback_coords else: return coords else: callback = None reader = CoordinateReader(f, shape, self.size) return find_link(reader, before_link=callback, **_kwargs)
def link(self, f, shape, remove=None, **kwargs): _kwargs = dict(diameter=self.diameter, search_range=self.search_range, separation=self.separation, preprocess=False) _kwargs.update(kwargs) if remove is not None: callback_coords = f.loc[f['frame'] == 1, ['y', 'x']].values remove = np.array(remove, dtype=np.int) if np.any(remove < 0) or np.any(remove > len(callback_coords)): raise RuntimeError('Invalid test: `remove` is out of bounds.') callback_coords = np.delete(callback_coords, remove, axis=0) def callback(image, coords, **unused_kwargs): if image.frame_no == 1: return callback_coords else: return coords else: callback = None reader = CoordinateReader(f, shape, self.size) return find_link(reader, before_link=callback, **_kwargs)