Closed tashrifbillah closed 6 years ago
Merging #74 into master will increase coverage by
0.72%
. The diff coverage is62.5%
.
@@ Coverage Diff @@
## master #74 +/- ##
==========================================
+ Coverage 87.39% 88.12% +0.72%
==========================================
Files 6 6
Lines 357 362 +5
Branches 114 117 +3
==========================================
+ Hits 312 319 +7
+ Misses 22 21 -1
+ Partials 23 22 -1
Impacted Files | Coverage Ξ | |
---|---|---|
nrrd/reader.py | 83.73% <62.5%> (+1.74%) |
:arrow_up: |
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 5310894...f82bfcb. Read the comment docs.
cc: @ihnorton
Let me know what do you think @addisonElliott
How does it look now? I understand for all compressed data, data.flags['WRITEABLE']
is False
for some reason, but don't know why.
I have taken care of the previous failures. Sorry, it took me some time to realize that the version installed in my computer was different from the cloned one. This mismatch attributed to all the mysterious missing lines so far.
We should be good now.
How does it look now? I understand for all compressed data,
data.flags['WRITEABLE']
isFalse
for some reason, but don't know why.
Take a look there: https://github.com/mhe/pynrrd/pull/68
Here is the relevant information I discovered:
Use fromstring function when dealing with compressed data because it will copy the data from the string into a Numpy array and allow the data to be editable. If you use frombuffer, then it will simply reference the memory. For a binary string, this ends up with the numpy array not being editable.
Done, sorry about that.
Code looks good, just add a few quick tests to test it and we should be good to go! π
Test that it throws an exception when byte_skip is negative (but not -1) Change the byte_skip dataset to add fake data to the front of it so that you have to do a byte_skip=-1 to get it to work. Then add a test with/without byte_skip being -1 to ensure it works. Repeat the above test for raw, ASCII & GZIP
Your test data addition suggestion should be straightforward. I'll try to complete them soon.
Test that it throws an exception when byte_skip is negative (but not -1)
This is done using numpy.testing.assert_raises.
I am working on the rest.
Wasn't aware of numpy.testing.assert_raises so that's great, but the NRRD test util has it's own function, see here: https://github.com/mhe/pynrrd/blob/master/nrrd/tests/test_reading.py#L122
I would use that just to be consistent.
You edited your comment but you make a good point about adding random data. Not sure...but it would be nice to verify that byte_skip=-1 is working correctly in a sense that it won't work without byte_skip = -1.
If it can't be done then that's okay, just stick with the normal tests.
Yeah, after putting my comment, I realized there might be a way of doing the way you suggested. So, let's see if I can come up with that design. Otherwise, you have my all ears.
Not entirely sure but based on the comment, I think it is seeking to right where the header stops. It seems here so the next parts are where the data is located
Sounds like it was a special case added to fix something
Hey @addisonElliott , I have been able to form a test case that demonstrates the use of byte_skip: -1
.
I am at the final stage of my editing. However, can you help a little but about https://github.com/mhe/pynrrd/blob/master/nrrd/tests/test_reading.py#L122 ?
I mean how do I apply it instead of
np.testing.assert_raises(nrrd.errors.NRRDError, nrrd.read, GZ_NIFTI_NHDR_FILE_PATH)
that I have used?
In my opinion, since you have used np.testing
all through the test_reading.py
, I think you are better off using np.testing.assert_raises
.
Yeah, I understand. The benefit of the utility assertRaises function is that you can ensure that the error message is exactly what you expect. Not sure if np.testing has that capability.
Either way works, but for consistency, just stick with the utility function.
It works like this: take that line of code, change the message to what it should be, and then inside the context of the with statement, place your core that should cause an exception
Should be something like:
with self.assertRaises(nrrd.NRRDError, 'Message here of exception'):
nrrd.read(GZ_NIFTI_NHDR_FILE_PATH)
I hope we have done what we wanted. Now Pynrrd
supports byte skip: -1
even for compressed data.
Great job @tashrifbillah!
The test cases are great, and I'm especially pleased by the byte_skip=-1 with NIFTI TAR file as the data. Great practical test.
I'm going to merge this into master and I'll wait a few weeks before publishing a new version in case any other PRs are submitted. If I forget in a few weeks, bug me somehow and I'll publish a new version.
π
No problem, happy to work on it. @ihnorton may also put his two cents in when he gets back.
Fixed byteskip -1 reading issue #70
Added test for both
nrrd
andnhdr
files withbyte skip: -1
Added test data with
nrrd
gzip andnhdr
raw files withbyte skip: -1