Skip to content

ComputeWaveforms and ComputeTemplates: int() truncation causes inconsistent sample counts across slightly different sampling rates #4474

@Antorhythms

Description

@Antorhythms

In analyzer_extension_core.py, the nbefore and nafter properties in ComputeWaveforms and ComputeTemplates use int() (truncation) to convert millisecond parameters to sample counts:

@property
def nbefore(self):    
	return int(self.params["ms_before"] * self.sorting_analyzer.sampling_frequency / 1000.0)

This causes a ±1 sample inconsistency when the sampling rate deviates slightly from a round number. For example, with ms_before=2.0:
fs = 29999 Hz → int(59.998) = 59
fs = 30000 Hz → int(60.0) = 60

This means waveform arrays have different shapes and different center indices across datasets with nearly identical sampling rates.

Proposed fix:
Replace int() with round() in the nbefore/nafter properties of both ComputeWaveforms (lines 163, 167) and ComputeTemplates (lines 526, 532).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions