diff --git a/OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs b/OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs index c213349..dfb8a7c 100644 --- a/OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs +++ b/OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs @@ -169,10 +169,10 @@ private struct ProbeEdge public ProbeEdge(ZedGraphControl zedGraphControl) { - Left = GetProbeContourMinX(zedGraphControl.GraphPane.GraphObjList); - Right = GetProbeContourMaxX(zedGraphControl.GraphPane.GraphObjList); - Bottom = GetProbeContourMinY(zedGraphControl.GraphPane.GraphObjList); - Top = GetProbeContourMaxY(zedGraphControl.GraphPane.GraphObjList); + Left = GetProbeMinX(zedGraphControl.GraphPane.GraphObjList); + Right = GetProbeMaxX(zedGraphControl.GraphPane.GraphObjList); + Bottom = GetProbeMinY(zedGraphControl.GraphPane.GraphObjList); + Top = GetProbeMaxY(zedGraphControl.GraphPane.GraphObjList); } } @@ -423,13 +423,13 @@ private void FormShown(object sender, EventArgs e) } } - internal virtual void OpenFile() where T : ProbeGroup + internal virtual bool OpenFile() where T : ProbeGroup { var newConfiguration = OpenAndParseConfigurationFile(); if (newConfiguration == null) { - return; + return false; } if (ChannelConfiguration.NumberOfContacts == newConfiguration.NumberOfContacts) @@ -439,11 +439,15 @@ internal virtual void OpenFile() where T : ProbeGroup ChannelConfiguration = newConfiguration; DrawProbeGroup(); RefreshZedGraph(); + + return true; } else { - throw new InvalidOperationException($"Number of contacts does not match; expected {ChannelConfiguration.NumberOfContacts} contacts" + - $", but found {newConfiguration.NumberOfContacts} contacts"); + MessageBox.Show($"Error: Number of contacts does not match; expected {ChannelConfiguration.NumberOfContacts} contacts" + + $", but found {newConfiguration.NumberOfContacts} contacts", "Contact Number Mismatch"); + + return false; } } @@ -460,7 +464,7 @@ internal T OpenAndParseConfigurationFile() where T : ProbeGroup { var newConfiguration = DesignHelper.DeserializeString(File.ReadAllText(ofd.FileName)); - return newConfiguration ?? throw new InvalidOperationException($"Unable to open {ofd.FileName}"); + return newConfiguration; } return null; @@ -471,9 +475,9 @@ internal void DrawProbeGroup() zedGraphChannels.GraphPane.GraphObjList.Clear(); DrawProbeContour(); + DrawContacts(); SetEqualAspectRatio(); SetZoomOutBoundaries(); - DrawContacts(); HighlightEnabledContacts(); HighlightSelectedContacts(); DrawContactLabels(); @@ -492,6 +496,8 @@ internal void DrawProbeContour() foreach (var probe in ChannelConfiguration.Probes) { + if (probe == null || probe.ProbePlanarContour == null) continue; + PointD[] planarContours = ConvertFloatArrayToPointD(probe.ProbePlanarContour); PolyObj contour = new(planarContours, Color.LightGray, Color.White) { @@ -521,10 +527,10 @@ internal void SetEqualAspectRatio() if (zedGraphChannels.GraphPane.GraphObjList.Count == 0) return; - var minX = GetProbeContourMinX(zedGraphChannels.GraphPane.GraphObjList); - var minY = GetProbeContourMinY(zedGraphChannels.GraphPane.GraphObjList); - var maxX = GetProbeContourMaxX(zedGraphChannels.GraphPane.GraphObjList); - var maxY = GetProbeContourMaxY(zedGraphChannels.GraphPane.GraphObjList); + var minX = GetProbeMinX(zedGraphChannels.GraphPane.GraphObjList); + var minY = GetProbeMinY(zedGraphChannels.GraphPane.GraphObjList); + var maxX = GetProbeMaxX(zedGraphChannels.GraphPane.GraphObjList); + var maxY = GetProbeMaxY(zedGraphChannels.GraphPane.GraphObjList); var rangeX = maxX - minX; var rangeY = maxY - minY; @@ -578,6 +584,8 @@ internal void DrawContacts() contactObj.Border.Width = borderWidth; contactObj.Border.IsVisible = false; + contactObj.Location.AlignV = AlignV.Center; + contactObj.Location.AlignH = AlignH.Center; zedGraphChannels.GraphPane.GraphObjList.Add(contactObj); } @@ -593,6 +601,8 @@ internal void DrawContacts() contactObj.Border.Width = borderWidth; contactObj.Border.IsVisible = false; + contactObj.Location.AlignV = AlignV.Bottom; + contactObj.Location.AlignH = AlignH.Left; zedGraphChannels.GraphPane.GraphObjList.Add(contactObj); } @@ -802,6 +812,26 @@ internal float ContactSize() return 1f; } + // TODO: Convert from MinX/MaxX/... to Left / Right / etc. + internal static double GetProbeMinX(GraphObjList graphObjs) + { + if (graphObjs == null || graphObjs.Count == 0) return 0f; + + if (graphObjs.OfType().Count() == 0) + { + return GetContactMinX(graphObjs); + } + else + { + return GetProbeContourMinX(graphObjs); + } + } + + internal static double GetContactMinX(GraphObjList graphObjs) + { + return graphObjs.OfType() + .Min(obj => { return obj.Location.Rect.Left; }); + } internal static double GetProbeContourMinX(GraphObjList graphObjs) { @@ -809,18 +839,78 @@ internal static double GetProbeContourMinX(GraphObjList graphObjs) .Min(obj => { return obj.Points.Min(p => p.X); }); } + internal static double GetProbeMinY(GraphObjList graphObjs) + { + if (graphObjs == null || graphObjs.Count == 0) return 0f; + + if (graphObjs.OfType().Count() == 0) + { + return GetContactMinY(graphObjs); + } + else + { + return GetProbeContourMinY(graphObjs); + } + } + + internal static double GetContactMinY(GraphObjList graphObjs) + { + return graphObjs.OfType() + .Min(obj => { return obj.Location.Rect.Top - obj.Location.Height; }); + } + internal static double GetProbeContourMinY(GraphObjList graphObjs) { return graphObjs.OfType() .Min(obj => { return obj.Points.Min(p => p.Y); }); } + internal static double GetProbeMaxX(GraphObjList graphObjs) + { + if (graphObjs == null || graphObjs.Count == 0) return 0f; + + if (graphObjs.OfType().Count() == 0) + { + return GetContactMaxX(graphObjs); + } + else + { + return GetProbeContourMaxX(graphObjs); + } + } + + internal static double GetContactMaxX(GraphObjList graphObjs) + { + return graphObjs.OfType() + .Max(obj => { return obj.Location.Rect.Right; }); + } + internal static double GetProbeContourMaxX(GraphObjList graphObjs) { return graphObjs.OfType() .Max(obj => { return obj.Points.Max(p => p.X); }); } + internal static double GetProbeMaxY(GraphObjList graphObjs) + { + if (graphObjs == null || graphObjs.Count == 0) return 0f; + + if (graphObjs.OfType().Count() == 0) + { + return GetContactMaxY(graphObjs); + } + else + { + return GetProbeContourMaxY(graphObjs); + } + } + + internal static double GetContactMaxY(GraphObjList graphObjs) + { + return graphObjs.OfType() + .Max(obj => { return obj.Location.Rect.Bottom - obj.Location.Height; }); + } + internal static double GetProbeContourMaxY(GraphObjList graphObjs) { return graphObjs.OfType() @@ -969,9 +1059,11 @@ private void UpdateControlSizeBasedOnAxisSize() private void MenuItemOpenFile(object sender, EventArgs e) { - OpenFile(); - DrawProbeGroup(); - RefreshZedGraph(); + if (OpenFile()) + { + DrawProbeGroup(); + RefreshZedGraph(); + } } private void MenuItemLoadDefaultConfig(object sender, EventArgs e) @@ -1009,13 +1101,14 @@ public void MoveToVerticalPosition(float relativePosition) { if (relativePosition < 0.0 || relativePosition > 1.0) { - throw new ArgumentOutOfRangeException(nameof(relativePosition)); + MessageBox.Show($"Warning: Invalid relative position given while moving. Expected values between 0.0 and 1.0, but received {relativePosition}.", "Invalid Relative Position"); + return; } var currentRange = zedGraphChannels.GraphPane.YAxis.Scale.Max - zedGraphChannels.GraphPane.YAxis.Scale.Min; - var minY = GetProbeContourMinY(zedGraphChannels.GraphPane.GraphObjList); - var maxY = GetProbeContourMaxY(zedGraphChannels.GraphPane.GraphObjList); + var minY = GetProbeMinY(zedGraphChannels.GraphPane.GraphObjList); + var maxY = GetProbeMaxY(zedGraphChannels.GraphPane.GraphObjList); var newMinY = (maxY - minY - currentRange) * relativePosition; @@ -1025,8 +1118,8 @@ public void MoveToVerticalPosition(float relativePosition) internal float GetRelativeVerticalPosition() { - var minY = GetProbeContourMinY(zedGraphChannels.GraphPane.GraphObjList); - var maxY = GetProbeContourMaxY(zedGraphChannels.GraphPane.GraphObjList); + var minY = GetProbeMinY(zedGraphChannels.GraphPane.GraphObjList); + var maxY = GetProbeMaxY(zedGraphChannels.GraphPane.GraphObjList); var currentRange = zedGraphChannels.GraphPane.YAxis.Scale.Max - zedGraphChannels.GraphPane.YAxis.Scale.Min; @@ -1200,7 +1293,9 @@ internal void SetAllSelections(bool newStatus) private bool GetContactStatus(ContactTag tag) { if (tag == null) - throw new ArgumentNullException("Attempted to check contact status of an object that is not a contact."); + { + MessageBox.Show($"Error: Attempted to check status of an object that is not a contact.", "Invalid Object Selected"); + } return SelectedContacts[tag.ContactIndex]; } diff --git a/OpenEphys.Onix1.Design/DesignHelper.cs b/OpenEphys.Onix1.Design/DesignHelper.cs index 8a56783..f8c23f7 100644 --- a/OpenEphys.Onix1.Design/DesignHelper.cs +++ b/OpenEphys.Onix1.Design/DesignHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -9,10 +9,44 @@ namespace OpenEphys.Onix1.Design { static class DesignHelper { - public static T DeserializeString(string channelLayout) + /// + /// Given a string with a valid JSON structure, deserialize the string to the given type. + /// + /// + /// + /// + #nullable enable + public static T? DeserializeString(string channelLayout) { - return JsonConvert.DeserializeObject(channelLayout); + var errors = new List(); + + var serializerSettings = new JsonSerializerSettings() + { + Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) + { + errors.Add(args.ErrorContext.Error.Message); + args.ErrorContext.Handled = true; + } + }; + + var obj = JsonConvert.DeserializeObject(channelLayout, serializerSettings); + + if (errors.Count > 0) + { + MessageBox.Show($"There were errors encountered while parsing a JSON string. Check the console " + + $"for an error log.", "JSON Parse Error"); + + foreach (var e in errors) + { + Console.Error.WriteLine(e); + } + + return default; + } + + return obj; } + #nullable disable public static void SerializeObject(object _object, string filepath) { diff --git a/OpenEphys.Onix1.Design/NeuropixelsV1eChannelConfigurationDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV1eChannelConfigurationDialog.cs index d65b4e3..6bab162 100644 --- a/OpenEphys.Onix1.Design/NeuropixelsV1eChannelConfigurationDialog.cs +++ b/OpenEphys.Onix1.Design/NeuropixelsV1eChannelConfigurationDialog.cs @@ -62,14 +62,19 @@ internal override void LoadDefaultChannelLayout() OnFileOpenHandler(); } - internal override void OpenFile() + internal override bool OpenFile() { - base.OpenFile(); + if (base.OpenFile()) + { + ProbeConfiguration = new((NeuropixelsV1eProbeGroup)ChannelConfiguration, ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter); + ChannelConfiguration = ProbeConfiguration.ChannelConfiguration; - ProbeConfiguration = new((NeuropixelsV1eProbeGroup)ChannelConfiguration, ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter); - ChannelConfiguration = ProbeConfiguration.ChannelConfiguration; + OnFileOpenHandler(); - OnFileOpenHandler(); + return true; + } + + return false; } private void OnFileOpenHandler() @@ -122,9 +127,11 @@ internal override void DrawScale() var majorTickOffset = MajorTickLength + CalculateScaleRange(zedGraphChannels.GraphPane.XAxis.Scale) * 0.015; majorTickOffset = majorTickOffset > 50 ? 50 : majorTickOffset; - var x = GetProbeContourMaxX(zedGraphChannels.GraphPane.GraphObjList) + 40; - var minY = GetProbeContourMinY(zedGraphChannels.GraphPane.GraphObjList); - var maxY = GetProbeContourMaxY(zedGraphChannels.GraphPane.GraphObjList); + var x = GetProbeMaxX(zedGraphChannels.GraphPane.GraphObjList) + 40; + var minY = GetProbeMinY(zedGraphChannels.GraphPane.GraphObjList); + var maxY = GetProbeMaxY(zedGraphChannels.GraphPane.GraphObjList); + + int textPosition = 0; PointPairList pointList = new(); @@ -138,15 +145,17 @@ internal override void DrawScale() pointList.Add(majorTickLocation); pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks)); - if (!zoomedOut || i % (5 * MajorTickIncrement) == 0) + if (!zoomedOut || countMajorTicks % 5 == 0) { - TextObj textObj = new($"{i} µm", majorTickLocation.X + 10, majorTickLocation.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center) + TextObj textObj = new($"{textPosition} µm", majorTickLocation.X + 10, majorTickLocation.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center) { Tag = ScaleTextTag }; textObj.FontSpec.Border.IsVisible = false; textObj.FontSpec.Size = fontSize; zedGraphChannels.GraphPane.GraphObjList.Add(textObj); + + textPosition += zoomedOut ? 5 * MajorTickIncrement : MajorTickIncrement; } if (!zoomedOut) diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eChannelConfigurationDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eChannelConfigurationDialog.cs index 254f932..37354f2 100644 --- a/OpenEphys.Onix1.Design/NeuropixelsV2eChannelConfigurationDialog.cs +++ b/OpenEphys.Onix1.Design/NeuropixelsV2eChannelConfigurationDialog.cs @@ -54,38 +54,21 @@ internal override void LoadDefaultChannelLayout() ProbeConfiguration = new(ProbeConfiguration.Probe, ProbeConfiguration.Reference); ChannelConfiguration = ProbeConfiguration.ChannelConfiguration; - DrawProbeGroup(); - RefreshZedGraph(); - OnFileOpenHandler(); } - internal override void OpenFile() + internal override bool OpenFile() { - var newConfiguration = OpenAndParseConfigurationFile(); - - if (newConfiguration == null) - { - return; - } - - if (ProbeConfiguration.ChannelConfiguration.NumberOfContacts == newConfiguration.NumberOfContacts) + if (base.OpenFile()) { - newConfiguration.Validate(); + ProbeConfiguration = new((NeuropixelsV2eProbeGroup)ChannelConfiguration, ProbeConfiguration.Reference, ProbeConfiguration.Probe); - ProbeConfiguration = new(newConfiguration, ProbeConfiguration.Reference, ProbeConfiguration.Probe); - ChannelConfiguration = ProbeConfiguration.ChannelConfiguration; + OnFileOpenHandler(); - DrawProbeGroup(); - RefreshZedGraph(); - } - else - { - throw new InvalidOperationException($"Number of contacts does not match; expected {ProbeConfiguration.ChannelConfiguration.NumberOfContacts} contacts" + - $", but found {newConfiguration.NumberOfContacts} contacts"); + return true; } - OnFileOpenHandler(); + return false; } private void OnFileOpenHandler() @@ -138,9 +121,11 @@ internal override void DrawScale() var majorTickOffset = MajorTickLength + CalculateScaleRange(zedGraphChannels.GraphPane.XAxis.Scale) * 0.015; majorTickOffset = majorTickOffset > 50 ? 50 : majorTickOffset; - var x = GetProbeContourMaxX(zedGraphChannels.GraphPane.GraphObjList) + 50; - var minY = GetProbeContourMinY(zedGraphChannels.GraphPane.GraphObjList); - var maxY = GetProbeContourMaxY(zedGraphChannels.GraphPane.GraphObjList); + var x = GetProbeMaxX(zedGraphChannels.GraphPane.GraphObjList) + 50; + var minY = GetProbeMinY(zedGraphChannels.GraphPane.GraphObjList); + var maxY = GetProbeMaxY(zedGraphChannels.GraphPane.GraphObjList); + + int textPosition = 0; PointPairList pointList = new(); @@ -154,15 +139,17 @@ internal override void DrawScale() pointList.Add(majorTickLocation); pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks)); - if (!zoomedOut || i % (5 * MajorTickIncrement) == 0) + if (!zoomedOut || countMajorTicks % 5 == 0) { - TextObj textObj = new($"{i} µm\n", majorTickLocation.X + 5, majorTickLocation.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center) + TextObj textObj = new($"{textPosition} µm\n", majorTickLocation.X + 5, majorTickLocation.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center) { Tag = ScaleTextTag, }; textObj.FontSpec.Border.IsVisible = false; textObj.FontSpec.Size = fontSize; zedGraphChannels.GraphPane.GraphObjList.Add(textObj); + + textPosition += zoomedOut ? 5 * MajorTickIncrement : MajorTickIncrement; } if (!zoomedOut) @@ -182,13 +169,14 @@ internal override void DrawScale() countMajorTicks++; } - var curve = zedGraphChannels.GraphPane.AddCurve(ScalePointsTag, pointList, Color.Black, SymbolType.None); + var curve = zedGraphChannels.GraphPane.AddCurve("", pointList, Color.Black, SymbolType.None); const float scaleBarWidth = 1; curve.Line.Width = scaleBarWidth; curve.Label.IsVisible = false; curve.Symbol.IsVisible = false; + curve.Tag = ScalePointsTag; } internal override void HighlightEnabledContacts() diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs index c3a301a..9119a44 100644 --- a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs +++ b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs @@ -72,7 +72,7 @@ private string GetProbeName(NeuropixelsV2Probe probe) { NeuropixelsV2Probe.ProbeA => "Probe A", NeuropixelsV2Probe.ProbeB => "Probe B", - _ => throw new ArgumentException("Invalid probe was specified.") + _ => "Invalid probe was specified." }; } diff --git a/OpenEphys.Onix1.Design/OpenEphys.Onix1.Design.csproj b/OpenEphys.Onix1.Design/OpenEphys.Onix1.Design.csproj index 8737a92..3cba2d4 100644 --- a/OpenEphys.Onix1.Design/OpenEphys.Onix1.Design.csproj +++ b/OpenEphys.Onix1.Design/OpenEphys.Onix1.Design.csproj @@ -15,7 +15,7 @@ - + diff --git a/OpenEphys.Onix1/NeuropixelsV1Helper.cs b/OpenEphys.Onix1/NeuropixelsV1Helper.cs index 931e171..47ae555 100644 --- a/OpenEphys.Onix1/NeuropixelsV1Helper.cs +++ b/OpenEphys.Onix1/NeuropixelsV1Helper.cs @@ -20,14 +20,24 @@ public static class NeuropixelsV1Helper /// public static NeuropixelsV1eAdcCalibration ParseAdcCalibrationFile(StreamReader file) { + // TODO: "file" input argument should either be a FileStream or a path string. StreamReader is to + // general because cal data is always provided in a file and this function call expects to start + // from the beginning of the stream. This will require a change in the public API. + if (file == null || file.EndOfStream) { throw new ArgumentException("Incoming stream reader is not pointing to a valid ADC calibration file."); } - var adcSerialNumber = ulong.Parse(file.ReadLine()); + string path = (file.BaseStream as FileStream)?.Name; + + if (!ulong.TryParse(file.ReadLine(), out ulong adcSerialNumber)) + { + throw new ArgumentException($"The calibration file {path} specified is " + + $"incorrectly formatted."); + } - NeuropixelsV1eAdc[] adcs = new NeuropixelsV1eAdc[NeuropixelsV1e.AdcCount]; + var adcs = new NeuropixelsV1eAdc[NeuropixelsV1e.AdcCount]; for (var i = 0; i < NeuropixelsV1e.AdcCount; i++) { @@ -64,12 +74,22 @@ public static NeuropixelsV1eAdcCalibration ParseAdcCalibrationFile(StreamReader /// public static NeuropixelsV1eGainCorrection ParseGainCalibrationFile(StreamReader file, NeuropixelsV1Gain apGain, NeuropixelsV1Gain lfpGain) { + // TODO: "file" input argument should either be a FileStream or a path string. StreamReader is to + // general because cal data is always provided in a file and this function call expects to start + // from the beginning of the stream. This will require a change in the public API. + if (file == null || file.EndOfStream) { throw new ArgumentException("Incoming stream reader is not pointing to a valid gain calibration file."); } - var serialNumber = ulong.Parse(file.ReadLine()); + string path = (file.BaseStream as FileStream)?.Name; + + if (!ulong.TryParse(file.ReadLine(), out ulong serialNumber)) + { + throw new ArgumentException($"The calibration file {path} specified is " + + $"incorrectly formatted."); + } var gainCorrections = file.ReadLine().Split(',').Skip(1); diff --git a/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs b/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs index f22b7b2..365d28c 100644 --- a/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs +++ b/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs @@ -38,10 +38,8 @@ public NeuropixelsV1eRegisterContext(DeviceContext deviceContext, uint i2cAddres $"{probeSerialNumber}"); } - StreamReader adcFile = new(adcCalibrationFile); - // parse ADC calibration file - var adcCalibration = NeuropixelsV1Helper.ParseAdcCalibrationFile(adcFile); + var adcCalibration = NeuropixelsV1Helper.ParseAdcCalibrationFile(new StreamReader(adcCalibrationFile)); if (adcCalibration.SN != probeSerialNumber) { @@ -49,10 +47,10 @@ public NeuropixelsV1eRegisterContext(DeviceContext deviceContext, uint i2cAddres $"match the ADC calibration file serial number: {adcCalibration.SN}."); } - StreamReader gainFile = new(gainCalibrationFile); - + // parse gain correction file - var gainCorrection = NeuropixelsV1Helper.ParseGainCalibrationFile(gainFile, probeConfiguration.SpikeAmplifierGain, probeConfiguration.LfpAmplifierGain); + var gainCorrection = NeuropixelsV1Helper.ParseGainCalibrationFile(new StreamReader(gainCalibrationFile), + probeConfiguration.SpikeAmplifierGain, probeConfiguration.LfpAmplifierGain); if (gainCorrection.SN != probeSerialNumber) { diff --git a/OpenEphys.Onix1/NeuropixelsV2.cs b/OpenEphys.Onix1/NeuropixelsV2.cs index af5b9ac..e171786 100644 --- a/OpenEphys.Onix1/NeuropixelsV2.cs +++ b/OpenEphys.Onix1/NeuropixelsV2.cs @@ -35,7 +35,6 @@ static class NeuropixelsV2 public const int DummyRegisterCount = 4; public const int RegistersPerShank = ElectrodePerShank + ReferencePixelCount + DummyRegisterCount; - internal static BitArray[] GenerateShankBits(NeuropixelsV2QuadShankProbeConfiguration probe) { BitArray[] shankBits = @@ -124,7 +123,11 @@ internal static double ReadGainCorrection(string gainCalibrationFile, ulong prob } var gainFile = new StreamReader(gainCalibrationFile); - var sn = ulong.Parse(gainFile.ReadLine()); + if(!ulong.TryParse(gainFile.ReadLine(), out ulong sn)) + { + throw new ArgumentException($"The calibration file {gainCalibrationFile} specified for {probe} is " + + $"incorrectly formatted."); + } if (probeSerialNumber != sn) { diff --git a/OpenEphys.Onix1/NeuropixelsV2QuadShankProbeConfiguration.cs b/OpenEphys.Onix1/NeuropixelsV2QuadShankProbeConfiguration.cs index 6bb8e94..849c8ca 100644 --- a/OpenEphys.Onix1/NeuropixelsV2QuadShankProbeConfiguration.cs +++ b/OpenEphys.Onix1/NeuropixelsV2QuadShankProbeConfiguration.cs @@ -6,6 +6,7 @@ using System.Text; using System.Xml.Serialization; using System.Linq; +using OpenEphys.ProbeInterface.NET; namespace OpenEphys.Onix1 { @@ -124,8 +125,8 @@ public NeuropixelsV2QuadShankProbeConfiguration(NeuropixelsV2Probe probe, Neurop public NeuropixelsV2QuadShankProbeConfiguration(NeuropixelsV2QuadShankProbeConfiguration probeConfiguration) { Reference = probeConfiguration.Reference; - ChannelConfiguration = new(); - ChannelConfiguration.UpdateDeviceChannelIndices(probeConfiguration.ChannelMap); + var probes = probeConfiguration.ChannelConfiguration.Probes.ToList().Select(probe => new Probe(probe)); + ChannelConfiguration = new(probeConfiguration.ChannelConfiguration.Specification, probeConfiguration.ChannelConfiguration.Version, probes.ToArray()); ChannelMap = NeuropixelsV2eProbeGroup.ToChannelMap(ChannelConfiguration); Probe = probeConfiguration.Probe; } @@ -142,8 +143,7 @@ public NeuropixelsV2QuadShankProbeConfiguration(NeuropixelsV2QuadShankProbeConfi public NeuropixelsV2QuadShankProbeConfiguration(NeuropixelsV2eProbeGroup channelConfiguration, NeuropixelsV2QuadShankReference reference, NeuropixelsV2Probe probe) { ChannelMap = NeuropixelsV2eProbeGroup.ToChannelMap(channelConfiguration); - ChannelConfiguration = new(); - ChannelConfiguration.UpdateDeviceChannelIndices(ChannelMap); + ChannelConfiguration = channelConfiguration; Reference = reference; Probe = probe; } diff --git a/OpenEphys.Onix1/OpenEphys.Onix1.csproj b/OpenEphys.Onix1/OpenEphys.Onix1.csproj index e15c6cf..d790a5c 100644 --- a/OpenEphys.Onix1/OpenEphys.Onix1.csproj +++ b/OpenEphys.Onix1/OpenEphys.Onix1.csproj @@ -13,6 +13,6 @@ - +