CaImAn icon indicating copy to clipboard operation
CaImAn copied to clipboard

NWB: save motion-corrected data

Open tbenst opened this issue 4 years ago • 7 comments

Looks like an initial attempt was made to save a CorrectedImageStack according to NWB schema. It'd be great to have this feature! Especially as the current mmap serialization will fail if the filename is ever changed, and hdf5 also supports (via hdf5plugin) BLOSC:zstd compression, for major space/IO savings.

https://github.com/flatironinstitute/CaImAn/blob/6c33118a5f55e5e178a0e18c896329f416ffef55/caiman/source_extraction/cnmf/estimates.py#L1633

tbenst avatar Apr 15 '20 05:04 tbenst

@bendichter What do you think about this? Is it worth doing? Do you want to make a PR?

epnev avatar Apr 15 '20 22:04 epnev

@epnev yes, definitely worth doing. I looked into this about a year ago. We wanted to be able to store a representation of the image transformation, not just the result, since some systems, e.g. SIMA, do it this way and compute the result on the fly. The current CorrectedImageStack in nwb schema just supports rigid translation, which I don't think is really used much anymore now that much more powerful methods are available and easy to use (e.g. CaImAn's NormCorre). It ended up being tricky to express the transformation in a way that was generalizable across popular ophys motion correction methods, and the project never quite reached the finish line (plus the lead of that started a new job). With all that context in mind, I'd be interested in rolling out something that's a little less ambitious. @tbenst, what would be useful for you to store? Storing the corrected image would be fairly easy to implement (though would take up a lot of space). The transformation might be tricky though, and I don't want to include it if it's not really right. Maybe we can just store a bit of meta-data about what algorithm was run. I can dig up the notes and preliminary implementation if someone is interested in following up on the project.

cc @rly, what do you think?

bendichter avatar Apr 15 '20 23:04 bendichter

@bendichter I think it would be a great idea to store this data. This is outside of my experience though, so, @tbenst, we would have to work closely with you and others in the community to get this right. If this is likely to take some iteration, I suggest making an NWB extension for the updated CorrectedImageStack.

rly avatar Apr 15 '20 23:04 rly

Storing the corrected image would be fairly easy to implement (though would take up a lot of space). The transformation might be tricky though, and I don't want to include it if it's not really right. Maybe we can just store a bit of meta-data about what algorithm was run.

Yes, storing the corrected images is exactly what I’m hoping for. NormCorre works quite well and I currently use the .mmap files for other analyses on raw images, and would be great to store these in NWB instead with compression.

Just a storing the metadata sounds great to me. I don’t have a use case for needing to know the translation, other than some QA/QC on amount of shift over time.

For now, perhaps could just insert NaN for xy_translation, then just output a new dataset with same ImageSeries/subclass of input data. Although changing/adding to NWB spec to account for non-rigid approaches is perhaps best.

tbenst avatar Apr 16 '20 06:04 tbenst

Just checking in to see if there was any movement on this. Do you know @pgunn or @bendichter ?

EricThomson avatar May 01 '23 18:05 EricThomson

I don't think we ever did this; I'd be happy to review a PR; if I get time I could look into implementing it myself.

pgunn avatar May 01 '23 18:05 pgunn

yeah, this has been on the back-burner for a while. I'd also be happy to contribute in an advisory/review role

bendichter avatar Jun 01 '23 14:06 bendichter