Skip to content

Commit 79e3842

Browse files
authored
Merge pull request #230 from open-ephys/issue-138
Improve neuropixels calibration file error messages
2 parents b7aae5e + b409519 commit 79e3842

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.IO;
34
using System.Linq;
45

56
namespace OpenEphys.Onix1
@@ -33,22 +34,36 @@ public NeuropixelsV1eRegisterContext(DeviceContext deviceContext, uint i2cAddres
3334
bool apFilter, string gainCalibrationFile, string adcCalibrationFile)
3435
: base(deviceContext, i2cAddress)
3536
{
36-
if (gainCalibrationFile == null || adcCalibrationFile == null)
37+
if (!File.Exists(gainCalibrationFile))
3738
{
38-
throw new ArgumentException("Calibration files must be specified.");
39+
throw new ArgumentException($"A gain calibration file must be specified for the probe with serial number " +
40+
$"{probeSerialNumber}");
3941
}
4042

41-
System.IO.StreamReader gainFile = new(gainCalibrationFile);
42-
var calSerialNumber = ulong.Parse(gainFile.ReadLine());
43+
if (!File.Exists(adcCalibrationFile))
44+
{
45+
throw new ArgumentException($"An ADC calibration file must be specified for the probe with serial number " +
46+
$"{probeSerialNumber}");
47+
}
48+
49+
50+
var gainFile = new StreamReader(gainCalibrationFile);
51+
var sn = ulong.Parse(gainFile.ReadLine());
4352

44-
if (calSerialNumber != probeSerialNumber)
45-
throw new ArgumentException("Gain calibration file serial number does not match probe serial number.");
53+
if (sn != probeSerialNumber)
54+
{
55+
throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " +
56+
$"match the gain calibration file serial number: {sn}.");
57+
}
4658

47-
System.IO.StreamReader adcFile = new(adcCalibrationFile);
48-
var adcSerialNumber = ulong.Parse(adcFile.ReadLine());
59+
var adcFile = new StreamReader(adcCalibrationFile);
60+
sn = ulong.Parse(adcFile.ReadLine());
4961

50-
if (adcSerialNumber != probeSerialNumber)
51-
throw new ArgumentException("ADC calibration file serial number does not match probe serial number.");
62+
if (sn != probeSerialNumber)
63+
{
64+
throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " +
65+
$"match the ADC calibration file serial number: {sn}.");
66+
}
5267

5368
// parse gain correction file
5469
var gainCorrections = gainFile.ReadLine().Split(',').Skip(1);

OpenEphys.Onix1/NeuropixelsV2.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.IO;
34

45
namespace OpenEphys.Onix1
56
{
@@ -116,13 +117,13 @@ internal static BitArray[] GenerateBaseBits(NeuropixelsV2QuadShankProbeConfigura
116117

117118
internal static double ReadGainCorrection(string gainCalibrationFile, ulong probeSerialNumber, NeuropixelsV2Probe probe)
118119
{
119-
if (gainCalibrationFile == null)
120+
if (!File.Exists(gainCalibrationFile) )
120121
{
121122
throw new ArgumentException($"A calibration file must be specified for {probe} with serial number " +
122-
$"{probeSerialNumber})");
123+
$"{probeSerialNumber}");
123124
}
124125

125-
System.IO.StreamReader gainFile = new(gainCalibrationFile);
126+
var gainFile = new StreamReader(gainCalibrationFile);
126127
var sn = ulong.Parse(gainFile.ReadLine());
127128

128129
if (probeSerialNumber != sn)

0 commit comments

Comments
 (0)