Commit 5d333182 authored by William Clarke's avatar William Clarke
Browse files

Sort out capitalisation of Value.

parent 18deb393
......@@ -258,8 +258,8 @@ class NIFTI_MRS(Image):
if isinstance(hdr_obj[key], list):
size_chk(hdr_obj[key])
elif isinstance(hdr_obj[key], dict)\
and 'value' in hdr_obj[key]:
size_chk(hdr_obj[key]['value'])
and 'Value' in hdr_obj[key]:
size_chk(hdr_obj[key]['Value'])
current_hdr_ext = self.hdr_ext
current_hdr_ext[f'dim_{dim + 1}_header'] = hdr_obj
......
......@@ -14,11 +14,11 @@ def test_short_to_long():
dict_repr = misc.dim_n_header_short_to_long([0.0, 0.1, 0.2], 3)
assert dict_repr == [0.0, 0.1, 0.2]
dict_repr = misc.dim_n_header_short_to_long({'value': [0.0, 0.1, 0.2], 'description': 'test'}, 3)
assert dict_repr == {'value': [0.0, 0.1, 0.2], 'description': 'test'}
dict_repr = misc.dim_n_header_short_to_long({'Value': [0.0, 0.1, 0.2], 'description': 'test'}, 3)
assert dict_repr == {'Value': [0.0, 0.1, 0.2], 'description': 'test'}
dict_repr = misc.dim_n_header_short_to_long({'value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}, 3)
assert dict_repr == {'value': [0.0, 0.1, 0.2], 'description': 'test'}
dict_repr = misc.dim_n_header_short_to_long({'Value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}, 3)
assert dict_repr == {'Value': [0.0, 0.1, 0.2], 'description': 'test'}
def test_long_to_short():
......@@ -28,11 +28,11 @@ def test_long_to_short():
dict_repr = misc.dim_n_header_long_to_short({'start': 0.0, 'increment': 0.1})
assert dict_repr == {'start': 0.0, 'increment': 0.1}
dict_repr = misc.dim_n_header_long_to_short({'value': [0.0, 0.1, 0.2], 'description': 'test'})
assert dict_repr == {'value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}
dict_repr = misc.dim_n_header_long_to_short({'Value': [0.0, 0.1, 0.2], 'description': 'test'})
assert dict_repr == {'Value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}
dict_repr = misc.dim_n_header_long_to_short({'value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'})
assert dict_repr == {'value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}
dict_repr = misc.dim_n_header_long_to_short({'Value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'})
assert dict_repr == {'Value': {'start': 0.0, 'increment': 0.1}, 'description': 'test'}
def test_dict_to_list():
......
......@@ -33,7 +33,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
# Headers occuring as a list.
......@@ -48,7 +48,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
assert hdr2 == {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -60,7 +60,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr1, hdr2 = nmrs_tools.split_merge._split_dim_header(hdr_in, 5, 4, [1, 3])
......@@ -74,7 +74,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
assert hdr2 == {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -86,7 +86,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
# Headers as a dict
......@@ -101,7 +101,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
assert hdr2 == {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -113,7 +113,7 @@ def test_split_dim_header():
'p2': [0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr1, hdr2 = nmrs_tools.split_merge._split_dim_header(hdr_in, 6, 4, [1, ])
......@@ -127,7 +127,7 @@ def test_split_dim_header():
'p2': [0.1, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
assert hdr2 == {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -139,7 +139,7 @@ def test_split_dim_header():
'p2': [0.2, ]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
# User defined structures
......@@ -154,7 +154,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2]}}
assert hdr2 == {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -166,7 +166,7 @@ def test_split_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 3, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 3, 'increment': 1}, 'description': 'user'},
'p2': [0.3, 0.4]}}
......@@ -182,7 +182,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_in_2 = {'dim_5': 'DIM_DYN',
'dim_5_info': 'averages',
......@@ -194,7 +194,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_out = nmrs_tools.split_merge._merge_dim_header(hdr_in_1, hdr_in_2, 5, 4, 4)
......@@ -208,7 +208,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_in_2 = {'dim_5': 'DIM_DYN',
......@@ -221,7 +221,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_out = nmrs_tools.split_merge._merge_dim_header(hdr_in_1, hdr_in_2, 6, 4, 4)
assert hdr_out == {'dim_5': 'DIM_DYN',
......@@ -234,7 +234,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_out = nmrs_tools.split_merge._merge_dim_header(hdr_in_2, hdr_in_1, 6, 4, 4)
......@@ -248,7 +248,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_in_2 = {'dim_5': 'DIM_DYN',
......@@ -261,7 +261,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 5, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 5, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4]}}
hdr_out = nmrs_tools.split_merge._merge_dim_header(hdr_in_1, hdr_in_2, 7, 4, 4)
assert hdr_out == {'dim_5': 'DIM_DYN',
......@@ -274,7 +274,7 @@ def test_merge_dim_header():
'p2': [0.1, 0.2, 0.3, 0.4]},
'dim_7': 'DIM_USER_0',
'dim_7_info': 'other',
'dim_7_header': {'p1': {'value': {'start': 1, 'increment': 1}, 'description': 'user'},
'dim_7_header': {'p1': {'Value': {'start': 1, 'increment': 1}, 'description': 'user'},
'p2': [0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4]}}
with pytest.raises(NIfTI_MRSIncompatible) as exc_info:
......
......@@ -43,8 +43,8 @@ def check_type(in_format):
and 'start' in in_format:
return 'short'
elif isinstance(in_format, dict)\
and 'value' in in_format:
return check_type(in_format['value'])
and 'Value' in in_format:
return check_type(in_format['Value'])
def dim_n_header_short_to_long(in_format, elements):
......@@ -54,9 +54,9 @@ def dim_n_header_short_to_long(in_format, elements):
and 'start' in in_format:
return _dict_to_list(in_format, elements)
elif isinstance(in_format, dict)\
and 'value' in in_format:
and 'Value' in in_format:
out = in_format.copy()
out['value'] = _dict_to_list(out['value'], elements)
out['Value'] = _dict_to_list(out['Value'], elements)
return out
......@@ -67,9 +67,9 @@ def dim_n_header_long_to_short(in_format):
and 'start' in in_format:
return in_format
elif isinstance(in_format, dict)\
and 'value' in in_format:
and 'Value' in in_format:
out = in_format.copy()
out['value'] = _list_to_dict(in_format['value'])
out['Value'] = _list_to_dict(in_format['Value'])
return out
......
......@@ -110,12 +110,12 @@ def _split_dim_header(hdr, dimension, dim_length, index):
def split_user_or_std(hdr_val):
if isinstance(hdr_val, dict)\
and 'value' in hdr_val:
tmp_1, tmp_2 = split_list(hdr_val['value'])
and 'Value' in hdr_val:
tmp_1, tmp_2 = split_list(hdr_val['Value'])
out_1 = hdr_val.copy()
out_2 = hdr_val.copy()
out_1.update({'value': tmp_1})
out_2.update({'value': tmp_2})
out_1.update({'Value': tmp_1})
out_2.update({'Value': tmp_2})
return out_1, out_2
else:
return split_list(hdr_val)
......@@ -243,10 +243,10 @@ def _merge_dim_header(hdr1, hdr2, dimension, dim_length1, dim_length2):
def merge_user_or_std(hdr_val1, hdr_val2):
if isinstance(hdr_val1, dict)\
and 'value' in hdr_val1:
tmp = merge_list(hdr_val1['value'], hdr_val2['value'])
and 'Value' in hdr_val1:
tmp = merge_list(hdr_val1['Value'], hdr_val2['Value'])
out = hdr_val1.copy()
out.update({'value': tmp})
out.update({'Value': tmp})
return out
else:
return merge_list(hdr_val1, hdr_val2)
......
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