-
Notifications
You must be signed in to change notification settings - Fork 262
WIP: loadsave refactoring #319
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
@effigies - one design concern that I came across while looking at implementing this myself:
I prefer that design, as it reuses the existing data rather than duplicates the extension information. What do you think about migrating to that design? |
Actually, |
Tried that first, but the Frankly not married to it, so do what you will. On July 9, 2015 12:20:15 PM EDT, Ben Cipollini notifications@github.com wrote:
Chris Markiewicz |
Is there any reason not to enumerate all valid file types in |
|
One possibility is reducing valid_exts to additional extensions (so just .mgz) and constructing most of IMAGE_MAP from files_types. The current construction is more explicit and eliminates the need for each image type to be imported into loadsave, but we could remove the redundancy which is really for just the one case. On July 9, 2015 12:33:57 PM EDT, Matthew Brett notifications@github.com wrote:
Chris Markiewicz |
The special-casing for |
We could just have Then just tweak
I also see that compression extensions are defined in quite a few places (in Do image types that have separate header files allow compressed files? Perhaps they compress the image only, eh... I will think about this. |
Image types that allow compressed files compress both header and image. |
Summary of
Used for:
|
By the way, you may know that '.mgz' files can also have extension '.mgh.gz' - nibabel will open either: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat |
I am looking at this now. @matthew-brett Why is Also, any concerns if we (secretly) allow reading of |
It's OK to read 'mgz.gz' - if a little weird. BinOpener, as you see, is just a hack allowing '.mgz' as an extension indicating that the file is zip compressed - so it's in volumeutils only because the hack is not intrinsic to openers, but to images. It should probably go in the freesurfer modules, now I think about it (and the other classes use Opener) |
OK that's good to hear. I agree, and I think not too much work will clean things up nicely. I'll try it out now. |
return False, sniff | ||
|
||
fname = froot + ftypes['header'] if 'header' in ftypes else filename | ||
if not sniff: |
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 also check the size of the sniff
@effigies I went through this today, seeing how things work if taking out the Found some things I left comments on here; please let me know if you think I'm off on any of the comments. I plan to try and work through those, and the other changes discussed, so no need to change them yourself. But ideas / feedback welcome! |
Glad to see you say that. Your comments made me worry you were treating this as the canonical PR for #317, while I've been operating under the assumption you have your own fork going on the issue. I've done a little more work trying to make I'll have a look and make comments. |
Thanks @effigies . I have a branch that should be pretty close today (though beefing up the tests would be good). Do you prefer I do a PR against your branch, or submit an independent PR here? The design is different enough that I think doing an independent PR makes sense, but thought I'd check with you since you did significant work on it too! In case it helps: |
A new PR is fine with me. |
MRG: Migrate load, save, class_map, ext_map to class properties and methods This is to address #317 and #323 (and aims to supercede PR #319), both issues around image-specific code being distributed across files, rather than localized in the class definition. Changes here include: * Removing image-specific code from `nib.load` and `nib.save` functions, moving the logic into `ImageKlass.is_image` and `HeaderKlass.is_header` class functions. * Deprecating `class_map` and `ext_map` objects, and moving necessary info to properties defined on the image classes themselves.
MRG: Migrate load, save, class_map, ext_map to class properties and methods This is to address nipy#317 and nipy#323 (and aims to supercede PR nipy#319), both issues around image-specific code being distributed across files, rather than localized in the class definition. Changes here include: * Removing image-specific code from `nib.load` and `nib.save` functions, moving the logic into `ImageKlass.is_image` and `HeaderKlass.is_header` class functions. * Deprecating `class_map` and `ext_map` objects, and moving necessary info to properties defined on the image classes themselves.
A first pass at #317, because apparently I don't have real work to do.
This so far only addresses the load half of load/save, but puts into practice some of the ideas we talked about, e.g. the decorator. (At first I tried just using
klass.files_types
, but that broke.mgz
.)One thing this demonstrates is that the checks in
guessed_image_type
were contextual; moving these checks into theklass.is_image
files doesn't produce standalone functions that you'd probably expect.A possibility is to make
@valid_exts
more forceful and add an assertion aroundis_image
.I killed off some tests along with their functions, so those'll need replacing.