Skip to content

Commit b52401e

Browse files
authored
Merge pull request #536 from open-ephys/issue-506
Ensure gain correction always exists for NeuropixelsV2e devices
2 parents 012fe92 + 6c9790a commit b52401e

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

OpenEphys.Onix1/NeuropixelsV2eBetaData.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,21 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
5151
return DeviceManager.GetDevice(DeviceName).SelectMany(deviceInfo =>
5252
{
5353
var info = (NeuropixelsV2eDeviceInfo)deviceInfo;
54-
var metadata = ProbeIndex switch
54+
var (metadata, gainCorrection) = ProbeIndex switch
5555
{
56-
NeuropixelsV2Probe.ProbeA => info.ProbeMetadataA,
57-
NeuropixelsV2Probe.ProbeB => info.ProbeMetadataB,
56+
NeuropixelsV2Probe.ProbeA => (info.ProbeMetadataA, info.GainCorrectionA),
57+
NeuropixelsV2Probe.ProbeB => (info.ProbeMetadataB, info.GainCorrectionB),
5858
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
5959
};
6060

6161
if (metadata.ProbeSerialNumber == null)
6262
{
6363
throw new InvalidOperationException($"{ProbeIndex} is not detected. Ensure that the flex connection is properly seated.");
6464
}
65+
else if (gainCorrection == null)
66+
{
67+
throw new NullReferenceException($"Gain correction value is null for {ProbeIndex}.");
68+
}
6569

6670
var device = info.GetDeviceContext(typeof(NeuropixelsV2eBeta));
6771
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
@@ -70,13 +74,6 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
7074
.Where(frame => NeuropixelsV2eBetaDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
7175
var invertPolarity = info.InvertPolarity;
7276

73-
var gainCorrection = ProbeIndex switch
74-
{
75-
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
76-
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
77-
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
78-
};
79-
8077
return Observable.Create<NeuropixelsV2eBetaDataFrame>(observer =>
8178
{
8279
var sampleIndex = 0;
@@ -89,7 +86,7 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
8986
frame =>
9087
{
9188
var payload = (NeuropixelsV2BetaPayload*)frame.Data.ToPointer();
92-
NeuropixelsV2eBetaDataFrame.CopyAmplifierBuffer(payload->SuperFrame, amplifierBuffer, frameCounter, sampleIndex, gainCorrection, invertPolarity);
89+
NeuropixelsV2eBetaDataFrame.CopyAmplifierBuffer(payload->SuperFrame, amplifierBuffer, frameCounter, sampleIndex, gainCorrection.Value, invertPolarity);
9390
hubClockBuffer[sampleIndex] = payload->HubClock;
9491
clockBuffer[sampleIndex] = frame.Clock;
9592
if (++sampleIndex >= bufferSize)

OpenEphys.Onix1/NeuropixelsV2eData.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
5555
return DeviceManager.GetDevice(DeviceName).SelectMany(deviceInfo =>
5656
{
5757
var info = (NeuropixelsV2eDeviceInfo)deviceInfo;
58-
var metadata = ProbeIndex switch
58+
var (metadata, gainCorrection) = ProbeIndex switch
5959
{
60-
NeuropixelsV2Probe.ProbeA => info.ProbeMetadataA,
61-
NeuropixelsV2Probe.ProbeB => info.ProbeMetadataB,
60+
NeuropixelsV2Probe.ProbeA => (info.ProbeMetadataA, info.GainCorrectionA),
61+
NeuropixelsV2Probe.ProbeB => (info.ProbeMetadataB, info.GainCorrectionB),
6262
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
6363
};
6464

6565
if (metadata.ProbeSerialNumber == null)
6666
{
6767
throw new InvalidOperationException($"{ProbeIndex} is not detected. Ensure that the flex connection is properly seated.");
6868
}
69+
else if (gainCorrection == null)
70+
{
71+
throw new NullReferenceException($"Gain correction value is null for {ProbeIndex}.");
72+
}
6973

7074
var device = info.GetDeviceContext(typeof(NeuropixelsV2e));
7175
var passthrough = device.GetPassthroughDeviceContext(typeof(DS90UB9x));
@@ -74,13 +78,6 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
7478
.Where(frame => NeuropixelsV2eDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
7579
var invertPolarity = info.InvertPolarity;
7680

77-
var gainCorrection = ProbeIndex switch
78-
{
79-
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
80-
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
81-
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
82-
};
83-
8481
return Observable.Create<NeuropixelsV2eDataFrame>(observer =>
8582
{
8683
var sampleIndex = 0;
@@ -92,7 +89,7 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
9289
frame =>
9390
{
9491
var payload = (NeuropixelsV2Payload*)frame.Data.ToPointer();
95-
NeuropixelsV2eDataFrame.CopyAmplifierBuffer(payload->AmplifierData, amplifierBuffer, sampleIndex, gainCorrection, invertPolarity);
92+
NeuropixelsV2eDataFrame.CopyAmplifierBuffer(payload->AmplifierData, amplifierBuffer, sampleIndex, gainCorrection.Value, invertPolarity);
9693
hubClockBuffer[sampleIndex] = payload->HubClock;
9794
clockBuffer[sampleIndex] = frame.Clock;
9895
if (++sampleIndex >= bufferSize)

0 commit comments

Comments
 (0)