@@ -621,17 +621,17 @@ def _warp_dir(intuple, nlevels=3):
621
621
Example
622
622
-------
623
623
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "i-"}))
624
- [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
624
+ [[1, 0.1 , 0.1 ], [1, 0.1 , 0.1 ], [1, 0.1 , 0.1 ]]
625
625
626
626
>>> _warp_dir(("epi.nii.gz", {"PhaseEncodingDirection": "j-"}), nlevels=2)
627
- [[0, 1, 0], [0, 1, 0]]
627
+ [[0.1 , 1, 0.1 ], [0.1 , 1, 0.1 ]]
628
628
629
629
"""
630
630
pe = intuple [1 ]["PhaseEncodingDirection" ][0 ]
631
631
return nlevels * [[1 if pe == ax else 0.1 for ax in "ijk" ]]
632
632
633
633
634
- def _extract_field (in_file , epi_meta , in_mask = None ):
634
+ def _extract_field (in_file , epi_meta , in_mask = None , demean = True ):
635
635
"""
636
636
Extract the nonzero component of the deformation field estimated by ANTs.
637
637
@@ -640,7 +640,9 @@ def _extract_field(in_file, epi_meta, in_mask=None):
640
640
>>> nii = nb.load(
641
641
... _extract_field(
642
642
... ["field.nii.gz"],
643
- ... ("epi.nii.gz", {"PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.005}))
643
+ ... ("epi.nii.gz", {"PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.005}),
644
+ ... demean=False,
645
+ ... )
644
646
... )
645
647
>>> nii.shape
646
648
(10, 10, 10)
@@ -668,13 +670,13 @@ def _extract_field(in_file, epi_meta, in_mask=None):
668
670
if ["PhaseEncodingDirection" ][0 ] in "ij" :
669
671
data *= - 1.0 # ITK/ANTs is an LPS system, flip direction
670
672
671
- if in_mask is None :
672
- mask = np . ones_like ( data , dtype = bool )
673
- else :
674
- mask = np .asanyarray (nb .load (in_mask ).dataobj , dtype = bool )
675
-
676
- # De-mean the result
677
- data -= np .median (data [mask ])
673
+ if demean :
674
+ mask = (
675
+ np . ones_like ( data , dtype = bool ) if in_mask is None
676
+ else np .asanyarray (nb .load (in_mask ).dataobj , dtype = bool )
677
+ )
678
+ # De-mean the result
679
+ data -= np .median (data [mask ])
678
680
679
681
out_file = Path (fname_presuffix (Path (in_file [0 ]).name , suffix = "_fieldmap" ))
680
682
nii = nb .Nifti1Image (data , fieldnii .affine , None )
0 commit comments