Repository navigation
Fix two volspike() errors and add tests - #1587
Merged
pgunn merged 1 commit intoSep 22, 2026
Merged
Conversation
Use a square footprint for the dilation and a column vector for cv2.dft
Merged
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.
Use a square footprint for the dilation and a column vector for cv2.dft
Description
volspike() currently crashes on every call, for two separate reasons.
The first is the TypeError from #1577 and #1582: the dilation call passes
_shift_footprint_old()two arguments and it only takes one. I pass a single square footprint instead. #1568 already has this same one-line change, but the new test needs it to pass, so I've included it here. Happy to drop it if #1568 merges first.The second only shows up once the first is fixed. With OpenCV 5,
cv2.dftreturns shape (n, 2) for a flat input, andwhitened_matched_filter()indexes it as (n, 1, 2), so it raises an IndexError (#1586). Passing the trace as a column vector gives the shape the code expects. A separate check of just that function on OpenCV 4.11, 4.13 and 4.14 gave matching output before and after, so older OpenCV shouldn't be affected.At the default context_size of 35 the helper leaves the footprint unchanged, so the mask matches the plain
dilation(bw, np.ones([cs, cs]))that was there before 9ed9293. I only checked that on one synthetic mask. Even sizes (34 and 12) came out different, and I didn't dig into that.Nothing tested volspike() before, which is how that line stayed broken through two releases. I added
caiman/tests/test_volpy.py, which builds a small synthetic single-cell movie. One test calls the matched filter directly. The other two run the whole single-cell path and check the output structure and that the spikes it finds line up with the ones I planted.Fixes #1586
Fixes #1577
Fixes #1582
Type of change
Branching
Targets
dev.Has your PR been tested?
Yes, on macOS 14.7 (Apple M1 Pro) with OpenCV 5.0.0, under both Python 3.12 and Python 3.11:
caimanmanager test: 51 passed (the 48 existing tests plus the 3 new ones)yapf --diffon the new test file is clean.I didn't run
caimanmanager demotest. On macOS the CLI demos hang without the__main__guard from #1565, andtest_demos.shskips the voltage demo anyway. Everything I ran was on macOS, so I'll watch the Linux CI results here.