Skip to content

feat(migrate): the content of a template in TemplateFlow 2.0 - #22

Merged
oesteban merged 2 commits into
masterfrom
feat/migrate-content
Dec 4, 2026
Merged

oesteban merged 2 commits into
masterfrom
feat/migrate-content

Conversation

@oesteban

@oesteban oesteban commented Dec 4, 2026

Copy link
Copy Markdown
Member

Summary

PR 5 of the migration to TemplateFlow 2.0 (WP4). It plans the content of each template after its renames, then joins names and content into one plan. Lookup tables (PR 5b) and licenses, authors and atlases (PR 5c) follow as their own PRs.

plan_template(snapshot, config, headers, date, authored)      # migrate/engine.py
  plan_names                                                  # PR 4, plus R21 and R22
  plan_content                                                # migrate/content.py
    T05  JSON: bids:: URIs, file names, Resolution keys, TemplateFlow cache paths
         config edits (fields to set or remove, with the reason)
    T06  template_description.json: res blocks of the res plan, RRID:, Funding list,
         cohort age [min, max], units in full, sex (was gender), DOIs as URLs
    T10  files written by hand (README.md, docs/)            # M201 while README is missing
    T08  generated files (cohorts tables)
    T09  .gitattributes (the config's text)
    flip BIDSVersion 1.11.0 + TemplateFlowVersion 2.0.0, only if strict-clean   # else M205
    T11  2.0.0 entry at the top of CHANGES, only with the flip
  rows       rename rows; n/a for renamed text files whose bytes change (freeze), and deletions
  fingerprints of the snapshot and of the result

Names addendum (golden renames table: 3 rows change):

 tpl-MNI152NLin2009cAsym
-  res-01_desc-brain_probseg  ->  res-1_desc-brain_probseg              R16
+  res-01_desc-brain_probseg  ->  res-1_label-brain_probseg             R16 R21 R22 (a 2020 copy of label-brain)
-  res-02_atlas-HOSPA_probseg ->  atlas-HOSPA_res-2_probseg             R16 R99
+  res-02_atlas-HOSPA_probseg ->  n/a                                   empty-HOSPA-probseg (every voxel is 0)
 tpl-WHS
+  res-2_desc-brain_probseg   ->  res-2_label-brain_probseg             R21
  • R21: a probseg of one volume (from the header facts) names its class with label.
  • R22: a file renamed onto a file with the same bytes merges into it, and its row points there.

Config (migrate/config/2.0.0.yaml):

 policies:
   res_key: zoom
+  content_change: freeze
+  flip: when-clean
+gitattributes: |            # binary files and *.gii in the annex; json, tsv, md, txt, LICENSE, CHANGES in git
+edits:
+  - id: Diedrichsen2009-source   # Source: a path on its author's Mac -> its path in SourceRepository

The Diedrichsen2009 source was checked: at SourceCommit, Diedrichsen_2009/atl-Anatom_space-MNI_dseg.nii has the sidecar's SourceSHA256.

Evidence

  • Before: the Archive after PR 4's renames only, validated in strict mode at the metadata level: 2988 errors.
    After: every template planned from the pinned v2 skeleton (python-client 45755e5): 374 errors, and no plan is blocked.

    Left after this PR Errors Where it goes
    TF401, TF402, TF403, TF404, TF406, TF407 168 PR 5b (lookup tables)
    TF310, TF502, TF504, TF505, TF601, TF608, TF301 (fsaverage Authors) 144 PR 5c (licenses, authors, atlases)
    TF340 (README.md) 24 WP5, written by hand
    TF314 (30), TF301 (8, four templates without version fields) 38 the flip, once a template is clean

    Gone: TF117, TF309, TF312, TF320, TF330, TF410, and the TF301 of res, cohorts and Funding.

  • test_migrate_content.py (17 tests):

    • each transform on small templates;
    • the flip both ways: a clean template gets its versions and its CHANGES entry; one that is not clean gets M205 and keeps both;
    • frozen rows;
    • fingerprints;
    • config checks;
    • on the whole Archive: pinned counts, check_fragment on every new .renames.tsv, and idempotence (planning the migrated Archive writes nothing and gives the same result fingerprint).
  • tests/data/res-2.0.0.tsv pins the res blocks: 30 kept, 4 rebuilt, 24 new.

  • Local mirror of pythonapp.yml: ruff and 313 tests on Python 3.13 and 3.15; the sdist and wheel build, pass twine check, and install with the same version.

Rebuilt and new res blocks
template res cohort zooms shape origin status
Fischer344 1 0.06 287, 477, 211 -9.1404, -16.1905, -0.8455 new
MNI152Lin 3 2 91, 109, 91 -90, -126, -72 new
MNI152NLin2009aAsym 1 1 197, 233, 189 -98, -134, -72 rebuilt
MNI152NLin2009aAsym 2 1 197, 103, 74 -98, -4, -72 new
MNI152NLin2009aAsym 4 4 46, 32, 59 -93.2, 14.9259, -167.0882 new
MNI152NLin2009aSym 1 1 197, 233, 189 -98, -134, -72 rebuilt
MNI152NLin2009aSym 2 1 197, 103, 74 -98, -4, -72 new
MNI152NLin2009aSym 4 4 46, 32, 59 -93.2, 14.9259, -167.0882 new
MNI152NLin2009cAsym 5 1 545, 653, 545 -272, -344, -254 new
MNI152NLin2009cAsym 6 2 104, 123, 104 -96, -132, -78 new
MNI152NLin2009cAsym 7 2 273, 327, 273 -272.5, -344.5, -254.5 new
MNI152NLin2009cAsym 8 3 104, 123, 104 -96, -132, -78 new
MNI152NLin6Sym 2 1 197, 103, 74 -98, -4, -72 new
MNI305 1 1 172, 220, 156 -86.095, -126.51, -68.25 new
MNI305 2 2 86, 111, 79 -86.095, -126.51, -68.25 new
MNIColin27 1 1 181, 217, 181 -90, -126, -72 new
MouseIn 1 0.15 108, 108, 64 -8.6191, -8.2339, -3.3092 rebuilt
MouseIn 2 0.025 456, 528, 320 -5.7, -7.9125, -2.7125 rebuilt
MouseIn 3 0.15 108, 108, 64 -8.6149, -8.2339, -3.3092 new
NKI 2 1 192, 256, 256 -95.5, -99.7603, -131.9588 new
NMT31Sym 1 0.25 400, 400, 300 -49.875, -38.75, -20.5 new
NMT31Sym 2 0.5 128, 156, 100 -31.75, -27.625, -7.875 new
RESILIENT 1 0.19 160, 160, 128 -15.5821, -12.033, -12.4577 new
RESILIENT 1 2 -15.1129, -12.1553, -12.2591 new
RESILIENT 1 3 -14.8654, -12.0066, -13.0358 new
RESILIENT 1 4 -15.1129, -12.6297, -14.3589 new
VALiDATe29 1 0.3 212, 212, 212 -31.5, -31.5, -31.5 new
dhcpVol 1 0.5 202, 274, 217 -48.5312, -84.5313, -39.0078 new

Zooms are isotropic. RESILIENT follows effective_grid: the template block takes cohort 1's grid, and the other cohorts override its origin.

Merge Danger

Door: two-way. Nothing in this PR touches a template: plans live in memory, and apply comes in PR 6.

Blast Radius: internal.

  • Library code only: there is no new command, and tfmgr validate, generate and add are unchanged.
  • Config gains fields with defaults.
  • The golden renames table changes in the 3 rows above.

oesteban and others added 2 commits December 4, 2026 15:10
R21: a probabilistic segmentation of one volume (from the header facts) names its
class with label, so desc-brain_probseg becomes label-brain_probseg in
MNI152NLin2009cAsym (res-1) and WHS (res-2). A 4D probseg keeps its desc.

R22: a file renamed onto a file with the same bytes merges into it. Its old name
stays a row of the renames table, pointing at the file it merges into. In
MNI152NLin2009cAsym, res-01_desc-brain_probseg was kept in 2020 as a copy of
res-01_label-brain_probseg; both old names now point at res-1_label-brain_probseg.

The empty res-02_atlas-HOSPA_probseg of MNI152NLin2009cAsym (every voxel 0) is
removed by a decision of the config (an n/a row).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
migrate.content plans the text files of a template after its renames:

- T05: bids:: URIs and file names in JSON strings follow the renames, and so do
  Resolution keys; paths into a TemplateFlow cache become bids:: URIs.
- T06: template_description.json takes the res blocks of the res plan (kept
  blocks keep their values; rebuilt and new ones take their files' grid; cohorts
  override what differs), RRID prefixes, Funding as one item per grant, cohort
  ages as [min, max] with units in full, sex for gender, DOIs as URLs.
- T10: files written by hand; T08: the generated files (cohorts tables);
  T09: the config's .gitattributes.
- The flip: BIDSVersion and TemplateFlowVersion change only when the result
  passes the validator in strict mode (metadata level); then T11 writes a
  2.0.0 entry at the top of CHANGES. Otherwise M205 says why.

The config gains its policies (content_change: freeze, flip: when-clean), the
.gitattributes text and edits of JSON fields. The first edit gives the
Diedrichsen2009 sidecar of MNI152NLin6Asym its source path inside
SourceRepository; at SourceCommit, that file has the sidecar's SourceSHA256.

migrate.engine.plan_template joins names and content, and derives the rows: a
renamed text file whose bytes change gets n/a (its old name keeps its old
bytes), and so do deleted files. Plans are deterministic, and carry the
fingerprints of their snapshot and of their result.

On the Archive, strict errors fall from 2988 to 374 and no plan is blocked;
the rest are lookup tables, licenses, authors and atlases (PR 5b and 5c), and
README files (WP5). tests/data/res-2.0.0.tsv pins the res blocks.

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

chatgpt-codex-connector Bot commented Dec 4, 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-04T17:12:43.720236Z 4f6bffe 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.

@oesteban
oesteban merged commit b30fd4e into master Dec 4, 2026
6 checks passed
@oesteban
oesteban deleted the feat/migrate-content branch December 4, 2026 17:11
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