Skip to content

Fix two volspike() errors and add tests - #1587

Merged
pgunn merged 1 commit into
flatironinstitute:devfrom
eeshaanjum:fix-spikepursuit-dilation
Sep 22, 2026
Merged

pgunn merged 1 commit into
flatironinstitute:devfrom
eeshaanjum:fix-spikepursuit-dilation

Conversation

@eeshaanjum

Copy link
Copy Markdown

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.dft returns shape (n, 2) for a flat input, and whitened_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

  • Bug fix (non-breaking change which fixes an issue)

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)
  • Without the fixes the new tests fail: volspike() raises the TypeError with neither fix and the IndexError with only the footprint fix. With both, all three pass.
  • yapf --diff on the new test file is clean.

I didn't run caimanmanager demotest. On macOS the CLI demos hang without the __main__ guard from #1565, and test_demos.sh skips the voltage demo anyway. Everything I ran was on macOS, so I'll watch the Linux CI results here.

Use a square footprint for the dilation and a column vector for cv2.dft
@pgunn
pgunn merged commit ae96a7f into flatironinstitute:dev Sep 22, 2026
3 checks passed
@eeshaanjum eeshaanjum mentioned this pull request Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants