Commit 18deb393 authored by William Clarke's avatar William Clarke
Browse files

More tests, tidying up edge cases add to setup.py.

parent 7360b144
......@@ -246,7 +246,12 @@ class NIFTI_MRS(Image):
# Check size
def size_chk(obj):
if len(obj) != self.shape[dim]:
# Allow for expansion along the next dimension
if dim == self.ndim:
dim_len = 1
else:
dim_len = self.shape[dim]
if len(obj) != dim_len:
raise ValueError(f'New dim header length must be {self.shape[dim]}')
for key in hdr_obj:
......
......@@ -404,7 +404,7 @@ def test_merge():
nmrs_1 = mrs_io.read_FID(test_data_merge_1)
nmrs_2 = mrs_io.read_FID(test_data_merge_2)
nmrs_bad_shape, _ = nmrs_tools.split(nmrs_2, 'DIM_COIL', 4)
nmrs_bad_shape, _ = nmrs_tools.split(nmrs_2, 'DIM_COIL', 3)
nmrs_no_tag = mrs_io.read_FID(test_data_other)
# Error testing
......@@ -498,6 +498,26 @@ def test_merge():
assert out.hdr_ext['dim_5'] == 'DIM_DYN'
assert out.hdr_ext['dim_5_header'] == {'RepetitionTime': {'start': 1, 'increment': 1}}
# Merge along squeezed singleton with header
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_2 = nhdr_1.copy()
nhdr_1_e = nmrs_tools.reorder(nhdr_1, ['DIM_DYN', 'DIM_EDIT', None])
nhdr_2_e = nmrs_tools.reorder(nhdr_2, ['DIM_DYN', 'DIM_EDIT', None])
nhdr_1_e.set_dim_header('DIM_DYN', {'RepetitionTime': {'start': 1, 'increment': 1}})
nhdr_2_e.set_dim_header('DIM_DYN', {'RepetitionTime': {'start': 1, 'increment': 1}})
nhdr_1_e.set_dim_header('DIM_EDIT', {'OtherTime': [0.1, ]})
nhdr_2_e.set_dim_header('DIM_EDIT', {'OtherTime': [0.2, ]})
out = nmrs_tools.merge((nhdr_1_e, nhdr_2_e), 'DIM_EDIT')
assert out.data.shape == (1, 1, 1, 10, 4, 2)
assert out.hdr_ext['dim_6'] == 'DIM_EDIT'
assert out.hdr_ext['dim_6_header'] == {'OtherTime': [0.1, 0.2, ]}
def test_reorder():
"""Test the reorder functionality
......
......@@ -281,7 +281,7 @@ def _merge_dim_header(hdr1, hdr2, dimension, dim_length1, dim_length2):
f'The second header contains {hdr2[key_str].keys()}.')
new_h = {}
for sub_key in hdr1[key_str]:
new_h[sub_key] = merge_single(hdr1[key_str][sub_key], hdr2[key_str][sub_key])
new_h[sub_key] = merge_single(hdr1[key_str][sub_key], hdr2[key_str][sub_key])
out_hdr[key_str] = new_h
elif key_str in hdr1 and key_str not in hdr2\
......
......@@ -26,6 +26,7 @@ setup(name='fsl_mrs',
'fsl_mrs.utils.preproc',
'fsl_mrs.utils.synthetic',
'fsl_mrs.utils.dynamic',
'fsl_mrs.utils.nifti_mrs_tools',
'fsl_mrs.denmatsim',
'fsl_mrs.mmbasis',
'fsl_mrs.auxiliary'
......
Supports Markdown
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