From c81222a0ace975ccf3b2c5c2ef39a61d2bb062b1 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 5 Dec 2026 06:09:18 +0100 Subject: [PATCH 1/2] feat(migrate): lookup and participants tables (T01 to T03) and the label 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 --- CHANGES.rst | 17 + tfmanager/cli.py | 73 + tfmanager/migrate/config.py | 213 +- tfmanager/migrate/config/2.0.0.yaml | 280 + tfmanager/migrate/config/schema.json | 157 +- tfmanager/migrate/content.py | 56 +- tfmanager/migrate/data/labels-2.0.0.tsv | 307 + tfmanager/migrate/data/labeltables-2.0.0.tsv | 18019 +++++++++++++++++ tfmanager/migrate/engine.py | 11 +- tfmanager/migrate/findings.py | 10 +- tfmanager/migrate/labels.py | 217 + tfmanager/migrate/lookups.py | 521 + tfmanager/tests/test_migrate_content.py | 47 +- tfmanager/tests/test_migrate_snapshot.py | 133 + tfmanager/tests/test_migrate_tables.py | 520 + 15 files changed, 20555 insertions(+), 26 deletions(-) create mode 100644 tfmanager/migrate/data/labels-2.0.0.tsv create mode 100644 tfmanager/migrate/data/labeltables-2.0.0.tsv create mode 100644 tfmanager/migrate/labels.py create mode 100644 tfmanager/migrate/lookups.py create mode 100644 tfmanager/tests/test_migrate_tables.py diff --git a/CHANGES.rst b/CHANGES.rst index 04715f2..d593828 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -37,6 +37,23 @@ Unreleased joins names and content: a renamed file whose bytes change gets an ``n/a`` row, so its old name keeps its old bytes. The config's ``edits`` correct fields of JSON files. A test pins the ``res`` blocks of the migrated Archive (``tests/data/res-2.0.0.tsv``). +* The tables of the migration to TemplateFlow 2.0 (``tfmanager.migrate.lookups``): lookup + tables take the BIDS columns ``index``, ``name``, ``abbreviation``, ``color`` (``#rrggbb``) + and ``mapping``, in UTF-8 with tabs and ``n/a``, rows sorted by index (T01). The config's + ``tables.layouts`` say how each other layout converts and describe the columns it keeps + in the table's JSON sidecar; the fsaverage tables are rebuilt from the label tables of + their GIFTI files. ``tables.sources`` writes tables from cited upstream files (T02), and + ``participants`` converts participants tables to ``participant_id`` (``sub-`` and the + letters and digits of the original, kept in ``source_id``), merging the rows of a + participant imaged more than once (T03). Descriptions of columns no table has are + removed. +* Every lookup table is checked against its images: label values without a row (M206) and, + for 4D probabilistic segmentations, rows that are not the volumes 1 to N block a plan; + segmentations without a table (M202), rows that label nothing (M207) and values stored + as non-integers (M208) are notes. New command ``tfmgr migrate labels ARCHIVE [--needs] + -o DIR`` reads the label values of every segmentation, and the label tables of GIFTI + files, into two tables keyed by md5, shipped with tfmanager + (``migrate/data/labels-2.0.0.tsv``, ``labeltables-2.0.0.tsv``). * New warning TF118 redundant-entity: a ``desc``, ``seg`` or ``label`` that tells its file apart from no other file of the template (``res``, ``den``, ``hemi`` and ``cohort`` aside). Masks keep ``desc``, probabilistic segmentations keep ``label``, and diff --git a/tfmanager/cli.py b/tfmanager/cli.py index a8902c3..ea95eb8 100644 --- a/tfmanager/cli.py +++ b/tfmanager/cli.py @@ -307,6 +307,79 @@ def headers(archive, templates, needs, output): click.echo(text, nl=False) +@migrate.command() +@click.argument('archive', type=click.Path(exists=True, file_okay=False), default='.') +@click.option( + '-t', '--template', 'templates', multiple=True, help='Only this template (tpl-