<jupyter_start><jupyter_text>Simple track features 1. Create some simulated tracks1. Simulate tracks * brownian motion (pure random walk) * linear motion with some randomness<jupyter_code>trj_brownian = tp.simulate.brownian(n_tracks=10)
trj_linear   = tp.simulate.brownian_linear(n_tracks=10)

trj_brownian<jupyter_output><empty_output><jupyter_text>2. Add information to tables and concatenate tracks1. Define column identifiers2. Give tracks a tag `"label"` for later use3. Merge the two track tables into one<jupyter_code>trackid = "TrackID"
frameid = "FRAME"
coords_xy = ["Position X", "Position Y"]

trj_brownian["label"] = 0
trj_linear["label"]   = 1

# concatenate (note: the trackids need to be relabeled) 
trj = tp.concat_relabel([trj_linear, trj_brownian], trackid=trackid)

trj<jupyter_output><empty_output><jupyter_text>3. Plot tracks<jupyter_code>trj.groupby(trackid).apply(tp.visu.plot_trj, coords=coords_xy, line_fmt=".-");<jupyter_output><empty_output><jupyter_text>3. Compute simple track features * Confinement ratio (ratio of start/end net distance vs. total track distance) * Statistics of the instantaneous speed<jupyter_code># prepare feature factory
feature_factory = tp.features.Features(frame=frameid, coords=coords_xy)

# compute two features
conf_ratio  = feature_factory.get("confinement_ratio")
speed_stats = feature_factory.get("speed_stats")

conf_ratio_res  = trj.groupby(trackid).apply(conf_ratio.compute)
speed_stats_res = trj.groupby(trackid).apply(speed_stats.compute)

# retrieve labels assignment
y = trj.groupby(trackid)["label"].first()

# merge into single DataFrame
features = pd.concat([conf_ratio_res, speed_stats_res, y], axis=1)<jupyter_output><empty_output><jupyter_text>Visualize two features as scatter plot* Confinement ratio* speed average and color code each tracks motion type.The two motion types have similar average speed, but confinement ratio is disciminating them<jupyter_code># plot with pandas
features.plot.scatter(x="confinement_ratio", y="speed_stats_mean", c="label", cmap="coolwarm");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10384615384615385, 'fraction_numerical': 0.007211538461538462, 'mean_word_length': 7.670833333333333, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '489053', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 709, 'n_tokens_neox': 685, 'n_words': 165, 'path': 'examples/01_track_features.ipynb', 'repo_name': 'sommerc/trackpal', 'size': '2080'}