Importing MyPTV data¶
flowtracks.myptv reads MyPTV trajectory files (produced by the
MyPTV 3D-PTV pipeline, e.g.
example/trajecotries_stitched) and converts them into flowtracks
Trajectory objects — and optionally into a
trajectories Zarr store that ZarrScene
reads natively, with no further conversion. This is how the two pipelines
interoperate: MyPTV tracks, postptv post-processes.
Two file forms are recognized (detected from the column count):
Smoothed / stitched (11 columns):
[trajid, x, y, z, vx, vy, vz, ax, ay, az, frame]— the final output of the MyPTVsmoothingandstitchingstages.Tracked (5 or 9 columns): raw output of MyPTV’s tracking (
myptv.tracking_mod.save_results). Columns are[trajid, x, y, z, <per-camera blob index columns>, <per-camera error>, frame]; the last column is always the frame number. Velocity is not stored here; the translator re-derives it by finite differences over the frame column, exactly astraj_stitching_moddoes — in metres per frame. Acceleration is not inferred and stays absent.
Rows with trajectory id -1 (unlinked samples the tracker could not link)
are kept as one-sample trajectories, so no data is dropped.
from flowtracks.myptv import read_myptv_trajectories, convert_myptv_to_zarr
trajects = read_myptv_trajectories("smoothed_trajectories")
convert_myptv_to_zarr("smoothed_trajectories", "run.zarr")
# ZarrScene opens the converted store with no conversion step:
from flowtracks.zarr_scene import ZarrScene
scene = ZarrScene("run.zarr")
convert_myptv_to_zarr writes a trajectories group with pos,
vel, time, trajid (and accel when present), the same layout
flowtracks.io.save_zarr_trajectories() and openptv2’s RunStore
write. Units default to honest per-frame units (m frame-1, never
m s-1) because a MyPTV file carries no frame rate; pass units= to
state absolute units explicitly. A source_format/source_file
attribute pair is recorded on the group for provenance.
Note: MyPTV units are not assumed by the translator. Run the pipeline
against the same unit system the source file was produced with, and scale
the input (or pass units= explicitly) if you need SI units.
From file to picture¶
The figure below shows the example stitched file from the MyPTV repository
(example/trajecotries_stitched, 325 samples, 43 linked trajectories)
converted to a Zarr store by convert_myptv_to_zarr() and rendered
with flowtracks.graphics.plot_trajectories_3d() — a 3D view of the
8 longest linked trajectories, coloured by speed (stored per-frame velocity).
Faint grey points show the rest of the cloud for context.
from flowtracks.myptv import convert_myptv_to_zarr
from flowtracks.graphics import plot_trajectories_3d, select_trajectories
import pyvista as pv
convert_myptv_to_zarr("example/trajecotries_stitched", "myptv_run.zarr")
sel = select_trajectories("myptv_run.zarr", by="length", n=8)
plotter = pv.Plotter(off_screen=True)
plot_trajectories_3d("myptv_run.zarr", trajids=sel, context=1000,
plotter=plotter, show=False)
plotter.screenshot("myptv_trajectories.png", window_size=(900, 600))
Trajectories from MyPTV’s stitched file, recovered through postptv.¶
MyPTV trajectory import: read MyPTV TSV output as flowtracks Trajectories.
MyPTV writes each pipeline stage as a plain-text, tab-separated file with no header row. The two forms this module understands are:
smoothed / stitched trajectories (11 columns):
[trajid, x, y, z, vx, vy, vz, ax, ay, az, frame]— the raw output ofmyptv.tracking_mod.save_resultsstage produces the tracked form, whilemyptv.traj_smoothing_mod.smooth_trajectories.save_resultsandmyptv.traj_stitching_mod.traj_stitching.save_resultsproduce the smoothed/stitched form (the finalstitchingstage file is the canonical one).tracked particles (5 or 9 columns):
[trajid, x, y, z, <per-camera blob index columns>, <per-camera error>, frame]— the last column is always the frame number. Velocity is not stored by MyPTV in this form; the translator re-derives it by finite differences over the frame column, exactly astraj_stitching_moddoes for thin trajectories. Acceleration is unavailable and is not guessed.
Rows with trajectory id -1 are unlinked samples (particles the tracker could not link). They are emitted as one-sample Trajectory objects so no data is dropped.
- flowtracks.myptv._finite_difference_velocity(pos, time)[source]¶
Forward-difference velocity from position over the frame column.
Matches the convention used by
traj_stitching_modfor the thin trajectories it encounters: velocity in metres per frame.
- flowtracks.myptv.read_myptv_trajectories(path, sort=True)[source]¶
Read a MyPTV trajectory file into a list of
Trajectoryobjects.The schema is detected from the column count (5, 9 or 11 columns). The last column is always treated as the frame number and the first three columns (after the id) as x, y, z — a rule that holds for every MyPTV tracker regardless of the number of cameras.
Arguments
path: path to the MyPTV TSV file.sort: if True (default), trajectories are returned sorted by (trajid, frame).
Returns
trajects: a list ofTrajectoryobjects. Unlinked samples (trajid == -1 in the source) each become a one-sample trajectory.
- flowtracks.myptv.convert_myptv_to_zarr(path, zarr_path, group='trajectories', overwrite=True, units=None, sort=True)[source]¶
Convert a MyPTV trajectory TSV file into a Zarr store.
The store holds a
trajectoriesgroup withpos,vel,time,trajid(andaccelwhen present) arrays — the layoutflowtracks.zarr_scene.ZarrScenereads natively, and the same layout produced byopenptv2’s RunStore. It can therefore be fed to flowtracks’ Eulerian/phase-averaging pipeline without any conversion.Arguments
path: path to the MyPTV TSV file (tracked, smoothed or stitched).zarr_path: target.zarrdirectory.group: sub-group name inside the store (default"trajectories").overwrite: if True, overwrite existing arrays in the group.units: units dict recorded on the group, e.g.{"pos": "m", "vel": "m frame-1", "time": "frame"}. Defaults to per-frame per-metre units honest for a file with no stated frame rate; pass your own to state absolute units.sort: if True (default), trajectories are sorted by (trajid, frame).
Returns
trajects: the list ofTrajectoryobjects that were written.