Skip to content

feat(migrate): lookup and participants tables (T01 to T03) and the label check - #23

Merged
oesteban merged 2 commits into
masterfrom
feat/migrate-tables
Dec 5, 2026
Merged

oesteban merged 2 commits into
masterfrom
feat/migrate-tables

Conversation

@oesteban

@oesteban oesteban commented Dec 5, 2026

Copy link
Copy Markdown
Member

Summary

PR 5b of the migration to TemplateFlow 2.0: lookup and participants tables, and a check of every lookup table against its images. The 54 missing tables and the MNI152NLin6Asym HOCPAL table come next (PR 5b2), each from a cited upstream source.

 plan_content
   T05 references, config edits
+  plan_tables                    # migrate/lookups.py
+    T01 layouts (config tables.layouts) or format only (BIDS columns)
+        fsaverage: rebuilt from the GIFTI label tables
+    T02 tables from cited files (config tables.sources; used by PR 5b2)
+    stale column descriptions removed
+    T03 participants (config participants)
+  check_labels                   # label facts vs. table rows
   T06, T08, T09, T10, T11
 tfmanager/migrate/
+├── labels.py                    # label facts: values of segmentations, GIFTI label tables
+├── lookups.py                   # T01 to T03, check_labels
 ├── data/
 │   ├── headers-2.0.0.tsv
+│   ├── labels-2.0.0.tsv         # 306 segmentations (path, md5, values, rounding, table)
+│   └── labeltables-2.0.0.tsv    # 77 GIFTI label tables, 18,018 rows (about 940 KB)
 └── config/2.0.0.yaml            # + tables.layouts (12), participants (2)
  • T01: lookup tables take the BIDS columns (index, name, abbreviation, color as #rrggbb, mapping), in UTF-8 with tabs and n/a, rows sorted by index. 12 layouts convert the other headers and describe the columns they keep in the table's JSON sidecar, each with its evidence:

    • CHARM/SARM levels;
    • DiFuMo overlaps;
    • CerebrA's Mindboggle columns;
    • FSL's centres of gravity;
    • and others.

    NKI and OASIS30ANTs mapping values move to BIDS 1.11.0 (CGM 8, SGM 9, BS 10, CBM 11).

  • fsaverage: the old index column held FreeSurfer annotation values. The tables are now rebuilt from the label tables of the .label.gii files:

    • one table per atlas when both hemispheres agree;
    • one per hemisphere otherwise.

    Where densities disagree, the 164k mesh wins (Desikan2006: FreeSurfer's temporal pole color, M210 note).

  • T03:

    • participant_id is sub- plus the letters and digits of the original ID, which source_id keeps.
    • OASIS30ANTs had 35 rows for 30 subjects. It now has one row per subject and an images column (2 for the five subjects with both OASIS-1 sessions).
    • The repeated rows of OAS1_0379 and OAS1_0395 said M. OASIS-1's oasis_cross-sectional.xlsx gives F for both sessions, and the config cites it.
  • Label check:

    • Blocking: image values without a row (M206), and 4D probseg tables whose rows are not volumes 1 to N.
    • Notes: segmentations without a table (M202, for PR 5b2), rows that label nothing (M207), non-integer values (M208).
    • The facts come from the new tfmgr migrate labels ARCHIVE [--needs] -o DIR, which reads them from a checkout with the image data present. They are keyed by md5, so plans need no image data.

Evidence

Planning the whole Archive from the pinned v2 skeleton (test_archive):

  • Before (master b30fd4e): 374 strict errors, including TF402 26, TF403 42, TF404 42 and TF406 4. No table checked against its images.
    After: 260 strict errors. Every TF402, TF403, TF404 and TF406 error is gone (114); TF401 (42, missing tables) and TF407 (12, 4D probseg) remain for PR 5b2.
Transforms T01 140 files, T03 4
Findings M202 54, M206 6, M207 6, M208 6, M210 2
Blocked tpl-MNI152NLin6Asym

MNI152NLin6Asym is blocked by a real defect the check found: its six HOCPAL volumes carry 43 to 45 label values that tpl-MNI152NLin6Asym_atlas-HOCPAL_dseg.tsv has no row for. PR 5b2 rebuilds that table from its upstream source.

Notes in the plans, for the WP5 template PRs:

  • NKI desc-malf_dseg: 207 labels stored as uint8 with a scale factor of 0.8118, so the values cannot be recovered. NKI's WP5 PR re-exports it from upstream.
  • SUIT Buckner2011 desc-confidence_dseg: float confidence maps, not segmentations.
  • NKI and OASIS30ANTs tissue maps: stored with a scale factor, and they check fine after rounding.
  • Rows that label nothing: CHARM scales 3 to 6 (1 to 5 rows each), VALiDATe (7), fsaverage Destrieux2005 (1, 2, 78).

Tests:

  • test_migrate_tables.py (21 tests) covers:
    • format-only tables, layouts, headerless and per-hemisphere tables;
    • the GIFTI rebuild with its preference and M210;
    • sources, participants with repeats and corrections;
    • the label check;
    • config errors.
  • The label facts, the CLI and the bundled coverage (306 of 306 segmentations) are tested in test_migrate_snapshot.py.
  • Planning the migrated Archive again writes nothing and gives the same notes (M210 aside: it notes a rebuild).
  • Local mirror of CI: 340 passed on 3.13 and 3.15, ruff clean; sdist and wheel pass twine check and ship both fact tables.

Merge Danger

Door: two-way

Library code, config and package data only; nothing in the Archive changes until a template's WP5 PR applies a plan.

Blast Radius: packaging

  • The wheel grows by about 1 MB (the two fact tables).
  • Once applied in WP5, a table whose name stays the same changes for every client (decision 1). That covers the format-only tables and the fsaverage atlases with one table. Tables that are renamed or split keep their old bytes under their old names (n/a rows): 71 in the Archive, 31 of them fsaverage.

…bel check

Lookup tables take the BIDS columns (index, name, abbreviation, color,
mapping) and format, rows sorted by index (T01). The config's
tables.layouts convert the 12 other layouts of the Archive and describe
the columns they keep in the table's sidecar; the fsaverage tables are
rebuilt from the label tables of their GIFTI files (the native 164k mesh
wins where densities disagree). tables.sources writes tables from cited
upstream files (T02, used by the next PR). participants converts the
NKI and OASIS30ANTs tables to participant_id and source_id; OASIS30ANTs
gets one row per subject and an images column, with the sex of
OAS1_0379 and OAS1_0395 from OASIS-1 (T03).

Every lookup table is checked against the label values of its images
(M206 to M208, M202) from label facts read by the new
`tfmgr migrate labels` and shipped as labels-2.0.0.tsv and
labeltables-2.0.0.tsv.

Strict errors of the planned Archive: 374 to 260. MNI152NLin6Asym stays
blocked by its HOCPAL table until the next PR rebuilds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oesteban
oesteban marked this pull request as ready for review December 5, 2026 05:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T05:25:09.919188Z c81222a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c81222a0ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tfmanager/migrate/lookups.py Resolved
A row with a missing cell was padded with n/a, so a missing middle field
shifted the later values into the wrong columns and the table still
converted. Such rows are now a conversion problem (M209), like rows with
too many cells. No table of the Archive has one, so no plan changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oesteban
oesteban merged commit 2997ccc into master Dec 5, 2026
6 checks passed
@oesteban
oesteban deleted the feat/migrate-tables branch December 5, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant