Skip to content

Commit 728bc57

Browse files
committed
Refactor gain correction handling to ensure non-null values for probes
1 parent 9c9c37e commit 728bc57

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

OpenEphys.Onix1/NeuropixelsV2eBetaData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public unsafe override IObservable<NeuropixelsV2eBetaDataFrame> Generate()
7070
.Where(frame => NeuropixelsV2eBetaDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
7171
var invertPolarity = info.InvertPolarity;
7272

73-
var gainCorrection = ProbeIndex switch
73+
double gainCorrection = ProbeIndex switch
7474
{
75-
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
76-
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
75+
NeuropixelsV2Probe.ProbeA => info.GainCorrectionA ?? throw new NullReferenceException($"No gain correction value found for {ProbeIndex}. Ensure that the probe is connected and the gain correction file is selected."),
76+
NeuropixelsV2Probe.ProbeB => info.GainCorrectionB ?? throw new NullReferenceException($"No gain correction value found for {ProbeIndex}. Ensure that the probe is connected and the gain correction file is selected."),
7777
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
7878
};
7979

OpenEphys.Onix1/NeuropixelsV2eData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public unsafe override IObservable<NeuropixelsV2eDataFrame> Generate()
7474
.Where(frame => NeuropixelsV2eDataFrame.GetProbeIndex(frame) == (int)ProbeIndex);
7575
var invertPolarity = info.InvertPolarity;
7676

77-
var gainCorrection = ProbeIndex switch
77+
double gainCorrection = ProbeIndex switch
7878
{
79-
NeuropixelsV2Probe.ProbeA => (double)info.GainCorrectionA,
80-
NeuropixelsV2Probe.ProbeB => (double)info.GainCorrectionB,
79+
NeuropixelsV2Probe.ProbeA => info.GainCorrectionA ?? throw new NullReferenceException($"No gain correction value found for {ProbeIndex}. Ensure that the probe is connected and the gain correction file is selected."),
80+
NeuropixelsV2Probe.ProbeB => info.GainCorrectionB ?? throw new NullReferenceException($"No gain correction value found for {ProbeIndex}. Ensure that the probe is connected and the gain correction file is selected."),
8181
_ => throw new InvalidEnumArgumentException($"Unexpected {nameof(ProbeIndex)} value: {ProbeIndex}")
8282
};
8383

0 commit comments

Comments
 (0)