Repository navigation
Use the official bifti package for BIfTI phantoms - #202
Merged
Merged
Conversation
Replace the internal phantom config dataclasses and NIfTI loader with the published `bifti` package. NiftiPhantom, NiftiTissue and ResliceConfig are kept as aliases of the bifti classes, and TissueDict.load now uses the bifti reference loader (density-weighted resampling, patient position). bifti requires Python >= 3.12, so requires-python is raised accordingly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NHKPBcYamTCDbaAVtBYRMR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NHKPBcYamTCDbaAVtBYRMR
bifti 0.3.0 loads complex B1 maps, names saved NIfTIs after the JSON and can store near-constant maps as values, so the hand-written NIfTI writer in TissueDict.save is no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NHKPBcYamTCDbaAVtBYRMR
Simulation test: main (before) vs. this PR (after)
|
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.











Closes #201.
Replaces the internal BIfTI phantom config, NIfTI loader and NIfTI writer with the published
biftipackage (>= 0.3.0).Changes
bifti>=0.3.0; removes ~480 lines of internal code.requires-pythonraised from>=3.10to>=3.12, sincebiftirequires 3.12 (and numpy ≥ 2.5.1).phantom/nifti_phantom.py: now only re-exports thebifticlasses.NiftiPhantom,NiftiTissueandResliceConfigremain as aliases ofBiftiPhantom,BiftiTissueandResliceTo, so existing user code and brainweb generation keep working.mr0additionally exportsBiftiPhantom,BiftiTissue,ResliceTo,Patient,PhantomUnitsandPhantomSystem(the last two were documented but not previously exported).TissueDict.load: uses thebiftiloader. Behavioural differences:reslice_tois density-weighted averaging instead of trilinear interpolation with slab averaging, so resliced values can differ slightly;patientposition is applied to the affine (nopatient→ unchanged);funcmappings are parsed by bifti's restricted grammar instead ofeval; complex B1+/B1- maps keep their phase.TissueDict.save: now converts tobifti.NumpyTissues and callsbifti.NumpyPhantom.save(..., constant_threshold=1e-5). Differences to before:<json name>_<property>.nii.gz(e.g.phantom_B1plus_0.nii.gzinstead ofphantom_B1+.nii.gz), still one file per property with tissues stacked;reslice_toand tissues are written in sorted name order;$schemapoints to the official schema URL.api-nifti.md,api-phantom.md,api.md) and CHANGELOG updated.Cargo.toml,Cargo.lock,pyproject.toml, CHANGELOG).Testing
Run locally without building the Rust extension (CPU torch, bifti 0.3.0):
TissueDict.save()→TissueDict.load()round-trip of a two-tissue phantom reproduces all maps and the affine exactly;.build()works.patient=HFSgives the expected shape and affine; tissue densities still sum to 1.The simulation test workflow and notebooks were not run locally.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NHKPBcYamTCDbaAVtBYRMR