def test_merge_segments(): """ """ trajs = Trajectories(data.brownian_trajs_df()) trajs.reset_index(inplace=True) trajs.loc[15, ['label']] = 88 trajs.loc[20, ['label']] = 88 trajs.set_index(['t_stamp', 'label'], inplace=True) new_trajs = trajs.merge_segments([0, 88], inplace=False) assert_array_almost_equal(trajs.values, new_trajs.values) trajs = Trajectories(data.brownian_trajs_df()) good_trajs = trajs.copy() trajs.reset_index(inplace=True) trajs.loc[15, ['label']] = 88 trajs.loc[20, ['label']] = 88 trajs.set_index(['t_stamp', 'label'], inplace=True) trajs.merge_segments([0, 88], inplace=True) assert_array_almost_equal(trajs.values, good_trajs.values)
def test_radial_speed(): trajs = Trajectories(data.with_gaps_df()) trajs.reset_index(level='label', drop=True, inplace=True) trajs.set_index('true_label', drop=True, append=True, inplace=True) trajs.index.set_names(['t_stamp', 'label'], inplace=True) rd_speeds = rotation.radial_speed(trajs, in_coords=['x', 'y'], from_polar=False)
def test_interpolate(): trajs = Trajectories(data.with_gaps_df()) trajs.set_index('true_label', inplace=True, append=True) trajs.reset_index(level='label', drop=True, inplace=True) trajs.index.set_names(['t_stamp', 'label'], inplace=True) interpolated = trajs.time_interpolate(sampling=3, time_step=0.1, s=1) # t_stamps_in = interpolated.index.get_level_values('t_stamp') # indexer = t_stamps_in % 2 == 0 # interpolated.loc[indexer].shape, trajs.shape # indexer = interpolated.t_stamps % 3 == 0 # assert interpolated.loc[indexer].shape[0] == trajs.shape[0] dts = interpolated.get_segments()[0].t.diff().dropna() # All time points should be equaly spaced assert_almost_equal(dts.min(), dts.max())