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
731c7a45
Commit
731c7a45
authored
Jul 22, 2021
by
William Clarke
Browse files
Fix bug in mrs_tools split.
parent
f2d796e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/scripts/mrs_tools
View file @
731c7a45
...
...
@@ -256,7 +256,7 @@ def split(args):
split_name
=
args
.
file
.
with_suffix
(
''
).
with_suffix
(
''
).
name
# 2. Merge the files
if
args
.
index
:
if
args
.
index
is
not
None
:
split_1
,
split_2
=
nmrs_tools
.
split
(
to_split
,
args
.
dim
,
args
.
index
)
elif
args
.
indices
:
split_1
,
split_2
=
nmrs_tools
.
split
(
to_split
,
args
.
dim
,
args
.
indices
)
...
...
fsl_mrs/tests/test_scripts_mrs_tools.py
View file @
731c7a45
...
...
@@ -7,6 +7,7 @@ Copyright Will Clarke, University of Oxford, 2021'''
# Imports
import
subprocess
from
pathlib
import
Path
import
nibabel
as
nib
# Files
testsPath
=
Path
(
__file__
).
parent
...
...
@@ -99,6 +100,10 @@ def test_split(tmp_path):
assert
(
tmp_path
/
'split_file_1.nii.gz'
).
exists
()
assert
(
tmp_path
/
'split_file_2.nii.gz'
).
exists
()
f1
=
nib
.
load
(
tmp_path
/
'split_file_1.nii.gz'
)
f2
=
nib
.
load
(
tmp_path
/
'split_file_2.nii.gz'
)
assert
f1
.
shape
[
5
]
==
32
assert
f2
.
shape
[
5
]
==
32
subprocess
.
check_call
([
'mrs_tools'
,
'split'
,
'--dim'
,
'DIM_DYN'
,
...
...
@@ -108,15 +113,24 @@ def test_split(tmp_path):
assert
(
tmp_path
/
'metab_raw_1.nii.gz'
).
exists
()
assert
(
tmp_path
/
'metab_raw_2.nii.gz'
).
exists
()
f1
=
nib
.
load
(
tmp_path
/
'metab_raw_1.nii.gz'
)
f2
=
nib
.
load
(
tmp_path
/
'metab_raw_2.nii.gz'
)
assert
f1
.
shape
[
5
]
==
32
assert
f2
.
shape
[
5
]
==
32
subprocess
.
check_call
([
'mrs_tools'
,
'split'
,
'--dim'
,
'DIM_DYN'
,
'--indices'
,
'31'
,
'34'
,
'40'
,
'--filename'
,
'indicies_select'
,
'--output'
,
str
(
tmp_path
),
'--file'
,
str
(
test_data_split
)])
assert
(
tmp_path
/
'metab_raw_1.nii.gz'
).
exists
()
assert
(
tmp_path
/
'metab_raw_2.nii.gz'
).
exists
()
assert
(
tmp_path
/
'indicies_select_1.nii.gz'
).
exists
()
assert
(
tmp_path
/
'indicies_select_2.nii.gz'
).
exists
()
f1
=
nib
.
load
(
tmp_path
/
'indicies_select_1.nii.gz'
)
f2
=
nib
.
load
(
tmp_path
/
'indicies_select_2.nii.gz'
)
assert
f1
.
shape
[
5
]
==
61
assert
f2
.
shape
[
5
]
==
3
# Test reorder option
...
...
fsl_mrs/utils/nifti_mrs_tools/split_merge.py
View file @
731c7a45
...
...
@@ -53,7 +53,7 @@ def split(nmrs, dimension, index_or_indicies):
# Construct indexing
if
isinstance
(
index_or_indicies
,
int
):
if
index_or_indicies
<
0
\
or
index_or_indicies
>=
nmrs
.
shape
[
dim_index
]:
or
(
index_or_indicies
+
1
)
>=
nmrs
.
shape
[
dim_index
]:
raise
ValueError
(
'index_or_indicies must be between 0 and N-1,'
f
' where N is the size of the specified dimension (
{
nmrs
.
shape
[
dim_index
]
}
).'
)
index
=
np
.
arange
(
index_or_indicies
+
1
,
nmrs
.
shape
[
dim_index
])
...
...
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