-
Notifications
You must be signed in to change notification settings - Fork 260
RF: move load/save logic out of SpatialImage #364
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
Conversation
class ImageDataError(Exception): | ||
pass | ||
class Header(SpatialHeader): | ||
'''Alias for SpatialHeader; kept for backwards compatibility.''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be marked deprecated? e.g.
def __init__(self, *args, **kwargs):
warnings.warn('Header is deprecated, use SpatialHeader', DeprecationWarning)
SpatialHeader.__init__(self, *args, **kwargs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably note that you'll want stacklevel=2
in that warning.
Thanks @effigies! A question: for some comments, it's about old code. Most of the code is copy-pasted from I'm happy to deal with those things here, but I wanted to double-check first. Thanks! |
Could be a separate PR, but my thought is that while people are looking at code is a good time to make changes. And the changes will be tracked in the commits, if not the full PR diff. |
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## | ||
''' Common interface for any image format--volume or surface, binary or xml.''' | ||
|
||
from ..externals.six import string_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.externals
, not ..externals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I pushed before running tests; give me a min..
OK @effigies ; cleaned up and ran tests; pls take a look! |
doctests are failing; will work on those now. |
Made the code updates. A bit worried about deprecating Also a bit concerned about changing the base class of images from |
@bcipolli Regarding 9cc27ea: For images where there's a Is there any possibility that XML-based datasets will have multiple files (so a canonical filename is needed)? If not, then |
To be honest, I'm not quite sure what the difference is between posting an intent to deprecate and actually deprecating but not removing. Documentation should be updated ASAP, and
Good question. Is pickling really a thing we care about? The only case I can see is in In any event, I'm also okay with leaving things as subclassed from |
Done
I don't see any reason to keep it off of
I'm not sure; perhaps some people or tools use
I'd prefer not to do that; I think that introduces complexity without much of the benefits. I suggest we either use I'll try this out. |
@effigies I removed the commit and tested |
Okay. So no barrier to deprecating |
Not that I see. I agree that deprecating directly is a fine user experience, from my POV |
work: | ||
''' | ||
files_types = (('image', None),) | ||
alternate_exts = () # Modified by @ImageOpener.register_ext_from_image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid_exts
No _meta_sniff_len
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_meta_sniff_len
is optional, and on the header.
valid_exts
is required, but is also required to be defined by each subclass. Defining it here makes it easier to forget to do that, so I excluded it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof_hdr
is on the header, _meta_sniff_len
is on the image and used in path_maybe_image
without being checked to exist, first. (It does check whether the header class defines may_contain_header
, but that's not tied to presence of _meta_sniff_len
, AFAICT.)
files_types
must also be defined by subclasses, correct? I think its purpose here is documentary. But the point of my comment was that alternate_exts
has been removed from SpatialImage
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@classmethod | ||
def is_valid_extension(klass, ext): | ||
valid = tuple(ft[1] for ft in klass.files_types) + klass.alternate_exts | ||
return ext.lower() in valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_valid_extension
was removed from SpatialImage
in 0c06464.
Had another read through, and once we agree on the above issues, I think this can go in. |
…I was doing this PR.
Pushed a PEP8 cleanup for |
Agree, thanks for doing that! |
Alright. If you're happy with that commit (and the tests pass), in it goes. |
👍 |
RF: Move load/save logic out of SpatialImage into FileBasedImage Prepares for XML-based images that do not store data as binary arrays. Spatial{Image,Header} now subclass FileBased{Image,Header} Header is a deprecated alias for SpatialHeader
RF: Move load/save logic out of SpatialImage into FileBasedImage Prepares for XML-based images that do not store data as binary arrays. Spatial{Image,Header} now subclass FileBased{Image,Header} Header is a deprecated alias for SpatialHeader
This PR precedes #360, which builds off of this work. I'll copy some text from that PR; there's quite a bit of discussion about how this fits into forward-looking design of surface vs. spatial, binary vs. xml object models.
Issue:
The final issue blocking streamlined GIFTI/CIFTI in nibabel is: image file I/O functions are tied directly to the
SpatialImage
class; non-volumetric images (GIFTI/CIFTI) can't extendSpatialImage
and so can't easily get in theload
/save
patheway.Proposed Solution:
The good news is, the file I/O code actually is quite general. We can easily abstract the file I/O into a higher-level class (which I've called
FileBasedHeader
/FileBasedImage
, as the more genericHeader
was already taken) thatSpatialImage
andGiftiImage
inherit from.To do:
SpatialImage
intoFileBasedHeader
/FileBasedImage
SpatialImage
Notes: