Add fix_rbc_release_tr.py for the C-PAC TR bandpass bug#342
Closed
nx10 wants to merge 1 commit into
Closed
Conversation
Lets users of an RBC data release re-derive the cleaned BOLD with a correctly-bandpassed `3dTproject`, by patching the template-space `desc-head_bold.nii.gz` header (TR=0.0 on disk) with the TR read from the native-space `desc-preproc_bold.nii.gz` header before regression. Only the bandpass bug (#4 in docs/cpac_comparison.md) is addressed. Downstream derivatives (ALFF, ReHo, atlas timeseries, connectivity) are not regenerated; users wanting those should recompute from the fixed BOLD with their own tooling. Also promotes `_restore_tr` to a public `restore_tr` for reuse by external tooling.
Contributor
Author
|
Closing to revise — will reopen after iteration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For users who have already downloaded an RBC data release and want to fix the C-PAC TR/bandpass bug (#4 in
docs/cpac_comparison.md) without re-running anything upstream.How it works
Walks a release tree (
sub-*/ses-*/func/) and for each functional run:desc-preproc_bold.nii.gzheader (or accepts--tr-override).desc-head_bold.nii.gzheader — released withpixdim[4]=0.0, which gets silently coerced to 1.0 by AFNI inside C-PAC and ends up driving the bandpass off by 2x.apply_regression_bandpass(AFNI3dTproject -bandpass) using C-PAC's raw (unfiltered) regressors as the ort matrix.--output-dirtree. Originals untouched.Scope
Intentionally narrow — only fixes divergence #4. Downstream derivatives (ALFF, fALFF, ReHo, atlas timeseries, connectivity matrices) all sit downstream of the broken bandpass and are NOT regenerated; that's a follow-up if users want it (most of the RBC library functions are right there to call). Other divergences (#1 N4 discarded, #2 despike in template, #3 ALFF formula) are left as-is per the comparison doc's framing.
CLI
--verifydoes a sanity check on the first run: confirmshead_boldhas the broken TR and reports the expected TR from the native preproc_bold, so users can validate the bug is actually present before kicking off bulk work.Other changes
rbc.core.functional.resampling._restore_trto a publicrestore_tr(the script reuses it; internal callers + the longitudinal mock were updated).Test plan
uv run pytest tests/unit/scripts/— 8 new tests covering discovery, TR detection, dry-run, verify, participant-label filtering, and graceful skipping of incomplete runs.uv run pytest tests/unit -m unit— 710 passed (longitudinal mock target updated).uv run ruff check+uv run mypyon all touched files.ds000001fixture: discovery, TR detection, head_bold patching, 3dTproject command construction all verified. The actual AFNI call wasn't exercised here (Docker daemon was down locally) but the call site is the already-testedapply_regression_bandpass.