Skip to content

Commit 76ee358

Browse files
committed
docstring and function name clarification, change get_data to get_fdata()
1 parent d057249 commit 76ee358

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

nibabel/cmdline/diff.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_opt_parser():
5151
type=float,
5252
default=0.0,
5353
help="Maximal relative difference in data between files to tolerate."
54-
" If also --data-max-abs-diff specified, only the data points "
54+
" If --data-max-abs-diff is also specified, only the data points "
5555
" with absolute difference greater than that value would be "
5656
" considered for relative difference check."),
5757
])
@@ -116,7 +116,7 @@ def get_headers_diff(file_headers, names=None):
116116
return difference
117117

118118

119-
def get_data_md5_diff(files):
119+
def get_data_hash_diff(files):
120120
"""Get difference between md5 values of data
121121
122122
Parameters
@@ -130,7 +130,7 @@ def get_data_md5_diff(files):
130130
"""
131131

132132
md5sums = [
133-
hashlib.md5(np.ascontiguousarray(nib.load(f).get_data(), dtype=np.float32)).hexdigest()
133+
hashlib.md5(np.ascontiguousarray(nib.load(f).get_fdata())).hexdigest()
134134
for f in files
135135
]
136136

@@ -156,11 +156,15 @@ def get_data_diff(files, max_abs=0, max_rel=0):
156156
157157
Returns
158158
-------
159-
OrderedDict
160-
str: absolute and relative differences of each file, given as float
159+
diffs: OrderedDict
160+
An ordered dict with a record per each file which has differences with other files subsequent detected.
161+
Each record is a list of difference records, one per each file pair. Each difference record is an Ordered
162+
Dict with possible keys 'abs' or 'rel' showing maximal absolute or relative differences in the file
163+
or record ('CMP': 'incompat') if file shapes are incompatible.
161164
"""
165+
162166
# we are doomed to keep them in RAM now
163-
data = [f if isinstance(f, np.ndarray) else nib.load(f).get_data() for f in files]
167+
data = [f if isinstance(f, np.ndarray) else nib.load(f).get_fdata() for f in files]
164168
diffs = OrderedDict()
165169
for i, d1 in enumerate(data[:-1]):
166170
# populate empty entries for non-compared
@@ -274,7 +278,7 @@ def diff(files, header_fields='all', data_max_abs_diff=None, data_max_rel_diff=N
274278

275279
diff = get_headers_diff(file_headers, header_fields)
276280

277-
data_md5_diffs = get_data_md5_diff(files)
281+
data_md5_diffs = get_data_hash_diff(files)
278282
if data_md5_diffs:
279283
# provide details, possibly triggering the ignore of the difference
280284
# in data

nibabel/cmdline/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import nibabel as nib
1212
import numpy as np
1313
from nibabel.cmdline.utils import *
14-
from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_md5_diff, get_data_diff
14+
from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_hash_diff, get_data_diff
1515
from os.path import (join as pjoin)
1616
from nibabel.testing import data_path
1717
from collections import OrderedDict
@@ -114,7 +114,7 @@ def test_get_data_diff():
114114
# testing for identical files specifically as md5 may vary by computer
115115
test_names = [pjoin(data_path, f)
116116
for f in ('standard.nii.gz', 'standard.nii.gz')]
117-
assert_equal(get_data_md5_diff(test_names), [])
117+
assert_equal(get_data_hash_diff(test_names), [])
118118

119119
# testing the maximum relative and absolute differences' different use cases
120120
test_array = np.arange(16).reshape(4, 4)

0 commit comments

Comments
 (0)