Skip to content

Commit 50a480e

Browse files
committed
fixed problems noted by Travis CI
1 parent 5db2654 commit 50a480e

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

nibabel/cmdline/diff.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ def diff_header_fields(key, inputs):
101101

102102

103103
def get_headers_diff(files, opts):
104-
"""
104+
"""
105105
Getting the difference of headers.
106106
Returns a dictionary that is later processed.
107-
107+
108108
Parameters
109109
----------
110110
files: list of files
@@ -113,7 +113,7 @@ def get_headers_diff(files, opts):
113113

114114
header_list = [nib.load(f).header for f in files]
115115

116-
if opts.header_fields: # will almost always have a header field
116+
if opts.header_fields: # will almost always have a header field
117117
# signals "all fields"
118118
if opts.header_fields == 'all':
119119
# TODO: header fields might vary across file types, thus prior sensing would be needed
@@ -134,19 +134,17 @@ def get_headers_diff(files, opts):
134134
return {}
135135

136136

137-
def get_data_diff(files):
137+
def get_data_md5sums(files):
138138

139-
data_list = [nib.load(f).get_data() for f in files]
140-
output = []
139+
md5sums = [
140+
hashlib.md5(np.ascontiguousarray(nib.load(f).get_data(), dtype=np.float32)).hexdigest()
141+
for f in files
142+
]
141143

142-
for a, b in itertools.combinations(data_list, 2):
143-
if diff_values(hash(str(a)), hash(str(b))):
144-
if hash(str(a)) not in output:
145-
output.append(str(hash(str(a))))
146-
if hash(str(b)) not in output:
147-
output.append(str(hash(str(b))))
144+
if len(set(md5sums)) == 1:
145+
return []
148146

149-
return output
147+
return md5sums
150148

151149

152150
def main():
@@ -164,7 +162,7 @@ def main():
164162
nib.imageglobals.logger.level = 50
165163

166164
header_diff = get_headers_diff(files, opts)
167-
data_diff = get_data_diff(files)
165+
data_diff = get_data_md5sums(files)
168166

169167
if len(data_diff) != 0 and len(header_diff) != 0:
170168
print("{:<11}".format('Field'), end="")

nibabel/tests/test_scripts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def check_nib_diff_examples(opts=[], hdrs_str="", other_str=""):
7272
for f in ('example4d.nii.gz', 'standard.nii.gz')]
7373
fnames2 = [pjoin(DATA_PATH, f)
7474
for f in ('example4d.nii.gz', 'example4d.nii.gz')]
75+
hash1 = str(hash(fnames[0]))
76+
hash2 = str(hash(fnames[1]))
7577
code, stdout, stderr = run_command(['nib-diff'] + fnames, check_code=False)
7678
assert_equal(stdout, "Field " + "{:<45}".format("example4d.nii.gz") + "{:<45}".format("standard.nii.gz")
7779
+ "\n" + "regular b'r' b'' "
@@ -109,11 +111,11 @@ def check_nib_diff_examples(opts=[], hdrs_str="", other_str=""):
109111
" " + "\n" + "srow_y [-6.7147157e-19, 1.9737115, -0.35552824, -35.722942][0.0, 3"
110112
".0, 0.0, 0.0] " + "\n" +
111113
"srow_z [8.2554809e-18, 0.32320762, 2.1710818, -7.2487984][0.0, 0.0, 2.0, 0.0] "
112-
" " + "\n" + "DATA: These files are different.")
114+
" " + "\n" + "DATA: These files are different.\nChecksum b0abbc49 "
115+
+ " 0a2576dd")
113116

114117
code, stdout, stderr = run_command(['nib-diff'] + fnames2, check_code=False)
115-
assert_equal(stdout, "Field "+ "{:<45}".format("example4d.nii.gz") + "{:<45}".format("example4d.nii.gz")
116-
+ "\n" + "DATA: These files are identical!")
118+
assert_equal(stdout, "DATA: These files are identical!")
117119

118120

119121

0 commit comments

Comments
 (0)