Skip to content

Commit 547ceee

Browse files
authored
Merge pull request #127 from mbel-tech/fatina-del-codice/3d-movement-integration-3a34e9
Side-view depth: camera-view setting, IL-15 vertical position, Zones canvas fix
2 parents 5de189b + 028f5f7 commit 547ceee

54 files changed

Lines changed: 2374 additions & 88 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
99

1010
### Added
1111

12+
- **Side-view depth: a camera-view setting and IL-15 vertical position.** The Calibration
13+
screen has a new *Camera view* setting (Not set / Top-down / Side view), saved with the
14+
project. It defaults to Not set, so existing projects behave exactly as before. Declaring a
15+
side view switches on IL-15, which reports each animal's depth as a fraction of the water
16+
column (0 = surface, 1 = floor), the mean distance below the surface in cm when calibrated,
17+
the spread, and the share of frames that fell outside the column. The column is the vertical
18+
span of the main zones, so draw a main zone from the waterline to the floor on the Zones
19+
screen. With no main zone the values are empty and `depth_extent_source` says why; the video
20+
frame is never used instead. Frames outside the column are dropped and counted, not clipped.
21+
A metric the camera view rules out is greyed on the Metrics screen with the fix in its tooltip,
22+
skipped with a stated reason in the run's README, and a side view with no water column gets a
23+
warning on the Zones stage. The per-session README and `manifest.json` record the view and the
24+
water column used, and `list-metrics` has a VIEW column. Adding the setting changes
25+
`project_hash` once for every project, as any new manifest field does.
1226
- **Ctrax raw `.mat` input** ("Save Tracks as Matlab File"). One session per file; the frame
1327
rate comes from the file's timestamps (an average over the whole span) and the frame size is
1428
asked for, because Ctrax measures y from the bottom and the height is needed to put it back in
@@ -958,6 +972,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
958972

959973
### Fixed
960974

975+
- **Zones drawn for any tracker other than idtracker.ai were not in video pixels.** Only
976+
idtracker.ai sessions supplied a backdrop; every other reader got a blank 640x480 Zones canvas
977+
and saved zones recorded no frame size, so hand-drawn zones (and the Z-1 to Z-9, IL-3 and IL-14
978+
results that use them) were only right if the video happened to be 640x480. The canvas is now
979+
the size of the video frame and the first zone saved records it. The canvas is still blank for
980+
those trackers: there is no picture to draw on yet. **Zones you drew on the old blank canvas
981+
are not relabelled; redraw them.**
982+
- **The "superseded by Z-8" note on Z-2 disappeared as soon as a project was open.** The
983+
identity pass on the Metrics screen reset every tooltip it did not own.
984+
961985
- **The test process no longer aborts at exit.** After every GUI test passed, pytest could crash in Qt
962986
teardown (`QObject: shared QObject was deleted directly`, exit 134), failing the CI test jobs.
963987
Standalone screens, tables and dialogs created in tests are now registered with pytest-qt so they
@@ -1035,7 +1059,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
10351059
the manifest's session id, which can differ from the id the reader derives. Blob enrichment is
10361060
limited to idtracker.ai readers. Cached sessions made by the faulty path are not reused (cache
10371061
schema 3), so a rerun may recompute once.
1038-
10391062
- **A session in the legacy idtracker.ai layout could not be opened by auto-detection.**
10401063
A raw `trajectories.npy` array beside a `video_object.npy` was claimed first by the
10411064
unified reader, which then failed with `IDT_FORMAT_AMBIGUOUS` ("expected a dict, got

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
You tracked your animals. idtracker.ai gave you a folder of trajectories.
66
Track2Data turns that into tables you can put straight into R or Python:
7-
50 behavioural metrics, every one with a citation, in documented units,
7+
51 behavioural metrics, every one with a citation, in documented units,
88
with a record of exactly which frames were measured and which were
99
reconstructed.
1010

@@ -201,7 +201,7 @@ every export's `manifest.json`.
201201

202202
A rendered site is published from these files at
203203
**<https://mbel-tech.github.io/Track2Data/>**, including a browsable
204-
catalogue of all 50 metrics with their formulas, units and DOIs.
204+
catalogue of all 51 metrics with their formulas, units and DOIs.
205205

206206
The **[wiki](https://github.com/mbel-tech/Track2Data/wiki)** covers what sits
207207
around that reference material and is not pinned to a release:

‎app/main_window.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def __init__(self, parent: QWidget | None = None) -> None:
187187
self._store.sessionsChanged,
188188
self._store.calibrationChanged,
189189
self._store.zonesChanged,
190+
self._store.sceneChanged,
190191
self._store.metadataChanged,
191192
self._store.preprocessChanged,
192193
self._store.metricsChanged,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 3-D movement: roadmap
2+
3+
**Status:** approved 2026-10-08. Sub-project C is in progress; A, B and D are not started.
4+
**Relates to:** `docs/dev/DECISIONS.md` D-031, `docs/dev/ROADMAP.md` (Z-10),
5+
`docs/tracker-formats/2026-10-07-tracker-import-design.md` (Tier 3)
6+
7+
"Integrate 3-D movement" is four independent projects. Each gets its own spec, plan and
8+
build cycle.
9+
10+
| | Sub-project | Needs first |
11+
|---|---|---|
12+
| **C** | **Side-view depth**: a camera-view setting and a continuous vertical-position metric from ordinary 2-D side recordings | nothing unmerged, no 3-D data |
13+
| A | Read 3-D tracker files (Anipose pose-3d CSV, DLC-3D). Metrics run on a chosen plane and z is stored (D-031 as written) | `feat/native-units` merged |
14+
| B | Metrics that use z: 3-D speed and path length, vertical position, 3-D neighbour distance. **Amends D-031** | A for data, C for the vertical-axis setting |
15+
| D | Fuse top and side recordings into one 3-D session | B's data model, frame sync, identity matching across views |
16+
17+
**Order: C, A, B, D.** A moves first if real 3-D files turn up. C goes first because no data
18+
of any kind exists yet, it is testable on synthetic tracks, and it creates the project-level
19+
camera-view setting that B reuses.
20+
21+
## Hand-offs between the sub-projects
22+
23+
- `KeypointSelection.plane` and `camera_view` have no defined precedence. A and B must define
24+
a vertical axis for 3-D data.
25+
- The `has_pixel_frame` guard from native-units joins the IL-15 extent derivation when A lands.
26+
- Per-session camera views arrive with D (`Engine.camera_view_for(session)` is the seam).
27+
- Whether IL-3 and IL-14, which assume a top-down view, should be gated for side views is
28+
left open.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Side-view depth: camera-view setting and IL-15
2+
3+
**Status:** approved 2026-10-08 (sub-project C of [the 3-D roadmap](2026-10-08-3d-roadmap.md))
4+
5+
## Why
6+
7+
Stacked secondary-level zones already give band occupancy, latency, visits, transitions and
8+
dwell on a side view (Z-1 to Z-9). Missing: a way to say a recording *is* a side view
9+
(ROADMAP Z-10's blocker), a continuous depth measure, and a guard so "depth" is never
10+
computed from a top-down y axis.
11+
12+
## Decisions
13+
14+
- Depth runs 0 = water surface to 1 = tank floor. Height above the floor is `1 - value`.
15+
- The metric is **IL-15**, not Z-10: exports bucket metrics by ID prefix and the UI by level.
16+
Z-10 is re-reserved for auto depth bands.
17+
- Camera view is project-level. A per-session override arrives with sub-project D.
18+
- Existing metrics are not gated by camera view in this cycle.
19+
20+
## Design
21+
22+
1. **Setting.** `ProjectManifest.scene: SceneConfig` with `camera_view: "unknown" | "top" |
23+
"side"` (default `unknown`). Top-level, not in `ZoneSet` (Zones Clear/Load/Import replaces
24+
it) nor `CalibrationConfig` (hashed into the cache key). Store: `update_scene()` and
25+
`sceneChanged`.
26+
2. **Gating.** `Metric.valid_camera_views: frozenset | None` (None = any view; IL-15 =
27+
`{"side"}`). One predicate returns `{metric_id: reason}`; `Engine.skipped_metrics` merges
28+
identity and view reasons. `compute()` called directly with no water column still returns
29+
every column as NaN.
30+
3. **Extent.** `zones/extent.py` pools min/max y over every main-level "+" ROI vertex. No
31+
usable zone gives NaN and a token (`none:no_main_zone`, `none:degenerate_zone`,
32+
`none:frame_size_mismatch`, `none:not_derived`), never the frame height.
33+
4. **IL-15.** With `T`, `B` the surface and floor rows and `d = (y - T) / (B - T)` over frames
34+
inside `[T, B]`: `mean_depth_fraction`, `median_depth_fraction`, `sd_depth_fraction`
35+
(ddof 1), `mean_depth_cm` (NaN uncalibrated), `frac_outside_extent`, `depth_extent_source`.
36+
Out-of-extent frames are dropped and counted, never clipped.
37+
5. **Zones canvas.** For every reader except idtracker.ai v6 the canvas was a blank 640x480
38+
scene and saved zones carried no frame size, so zones were not in video pixels. The scene
39+
is now sized from the session frame, and `source_*_px` is stamped only when the ZoneSet has
40+
no ROIs yet. This gives correct units, not a backdrop to draw on.
41+
6. **UI.** A camera-view combo on the Calibration screen; a Zones-stage warning; one
42+
availability pass on the Metrics screen.
43+
7. **Provenance.** `SessionProvenance.camera_view` and README rows, written only when declared
44+
or when IL-15 is computed.
45+
46+
## Not in this cycle
47+
48+
Auto depth bands, vertical speed, freezing-by-depth, typed surface/bottom rows, a depth plot,
49+
any 3-D handling, gating IL-3/IL-14, and a Zones-canvas backdrop for non-idtracker.ai sessions.

‎docs/METRICS_SPEC.md‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ exporters, not metrics.
9393
**Binning rules.** Each bin is a slice of the session, but anything a metric
9494
derives *from the data* is resolved once on the whole session so bins stay
9595
comparable: the IL-4/IL-7 activity threshold (`mean speed x multiplier`), the fitted
96-
bout criterion (IL-7, Z-3/Z-4/Z-5), the IL-3/IL-14 arena, the Z-2/Z-8 zone areas.
96+
bout criterion (IL-7, Z-3/Z-4/Z-5), the IL-3/IL-14 arena, the IL-15 water column, the
97+
Z-2/Z-8 zone areas.
9798
Consequences: IL-1 path length loses the one step across each bin edge, so bins sum
9899
to slightly less than the whole session; Z-1 `time_s` is exactly additive; Z-6
99100
`first_entry_t_s` is a latency from the start of the bin. Z-5 event `frame`/`t_s` stay
@@ -127,6 +128,7 @@ Level Category IDs
127128
Individual Locomotion IL-1, IL-2, IL-6
128129
Activity / freezing IL-4, IL-7
129130
Space use IL-3, IL-9, IL-10, IL-14
131+
Vertical position IL-15
130132
Path geometry IL-5, IL-8, IL-11
131133
Group Social spacing GL-1, GL-2, GL-13
132134
Cohesion GL-4, GL-6, GL-10, GL-15
@@ -389,6 +391,24 @@ info-button modal (§6).
389391
| **Reference** | Simon et al. 1994, Behav. Brain Res. 61(1):59-64 (thigmotaxis as an index of anxiety in mice) — DOI [10.1016/0166-4328(94)90008-6](https://doi.org/10.1016/0166-4328(94)90008-6) |
390392
| **Supporting references** | Schnorr et al. 2012, Behav. Brain Res. 228(2):367-374 (thigmotaxis in larval zebrafish) (DOI: 10.1016/j.bbr.2011.12.016); Maximino et al. 2010, Behav. Brain Res. 214(2):157-171 (measuring anxiety in zebrafish: a critical review) (DOI: 10.1016/j.bbr.2010.05.031) |
391393

394+
#### IL-15 — Vertical position (depth)
395+
396+
| Field | Value |
397+
|---|---|
398+
| **Manuscript label** | Vertical position (depth in the water column) |
399+
| **Level** | Individual; trial summary |
400+
| **Priority** | Optional |
401+
| **Inputs** | `PreprocessedSession.xy` (the y column); the water column, derived per session from the main zones (never user-supplied); `px_per_cm` when calibrated |
402+
| **Required preprocessing** | Zone assignment is not needed; main-level zones must exist. The project's **camera view must be set to side view** (Calibration screen) or the metric is skipped and the run records why |
403+
| **Formula** | `T`, `B` = top and bottom image rows of the main zones (`T < B`); `d[t,k] = (y[t,k] − T) / (B − T)` for frames with `T ≤ y[t,k] ≤ B`; `mean_depth_fraction`, `median_depth_fraction` and `sd_depth_fraction` (n − 1) over those frames; `mean_depth_cm = mean(y − T) / px_per_cm`; `frac_outside_extent` = share of non-NaN frames with `y < T` or `y > B` |
404+
| **Output columns** | `individual_id`, `mean_depth_fraction`, `median_depth_fraction`, `sd_depth_fraction`, `mean_depth_cm`, `frac_outside_extent`, `depth_extent_source` |
405+
| **Units** | fraction (0 = water surface, 1 = tank floor); cm; fraction; categorical |
406+
| **Assumptions** | The project declares a side camera view, and the top edge of the main zones is the water surface and the bottom edge the tank floor. The camera is upright: image rows grow downward, so a larger y is deeper. Every main-level additive ("+") zone is pooled into one column, so tanks side by side share it; tanks stacked on top of each other would pool into one tall column. Subtractive ("−") zones and secondary-level zones do not move the extent. Frames outside the column are dropped and counted, never clipped to the surface or floor. Interpolated frames are included. |
407+
| **Warnings** | No refraction or parallax correction: a fish near the front glass looks larger and sits at a different apparent depth than one at the back, and depth in cm uses a single scale for the whole picture. A column taken from zones that do not match the video, or a tracker following reflections, shows up as a high `frac_outside_extent` (a warning is logged above 5 %). Without a main zone there is no depth: the values are NaN and `depth_extent_source` says why (`none:no_main_zone`, `none:degenerate_zone`, `none:frame_size_mismatch` for zones drawn at another recorded frame size, `none:not_derived`); the video frame is never used instead. Depth is measured from the surface; height above the floor is `1 − depth`. For band occupancy, latency, visits and dwell on a side view, draw stacked secondary-level zones and use Z-1 to Z-9. |
408+
| **Parameters** | `water_column` is `derived=True` and cannot be overridden. |
409+
| **Reference** | Standard descriptive statistic of vertical position in the water column; no single originating work defines this mean-depth fraction. The construct, vertical position as a behavioural measure in novel-tank assays, is in the supporting references. |
410+
| **Supporting references** | Cachat et al. 2010, Nat. Protoc. 5(11):1786-1799 (measuring behavioral and endocrine responses to novelty stress in adult zebrafish) (DOI: 10.1038/nprot.2010.140); Egan et al. 2009, Behav. Brain Res. 205(1):38-44 (understanding behavioral and physiological phenotypes of stress and anxiety in zebrafish) (DOI: 10.1016/j.bbr.2009.06.022); Maximino et al. 2010, Behav. Brain Res. 214(2):157-171 (measuring anxiety in zebrafish: a critical review) (DOI: 10.1016/j.bbr.2010.05.031); Stewart et al. 2012, Neuropharmacology 62(1):135-143 (modeling anxiety using adult zebrafish: a conceptual review -- no operational threshold given) (DOI: 10.1016/j.neuropharm.2011.07.037); Kalueff et al. 2013, Zebrafish 10(1):70-86 (towards a comprehensive catalog of zebrafish behavior 1.0 and beyond) (DOI: 10.1089/zeb.2012.0861) |
411+
392412
### 4.2 Zone metrics
393413

394414
#### Z-1 — Time in each zone
@@ -804,6 +824,7 @@ three together.
804824
| IL-10 Roaming Entropy | ❌ | Per-animal time series |
805825
| IL-11 Circular Statistics of Heading | ❌ | Per-animal time series |
806826
| IL-14 Wall-Distance Thigmotaxis | ❌ | Per-animal time series |
827+
| IL-15 Vertical Position (Depth) | ❌ | Per-animal time series |
807828
| GL-1 Nearest-Neighbour Distance | ✅ | Unordered point set per frame |
808829
| GL-2 Inter-Individual Distance | ✅ | Unordered point set per frame |
809830
| GL-3 Polarisation | ❌ | Heading requires per-individual tracklets |
@@ -1130,6 +1151,7 @@ Every metric ID maps to a concrete class in `track2data/metrics/*.py`.
11301151
| IL-9, IL-10 | `metrics/individual.py` | `HomeBaseOccupancy`, `RoamingEntropy` | Share `_occupancy_grid_counts` |
11311152
| IL-11 | `metrics/individual.py` | `CircularHeadingStats` | np-only; Zar's Rayleigh-test approximation |
11321153
| IL-14 | `metrics/individual.py` | `WallDistanceThigmotaxis` | `shapely` -- the only IL-* metric with that dependency |
1154+
| IL-15 | `metrics/individual.py` | `VerticalPosition` | np-only; the water column comes from `zones/extent.py`, derived in `metrics/derived.py`; gated by `Metric.valid_camera_views` (`metrics/availability.py`) |
11331155

11341156
### 5.1 Shared computations (no duplicated work)
11351157

@@ -1360,7 +1382,7 @@ exposed so future per-user opt-outs are non-breaking.
13601382
flicker debounce. The GUI's ⚙ button now opens `MetricConfigDialog`
13611383
(`ui/dialogs/metric_config_dialog.py`) for any metric that declares
13621384
`parameters`, one widget per parameter keyed off `MetricParameter.kind`;
1363-
it is disabled with an explanatory tooltip for the 15 of the 34
1385+
it is disabled with an explanatory tooltip for the 15 of the 35
13641386
metrics it lists that declare none (diagnostics always run and
13651387
aren't selectable there, so they don't count towards either
13661388
figure; both are pinned by

0 commit comments

Comments
 (0)