Skip to content

BUG: preserve correlogram unit axes across segments - #4767

Merged
alejoe91 merged 6 commits into
SpikeInterface:mainfrom
AtomicGlance:fix-numpy-correlogram-segment-units
Sep 14, 2026
Merged

BUG: preserve correlogram unit axes across segments#4767
alejoe91 merged 6 commits into
SpikeInterface:mainfrom
AtomicGlance:fix-numpy-correlogram-segment-units

Conversation

@AtomicGlance

Copy link
Copy Markdown
Contributor

Fixes #4736.

When a unit is silent in one segment, the NumPy path sizes its segment result from the number of active units. With two units this can broadcast counts into the wrong pairs; non-contiguous indices can also raise an error. Pass the complete sorting's unit count to both segment helpers so each result preserves the global unit axes, including empty segments.

The optional num_units argument also affects direct calls to the exported helpers. Without it, the size is inferred as max(unit_index) + 1 (zero for empty input), leaving zero rows for missing indices. For example, labels [0, 2] now produce three auto-correlogram rows rather than two. This preserves index coordinates instead of dropping counts or raising for non-contiguous indices. I am open to using an accumulator argument instead if that is the preferred API.

The regression checks exact auto- and cross-correlogram counts for two and three units across segments, including an empty segment. It runs without Numba and additionally compares both implementations when Numba is installed. Both cases fail against the corresponding functions from upstream f03253e9c and pass with this change.

Validation on Python 3.13:

  • Full test_correlograms.py module: 42 passed, 40 skipped.
  • Black check on both changed files: passed.
  • git diff --check: passed.

The test environment uses the development ProbeInterface dependency required by this checkout and its declared Zarr 2 / numcodecs constraints. Pytest plugin autoload was disabled to avoid loading an unrelated DANDI plugin from the host environment.

@alejoe91 alejoe91 added the postprocessing Related to postprocessing module label Sep 8, 2026
@alejoe91
alejoe91 requested a review from yger September 8, 2026 07:32
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
@alejoe91 alejoe91 added this to the 0.105.0 milestone Sep 8, 2026

@alejoe91 alejoe91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since correlogram_for_one_segment and auto_correlogram_for_one_segment are only used internally and not exposed at the module level, let's just make num_units mandatory to avoid any confusion

Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
Comment thread src/spikeinterface/postprocessing/correlograms.py Outdated
@AtomicGlance

Copy link
Copy Markdown
Contributor Author

Done in 478f0dc. Both internal helpers now require num_units, and the unique-index fallback is removed. I also updated the docstrings to say int and adjusted the existing helper test to pass the complete unit count explicitly.

The correlogram test module passed locally: 43 passed, 40 skipped. Black and git diff --check passed too. Pytest plugin autoload was disabled to avoid an unrelated DANDI plugin from the shared environment. CI is rerunning for this commit.

@alejoe91
alejoe91 merged commit e6335e7 into SpikeInterface:main Sep 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postprocessing Related to postprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong correlograms from method="numpy" when a unit has no spikes in a segment

3 participants