Skip to content

Commit

Permalink
Merge pull request #230 from open-ephys/issue-138
Browse files Browse the repository at this point in the history
Improve neuropixels calibration file error messages
  • Loading branch information
jonnew authored Aug 22, 2024
2 parents b7aae5e + b409519 commit 79e3842
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
35 changes: 25 additions & 10 deletions OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.IO;
using System.Linq;

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

System.IO.StreamReader gainFile = new(gainCalibrationFile);
var calSerialNumber = ulong.Parse(gainFile.ReadLine());
if (!File.Exists(adcCalibrationFile))
{
throw new ArgumentException($"An ADC calibration file must be specified for the probe with serial number " +
$"{probeSerialNumber}");
}


var gainFile = new StreamReader(gainCalibrationFile);
var sn = ulong.Parse(gainFile.ReadLine());

if (calSerialNumber != probeSerialNumber)
throw new ArgumentException("Gain calibration file serial number does not match probe serial number.");
if (sn != probeSerialNumber)
{
throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " +
$"match the gain calibration file serial number: {sn}.");
}

System.IO.StreamReader adcFile = new(adcCalibrationFile);
var adcSerialNumber = ulong.Parse(adcFile.ReadLine());
var adcFile = new StreamReader(adcCalibrationFile);
sn = ulong.Parse(adcFile.ReadLine());

if (adcSerialNumber != probeSerialNumber)
throw new ArgumentException("ADC calibration file serial number does not match probe serial number.");
if (sn != probeSerialNumber)
{
throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " +
$"match the ADC calibration file serial number: {sn}.");
}

// parse gain correction file
var gainCorrections = gainFile.ReadLine().Split(',').Skip(1);
Expand Down
7 changes: 4 additions & 3 deletions OpenEphys.Onix1/NeuropixelsV2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.IO;

namespace OpenEphys.Onix1
{
Expand Down Expand Up @@ -116,13 +117,13 @@ internal static BitArray[] GenerateBaseBits(NeuropixelsV2QuadShankProbeConfigura

internal static double ReadGainCorrection(string gainCalibrationFile, ulong probeSerialNumber, NeuropixelsV2Probe probe)
{
if (gainCalibrationFile == null)
if (!File.Exists(gainCalibrationFile) )
{
throw new ArgumentException($"A calibration file must be specified for {probe} with serial number " +
$"{probeSerialNumber})");
$"{probeSerialNumber}");
}

System.IO.StreamReader gainFile = new(gainCalibrationFile);
var gainFile = new StreamReader(gainCalibrationFile);
var sn = ulong.Parse(gainFile.ReadLine());

if (probeSerialNumber != sn)
Expand Down

0 comments on commit 79e3842

Please sign in to comment.