surface template image alignment data for QC purpose#8
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
So far in the CaImAn MSR tool on IDEAS, the only available QC information was related to the registered cells (registration yield, average footprint centroid distances and overlap...). Yet, MSR consists in 2 steps: aligning the cellsets (precisely, aligning the sets of footprints based on x/y shifts obtained from aligning the template images), and register aligned cells across sessions. And even if alignment fails miserably, there could still be registered cells as long as they pass the centroid distance and overlap criteria. In other words, only relying on registered cells-related metrics for QCing MSR is risky and can mask catastrophic alignment failures.
This PR surfaces 2 pieces of information pertaining to the alignment step of MSR: the aligned template for the 1st session, and the x/y shifts necessary to align said template and footprints. It does so for both optical flow and NoRMCorre piecewise rigid approaches.
Also, this PR implements max_shifts-adaptive overlaps and square ratio for patches:
overlapswas hardcoded to[16, 16], which led (for some complex reason) tonan-onlyaligned patches when the needed shift to properly align templates was over 8 pixels; x/y shifts could still be computed and applied to the footprints, so MSR did work fine, but the aligned template was nan-only and couldn't be used to QC alignment. In this PR,overlapsis now set as the maximum betweenmax_shifts * 2andstrides / 4. Withstridesbeing defined as a quarter of the smaller FoV dimension (e.g., for a (640, 400)-shaped FoV,strideswould be100), this adaptiveoverlapskicks in formax_shifts> 12.5: ifmax_shifts = 10(defaults),overlapswould be25(strides / 4), but ifmax_shifts = 64(pixels),overlapswould be128(max_shifts * 2). Any value belowmax_shifts * 2leads to sparse aligned template (again, for some complex reason around this line in the CaImAn motion correction code), and impairs alignment QCing.stridesandoverlapsparameters; these 2 params were set based on the FoV dimensions, so non-square FoVs led to non-squre patches (e.g., (640, 400) FoVs led to (160, 100) patches). As the FoV is isotropic (both x and y axis have the same spatial resolution, it just happens that for some movies we record more data on one axis than on the other), I think it makes more sense to have square-ratio patches, which I implemented in this PR.TL;DR: we need this PR for QCing the alignment step of CaImAn MSR