Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
William Clarke
fsl_mrs
Commits
25d9cd96
Commit
25d9cd96
authored
Mar 11, 2021
by
William Clarke
Browse files
Update to data reader to deal with dots in paths
parent
eb52cb94
Changes
4
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/scripts/fsl_mrs
View file @
25d9cd96
...
...
@@ -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
,
...
...
fsl_mrs/tests/test_mrs_io.py
View file @
25d9cd96
...
...
@@ -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'
fsl_mrs/utils/mrs_io/__init__.py
View file @
25d9cd96
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
fsl_mrs/utils/mrs_io/main.py
View file @
25d9cd96
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment