Skip to content

Commit 8549b09

Browse files
authored
Merge pull request #140 from mbel-tech/fatina-del-codice/beautiful-hypatia-wlxfol
docs: describe ID correspondence between views (G)
2 parents b00ab90 + 69f3b99 commit 8549b09

6 files changed

Lines changed: 80 additions & 11 deletions

File tree

‎CHANGELOG.md‎

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

1010
### Added
1111

12+
- **ID correspondence between views (3-D projects).** A new **Views** page (page 10, under the Sessions row of the sidebar, reached by Next/Back between Sessions and Calibration; 3-D projects only) records which session is the top view and which the side view, pairs them by two session-name patterns with a `key` group (with an ⓘ help and a live "catches N sessions" line) or by hand, and maps each top-view fish to a side-view fish: by a "Same IDs" tick, or in a table with two highlighted track plots. The project file gains `SessionRef.view_role`, `view_pairs` and `mode.pairing`; `mode.id_map` is gone (projects that contain it still load). It never blocks Next, and 3-D projects still cannot be run.
1213
- **Session calibration works beyond idtracker.ai.** The Calibration screen describes the mode per tracker, with an ⓘ note linking to each tracker's documentation, and disables it when no session can supply a scale. DeepLabCut, SLEAP and Ctrax raw files take an optional **Scale (pixels per cm)** import option.
1314
- **`trx.mat` reader (Ctrax / FlyTracker / JAABA).** Built from the documented layout, unverified against a real sample. `pxpermm` becomes the session scale.
1415
- **Average or median of several idtracker.ai length calibrations.** The average (idtracker.ai's own `length_unit`) stays the default.

‎docs/3d-movement/2026-10-08-3d-roadmap.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build cycle.
1111
|---|---|---|
1212
| **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 |
1313
| **E** | **2D/3D project mode**: `ProjectManifest.mode`, Project-screen choice, lock, 3-D compute blocked. Done; see [the spec](2026-10-09-mode-switch-design.md) | nothing |
14-
| G | **ID correspondence**: view roles, pairing top and side sessions (regex or by hand), fish mapping between views, a Views step. In design; see [the spec](2026-10-09-id-correspondence-design.md) | E |
14+
| G | **ID correspondence**: view roles, pairing top and side sessions (regex or by hand), fish mapping between views, a Views step. Done; see [the spec](2026-10-09-id-correspondence-design.md) | E |
1515
| 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 |
1616
| 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 |
1717
| D | Fuse top and side recordings into one 3-D session | B's data model, frame sync, identity matching across views |

‎docs/3d-movement/2026-10-09-id-correspondence-design.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ID correspondence between views (sub-project G)
22

3-
**Status:** draft 2026-10-09, awaiting review
3+
**Status:** implemented
44
**Part of:** [the 3-D roadmap](2026-10-08-3d-roadmap.md). Builds on [the mode switch](2026-10-09-mode-switch-design.md) (sub-project E).
55

66
## Why
@@ -48,10 +48,11 @@ G is built and tested against any two sessions, so it does not wait for F.
4848
1. **Data model** (`track2data/core/models.py`).
4949
- `SessionRef.view_role: Literal["top", "side"] | None = None`.
5050
- `ViewPair(top_session_id: str, side_session_id: str, same_ids: bool = False,
51-
fish_map: dict[str, str] = {})`. `fish_map` maps a top-view label to a side-view label; a fish
52-
not in it is unmatched.
51+
fish_map: dict[str, str] = {}, auto: bool = False)`. `fish_map` maps a top-view label to a
52+
side-view label; a fish not in it is unmatched. `auto` marks pairs made by the pattern. A
53+
session belongs to at most one pair.
5354
- `PairingPatterns(top_regex: str = "", side_regex: str = "")`, stored as
54-
`ProjectMode.pairing`.
55+
`ProjectMode.pairing` and edited through `modeChanged`.
5556
- `ProjectManifest.view_pairs: list[ViewPair] = []`.
5657
- Labels are `Session.identities_labels`, falling back to the 0-based index as text (the same
5758
fallback as `MappingRule.individual_match`).
@@ -70,16 +71,16 @@ G is built and tested against any two sessions, so it does not wait for F.
7071
hand-made ones), `update_view_pair(pair)`, `remove_view_pair(top_id, side_id)`, and a
7172
`viewsChanged` signal wired into `_on_manifest_changed`. Removing a session removes its pairs
7273
and clears nothing else. All of this is for 3-D projects only; the calls are rejected in 2-D.
73-
4. **The Views step** (`ui/views_screen.py`, 3-D only, between Sessions and Calibration).
74+
4. **The Views step** (`ui/views_screen.py`, 3-D only: page 10, belongs to the Sessions sidebar row, reached by Next/Back between Sessions and Calibration in 3-D projects).
7475
- *Roles and patterns.* A role selector per session and the two regex fields. Each field has an
7576
ⓘ popover in plain language (what `key` is, three worked examples such as `trial01_top`, and
7677
a live "this catches N sessions" line), plus a preview that lists unpaired sessions.
7778
- *Pairs.* One row per pair with the "same IDs" tick, a status (matched, needs matching,
7879
identity-free) and a manual re-pair option.
7980
- *Matching.* A table with one row per top-view fish and a dropdown for the side-view fish or
8081
"no match"; beside it two `TrajectoryView` plots with the selected fish highlighted.
81-
5. **Navigation.** The sidebar and page lists are static today. Views is a new page, shown only in
82-
3-D projects; in 2-D it is hidden and skipped by Next and Back. `screen_flow(mode)` returns
82+
5. **Navigation.** The sidebar and page lists are static today. Views is a new page (page 10, belongs to the
83+
Sessions sidebar row), shown only in 3-D projects; in 2-D it is hidden and skipped by Next and Back. `screen_flow(mode)` returns
8384
which variant of the Sessions-to-Calibration route to show. `stage_status` marks Views `empty`
8485
until every session has a role, `warning` while any pair needs matching or is identity-free,
8586
and `valid` when every pair has a complete map. It never returns `blocked`.

‎docs/3d-movement/2026-10-09-mode-switch-design.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ F and G are independent of each other. Order: E, F and G, D, B.
2929
- The mode is locked once the project has a session. Removing every session unlocks it.
3030
- A 3-D project cannot run the pipeline or export until D and B exist. Sessions can still be added
3131
and the project saved.
32-
- ID correspondence is not built here. E reserves its place in the file (`mode.id_map`) only.
32+
- ID correspondence is not built here. E reserves its place in the file (`mode.id_map`) only. (G later replaced `id_map` by `view_pairs` and `mode.pairing`.)
3333

3434
## Design
3535

3636
1. **Model.** `ProjectMode` in `core/models.py`:
3737
- `dimension: "2d" | "3d"` (default `"2d"`)
3838
- `layout: None | "single_video_two_panels" | "two_videos"` (default `None`)
39-
- `id_map: dict[str, str]` (default `{}`, reserved for G, never read or written in E)
39+
- `id_map: dict[str, str]` (default `{}`, reserved for G, never read or written in E; replaced by `view_pairs` and `mode.pairing` in G)
4040

4141
A validator requires `layout` to be set if and only if `dimension == "3d"`. Existing manifests
4242
have no `mode` key and load as 2-D unchanged. `ProjectManifest.mode: ProjectMode` is hashed into

‎docs/dev/DECISIONS.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,40 @@ have sessions added and be saved, but nothing computes: Processing, Preview and
860860
with "3-D fusion is not available yet". The gate is `Engine.require_computable()` and it covers
861861
every compute entry point, including `compute_metrics` and the `sensitivity` command, not only
862862
the screens, so the CLI and API cannot produce 2-D numbers for a 3-D project. *id_map.* Reserved
863-
for sub-project G (ID correspondence between views); E never reads or writes it. *Order.* E, then F
863+
for sub-project G (ID correspondence between views); E never reads or writes it. (G replaced it by
864+
`view_pairs` and `mode.pairing`; see D-038.) *Order.* E, then F
864865
(panel split) and G in either order, then D, then B.
865866

866867
**Rationale:** Fusion, ID correspondence and 3-D metrics all need to know the dimension and the
867868
recording layout first, and need it fixed before sessions exist. Running the 2-D pipeline on a
868869
3-D project would give plausible but wrong results, so refusing at the engine is safer than
869870
hiding buttons.
871+
872+
### D-038 · ID correspondence between views: G owns the pair record, pairing is by regex, and the Views page never blocks
873+
874+
**Status:** accepted; implemented. Design: `docs/3d-movement/2026-10-09-id-correspondence-design.md`
875+
(sub-project G of `docs/3d-movement/2026-10-08-3d-roadmap.md`). Replaces the reserved `id_map` of D-037.
876+
877+
**Decision:** *Ownership.* G owns the pair record and the fish mapping: `ProjectManifest.view_pairs`
878+
holds `ViewPair(top_session_id, side_session_id, same_ids, fish_map, auto)` and `SessionRef.view_role`
879+
is `top`, `side` or unset. `mode.id_map` is removed (a manifest that still contains it loads, the key
880+
is ignored) and replaced by `view_pairs` plus `mode.pairing` (`PairingPatterns`, a top and a side
881+
regex, both empty by default). *Pairing.* Two regexes, searched in the session id, each with a `key`
882+
group; sessions with an equal key pair up. An empty `key` means no match, and a key shared by several
883+
sessions on one side is ambiguous and not paired. A session belongs to at most one pair. *Same IDs.*
884+
A per-pair tick says fish with the same label are the same fish; otherwise the user matches by hand.
885+
*Identity-free.* A session without stable identities cannot be matched; the pair is flagged "cannot
886+
match fish: this session has no stable identities" (matching by geometry is not done). *auto.*
887+
Applying the pattern again replaces the pairs it made earlier (`auto=True`) and never touches
888+
hand-made ones. *Navigation.* Views is page 10, belongs to the Sessions sidebar row, shows only in 3-D
889+
and is reached by Next and Back between Sessions and Calibration; `PAGE_NAMES` keeps its ten entries.
890+
*Gate.* Pairs never block Next (3-D cannot compute anyway); the Views status is never `blocked`.
891+
*Status.* The sidebar status uses manifest data only (roles, pairs, `same_ids`, a non-empty map),
892+
while the page validates fish maps strictly (duplicate, unknown labels, counts) against the sessions'
893+
labels.
894+
895+
**Rationale:** A fish mapping hangs off a pair of sessions, and one project-wide dictionary cannot
896+
describe many pairs, so the pair record and its UI belong with the mapping. Regex pairing scales to
897+
many trials, and the manual path covers names that follow no rule. Keeping hand-made pairs out of
898+
re-pairing means a correction is never silently undone. Fusion (D) will be the stage that requires
899+
complete pairs.

‎docs/guide/USER_GUIDE.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,43 @@ sidebar shows ⚠ while any session is identity-free.
185185
- Supported: idtracker.ai 6.x output (the legacy v5 layout is also read). v4 is not supported yet (Track2Data tells you so if it recognises a v4 folder; see
186186
[sending a v4 sample](../IDTRACKERAI_V4_SAMPLES.md)).
187187

188+
### Views (3-D projects)
189+
190+
In a 3-D project (set on the Project screen) every fish is tracked in two views, so Track2Data has
191+
to know which session is the top view, which is the side view, and which top session goes with
192+
which side session. This is the **Views** page. It appears only in 3-D projects, under the
193+
**Sessions** row of the sidebar, and **Next** and **Back** pass through it between Sessions and
194+
Calibration. In 2-D projects it does not exist.
195+
196+
- **Roles.** Each session has a **View** selector: *(not set)*, *Top* or *Side*.
197+
- **Pair by session name.** Two pattern fields, **Top sessions** and **Side sessions**, find the
198+
pairs from the session names. A pattern is a regular expression, searched anywhere in the session
199+
id, with a group called `key` that marks the part shared by both views. Sessions whose `key` is
200+
equal become a pair. Example: `(?P<key>.+)_top$` matches `trial01_top` with key `trial01`, and
201+
`(?P<key>.+)_side$` matches `trial01_side` with the same key, so the two are paired. The **ⓘ**
202+
button next to each field explains this in the app. A line under the fields says how many
203+
sessions each pattern catches and lists unpaired or ambiguous ones (several sessions with the
204+
same key are not paired). An empty `key` means no match. Press **Pair by pattern** to set the
205+
roles and create the pairs; pressing it again replaces the pairs it made earlier, and never
206+
touches pairs you made by hand.
207+
- **Pairs.** One row per pair, with a **Same IDs** tick, a **Status** and **Remove**. To pair by
208+
hand, choose a top and a side session below the list (only sessions with that role and not yet in
209+
a pair are offered) and press **Add pair**. A session belongs to at most one pair.
210+
- **Same IDs.** Tick it when fish with the same label are the same fish in both views; the fish map
211+
is then filled in from the labels. Leave it unticked to match by hand.
212+
- **Match fish.** Select a pair to get a table with one row per top-view fish and a dropdown for the
213+
side-view fish (or *(no match)*; a side fish already used is marked). Selecting a row highlights
214+
that fish and its match in the two track plots beside the table.
215+
- **Status.** *Needs matching*: no fish matched yet. *Matched*: a fish map exists (a tooltip lists
216+
fish still unmatched). Otherwise the status is the problem, for example "cannot match fish: this
217+
session has no stable identities" (identity-free sessions cannot be matched), "duplicate side
218+
fish: ...", "unknown top fish: ..." or "3 top fish vs 2 side fish". The sidebar badge is ○ until
219+
every session has a role, ⚠ while a session is unpaired or a pair needs matching or has no
220+
stable identities, and ✓ when every pair is matched. It never stops you from continuing.
221+
222+
This only records the correspondence. 3-D fusion and 3-D metrics do not exist yet, so a 3-D project
223+
still cannot be run: Processing, Preview and Export stay blocked.
224+
188225
## 3. Calibration
189226

190227
Calibration decides which units distances and speeds are reported in. Figure 4 shows the default,

0 commit comments

Comments
 (0)