Unit C: contrast-enhanced T1 detection + non-contrast anchor preference#148
Merged
Merged
Conversation
is_contrast_enhanced_t1 (JSON ContrastBolusAgent / ImageType CONTRAST, conservative filename fallback, bash-3.2-portable). When PREFER_EXTERNAL_NONCONTRAST_T1 is set and the in-study T1 is contrast-enhanced, swap in a configured external non-contrast anchor (via a shared adopt_external_anatomical_t1 helper, also used by the Unit A no-T1 path) and export CONTRAST_ENHANCED_T1 so the contrast T1 stays available as enhancement signal. Backward-compatible: default off = unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Detection (
is_contrast_enhanced_t1insrc/modules/reference_space_selection.sh): inspects the dcm2niix JSON sidecar first (viajqor grep fallback) forContrastBolusAgentandImageType CONTRAST; falls back to conservative filename heuristics only when no sidecar is available. All${var^^}bash-4-only expansions replaced with portableprintf '%s' | trfor bash 3.2 compatibility (macOS system shell).Preference/swap (Unit C block in
src/pipeline.sh): whenPREFER_EXTERNAL_NONCONTRAST_T1=trueand the in-study T1 is detected as contrast-enhanced, the external non-contrast anchor (ANATOMICAL_REFERENCE_T1) is adopted as the structural reference. The in-study contrast-enhanced T1 is never deleted — it is exported asCONTRAST_ENHANCED_T1so downstream analysis can use it as an enhancement signal. The swap is graceful: missing/unsetANATOMICAL_REFERENCE_T1logs a WARNING and keeps the contrast T1 in place.Shared helper refactor (
adopt_external_anatomical_t1): the ~30-line copy + size-check + sanity-check + provenance block that was duplicated across Unit A and Unit C is now a single shared helper. Both Unit A (no in-study T1) and Unit C (contrast swap) call it. Behavior of both paths is preserved exactly.Additional self-review fixes applied:
+cand_c_from the heuristic fallback to prevent false-positives on names likeacq+contrast.[ "${agent_upper}" != "" ]condition (identical to the preceding[ -n "${agent_upper}" ]).ImageTypeinto a single piped check.Backward compatibility: the Unit C preference/swap block is guarded by
[ "${PREFER_EXTERNAL_NONCONTRAST_T1:-false}" = "true" ]. With the defaultfalse, the entire block is unreachable and pipeline behaviour is byte-identical to before. Unit A's no-T1 adoption path is also unchanged in behaviour after the helper extraction.Test plan
bash -n src/modules/reference_space_selection.sh— syntax OKbash -n src/pipeline.sh— syntax OKshellcheck --severity=errorboth files — 0 findingsbash tests/test_environment_unit.sh— 100/100 PASSbash tests/test_pipeline_control_unit.sh— 98/98 PASSbash tests/test_import_unit.sh— 29/29 PASSbash src/pipeline.sh --help | grep -q "Usage:"— PASSdeclare -f is_contrast_enhanced_t1resolves after sourcing module — OKgit diff --cached | grep -nEi '/Users/|...') — CLEANgit diff --statshows only 2 files🤖 Generated with Claude Code