Commit 25d9cd96 authored by William Clarke's avatar William Clarke
Browse files

Update to data reader to deal with dots in paths

parent eb52cb94
......@@ -349,13 +349,12 @@ def main():
# Save image of MRS voxel
location_fig = None
if args.t1 is not None:
datatype = mrs_io.check_datatype(args.data)
if datatype == 'NIFTI':
fig = plotting.plot_world_orient(args.t1, args.data)
fig.tight_layout()
location_fig = os.path.join(args.output, 'voxel_location.png')
fig.savefig(location_fig, bbox_inches='tight', facecolor='k')
if args.t1 is not None \
and FID.getXFormCode() > 0:
fig = plotting.plot_world_orient(args.t1, args.data)
fig.tight_layout()
location_fig = os.path.join(args.output, 'voxel_location.png')
fig.savefig(location_fig, bbox_inches='tight', facecolor='k')
# Save quick summary figure
report.fitting_summary_fig(mrs, res,
......
......@@ -7,6 +7,7 @@ Copyright Will Clarke, University of Oxford, 2021'''
import fsl_mrs.utils.mrs_io as mrsio
import fsl_mrs.utils.mrs_io.fsl_io as fslio
from fsl_mrs.utils.mrs_io.main import _check_datatype
from fsl_mrs.utils import plotting
import numpy as np
import os.path as op
......@@ -150,3 +151,17 @@ def test_fslBasisRegen():
assert names_fsl2 == names_fsl
for r in headerReqFields:
assert headers_fsl[0][r] == headers_fsl2[0][r]
def test_check_datatype():
'''Check various paths through _check_datatype'''
assert _check_datatype('fake/path/test.RAW') == 'RAW'
assert _check_datatype('fake/path/test.H2O') == 'RAW'
assert _check_datatype('fake/path/test.txt') == 'TXT'
assert _check_datatype('fake/path/test.nii') == 'NIFTI'
assert _check_datatype('fake/path/test.nii.gz') == 'NIFTI'
assert _check_datatype('fake/path/test.blah.nii.gz') == 'NIFTI'
assert _check_datatype('fake/path/test.blah.nii') == 'NIFTI'
from fsl_mrs.utils.mrs_io.main import read_FID, read_basis, check_datatype
from fsl_mrs.utils.mrs_io.main import read_FID, read_basis
......@@ -28,28 +28,21 @@ class FileNotRecognisedError(Exception):
# Reciever bandwidth
# Dwell time
# central frequency
def check_datatype(filename):
def _check_datatype(filename):
"""
Identify the file type (.nii(.gz),.RAW/.H2O,.txt)
Returns one of: 'NIFTI_MRS', 'NIFTI','RAW','TXT','Unknown'
If data isn't NIFTI_MRS then
identify the file type (.nii(.gz),.RAW/.H2O,.txt)
Returns one of: 'NIFTI', 'RAW', 'TXT', 'Unknown'
"""
try:
nifti_mrs.NIFTI_MRS(filename)
except (nifti_mrs.NotNIFTI_MRS, fslpath.PathError):
_, ext = filename.split(os.extsep, 1)
if ext.lower() == 'nii' or ext.lower() == 'nii.gz':
fsl.readNIFTI(filename)
return 'NIFTI'
elif ext.lower() == 'raw' or ext.lower() == 'h2o':
lcm.readLCModelRaw(filename)
return 'RAW'
elif ext.lower() == 'txt':
jmrui.readjMRUItxt(filename)
return 'TXT'
else:
return 'Unknown'
_, ext = filename.split(os.extsep, 1)
if 'nii' in ext.lower() or 'nii.gz' in ext.lower():
return 'NIFTI'
elif ext.lower() == 'raw' or ext.lower() == 'h2o':
return 'RAW'
elif ext.lower() == 'txt':
return 'TXT'
else:
return 'NIFTI_MRS'
return 'Unknown'
def read_FID(filename):
......@@ -68,7 +61,7 @@ def read_FID(filename):
try:
return nifti_mrs.NIFTI_MRS(filename)
except (nifti_mrs.NotNIFTI_MRS, fslpath.PathError):
data_type = check_datatype(filename)
data_type = _check_datatype(filename)
if data_type == 'RAW':
return lcm.read_lcm_raw_h2o(filename)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment