Skip to content

MRG: implementing / testing get_fdata #551

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 6 commits into from
Sep 5, 2017

Conversation

matthew-brett
Copy link
Member

@matthew-brett matthew-brett commented Aug 24, 2017

get_fdata the new proposed default method for getting the data from the image.
It always returns floating point.

See also discussion at https://mail.python.org/pipermail/neuroimaging/2017-April/001383.html

@matthew-brett matthew-brett mentioned this pull request Aug 24, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 96.233% when pulling 5cd1994 on matthew-brett:master into a4a667d on nipy:master.

@codecov-io
Copy link

codecov-io commented Aug 24, 2017

Codecov Report

Merging #551 into master will increase coverage by 0.01%.
The diff coverage is 98.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #551      +/-   ##
==========================================
+ Coverage   94.27%   94.29%   +0.01%     
==========================================
  Files         177      177              
  Lines       24332    24440     +108     
  Branches     2610     2619       +9     
==========================================
+ Hits        22940    23046     +106     
- Misses        918      919       +1     
- Partials      474      475       +1
Impacted Files Coverage Δ
nibabel/tests/test_filebasedimages.py 98.55% <100%> (+0.04%) ⬆️
nibabel/tests/test_spatialimages.py 99.7% <100%> (+0.04%) ⬆️
nibabel/tests/test_image_api.py 99.04% <100%> (+0.17%) ⬆️
nibabel/dataobj_images.py 95.55% <86.66%> (-4.45%) ⬇️

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 a4a667d...33138b5. Read the comment docs.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Looks reasonable. Only noticed a couple typos.

(no reference to the array). If the cache is full, "unchanged" leaves
the cache full and returns the cached array reference.

The cache can effect the behavior of the image, because if the cache is
Copy link
Member

Choose a reason for hiding this comment

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

affect

assert_true(is_proxy(img.dataobj))
# Confirm it is not a numpy array
assert_false(isinstance(img.dataobj, np.ndarray))
# Confirm it can be converted to a numpy array with is_array
Copy link
Member

Choose a reason for hiding this comment

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

asarray

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Woops. Codecov shows the following branch missed.

>>> data_again[0, 0, 0, 0]
0.0
"""
if caching not in ('fill', 'unchanged'):
Copy link
Member

Choose a reason for hiding this comment

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

Want to test caching='unknown'?

@@ -191,11 +204,155 @@ def get_data(self, caching='fill'):
self._data_cache = data
return data

def get_fdata(self, caching='fill', dtype=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.

any reason why float64 over float32 is the default?

Copy link
Member Author

Choose a reason for hiding this comment

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

@satra - the default up till now has been to return float64 for images with scaling. Also, some images do have float64 and it seems a shame to downgrade them with this call. So float32 seems to me like an option rather than a default.

@satra
Copy link
Member

satra commented Aug 26, 2017

@matthew-brett - other than my question, which shouldn't prevent this from being merged, and on top of @effigies review, the code and documentation looks good.

@effigies
Copy link
Member

Shouldn't, maybe?

@satra
Copy link
Member

satra commented Aug 26, 2017

thanks @effigies - that was definitely a lapso

Thanks for your eagle eye.
Restore test of not-valid string specifycing caching to `get_data` and
`get_fdata`.
@matthew-brett
Copy link
Member Author

Guys - thanks for the reviews. I've updated to respond to your comments, and I've added some more tests of the caching, along with a fix to the code. To help reviewing, can I suggest that y'all look at commit c729e06 separately (it has the caching changes, and tests)?

@matthew-brett matthew-brett changed the title WIP: implementing / testing get_fdata MRG: implementing / testing get_fdata Sep 4, 2017
The image cache gets reset when you ask for a new data type.  For
example, you might first read float64, and float64 gets cached, but then
you read float32, at which point you lose the float64 cache and get a
float32 cache.
@matthew-brett
Copy link
Member Author

Oops sorry - I missed a changed I needed to make in the tests, to reflect the change in caching behavior. I rebased. New commit with all the relevant changes is c800493.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 96.24% when pulling c800493 on matthew-brett:master into a4a667d on nipy:master.

PEP8 didn't like the indent, and my editor does, so change the syntax to
make PEP8 and my editor agree.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 96.24% when pulling 33138b5 on matthew-brett:master into a4a667d on nipy:master.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Looks good. @satra any further comments?

@satra
Copy link
Member

satra commented Sep 5, 2017

+1 from me as well.

@matthew-brett matthew-brett merged commit bb8c318 into nipy:master Sep 5, 2017
@matthew-brett
Copy link
Member Author

@effigies - any interests in being release manager again? It's ready as far as I am concerned - but I've got 15 hours of completely new teaching to prepare in the next couple of weeks, and I'm really slammed for time.

@effigies
Copy link
Member

effigies commented Sep 5, 2017

Sure. I'll aim to release by the end of the week. I'll let you know if I have any issues.

@mwaskom
Copy link
Member

mwaskom commented Oct 13, 2017

Was this discussed more somewhere else? The release notes link here for information about this change, but there's no information in the PR (aside from the code itself!) that motivates the new function. (I ask as it's my vague sense that get_fdata is intended to replace get_data).

@effigies
Copy link
Member

@mwaskom This thread is probably the better link... https://mail.python.org/pipermail/neuroimaging/2017-April/001383.html

@mwaskom
Copy link
Member

mwaskom commented Oct 13, 2017

Thanks @effigies. Perhaps the PR intro could be edited to include this link.

@effigies
Copy link
Member

Done.

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.

6 participants