Skip to content

Commit 4378d35

Browse files
committed
STY: rename get_dimension_labels to get_volume_labels
1 parent 272c5cc commit 4378d35

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

nibabel/parrec.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ def get_sorted_slice_indices(self):
11261126
n_used = np.prod(self.get_data_shape()[2:])
11271127
return sort_order[:n_used]
11281128

1129-
def get_dimension_labels(self, collapse_slices=True):
1129+
def get_volume_labels(self, collapse_slices=True):
11301130
""" Dynamic labels corresponding to the final data dimension(s).
11311131
11321132
This is useful for custom data sorting. A subset of the info in
@@ -1148,6 +1148,8 @@ def get_dimension_labels(self, collapse_slices=True):
11481148
The ordering of each value corresponds to that returned by
11491149
``self.get_sorted_slice_indices``.
11501150
"""
1151+
sorted_indices = self.get_sorted_slice_indices()
1152+
image_defs = self.image_defs
11511153

11521154
# define which keys to store sorting info for
11531155
dynamic_keys = ['slice number',
@@ -1163,9 +1165,6 @@ def get_dimension_labels(self, collapse_slices=True):
11631165
'gradient orientation number',
11641166
'diffusion b value number']
11651167

1166-
sorted_indices = self.get_sorted_slice_indices()
1167-
image_defs = self.image_defs
1168-
11691168
if collapse_slices:
11701169
dynamic_keys.remove('slice number')
11711170

@@ -1187,15 +1186,12 @@ def get_dimension_labels(self, collapse_slices=True):
11871186
non_unique_keys.append(key)
11881187

11891188
if collapse_slices:
1190-
if 'slice orientation' in non_unique_keys:
1191-
raise ValueError("for non-unique slice orientation, need "
1192-
"collapse_slice=False")
1193-
if 'image angulation' in non_unique_keys:
1194-
raise ValueError("for non-unique image angulation, need "
1195-
"collapse_slice=False")
1196-
if 'image_display_orientation' in non_unique_keys: # ???
1197-
raise ValueError("for non-unique display orientation, need "
1198-
"collapse_slice=False")
1189+
for key in ('slice_orientation', 'image_angulation',
1190+
'image_display_orientation'):
1191+
if key in non_unique_keys:
1192+
raise ValueError(
1193+
'for values of {0} that differ overslices, use '
1194+
'"collapse_slice=False"'.format(key))
11991195
sl1_indices = image_defs['slice number'][sorted_indices] == 1
12001196

12011197
sort_info = {}

nibabel/tests/test_parrec.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ def test_header_scaling():
192192
def test_header_dimension_labels():
193193
hdr = PARRECHeader(HDR_INFO, HDR_DEFS)
194194
# check volume labels
195-
vol_labels = hdr.get_dimension_labels()
195+
vol_labels = hdr.get_volume_labels()
196196
assert_equal(list(vol_labels.keys()), ['dynamic scan number'])
197197
assert_array_equal(vol_labels['dynamic scan number'], [1, 2, 3])
198198
# check that output is ndarray rather than list
199199
assert_true(isinstance(vol_labels['dynamic scan number'], np.ndarray))
200200
# check case with individual slice labels
201-
slice_vol_labels = hdr.get_dimension_labels(collapse_slices=False)
201+
slice_vol_labels = hdr.get_volume_labels(collapse_slices=False)
202202
# verify that both expected keys are present
203203
assert_true('slice number' in slice_vol_labels)
204204
assert_true('dynamic scan number' in slice_vol_labels)
@@ -302,7 +302,7 @@ def test_sorting_dual_echo_T1():
302302
assert_equal(np.all(sorted_echos[n_half:] == 2), True)
303303

304304
# check volume labels
305-
vol_labels = t1_hdr.get_dimension_labels()
305+
vol_labels = t1_hdr.get_volume_labels()
306306
assert_equal(list(vol_labels.keys()), ['echo number'])
307307
assert_array_equal(vol_labels['echo number'], [1, 2])
308308

@@ -349,7 +349,7 @@ def test_sorting_multiple_echos_and_contrasts():
349349
assert_equal(np.all(sorted_types[3*ntotal//4:ntotal] == 3), True)
350350

351351
# check volume labels
352-
vol_labels = t1_hdr.get_dimension_labels()
352+
vol_labels = t1_hdr.get_volume_labels()
353353
assert_equal(sorted(list(vol_labels.keys())),
354354
['echo number', 'image_type_mr'])
355355
assert_array_equal(vol_labels['echo number'], [1, 2, 3]*4)
@@ -398,7 +398,7 @@ def test_sorting_multiecho_ASL():
398398
assert_array_equal(sorted_slices[:nslices], np.arange(1, nslices+1))
399399

400400
# check volume labels
401-
vol_labels = asl_hdr.get_dimension_labels()
401+
vol_labels = asl_hdr.get_volume_labels()
402402
assert_equal(sorted(list(vol_labels.keys())),
403403
['dynamic scan number', 'echo number', 'label type'])
404404
assert_array_equal(vol_labels['dynamic scan number'], [1]*6 + [2]*6)

0 commit comments

Comments
 (0)