-
Notifications
You must be signed in to change notification settings - Fork 258
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
WIP: add GIFTI to nib.load/save (and enable non-SpatialImage classes in load/save) #360
Conversation
It's worth noting that the code in |
In general it would be good to allow images that are not instances of |
Haven't had more than a glance at the code (any chance you could rebase against master so we can look at individual commits?), but the strategy in the solution seems reasonable to me. That said, maybe another approach is to make
Some file formats would support multiple of these interfaces, and having a hierarchy could lead to method-resolution-ordering issues. But maybe this is overcomplicating? |
@effigies This is interesting, as The downside, if I'm understanding properly, is that every image will have to have dual inheritance from But I'm not too familiar with mixins, honestly. |
I think of mixins as superclasses that try not to mess with the class hierarchy. Sure, they'd have multiple inheritance, but that doesn't strike me as onerous. One compromise would be to have something like |
I like the cleaner mixin idea; aliasing seems unnecessary to me. |
From your previous comment? Yeah, that's exactly the sort of thing I was thinking. But I don't really know enough about CIFTI to speak in any greater detail. Is it the case that in some cases you'll want to save it as a volume and others as a surface? Or can it contain both? I know it's XML serializable. It's worth noting what this idea vould be giving up. Right now
Sorry, I know I'm jumping all over the place. |
Not sorry for me--this kind of discussion is why I opened up this PR now. So, thank you!
So I would go for:
Though a problem may be that
|
Sorry, I think I was unclear. I meant that I think Your final hierarchy looks a bit like what I was suggesting two comments ago. To update with my last proposal:
|
In the interest of simplicity, I cherry-picked your commits. It's very slightly different from this branch, mostly name/ordering/style differences, as well as a couple things that got deleted/restored by your last merge that probably shouldn't have. Diff. Green is me, red is you. |
@effigies Thanks for that. Looks good to me. Your design looks good to me as well. Shall we do that now? You're welcome to force-push your cherry-picked changes to my branch; you should still have collaborator access. |
Pushed. Sounds good to me. To be clear, at this point I think this simply means abstracting Would you have some way of checking that |
Some |
I think we'd also change how each image class is declared; they would import from I'm not clear yet what Any thoughts about that?
CIFTI is implemented just as GIFTI was before--with |
So this PR is about getting Gifti (and then Cifti) into the I think the sketch-out we did above is useful for having a context for where we think we'll be going (pending broader review), especially for thinking about avoiding creating problems for that future PR, but I think it should be a future PR. What do you think? Regarding CIFTI, sounds like that means you can pretty much use the |
@effigies Sounds great to me. I was worried about fully fleshing things out now; definitely much broader in scope. I would even suggest leaving the XmlImage refactoring to the CIFTI PR, when there's a need for it, rather than trying to anticipate too much here. Presumably that'd be done before the next release, and anyway wouldn't interfere with how GIFTI is accessed. |
Yeah, holding off on @matthew-brett Pinging you just to give you a sync-point. As far as I'm concerned, we can move on to fiddly details. |
@effiges in order to simplify things, I think I'll break the refactoring of |
@effigies After starting on the Though I realize now we're using two different ways to name. I am using Lemme know what you think, when you have a chance! |
I was mainly using "XMLImage" because it's easier to type. I'd be a little hesitant to use both classes, just because they're similar enough names to cause confusion. But we can beat that horse when we come to it. Does it make sense to have the |
I'm pretty confident that I'll review what's on |
If there are definitely going to be common structures decided in #249, I'm okay with leaving This is just my initial thought, but I could be argued out. Don't know how much time I'll have to look at this again before next week, but if you want to rebase against master, that'll clean #364 out of this diff and make it easier to think about. |
@effiges I've moved over But as implementing an |
Separate PR for refactoring is fine by me. The only thing I wanted to avoid was putting a stub in now that will remain a stub. |
Sounds good. I have pulled back the commits for |
Sounds good. And that diff looks much more manageable. I'll have a detailed look through, soon. |
Brings branch into better alignment with 0ce347f
class GiftiImage(FileBasedImage, xml.XmlSerializable): | ||
valid_exts = ('.gii',) | ||
files_types = (('image', '.gii'),) | ||
valid_exts = ('.gii',) |
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.
Duplicated valid_exts
.
Removed duplicate |
Did you want to raise deprecation warnings on calls to I can go either way. It's documented. |
@effigies I think deprecation warnings to I've removed the |
Looks good. In it goes. |
MRG: Subclass GIFTI from FileBasedImage Deprecate gifti.read/write for nib.load/save
MRG: Subclass GIFTI from FileBasedImage Deprecate gifti.read/write for nib.load/save
This is for #316. All the recent work has been to get us here :D Thanks @matthew-brett and @effigies !
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.Caveats:
One danger in doing this is that not all image classes (
nibabel.imageclasses.all_image_classes
) will be of typeSpatialImage
. Some tests assume this, and I'm not sure if there's other code out there that might.To do:
SpatialImage
intoFileBasedHeader
/FileBasedImage
SpatialImage
GiftiImage
fromFileBasedImage
nibabel.gifti.read
andnibabel.gifti.write
Notes: