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
7360b144
Commit
7360b144
authored
May 26, 2021
by
William Clarke
Browse files
add test for split and fix off by one bug.
parent
7c74c410
Changes
2
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/tests/test_utils_nifti_mrs_tools_split_merge.py
View file @
7360b144
...
...
@@ -364,7 +364,7 @@ def test_split():
# Functionality testing
out_1
,
out_2
=
nmrs_tools
.
split
(
nmrs
,
'DIM_DYN'
,
3
2
)
out_1
,
out_2
=
nmrs_tools
.
split
(
nmrs
,
'DIM_DYN'
,
3
1
)
assert
out_1
.
data
.
shape
==
(
1
,
1
,
1
,
4096
,
32
,
32
)
assert
out_2
.
data
.
shape
==
(
1
,
1
,
1
,
4096
,
32
,
32
)
assert
np
.
allclose
(
out_1
.
data
,
nmrs
.
data
[:,
:,
:,
:,
:,
0
:
32
])
...
...
@@ -382,6 +382,21 @@ def test_split():
assert
np
.
allclose
(
out_1
.
data
,
nmrs
.
data
[:,
:,
:,
:,
:,
test_list
])
assert
np
.
allclose
(
out_2
.
data
,
nmrs
.
data
[:,
:,
:,
:,
:,
[
0
,
32
,
63
]])
# Split some synthetic data with header information
nhdr_1
=
gen_new_nifti_mrs
(
np
.
ones
((
1
,
1
,
1
,
10
,
4
),
dtype
=
complex
),
1
/
1000
,
100
,
'1H'
,
dim_tags
=
[
'DIM_DYN'
,
None
,
None
])
nhdr_1
.
set_dim_header
(
'DIM_DYN'
,
{
'RepetitionTime'
:
[
1
,
2
,
3
,
4
]})
out_1
,
out_2
=
nmrs_tools
.
split
(
nhdr_1
,
'DIM_DYN'
,
1
)
assert
out_1
.
shape
==
(
1
,
1
,
1
,
10
,
2
)
assert
out_1
.
hdr_ext
[
'dim_5'
]
==
'DIM_DYN'
assert
out_1
.
hdr_ext
[
'dim_5_header'
]
==
{
'RepetitionTime'
:
[
1
,
2
]}
assert
out_2
.
hdr_ext
[
'dim_5_header'
]
==
{
'RepetitionTime'
:
[
3
,
4
]}
def
test_merge
():
"""Test the merge functionality
...
...
fsl_mrs/utils/nifti_mrs_tools/split_merge.py
View file @
7360b144
...
...
@@ -56,7 +56,7 @@ def split(nmrs, dimension, index_or_indicies):
or
index_or_indicies
>=
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
,
nmrs
.
shape
[
dim_index
])
index
=
np
.
arange
(
index_or_indicies
+
1
,
nmrs
.
shape
[
dim_index
])
elif
isinstance
(
index_or_indicies
,
list
):
if
not
np
.
logical_and
(
np
.
asarray
(
index_or_indicies
)
>=
0
,
...
...
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