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

Conversation

chrispycheng
Copy link
Contributor

@chrispycheng chrispycheng commented Oct 3, 2018

This PR is based on PR #661
It should now be possible to modify the datatype used to compare the differences as seen below:

$> nib-diff --dt float32 nibabel/tests/data/standard.nii.gz nibabel/tests/data/example4d.nii.gz 
These files are different.
Field/File     1:standard.nii.gz                                      2:example4d.nii.gz                                     
regular        b''                                                    b'r'                                                   
dim_info       0                                                      57                                                     
dim            [3 4 5 7 1 1 1 1]                                      [  4 128  96  24   2   1   1   1]                      
datatype       2                                                      4                                                      
bitpix         8                                                      16                                                     
pixdim         [ 1.  1.  3.  2.  1.  1.  1.  1.]                      [ -1.00000000e+00   2.00000000e+00   2.00000000e+00   2.19999909e+00
   2.00000000e+03   1.00000000e+00   1.00000000e+00   1.00000000e+00]
slice_end      0                                                      23                                                     
xyzt_units     0                                                      10                                                     
cal_max        0.0                                                    1162.0                                                 
descrip        b''                                                    b'FSL3.3\x00 v2.25 NIfTI-1 Single file format'         
qform_code     0                                                      1                                                      
sform_code     2                                                      1                                                      
quatern_b      0.0                                                    -1.9451068140294884e-26                                
quatern_c      0.0                                                    -0.9967085123062134                                    
quatern_d      0.0                                                    -0.0810687392950058                                    
qoffset_x      0.0                                                    117.8551025390625                                      
qoffset_y      0.0                                                    -35.72294235229492                                     
qoffset_z      0.0                                                    -7.248798370361328                                     
srow_x         [ 1.  0.  0.  0.]                                      [ -2.00000000e+00   6.71471565e-19   9.08102451e-18   1.17855103e+02]
srow_y         [ 0.  3.  0.  0.]                                      [ -6.71471565e-19   1.97371149e+00  -3.55528235e-01  -3.57229424e+01]
srow_z         [ 0.  0.  2.  0.]                                      [  8.25548089e-18   3.23207617e-01   2.17108178e+00  -7.24879837e+00]
DATA(md5)      0a2576dd6badbb25bfb3b12076df986b                       b0abbc492b4fd533b2c80d82570062cf                       
DATA(diff 1:)  -                                                      CMP: incompat

TODOs

  • Write tests for accessing dtype on cmdline
  • Get feedback on this implementation @yarikoptic @effigies

@coveralls
Copy link

coveralls commented Oct 3, 2018

Coverage Status

Coverage remained the same at 91.84% when pulling edb72bc on chrispycheng:enh-diff-dtype into def0364 on nipy:master.

@codecov-io
Copy link

codecov-io commented Oct 4, 2018

Codecov Report

Merging #672 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #672   +/-   ##
=======================================
  Coverage   88.86%   88.86%           
=======================================
  Files          93       93           
  Lines       11434    11434           
  Branches     1890     1890           
=======================================
  Hits        10161    10161           
  Misses        933      933           
  Partials      340      340
Impacted Files Coverage Δ
nibabel/cmdline/diff.py 93.75% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update def0364...edb72bc. Read the comment docs.

@@ -313,7 +320,8 @@ def main(args=None, out=None):
files,
header_fields=opts.header_fields,
data_max_abs_diff=opts.data_max_abs_diff,
data_max_rel_diff=opts.data_max_rel_diff
data_max_rel_diff=opts.data_max_rel_diff,
dtype=opts.dtype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't work as is. In cmdline you will get a string, like "float64", whenever functions expect actual type, like np.float64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested code is broken code :-P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov appears green for it though? And I tested it in cmdline for myself. Could you please specify the use case you think I'm missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine because whenever we get a dtype_var, we generally immediately turn around and run dtype(dtype_var), which will take np.float64, or '<f8' or 'float64'.

dtype = np.dtype(dtype)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still would be nice to have a test which invokes main here providing then dtype as a string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming these pass, please check to make sure this meets with your standards. I checked with @yarikoptic -- is this what you had in mind?

@yarikoptic
Copy link
Member

ok, let me push a tiny change just to see the proper diff for this PR -- should be only dtype specification relevant now that we merged the other into master

@yarikoptic
Copy link
Member

oh, I am not allowed to push to @chrispycheng branch. Do you have a check mark "checked" for "Allow changes from contributors" ... see e.g https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/

@effigies
Copy link
Member

Merging master in, it looks like this is a test/style update.

@effigies effigies changed the title ENH: nib-diff - allow cmdline specification of which datatype to use to compare files' absolute and relative diff TST: Validate nib-diff dtype command-line option Oct 11, 2018
@effigies
Copy link
Member

I'm good with this if y'all are.

@yarikoptic
Copy link
Member

Thanks @effigies ... let's just travis to complete so nothing ugly creeps in

@chrispycheng
Copy link
Contributor Author

Seems like everything's in order

@yarikoptic yarikoptic merged commit 679aa5b into nipy:master Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants