Skip to content

TST: Validate nib-diff dtype command-line option #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions nibabel/cmdline/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@ def get_opt_parser():

Option("-H", "--header-fields",
dest="header_fields", default='all',
help="Header fields (comma separated) to be printed as well (if present)"),
help="Header fields (comma separated) to be printed as well"
" (if present)"),

Option("--ma", "--data-max-abs-diff",
dest="data_max_abs_diff",
type=float,
default=0.0,
help="Maximal absolute difference in data between files to tolerate."),
help="Maximal absolute difference in data between files"
" to tolerate."),

Option("--mr", "--data-max-rel-diff",
dest="data_max_rel_diff",
type=float,
default=0.0,
help="Maximal relative difference in data between files to tolerate."
" If --data-max-abs-diff is also specified, only the data points "
" with absolute difference greater than that value would be "
" considered for relative difference check."),
help="Maximal relative difference in data between files to"
" tolerate. If --data-max-abs-diff is also specified,"
" only the data points with absolute difference greater"
" than that value would be considered for relative"
" difference check."),
Option("--dt", "--datatype",
dest="dtype",
default=np.float64,
Expand Down Expand Up @@ -302,15 +305,16 @@ def display_diff(files, diff):
return output


def diff(files, header_fields='all', data_max_abs_diff=None, data_max_rel_diff=None,
dtype=np.float64):
def diff(files, header_fields='all', data_max_abs_diff=None,
data_max_rel_diff=None, dtype=np.float64):
assert len(files) >= 2, "Please enter at least two files"

file_headers = [nib.load(f).header for f in files]

# signals "all fields"
if header_fields == 'all':
# TODO: header fields might vary across file types, thus prior sensing would be needed
# TODO: header fields might vary across file types,
# thus prior sensing would be needed
header_fields = file_headers[0].keys()
else:
header_fields = header_fields.split(',')
Expand Down
4 changes: 4 additions & 0 deletions nibabel/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def check_nib_diff_examples():
code, stdout, stderr = run_command(['nib-diff'] + fnames4, check_code=False)
assert_equal(stdout, "These files are identical.")

code, stdout, stderr = run_command(['nib-diff', '--dt', 'float64'] + fnames, check_code=False)
for item in checked_fields:
assert_true(item in stdout)



@script_test
Expand Down