def expected_sq_displacement(trj: TrajaDataFrame, n: int = 0, eqn1: bool = True) -> float: """Expected displacement. .. note:: This method is experimental and needs testing. """ sl = traja.step_lengths(trj) ta = traja.angles(trj) l = np.mean(sl) l2 = np.mean(sl**2) c = np.mean(np.cos(ta)) s = np.mean(np.sin(ta)) s2 = s**2 if eqn1: # Eqn 1 alpha = np.arctan2(s, c) gamma = ((1 - c)**2 - s2) * np.cos( (n + 1) * alpha) - 2 * s * (1 - c) * np.sin((n + 1) * alpha) esd = (n * l2 + 2 * l**2 * ((c - c**2 - s2) * n - c) / ((1 - c)**2 + s2) + 2 * l**2 * ((2 * s2 + (c + s2)**((n + 1) / 2)) / ((1 - c)**2 + s2)**2) * gamma) return abs(esd) else: logger.info("This method is experimental and requires testing.") # Eqn 2 esd = n * l2 + 2 * l**2 * c / (1 - c) * (n - (1 - c**n) / (1 - c)) return esd
def test_step_lengths(): df_copy = df.copy() step_lengths = traja.step_lengths(df_copy) actual = step_lengths.to_numpy()[:5] expected = np.array( [np.nan, 1.829_180_85, 1.489_402_04, 2.130_723_72, 2.172_887_24]) npt.assert_allclose(actual, expected) assert len(step_lengths == len(df_copy))