More accurate velocities: the spatial consensus (costs time)¶
You have: a run that tracks well, but the velocities or accelerations are noisy, or the tracks contain jumps (wrong links). You want: fewer wrong links and smoother tracks, and you accept a slower tracking step. Time: 30 minutes to set up and compare. The tracking step then takes 1.2 to 1.5 times as long (with the compiled build).
Read course page 6 (tracking) and page 7 (is the result good?) first.
1. What you get and what it costs (read this first)¶
The idea is simple: particles that are close to each other move almost the same way. The tracker looks at the links of the
neighbours of every candidate link. A link that moves very differently from its neighbours is probably wrong (a ghost
point, or a swap between two particles), and the tracker does not use it. This is the spatial consensus
(vfc_mode, all details). It is off by default.
The gain is moderate. The cost is real. What we measured, with the same settings on the same frames, switching it on:
| Real recordings (two of 120 frames, one noisier of 20 frames) | Benchmark with known truth (1, 2, 4 times our usual density) | |
|---|---|---|
| Jumps in the tracks (share of steps where the depth velocity changes by more than 0.3 mm) | down by a quarter to a third (1.4 to 1.0 %), by 90 % on the noisier recording | not measured (truth is better: next row) |
| Worst tenth of the depth jitter | down 6 to 8 %; down 28 % on the noisier recording | |
| Velocity error against the truth | down 2 to 3 % (1 and 2 times), 6 to 7 % (4 times); 4 to 8 % if all points count | |
| Tracks of 50 frames or more | fewer by 4 to 8 % | yield down by about half a point |
| Mean track length | shorter by 3 to 5 % (11 % on the noisier one) | |
| Tracking time | not re-measured after the speed-up (it was twice as long) | 1.2 to 1.5 times as long (it was 2.3 to 3 times before the speed-up) |
With the merged-blob loop (holistic_rounds: 2) switched on as well, the loop itself is slow
(10 to 20 times the plain tracker), so the consensus adds only 10 to 60 % on top, and on dense benchmark data the two
together lowered the velocity error by 11 to 12 % (2 and 4 times our density). Without the loop and on clean,
sparse data, expect a few percent and a longer wait.
Why only moderate? Wrong links are 4 to 7 % of all links in our benchmark. If you could remove every wrong link (we tested this with the known truth) the velocity error would fall by only 3.5 to 7 %. The larger part of the error comes from tracks that break into pieces, and from ghost points, which the consensus touches only a little. So it is a fix for one specific defect, not a general accuracy switch. It helps most where that defect is large: dense seeding and noisy recordings.
Why slower? For every frame the tracker finds the neighbours of every point and takes the median of their velocities. We
profiled it and moved that step into a compiled kernel (algorithms/consensus_kernels.py: a grid search and a quickselect, same results as before).
That took the cost from 2.3 to 3 times the plain tracker to 1.2 to 1.5 times. The speed-up needs the compiled build; the
interpreted fallback uses a slower numpy version and costs about 1.8 times. Two further options,
vfc_bootstrap and vfc_affine, double the time again for about 1 % more. Leave them off.
2. Is it for you?¶
| Your situation | Use it? |
|---|---|
| dense seeding, or a noisy recording (many jumps in the tracks) | yes: this is where it helped most |
| you already use the merged-blob loop and want the best accuracy | yes: the two stack |
| clean, sparse data with few jumps (jump share below 0.5 % without it) | no: a few percent for twice the time |
| you want more or longer tracks | no: it shortens them a little (it removes links) |
| the flow has sharp small-scale structure (a jet edge, a shear layer) | try on a short piece first: real links there differ from the neighbours' |
| fewer than 3 tracked neighbours per particle within 10 mm | no: it has nothing to compare with |
3. Set it up¶
Step 1. Keep a baseline. Track once without it and keep that run folder. You need it to measure the gain.
Step 2. Measure the gate from your own data. The gate is the largest difference (in mm per frame) between a link and its neighbours that the tracker accepts. Too tight removes good links; too wide does nothing. Read the baseline run:
It prints the typical step and the deviation of the links from their neighbours, and a first value for the gate (the 98th percentile of the deviations, about 0.2 to 0.3 mm per frame on our data). A tighter gate (the 95th percentile) lowers the error further and removes more good links: on the benchmark, a gate of 0.2 instead of 0.3 gave 7.6 % instead of 5 % lower velocity error and cost 1.7 instead of 0.5 points of yield.
Step 3. Switch it on in the copy.
plugins:
selected_tracking: two_phase
track:
vfc_mode: pre # off | pre | post | both ('pre' does nothing without vfc_gate)
vfc_gate: 0.25 # mm per frame: from step 2
vfc_radius: 10 # mm: about 3 times the distance between tracked particles
vfc_min_neighbors: 3
holistic_rounds: 2 # optional: the merged-blob loop, for dense seeding
In the graphical interface: Tracking Parameters, group Spatial Consensus (VFC): VFC mode pre, Pre-gate (mm/f) the value
from step 2, Radius, Min neighbors; Merged-blob loop rounds for the loop. post (a filter after the assignment) is the
gentler choice: it changes less, helps less, and costs about the same.
Step 4. Track the copy.
4. Measure the gain¶
Real data has no known truth, so you compare two runs on the same frames and read numbers that stand in for the accuracy.
uv run python scripts/realism_metrics.py RUN/res/run.zarr --last 100
uv run python scripts/realism_metrics.py RUN_consensus/res/run.zarr --last 100
| Number | What you want to see | Stop and loosen the gate if |
|---|---|---|
jump_share |
down by 20 % or more | it did not change: the consensus has nothing to do with your errors |
jitter_z_p90 |
down by 4 % or more | |
n_ge50 (tracks of 50 frames or more) |
not down by more than 10 % | it is down by more: the gate is too tight |
mean_len |
not down by more than 10 % | |
never4_share |
not up by more than 0.02 |
Three honest limits of these numbers:
- They are stand-ins. A lower jump share and jitter mean fewer wrong links and less noise. They do not prove that the velocity is closer to the truth. Only data with a known truth shows that (next).
- Check a quantity you care about. Wrong links inflate the tails of the acceleration distribution. Compare the statistic your study needs (an energy spectrum, the tails of the acceleration, a dissipation estimate) with and without. If it does not change, the extra time is not worth it.
- Check the cost. The tracking time and the number of long tracks are part of the answer.
A truth check at your density. Build a synthetic case with the density of your recording and compare both settings on it
(benchmarking guide). Use the common-set column (vErrC), which compares only the points both
runs found:
uv run python scripts/synth_bench.py build --level L1 --mult 2 --k 1 --n-out 150 --sigma-px 0.08 --amp-jitter 0.18 --amp-flicker 0.05
uv run python scripts/synth_bench.py track --case CASE --tracker two_phase
uv run python scripts/synth_bench.py track --case CASE --tracker "two_phase+vfc_mode=pre+vfc_gate=0.25"
uv run python scripts/synth_bench.py eval --case CASE --trackers two_phase "two_phase+vfc_mode=pre+vfc_gate=0.25" --ref two_phase
(CASE is the name of the new folder in the benchmark's cases/ folder. The synthetic noise is ours, not your camera's: use it to compare the two
settings, not to read an absolute error.)
If it did not work¶
| You see | Cause | What to do |
|---|---|---|
| nothing changes | vfc_mode: pre without vfc_gate; or the gate is far above the 99th percentile |
set a gate (step 2); post uses vfc_post_min_tol (default 0.5) |
| 10 % fewer long tracks or more | the gate is too tight | use the 99th percentile instead of the 98th |
| tracks missing at a jet edge or a shear layer | the real flow differs from the neighbours there | a smaller vfc_radius, a wider gate, or post |
| the run takes more than 2 times as long | vfc_bootstrap or vfc_affine is on |
switch both off |
| the statistics you care about got worse | the consensus removed real links | go back to the baseline; report the case |
What we have not tested¶
The effect on real data was measured on three recordings (the longest 120 frames) with truth-free numbers only. The gate was chosen on two of them. We did not test it together with self-calibration, with moving flow boundaries, or with sparse seeding. The numbers above come from the study, section 7.
Next¶
Spatial consensus: all keys, Dense seeding, Holistic tracking.