Add fix_rbc_release_tr.py for the C-PAC TR bandpass bug#343
Merged
Conversation
2144e0e to
9ac150e
Compare
kaitj
reviewed
May 22, 2026
Contributor
kaitj
left a comment
There was a problem hiding this comment.
A quick skimmed review, largely looks good. I think mostly checking against known entities currently (sub, ses, run, task) and defensive against space. Is it possible (for the datasets these are intended for) to encounter an entity that isn't accounted for?
158b55c to
7f4b3eb
Compare
140f360 to
c2b2e65
Compare
Lets users of an RBC data release re-derive a correctly-bandpassed cleaned BOLD and all downstream metrics, 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` before regression. Outputs land under a parallel `--output-dir` tree using the published release's filename conventions: * cleaned BOLD + bandpass-filtered regressors * ALFF / fALFF / ReHo at `desc-sm6`, `desc-smZstd`, `desc-zstd` * Atlas-based mean timeseries (`.1D`, `(n_timepoints, n_rois)`) * Pearson + nilearn partial-correlation matrices, per atlas Metrics compose `rbc.workflows.metrics.single_session_metrics` and `rbc.core.metrics.standardization.compute_zscore`. Atlas resolution goes through `rbc_resources.ATLAS_REGISTRY` so the release-name -> file mapping survives filename changes inside `rbc_resources`. The script ships with PEP 723 inline metadata so it can be invoked standalone via `uv run --script` without a clone. `--skip-metrics` falls back to BOLD-only behavior. `--verify` scans every discoverable run (header-only reads) and reports buggy / clean / inconclusive counts. `RBC_WORK_DIR` is scoped to the script's tempdir for the duration of the run so all niwrap exec folders get cleaned up. The TR-restore helper is inlined in the script (mirrors `rbc.core.functional.resampling._restore_tr`) so standalone PEP 723 runs against an unmodified `main` don't trip an ImportError on a symbol that isn't yet public.
c2b2e65 to
f1785bc
Compare
kaitj
reviewed
May 27, 2026
Existing file permissions were copied alongside the file itself, causing issues with overwrriting existing files even when in an temporary directory if user executing script did not have the appropriate permissions. This switches the `copy2` method used to `copyfile` which does not have this issue
Contributor
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.
Fixes the TR/bandpass bug (divergence #4) on a downloaded RBC release without re-running upstream.
For each functional run: reads the correct TR from the native
desc-preproc_bold.nii.gz, patches the template-spacedesc-head_bold.nii.gzheader (released withpixdim[4]=0.0, which AFNI silently coerces to 1.0 and drives the bandpass off by 2x), and re-runs nuisance regression + bandpass.The bad bandpass propagates to all downstream metrics, so the script also regenerates ALFF/fALFF/ReHo (
desc-sm6,desc-smZstd,desc-zstd), atlas mean timeseries, and Pearson + Nilearn partial-correlation matrices under the release's filename conventions.--skip-metricsopts out.Notes:
.1Dfiles written(T, n_rois)to match the release.ATLAS_REGISTRYshort names.Schaefer2018p300n17is skipped: upstream atlas has 619 labels instead of 300._stage_masklifts the BOLD's sform/qform/xyzt_units onto the mask copy so AFNI's grid check passes (release ships masks withsform_code=0).RBC_WORK_DIRscoped to a tempdir so niwrap exec folders don't accumulate._restore_trinlined so the script doesn't need a private rbc symbol exported.Validated end-to-end on
sub-10612(BHRC, 16 atlases, Docker): atlas ROI counts match the release exactly, cleaned BOLD RMS-diffs from the release by 4.7× of the original signal.