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_angles(lag): df_copy = df.copy() angles = traja.angles(df_copy, lag=lag) actual = angles.to_numpy() if lag == 1: expected = np.array([ np.nan, 50.536_377_13, 62.000_036_72, 89.961_185_41, 25.764_324_08, 27.737_271_33, 0.259_677_63, 26.958_350_61, 22.622_286, 19.665_283_71, 31.428_064_33, 35.554_608_67, 77.216_475_78, 80.981_399_37, 77.495_666_91, 64.779_921_95, 55.220_856_61, 12.418_644_03, 18.295_995_36, 9.327_266_35, ]) elif lag == 2: expected = np.array([ np.nan, np.nan, 55.679_398_79, 78.552_154_19, 57.510_652_27, 1.318_153_96, 11.741_160_75, 10.869_226_84, 24.615_298_57, 21.161_131_62, 26.022_239_16, 33.485_645_28, 55.060_685_9, 88.237_494_22, 79.351_771_4, 71.545_102_77, 59.557_726_58, 33.248_128_63, 15.505_016_09, 13.817_221_74, ]) npt.assert_allclose(actual, expected)