Use channel offsets, not gains, when scaling amplitudes to uV - #4765
Open
JESUSROYETH wants to merge 1 commit into
Open
Use channel offsets, not gains, when scaling amplitudes to uV#4765JESUSROYETH wants to merge 1 commit into
JESUSROYETH wants to merge 1 commit into
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.
SpikeAmplitudeNodeandAmplitudeScalingNoderead the channel gains into their offset array, so withreturn_in_uV=True(the default) they returnraw * gain + gaininstead ofraw * gain + offset:Every amplitude is therefore off by exactly
gain - offsetµV. On an Intan.rhdrecording (gain=0.195,offset=-6389.76) that is +6389.955 µV on spikes whose true amplitude is about -46 µV, which also flips their sign; on a zero-offset recording such as SpikeGLX (gain=2.34375) it is a constant +2.34 µV on every spike.Measured over 1443 spikes of a generated ground-truth recording, comparing each amplitude against
recording.get_traces(return_in_uV=True)at the exact sample and channel that amplitude is taken from:amplitude_scalingspasses the scaled waveform tolinregressand keeps only the slope, so a uniform offset is absorbed by the intercept and the scalings do not move. When gains and offsets vary per channel the shift is not uniform and the median scaling goes from 2.5162 to 1.0018.The scaling was correct before the node-pipeline refactor in d3ac13f, which replaced
recording.get_traces(..., return_scaled=return_scaled)with the inline expression. Of the seven places outside tests that populate an offset, the other five all callget_channel_offsets().One regression test is added to the existing
test_spike_amplitudes.py, asserting that an amplitude equals the trace sample it is taken from. On unpatchedmainit fails for 141/141 spikes with a maximum absolute difference of 102.0, which isgain - offsetfor the test's gain 2.0 and offset -100.0.Test suites on Linux / Python 3.12:
postprocessing98 passed 40 skipped,metrics+exporters58 passed,curation+ analyzer core 98 passed 1 skipped. Not run on macOS or Windows, and not on 3.10 / 3.13.