Skip to content

Commit 47b6264

Browse files
authored
Merge pull request #785 from nkeim/fix-msd-multi-index
BUG: Let imsd() use output of subtract_drift()
2 parents b431def + f5c931b commit 47b6264

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

trackpy/motion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def imsd(traj, mpp, fps, max_lagtime=100, statistic='msd', pos_columns=None):
212212
msds = []
213213
# Note: Index is set by msd, so we don't need to worry
214214
# about conformity here.
215-
for pid, ptraj in traj.groupby('particle'):
215+
for pid, ptraj in traj.reset_index(drop=True).groupby('particle'):
216216
msds.append(msd(ptraj, mpp, fps, max_lagtime, False, pos_columns))
217217
ids.append(pid)
218218
results = pandas_concat(msds, keys=ids)

trackpy/tests/test_motion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ def test_linear_emsd(self):
195195
actual.index = expected.index
196196
assert_series_equal(np.round(actual), expected)
197197

198+
def test_linear_msd_drift(self):
199+
'''Smoke test that imsd() and emsd() can use output of subtract_drift()'''
200+
N = 10
201+
EARLY = 7
202+
drift = DataFrame(np.zeros((N - 1, 2)),
203+
np.arange(1, N, dtype=int)).astype('float64')
204+
drift.columns = ['x', 'y']
205+
drift.index.name = 'frame'
206+
subtracted = tp.subtract_drift(self.many_walks, drift)
207+
actual_imsd = tp.imsd(subtracted, 1, 1, max_lagtime=EARLY)
208+
actual_emsd = tp.emsd(subtracted, 1, 1, max_lagtime=EARLY)
209+
198210
def test_linear_emsd_gaps(self):
199211
A = 1
200212
EARLY = 4 # only early lag times have good stats

0 commit comments

Comments
 (0)