Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_nii not looking for ImageComments and ImageType #171

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions shimmingtoolbox/load_nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ def read_nii(nii_path, auto_scale=True):

image = np.asarray(info.dataobj)
if auto_scale:
if ('Manufacturer' in json_data) and (json_data['Manufacturer'] == 'Siemens') \
and (("*phase*" in json_data['ImageComments']) or ("P" in json_data["ImageType"])):
if ('Manufacturer' in json_data) and (json_data['Manufacturer'] == 'Siemens')\
and (('ImageComments' in json_data) and ("*phase*" in json_data['ImageComments'])
or ('ImageType' in json_data) and ('P' in json_data['ImageType'])):
image = image * (2 * math.pi / PHASE_SCALING_SIEMENS)

return info, json_data, image
return info, json_data, image
12 changes: 12 additions & 0 deletions test/test_load_nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import numpy as np
import nibabel as nib
import json
import math

from io import StringIO
from pathlib import Path
from shimmingtoolbox.load_nifti import load_nifti
from shimmingtoolbox.load_nifti import read_nii
from shimmingtoolbox import __dir_testing__


class TestCore(object):
Expand Down Expand Up @@ -370,3 +373,12 @@ def test_load_nifti_modality_check(self, monkeypatch):
assert (json.dumps(json_info[0], sort_keys=True) == json.dumps(self._json_mag, sort_keys=True)), \
"JSON file is not correctly loaded for first JSON 2"
assert (niftis.shape == (3, 3, 3, 1, 1)), "Wrong shape for the Nifti output data 2"

def test_read_nii_real_data(self):
fname_phasediff = os.path.join(__dir_testing__, 'realtime_zshimming_data', 'nifti', 'sub-example', 'fmap',
'sub-example_phasediff.nii.gz')
nii, json_info, phasediff = read_nii(fname_phasediff)

assert nii.shape == (64, 96, 1, 10)
assert ('P' in json_info['ImageType'])
assert (phasediff.max() <= 2 * math.pi) and (phasediff.min() >= 0)