def test_isolated_continuous_random_walks(self): # Two 2D random walks np.random.seed(0) N = 30 Y = 250 M = 20 # margin, because negative values raise OutOfHash a = DataFrame({'x': M + random_walk(N), 'y': M + random_walk(N), 'frame': np.arange(N)}) b = DataFrame({'x': M + random_walk(N - 1), 'y': M + Y + random_walk(N - 1), 'frame': np.arange(1, N)}) f = pd.concat([a, b]) expected = f.copy().reset_index(drop=True) expected['particle'] = np.concatenate([np.zeros(N), np.ones(N - 1)]) pandas_sort(expected, ['particle', 'frame'], inplace=True) actual = self.link_df(f, 5) assert_traj_equal(actual, expected) # Many 2D random walks np.random.seed(0) initial_positions = [(100, 100), (200, 100), (100, 200), (200, 200)] import itertools c = itertools.count() def walk(x, y): i = next(c) return DataFrame({'x': x + random_walk(N - i), 'y': y + random_walk(N - i), 'frame': np.arange(i, N)}) f = pd.concat([walk(*pos) for pos in initial_positions]) expected = f.copy().reset_index(drop=True) expected['particle'] = np.concatenate([i*np.ones(N - i) for i in range(len(initial_positions))]) pandas_sort(expected, ['particle', 'frame'], inplace=True) actual = self.link_df(f, 5) assert_traj_equal(actual, expected)
def test_isolated_continuous_random_walks(self): # Two 2D random walks np.random.seed(0) N = 30 Y = 250 M = 20 # margin, because negative values raise OutOfHash a = DataFrame({'x': M + random_walk(N), 'y': M + random_walk(N), 'frame': np.arange(N)}) b = DataFrame({'x': M + random_walk(N - 1), 'y': M + Y + random_walk(N - 1), 'frame': np.arange(1, N)}) f = pd.concat([a, b]) expected = f.copy().reset_index(drop=True) expected['particle'] = np.concatenate([np.zeros(N), np.ones(N - 1)]) pandas_sort(expected, ['particle', 'frame'], inplace=True) actual = self.link(f, 5) assert_traj_equal(actual, expected) # Many 2D random walks np.random.seed(0) initial_positions = [(100, 100), (200, 100), (100, 200), (200, 200)] import itertools c = itertools.count() def walk(x, y): i = next(c) return DataFrame({'x': x + random_walk(N - i), 'y': y + random_walk(N - i), 'frame': np.arange(i, N)}) f = pd.concat([walk(*pos) for pos in initial_positions]) expected = f.copy().reset_index(drop=True) expected['particle'] = np.concatenate([i*np.ones(N - i) for i in range(len(initial_positions))]) pandas_sort(expected, ['particle', 'frame'], inplace=True) actual = self.link(f, 5) assert_traj_equal(actual, expected)
def walk(x, y): i = next(c) return DataFrame({'x': x + random_walk(N - i), 'y': y + random_walk(N - i), 'frame': np.arange(i, N)})