Skip to content

Commit

Permalink
Merge pull request #24 from hjmjohnson/fix-test-warnings
Browse files Browse the repository at this point in the history
Fix test warnings
  • Loading branch information
tashrifbillah authored Jul 18, 2022
2 parents 48f94ce + 3b60325 commit ec40c7e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion conversion/grad_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def grad_avg(imgFile, outFile, bvalFile= None, bvecFile= None):
bvecs= read_bvecs(bvecFile)

img= nib.load(imgFile)
data = img.get_data()
data = img.get_fdata()
if len(data.shape)!=4:
raise AttributeError('Not a valid dwi, check dimension')

Expand Down
2 changes: 1 addition & 1 deletion conversion/grad_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def grad_remove(imgFile, outFile, qc_bad_indices= [], interval= [], bvalFile= No
grad_axis= 3

img= nib.load(imgFile)
data = img.get_data()
data = img.get_fdata()
if len(data.shape)!=4:
raise AttributeError('Not a valid dwi, check dimension')

Expand Down
6 changes: 3 additions & 3 deletions conversion/nifti_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def nifti_write(inImg, prefix= None):
volume_axes.remove(grad_axis)
rotation= hdr['space directions'][volume_axes,:3]

xfrm_nhdr= np.matrix(np.vstack((np.hstack((rotation.T, np.reshape(translation,(3,1)))),[0,0,0,1])))
xfrm_nhdr= np.array(np.vstack((np.hstack((rotation.T, np.reshape(translation,(3,1)))),[0,0,0,1])))

# put the gradients along last axis
if grad_axis!=3:
Expand All @@ -87,7 +87,7 @@ def nifti_write(inImg, prefix= None):
f_vec= open(prefix+'.bvec', 'w')
b_max = float(hdr['DWMRI_b-value'])

mf= np.matrix(np.vstack((np.hstack((hdr['measurement frame'],
mf= np.array(np.vstack((np.hstack((hdr['measurement frame'],
[[0],[0],[0]])),[0,0,0,1])))
for ind in range(hdr['sizes'][grad_axis]):
bvec = [float(num) for num in hdr[f'DWMRI_gradient_{ind:04}'].split()]
Expand All @@ -97,7 +97,7 @@ def nifti_write(inImg, prefix= None):
bvec.append(1)
# bvecINijk= RAS2IJK @ SPACE2RAS @ mf @ np.matrix(bvec).T
# simplified below
bvecINijk= xfrm_nhdr.T @ mf @ np.matrix(bvec).T
bvecINijk= xfrm_nhdr.T @ mf @ np.array(bvec).T

L_2= np.linalg.norm(bvecINijk[:3])
if L_2:
Expand Down
16 changes: 8 additions & 8 deletions conversion/tests/test_file_conversion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import sys

# sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

from numpy import testing
from numpy import testing, array
from conversion.tests.util import *
from nrrd import read
from nibabel import load
Expand All @@ -21,14 +18,14 @@ def test_nrrd2nifti(self):

# load converted output
converted_nifti= load(PREFIX+'.nii.gz')
converted_nifti_data= converted_nifti.get_data()
converted_nifti_data= converted_nifti.get_fdata()
converted_nifti_affine= converted_nifti.affine
converted_nifti_bvals= conversion.read_bvals(PREFIX+'.bval')
converted_nifti_bvecs = conversion.read_bvecs(PREFIX+'.bvec')

# load converted reference
converted_nifti= load(CONVERTED_NIFTI)
reference_nifti_data= converted_nifti.get_data()
reference_nifti_data= converted_nifti.get_fdata()
reference_nifti_affine= converted_nifti.affine
reference_nifti_bvals= conversion.read_bvals(CONVERTED_BVAL)
reference_nifti_bvecs = conversion.read_bvecs(CONVERTED_BVEC)
Expand All @@ -37,8 +34,11 @@ def test_nrrd2nifti(self):
testing.assert_array_equal(reference_nifti_data, converted_nifti_data)
testing.assert_array_equal(reference_nifti_affine, converted_nifti_affine)
testing.assert_array_equal(reference_nifti_bvals, converted_nifti_bvals)
testing.assert_array_equal(reference_nifti_bvecs, converted_nifti_bvecs)

for bvec_idx in range(0,len(reference_nifti_bvecs)):
reference_bvec = array(reference_nifti_bvecs[bvec_idx])
converted_bvec = array(converted_nifti_bvecs[bvec_idx])
testing.assert_array_almost_equal_nulp(reference_bvec,
converted_bvec, 1)

def test_nifti2nrrd(self):

Expand Down

0 comments on commit ec40c7e

Please sign in to comment.