diff --git a/OpenEphys.Onix1.Design/GenericDeviceDialog.Designer.cs b/OpenEphys.Onix1.Design/GenericDeviceDialog.Designer.cs
index 637d44d..2201264 100644
--- a/OpenEphys.Onix1.Design/GenericDeviceDialog.Designer.cs
+++ b/OpenEphys.Onix1.Design/GenericDeviceDialog.Designer.cs
@@ -43,9 +43,9 @@ private void InitializeComponent()
//
this.propertyGrid.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid.Location = new System.Drawing.Point(0, 0);
- this.propertyGrid.Margin = new System.Windows.Forms.Padding(2);
+ this.propertyGrid.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.propertyGrid.Name = "propertyGrid";
- this.propertyGrid.Size = new System.Drawing.Size(252, 349);
+ this.propertyGrid.Size = new System.Drawing.Size(336, 438);
this.propertyGrid.TabIndex = 0;
//
// splitContainer1
@@ -54,7 +54,7 @@ private void InitializeComponent()
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
this.splitContainer1.IsSplitterFixed = true;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
- this.splitContainer1.Margin = new System.Windows.Forms.Padding(2);
+ this.splitContainer1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
@@ -66,19 +66,18 @@ private void InitializeComponent()
//
this.splitContainer1.Panel2.Controls.Add(this.buttonCancel);
this.splitContainer1.Panel2.Controls.Add(this.buttonOK);
- this.splitContainer1.Size = new System.Drawing.Size(252, 386);
- this.splitContainer1.SplitterDistance = 349;
- this.splitContainer1.SplitterWidth = 3;
+ this.splitContainer1.Size = new System.Drawing.Size(336, 475);
+ this.splitContainer1.SplitterDistance = 438;
this.splitContainer1.TabIndex = 1;
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.buttonCancel.Location = new System.Drawing.Point(135, 5);
- this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
+ this.buttonCancel.Location = new System.Drawing.Point(180, -2);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
- this.buttonCancel.Size = new System.Drawing.Size(108, 25);
+ this.buttonCancel.Size = new System.Drawing.Size(144, 31);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
@@ -86,23 +85,23 @@ private void InitializeComponent()
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonOK.Location = new System.Drawing.Point(13, 5);
- this.buttonOK.Margin = new System.Windows.Forms.Padding(2);
+ this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.buttonOK.Location = new System.Drawing.Point(17, -2);
+ this.buttonOK.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOK.Name = "buttonOK";
- this.buttonOK.Size = new System.Drawing.Size(108, 25);
+ this.buttonOK.Size = new System.Drawing.Size(144, 31);
this.buttonOK.TabIndex = 5;
this.buttonOK.Text = "OK";
this.buttonOK.UseVisualStyleBackColor = true;
- this.buttonOK.Click += new System.EventHandler(this.ButtonClick);
//
// GenericDeviceDialog
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(252, 386);
+ this.ClientSize = new System.Drawing.Size(336, 475);
this.Controls.Add(this.splitContainer1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Margin = new System.Windows.Forms.Padding(2);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GenericDeviceDialog";
diff --git a/OpenEphys.Onix1.Design/GenericDeviceDialog.cs b/OpenEphys.Onix1.Design/GenericDeviceDialog.cs
index ccd7293..638d704 100644
--- a/OpenEphys.Onix1.Design/GenericDeviceDialog.cs
+++ b/OpenEphys.Onix1.Design/GenericDeviceDialog.cs
@@ -15,20 +15,5 @@ public GenericDeviceDialog()
{
InitializeComponent();
}
-
- private void ButtonClick(object sender, System.EventArgs e)
- {
- if (sender is Button button)
- {
- if (button.Name == nameof(buttonOK))
- {
- DialogResult = DialogResult.OK;
- }
- else if (button.Name == nameof(buttonCancel))
- {
- DialogResult = DialogResult.Cancel;
- }
- }
- }
}
}
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs b/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs
index d8dedb0..163a938 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs
@@ -223,14 +223,14 @@ private void InitializeComponent()
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 1, 0, 1);
- this.menuStrip.Size = new System.Drawing.Size(1312, 30);
+ this.menuStrip.Size = new System.Drawing.Size(1312, 26);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
- this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 28);
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
this.fileToolStripMenuItem.Text = "File";
//
// panelProbe
@@ -241,7 +241,7 @@ private void InitializeComponent()
this.panelProbe.Location = new System.Drawing.Point(4, 4);
this.panelProbe.Margin = new System.Windows.Forms.Padding(4);
this.panelProbe.Name = "panelProbe";
- this.panelProbe.Size = new System.Drawing.Size(976, 677);
+ this.panelProbe.Size = new System.Drawing.Size(976, 681);
this.panelProbe.TabIndex = 0;
//
// panelTrackBar
@@ -250,7 +250,7 @@ private void InitializeComponent()
this.panelTrackBar.Controls.Add(label1);
this.panelTrackBar.Controls.Add(label3);
this.panelTrackBar.Controls.Add(this.trackBarProbePosition);
- this.panelTrackBar.Location = new System.Drawing.Point(915, 5);
+ this.panelTrackBar.Location = new System.Drawing.Point(915, 7);
this.panelTrackBar.Margin = new System.Windows.Forms.Padding(4);
this.panelTrackBar.Name = "panelTrackBar";
this.panelTrackBar.Size = new System.Drawing.Size(61, 666);
@@ -305,7 +305,7 @@ private void InitializeComponent()
this.panelOptions.Location = new System.Drawing.Point(987, 2);
this.panelOptions.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panelOptions.Name = "panelOptions";
- this.panelOptions.Size = new System.Drawing.Size(322, 681);
+ this.panelOptions.Size = new System.Drawing.Size(322, 685);
this.panelOptions.TabIndex = 2;
//
// textBoxLfpCorrection
@@ -342,7 +342,7 @@ private void InitializeComponent()
this.toolTip.SetToolTip(this.buttonViewAdcs, "Once an ADC calibration file is selected, this button will open a new window show" +
"ing the parsed ADC correction values.");
this.buttonViewAdcs.UseVisualStyleBackColor = true;
- this.buttonViewAdcs.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonViewAdcs.Click += new System.EventHandler(this.ViewAdcs_Click);
//
// buttonChooseAdcCalibrationFile
//
@@ -355,7 +355,7 @@ private void InitializeComponent()
this.buttonChooseAdcCalibrationFile.Text = "...";
this.toolTip.SetToolTip(this.buttonChooseAdcCalibrationFile, "Browse for an ADC calibration file.");
this.buttonChooseAdcCalibrationFile.UseVisualStyleBackColor = true;
- this.buttonChooseAdcCalibrationFile.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonChooseAdcCalibrationFile.Click += new System.EventHandler(this.ChooseAdcCalibrationFile_Click);
//
// buttonChooseGainCalibrationFile
//
@@ -368,7 +368,7 @@ private void InitializeComponent()
this.buttonChooseGainCalibrationFile.Text = "...";
this.toolTip.SetToolTip(this.buttonChooseGainCalibrationFile, "Browse for a gain calibration file.");
this.buttonChooseGainCalibrationFile.UseVisualStyleBackColor = true;
- this.buttonChooseGainCalibrationFile.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonChooseGainCalibrationFile.Click += new System.EventHandler(this.ChooseGainCalibrationFile_Click);
//
// buttonEnableContacts
//
@@ -383,7 +383,7 @@ private void InitializeComponent()
this.toolTip.SetToolTip(this.buttonEnableContacts, "Click and drag to select electrodes in the probe view. \r\nPress this button to ena" +
"ble the selected electrodes. \r\nNot all electrode combinations are possible.");
this.buttonEnableContacts.UseVisualStyleBackColor = true;
- this.buttonEnableContacts.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonEnableContacts.Click += new System.EventHandler(this.EnableContacts_Click);
//
// buttonClearSelections
//
@@ -398,7 +398,7 @@ private void InitializeComponent()
this.toolTip.SetToolTip(this.buttonClearSelections, "Deselect all electrodes in the probe view. \r\nNote that this does not disable elec" +
"trodes, but simply deselects them.");
this.buttonClearSelections.UseVisualStyleBackColor = true;
- this.buttonClearSelections.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonClearSelections.Click += new System.EventHandler(this.ClearSelection_Click);
//
// comboBoxChannelPresets
//
@@ -424,7 +424,7 @@ private void InitializeComponent()
this.buttonResetZoom.Text = "Reset Zoom";
this.toolTip.SetToolTip(this.buttonResetZoom, "Reset the zoom in the probe view so that the probe is zoomed out and centered.");
this.buttonResetZoom.UseVisualStyleBackColor = true;
- this.buttonResetZoom.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonResetZoom.Click += new System.EventHandler(this.ResetZoom_Click);
//
// checkBoxSpikeFilter
//
@@ -447,7 +447,7 @@ private void InitializeComponent()
this.textBoxAdcCalibrationFile.Size = new System.Drawing.Size(252, 22);
this.textBoxAdcCalibrationFile.TabIndex = 12;
this.textBoxAdcCalibrationFile.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- this.textBoxAdcCalibrationFile.TextChanged += new System.EventHandler(this.FileTextChanged);
+ this.textBoxAdcCalibrationFile.TextChanged += new System.EventHandler(this.AdcCalibrationFileTextChanged);
//
// textBoxGainCalibrationFile
//
@@ -459,7 +459,7 @@ private void InitializeComponent()
this.textBoxGainCalibrationFile.Size = new System.Drawing.Size(252, 22);
this.textBoxGainCalibrationFile.TabIndex = 9;
this.textBoxGainCalibrationFile.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- this.textBoxGainCalibrationFile.TextChanged += new System.EventHandler(this.FileTextChanged);
+ this.textBoxGainCalibrationFile.TextChanged += new System.EventHandler(this.GainCalibrationFileTextChanged);
//
// comboBoxReference
//
@@ -510,6 +510,7 @@ private void InitializeComponent()
//
// buttonOkay
//
+ this.buttonOkay.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOkay.Location = new System.Drawing.Point(1077, 2);
this.buttonOkay.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOkay.Name = "buttonOkay";
@@ -517,7 +518,6 @@ private void InitializeComponent()
this.buttonOkay.TabIndex = 0;
this.buttonOkay.Text = "OK";
this.buttonOkay.UseVisualStyleBackColor = true;
- this.buttonOkay.Click += new System.EventHandler(this.ButtonClick);
//
// tableLayoutPanel1
//
@@ -528,13 +528,13 @@ private void InitializeComponent()
this.tableLayoutPanel1.Controls.Add(this.panelOptions, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 30);
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 26);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 42F));
- this.tableLayoutPanel1.Size = new System.Drawing.Size(1312, 727);
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(1312, 731);
this.tableLayoutPanel1.TabIndex = 3;
//
// flowLayoutPanel1
@@ -544,7 +544,7 @@ private void InitializeComponent()
this.flowLayoutPanel1.Controls.Add(this.buttonOkay);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
- this.flowLayoutPanel1.Location = new System.Drawing.Point(2, 687);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(2, 691);
this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(2);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(1308, 38);
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.cs
index 4080207..6f8a903 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV1eDialog.cs
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
+using System.IO;
using System.Linq;
using System.Windows.Forms;
@@ -63,18 +64,18 @@ public NeuropixelsV1eDialog(ConfigureNeuropixelsV1e configureNode)
comboBoxApGain.DataSource = Enum.GetValues(typeof(NeuropixelsV1Gain));
comboBoxApGain.SelectedItem = ConfigureNode.ProbeConfiguration.SpikeAmplifierGain;
- comboBoxApGain.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxApGain.SelectedIndexChanged += SpikeAmplifierGainIndexChanged;
comboBoxLfpGain.DataSource = Enum.GetValues(typeof(NeuropixelsV1Gain));
comboBoxLfpGain.SelectedItem = ConfigureNode.ProbeConfiguration.LfpAmplifierGain;
- comboBoxLfpGain.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxLfpGain.SelectedIndexChanged += LfpAmplifierGainIndexChanged;
comboBoxReference.DataSource = Enum.GetValues(typeof(NeuropixelsV1ReferenceSource));
comboBoxReference.SelectedItem = ConfigureNode.ProbeConfiguration.Reference;
- comboBoxReference.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxReference.SelectedIndexChanged += ReferenceIndexChanged;
checkBoxSpikeFilter.Checked = ConfigureNode.ProbeConfiguration.SpikeFilter;
- checkBoxSpikeFilter.CheckedChanged += SelectedIndexChanged;
+ checkBoxSpikeFilter.CheckedChanged += SpikeFilterIndexChanged;
textBoxAdcCalibrationFile.Text = ConfigureNode.AdcCalibrationFile;
@@ -82,7 +83,7 @@ public NeuropixelsV1eDialog(ConfigureNeuropixelsV1e configureNode)
comboBoxChannelPresets.DataSource = Enum.GetValues(typeof(ChannelPreset));
CheckForExistingChannelPreset();
- comboBoxChannelPresets.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxChannelPresets.SelectedIndexChanged += ChannelPresetIndexChanged;
CheckStatus();
}
@@ -104,65 +105,54 @@ private void FormShown(object sender, EventArgs e)
private void ResizeTrackBar(object sender, EventArgs e)
{
- if (sender is ChannelConfigurationDialog dialog)
- {
- panelTrackBar.Height = dialog.zedGraphChannels.Size.Height;
- panelTrackBar.Location = new Point(panelProbe.Size.Width - panelTrackBar.Width, ChannelConfiguration.zedGraphChannels.Location.Y);
- }
+ panelTrackBar.Height = ((ChannelConfigurationDialog)sender).zedGraphChannels.Size.Height;
+ panelTrackBar.Location = new Point(panelProbe.Size.Width - panelTrackBar.Width, ChannelConfiguration.zedGraphChannels.Location.Y);
}
- private void FileTextChanged(object sender, EventArgs e)
+ private void GainCalibrationFileTextChanged(object sender, EventArgs e)
{
- if (sender is TextBox textBox && textBox != null)
- {
- if (textBox.Name == nameof(textBoxGainCalibrationFile))
- {
- ConfigureNode.GainCalibrationFile = textBox.Text;
- }
- else if (textBox.Name == nameof(textBoxAdcCalibrationFile))
- {
- ConfigureNode.AdcCalibrationFile = textBox.Text;
- }
- }
+ ConfigureNode.GainCalibrationFile = ((TextBox)sender).Text;
+ CheckStatus();
+ }
+ private void AdcCalibrationFileTextChanged(object sender, EventArgs e)
+ {
+ ConfigureNode.AdcCalibrationFile = ((TextBox)sender).Text;
CheckStatus();
}
- private void SelectedIndexChanged(object sender, EventArgs e)
+ private void SpikeAmplifierGainIndexChanged(object sender, EventArgs e)
{
- if (sender is ComboBox comboBox && comboBox != null)
- {
- if (comboBox.Name == nameof(comboBoxApGain))
- {
- ConfigureNode.ProbeConfiguration.SpikeAmplifierGain = (NeuropixelsV1Gain)comboBox.SelectedItem;
- CheckStatus();
- }
- else if (comboBox.Name == nameof(comboBoxLfpGain))
- {
- ConfigureNode.ProbeConfiguration.LfpAmplifierGain = (NeuropixelsV1Gain)comboBox.SelectedItem;
- CheckStatus();
- }
- else if (comboBox.Name == nameof(comboBoxReference))
- {
- ConfigureNode.ProbeConfiguration.Reference = (NeuropixelsV1ReferenceSource)comboBox.SelectedItem;
- }
- else if (comboBox.Name == nameof(comboBoxChannelPresets))
- {
- if ((ChannelPreset)comboBox.SelectedItem != ChannelPreset.None)
- {
- SetChannelPreset((ChannelPreset)comboBox.SelectedItem);
- }
- }
- }
- else if (sender is CheckBox checkBox && checkBox != null)
+ ConfigureNode.ProbeConfiguration.SpikeAmplifierGain = (NeuropixelsV1Gain)((ComboBox)sender).SelectedItem;
+ CheckStatus();
+ }
+
+ private void LfpAmplifierGainIndexChanged(object sender, EventArgs e)
+ {
+ ConfigureNode.ProbeConfiguration.LfpAmplifierGain = (NeuropixelsV1Gain)((ComboBox)sender).SelectedItem;
+ CheckStatus();
+ }
+
+ private void ReferenceIndexChanged(object sender, EventArgs e)
+ {
+ ConfigureNode.ProbeConfiguration.Reference = (NeuropixelsV1ReferenceSource)((ComboBox)sender).SelectedItem;
+ }
+
+ private void ChannelPresetIndexChanged(object sender, EventArgs e)
+ {
+ var channelPreset = (ChannelPreset)((ComboBox)sender).SelectedItem;
+
+ if (channelPreset != ChannelPreset.None)
{
- if (checkBox.Name == nameof(checkBoxSpikeFilter))
- {
- ConfigureNode.ProbeConfiguration.SpikeFilter = checkBox.Checked;
- }
+ SetChannelPreset(channelPreset);
}
}
+ private void SpikeFilterIndexChanged(object sender, EventArgs e)
+ {
+ ConfigureNode.ProbeConfiguration.SpikeFilter = ((CheckBox)sender).Checked;
+ }
+
private void SetChannelPreset(ChannelPreset preset)
{
var probeConfiguration = ChannelConfiguration.ProbeConfiguration;
@@ -245,20 +235,58 @@ private void CheckStatus()
const string NoFileSelected = "No file selected.";
const string InvalidFile = "Invalid file.";
- var adcCalibration = NeuropixelsV1Helper.TryParseAdcCalibrationFile(ConfigureNode.AdcCalibrationFile);
+ NeuropixelsV1eAdcCalibration? adcCalibration;
+
+ try
+ {
+ adcCalibration = NeuropixelsV1Helper.TryParseAdcCalibrationFile(ConfigureNode.AdcCalibrationFile);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"An error occurred while parsing {ConfigureNode.AdcCalibrationFile}. Check the error log below." +
+ $"\n\n" + ex.Message);
+ return;
+ }
+
+ Adcs = adcCalibration.HasValue
+ ? adcCalibration.Value.Adcs
+ : null;
- Adcs = adcCalibration.HasValue ? adcCalibration.Value.Adcs : null;
buttonViewAdcs.Enabled = adcCalibration.HasValue;
- toolStripAdcCalSN.Text = adcCalibration.HasValue ? adcCalibration.Value.SerialNumber.ToString() :
- string.IsNullOrEmpty(ConfigureNode.AdcCalibrationFile) ? NoFileSelected : InvalidFile;
+ toolStripAdcCalSN.Text = adcCalibration.HasValue
+ ? adcCalibration.Value.SerialNumber.ToString()
+ : string.IsNullOrEmpty(ConfigureNode.AdcCalibrationFile)
+ ? NoFileSelected
+ : InvalidFile;
- var gainCorrection = NeuropixelsV1Helper.TryParseGainCalibrationFile(ConfigureNode.GainCalibrationFile, ConfigureNode.ProbeConfiguration.SpikeAmplifierGain,
- ConfigureNode.ProbeConfiguration.LfpAmplifierGain);
+ NeuropixelsV1eGainCorrection? gainCorrection;
- toolStripGainCalSN.Text = gainCorrection.HasValue ? gainCorrection.Value.SerialNumber.ToString() :
- string.IsNullOrEmpty(ConfigureNode.GainCalibrationFile) ? NoFileSelected : InvalidFile;
- textBoxApCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.ApGainCorrectionFactor.ToString() : "";
- textBoxLfpCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.LfpGainCorrectionFactor.ToString() : "";
+ try
+ {
+ gainCorrection = NeuropixelsV1Helper.TryParseGainCalibrationFile(ConfigureNode.GainCalibrationFile,
+ ConfigureNode.ProbeConfiguration.SpikeAmplifierGain,
+ ConfigureNode.ProbeConfiguration.LfpAmplifierGain);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"An error occurred while parsing {ConfigureNode.GainCalibrationFile}. Check the error log below." +
+ $"\n\n" + ex.Message);
+ return;
+ }
+
+ toolStripGainCalSN.Text = gainCorrection.HasValue
+ ? gainCorrection.Value.SerialNumber.ToString()
+ : string.IsNullOrEmpty(ConfigureNode.GainCalibrationFile)
+ ? NoFileSelected
+ : InvalidFile;
+
+ textBoxApCorrection.Text = gainCorrection.HasValue
+ ? gainCorrection.Value.ApGainCorrectionFactor.ToString()
+ : "";
+
+ textBoxLfpCorrection.Text = gainCorrection.HasValue
+ ? gainCorrection.Value.LfpGainCorrectionFactor.ToString()
+ : "";
panelProbe.Visible = adcCalibration.HasValue && gainCorrection.HasValue;
@@ -284,100 +312,91 @@ private void CheckStatus()
}
}
- private void ButtonClick(object sender, EventArgs e)
+ private void ChooseGainCalibrationFile_Click(object sender, EventArgs e)
{
- if (sender is Button button && button != null)
+ var ofd = new OpenFileDialog()
{
- if (button.Name == nameof(buttonOkay))
- {
- DialogResult = DialogResult.OK;
- }
- else if (button.Name == nameof(buttonChooseGainCalibrationFile))
- {
- var ofd = new OpenFileDialog()
- {
- CheckFileExists = true,
- Filter = "Gain calibration files (*_gainCalValues.csv)|*_gainCalValues.csv|All Files|*.*",
- FilterIndex = 0
- };
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- textBoxGainCalibrationFile.Text = ofd.FileName;
- }
- }
- else if (button.Name == nameof(buttonChooseAdcCalibrationFile))
- {
- var ofd = new OpenFileDialog()
- {
- CheckFileExists = true,
- Filter = "ADC calibration files (*_ADCCalibration.csv)|*_ADCCalibration.csv|All Files|*.*",
- FilterIndex = 0
- };
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- textBoxAdcCalibrationFile.Text = ofd.FileName;
- }
- }
- else if (button.Name == nameof(buttonResetZoom))
- {
- ResetZoom();
- }
- else if (button.Name == nameof(buttonClearSelections))
- {
- ChannelConfiguration.SetAllSelections(false);
- ChannelConfiguration.HighlightEnabledContacts();
- ChannelConfiguration.HighlightSelectedContacts();
- ChannelConfiguration.UpdateContactLabels();
- ChannelConfiguration.RefreshZedGraph();
- }
- else if (button.Name == nameof(buttonEnableContacts))
- {
- EnableSelectedContacts();
- ChannelConfiguration.SetAllSelections(false);
- ChannelConfiguration.HighlightEnabledContacts();
- ChannelConfiguration.HighlightSelectedContacts();
- ChannelConfiguration.UpdateContactLabels();
- ChannelConfiguration.RefreshZedGraph();
- }
- else if (button.Name == nameof(buttonViewAdcs))
- {
- if (Adcs == null)
- return;
-
- System.Resources.ResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NeuropixelsV1eDialog));
-
- var adcForm = new Form()
- {
- Size = new Size(600, 1000),
- Text = "View ADC Correction Values",
- Icon = (Icon)resources.GetObject("$this.Icon"),
- StartPosition = FormStartPosition.CenterParent,
- };
-
- var dataGridView = new DataGridView
- {
- DataSource = Adcs,
- AllowUserToAddRows = false,
- AllowUserToDeleteRows = false,
- AllowUserToOrderColumns = false,
- ReadOnly = true,
- ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
- Dock = DockStyle.Fill,
- Location = new Point(0, 0),
- Margin = new Padding(2),
- Name = "dataGridViewAdcs",
- RowHeadersWidth = 62,
- AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
- };
- dataGridView.RowTemplate.Height = 28;
-
- adcForm.Controls.Add(dataGridView);
-
- adcForm.ShowDialog();
- }
+ CheckFileExists = true,
+ Filter = "Gain calibration files (*_gainCalValues.csv)|*_gainCalValues.csv|All Files|*.*",
+ FilterIndex = 0
+ };
+
+ if (ofd.ShowDialog() == DialogResult.OK)
+ {
+ textBoxGainCalibrationFile.Text = ofd.FileName;
}
+
+ CheckStatus();
+ }
+
+ private void ChooseAdcCalibrationFile_Click(object sender, EventArgs e)
+ {
+ var ofd = new OpenFileDialog()
+ {
+ CheckFileExists = true,
+ Filter = "ADC calibration files (*_ADCCalibration.csv)|*_ADCCalibration.csv|All Files|*.*",
+ FilterIndex = 0
+ };
+
+ if (ofd.ShowDialog() == DialogResult.OK)
+ {
+ textBoxAdcCalibrationFile.Text = ofd.FileName;
+ }
+
+ CheckStatus();
+ }
+
+ private void ResetZoom_Click(object sender, EventArgs e)
+ {
+ ResetZoom();
+ }
+
+ private void ClearSelection_Click(object sender, EventArgs e)
+ {
+ DeselectContacts();
+ }
+
+ private void EnableContacts_Click(object sender, EventArgs e)
+ {
+ EnableSelectedContacts();
+ DeselectContacts();
+ }
+
+ private void ViewAdcs_Click(object sender, EventArgs e)
+ {
+ if (Adcs == null)
+ return;
+
+ System.Resources.ResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NeuropixelsV1eDialog));
+
+ var adcForm = new Form()
+ {
+ Size = new Size(600, 1000),
+ Text = "View ADC Correction Values",
+ Icon = (Icon)resources.GetObject("$this.Icon"),
+ StartPosition = FormStartPosition.CenterParent,
+ };
+
+ var dataGridView = new DataGridView
+ {
+ DataSource = Adcs,
+ AllowUserToAddRows = false,
+ AllowUserToDeleteRows = false,
+ AllowUserToOrderColumns = false,
+ ReadOnly = true,
+ ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
+ Dock = DockStyle.Fill,
+ Location = new Point(0, 0),
+ Margin = new Padding(2),
+ Name = "dataGridViewAdcs",
+ RowHeadersWidth = 62,
+ AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
+ };
+ dataGridView.RowTemplate.Height = 28;
+
+ adcForm.Controls.Add(dataGridView);
+
+ adcForm.ShowDialog();
}
private void EnableSelectedContacts()
@@ -392,6 +411,15 @@ private void EnableSelectedContacts()
CheckForExistingChannelPreset();
}
+ private void DeselectContacts()
+ {
+ ChannelConfiguration.SetAllSelections(false);
+ ChannelConfiguration.HighlightEnabledContacts();
+ ChannelConfiguration.HighlightSelectedContacts();
+ ChannelConfiguration.UpdateContactLabels();
+ ChannelConfiguration.RefreshZedGraph();
+ }
+
private void ResetZoom()
{
ChannelConfiguration.ResetZoom();
@@ -407,13 +435,7 @@ private void MoveToVerticalPosition(float relativePosition)
private void TrackBarScroll(object sender, EventArgs e)
{
- if (sender is TrackBar trackBar && trackBar != null)
- {
- if (trackBar.Name == nameof(trackBarProbePosition))
- {
- MoveToVerticalPosition(trackBar.Value / 100.0f);
- }
- }
+ MoveToVerticalPosition(((TrackBar)sender).Value / 100.0f);
}
private void UpdateTrackBarLocation(object sender, EventArgs e)
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.Designer.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.Designer.cs
index cdccb6c..8981877 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.Designer.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.Designer.cs
@@ -48,49 +48,49 @@ private void InitializeComponent()
this.fileToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
- this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1);
- this.menuStrip.Size = new System.Drawing.Size(854, 24);
+ this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 1, 0, 1);
+ this.menuStrip.Size = new System.Drawing.Size(1139, 26);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStripNeuropixelsV2e";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
- this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 22);
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
this.fileToolStripMenuItem.Text = "File";
//
// tabControlProbe
//
this.tabControlProbe.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tabControlProbe.Location = new System.Drawing.Point(2, 2);
- this.tabControlProbe.Margin = new System.Windows.Forms.Padding(2);
+ this.tabControlProbe.Location = new System.Drawing.Point(3, 2);
+ this.tabControlProbe.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.tabControlProbe.Name = "tabControlProbe";
this.tabControlProbe.SelectedIndex = 0;
- this.tabControlProbe.Size = new System.Drawing.Size(850, 510);
+ this.tabControlProbe.Size = new System.Drawing.Size(1133, 632);
this.tabControlProbe.TabIndex = 1;
//
// buttonCancel
//
- this.buttonCancel.Location = new System.Drawing.Point(763, 2);
- this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
+ this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.buttonCancel.Location = new System.Drawing.Point(1017, 2);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
- this.buttonCancel.Size = new System.Drawing.Size(83, 28);
+ this.buttonCancel.Size = new System.Drawing.Size(111, 34);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
- this.buttonCancel.Click += new System.EventHandler(this.ButtonClick);
//
// buttonOkay
//
this.buttonOkay.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonOkay.Location = new System.Drawing.Point(676, 2);
- this.buttonOkay.Margin = new System.Windows.Forms.Padding(2);
+ this.buttonOkay.Location = new System.Drawing.Point(900, 2);
+ this.buttonOkay.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOkay.Name = "buttonOkay";
- this.buttonOkay.Size = new System.Drawing.Size(83, 28);
+ this.buttonOkay.Size = new System.Drawing.Size(111, 34);
this.buttonOkay.TabIndex = 0;
this.buttonOkay.Text = "OK";
this.buttonOkay.UseVisualStyleBackColor = true;
- this.buttonOkay.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonOkay.Click += new System.EventHandler(this.Okay_Click);
//
// tableLayoutPanel1
//
@@ -99,12 +99,13 @@ private void InitializeComponent()
this.tableLayoutPanel1.Controls.Add(this.tabControlProbe, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 24);
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 26);
+ this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
- this.tableLayoutPanel1.Size = new System.Drawing.Size(854, 554);
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 49F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(1139, 685);
this.tableLayoutPanel1.TabIndex = 3;
//
// flowLayoutPanel1
@@ -113,22 +114,23 @@ private void InitializeComponent()
this.flowLayoutPanel1.Controls.Add(this.buttonOkay);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
- this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 517);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(4, 640);
+ this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
- this.flowLayoutPanel1.Size = new System.Drawing.Size(848, 34);
+ this.flowLayoutPanel1.Size = new System.Drawing.Size(1131, 41);
this.flowLayoutPanel1.TabIndex = 2;
//
// NeuropixelsV2eDialog
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(854, 578);
+ this.ClientSize = new System.Drawing.Size(1139, 711);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.menuStrip);
this.DoubleBuffered = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip;
- this.Margin = new System.Windows.Forms.Padding(2);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "NeuropixelsV2eDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "NeuropixelsV2e Configuration";
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs
index 9119a44..4b87055 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs
@@ -97,21 +97,11 @@ private void FormShown(object sender, EventArgs e)
}
}
- internal void ButtonClick(object sender, EventArgs e)
+ internal void Okay_Click(object sender, EventArgs e)
{
- if (sender is Button button && button != null)
- {
- if (button.Name == nameof(buttonOkay))
- {
- SaveVariables();
+ SaveVariables();
- DialogResult = DialogResult.OK;
- }
- else if (button.Name == nameof(buttonCancel))
- {
- DialogResult = DialogResult.Cancel;
- }
- }
+ DialogResult = DialogResult.OK;
}
internal void SaveVariables()
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.Designer.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.Designer.cs
index 8f261b7..40ca176 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.Designer.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.Designer.cs
@@ -70,7 +70,7 @@ private void InitializeComponent()
this.buttonOkay.TabIndex = 5;
this.buttonOkay.Text = "OK";
this.buttonOkay.UseVisualStyleBackColor = true;
- this.buttonOkay.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonOkay.Click += new System.EventHandler(this.Okay_Click);
//
// menuStrip1
//
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.cs
index db580d3..5873ad2 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.cs
@@ -62,17 +62,11 @@ public NeuropixelsV2eHeadstageDialog(IConfigureNeuropixelsV2 configureNeuropixel
DialogBno055.Invalidate();
}
- private void ButtonClick(object sender, System.EventArgs e)
+ private void Okay_Click(object sender, System.EventArgs e)
{
- if (sender is Button button && button != null)
- {
- if (button.Name == nameof(buttonOkay))
- {
- DialogNeuropixelsV2e.SaveVariables();
+ DialogNeuropixelsV2e.SaveVariables();
- DialogResult = DialogResult.OK;
- }
- }
+ DialogResult = DialogResult.OK;
}
}
}
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.Designer.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.Designer.cs
index bdba9c9..6622e1e 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.Designer.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.Designer.cs
@@ -48,6 +48,7 @@ private void InitializeComponent()
this.panelTrackBar = new System.Windows.Forms.Panel();
this.trackBarProbePosition = new System.Windows.Forms.TrackBar();
this.panelChannelOptions = new System.Windows.Forms.Panel();
+ this.textBoxGainCorrection = new System.Windows.Forms.TextBox();
this.textBoxProbeCalibrationFile = new System.Windows.Forms.TextBox();
this.comboBoxReference = new System.Windows.Forms.ComboBox();
this.comboBoxChannelPresets = new System.Windows.Forms.ComboBox();
@@ -55,7 +56,6 @@ private void InitializeComponent()
this.buttonOkay = new System.Windows.Forms.Button();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
- this.textBoxGainCorrection = new System.Windows.Forms.TextBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripGainCalSN = new System.Windows.Forms.ToolStripStatusLabel();
label6 = new System.Windows.Forms.Label();
@@ -124,6 +124,22 @@ private void InitializeComponent()
labelPresets.TabIndex = 23;
labelPresets.Text = "Channel \nPresets:";
//
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new System.Drawing.Point(15, 63);
+ label1.Name = "label1";
+ label1.Size = new System.Drawing.Size(71, 32);
+ label1.TabIndex = 35;
+ label1.Text = "Gain\r\nCorrection:";
+ //
+ // toolStripLabelGainCalibrationSN
+ //
+ toolStripLabelGainCalibrationSN.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
+ toolStripLabelGainCalibrationSN.Name = "toolStripLabelGainCalibrationSN";
+ toolStripLabelGainCalibrationSN.Size = new System.Drawing.Size(153, 20);
+ toolStripLabelGainCalibrationSN.Text = "Gain Calibration SN: ";
+ //
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
@@ -132,14 +148,14 @@ private void InitializeComponent()
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 1, 0, 1);
- this.menuStrip.Size = new System.Drawing.Size(1112, 30);
+ this.menuStrip.Size = new System.Drawing.Size(1112, 26);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStripNeuropixelsV2e";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
- this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 28);
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
this.fileToolStripMenuItem.Text = "File";
//
// buttonEnableContacts
@@ -155,7 +171,7 @@ private void InitializeComponent()
this.toolTip.SetToolTip(this.buttonEnableContacts, "Click and drag to select electrodes in the probe view. \r\nPress this button to ena" +
"ble the selected electrodes. \r\nNot all electrode combinations are possible.");
this.buttonEnableContacts.UseVisualStyleBackColor = true;
- this.buttonEnableContacts.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonEnableContacts.Click += new System.EventHandler(this.EnableContacts_Click);
//
// buttonClearSelections
//
@@ -170,7 +186,7 @@ private void InitializeComponent()
this.toolTip.SetToolTip(this.buttonClearSelections, "Deselect all electrodes in the probe view. \r\nNote that this does not disable elec" +
"trodes, but simply deselects them.");
this.buttonClearSelections.UseVisualStyleBackColor = true;
- this.buttonClearSelections.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonClearSelections.Click += new System.EventHandler(this.ClearSelection_Click);
//
// buttonResetZoom
//
@@ -184,7 +200,7 @@ private void InitializeComponent()
this.buttonResetZoom.Text = "Reset Zoom";
this.toolTip.SetToolTip(this.buttonResetZoom, "Reset the zoom in the probe view so that the probe is zoomed out and centered.");
this.buttonResetZoom.UseVisualStyleBackColor = true;
- this.buttonResetZoom.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonResetZoom.Click += new System.EventHandler(this.ResetZoom_Click);
//
// buttonChooseCalibrationFile
//
@@ -197,7 +213,7 @@ private void InitializeComponent()
this.buttonChooseCalibrationFile.Text = "...";
this.toolTip.SetToolTip(this.buttonChooseCalibrationFile, "Browse for a gain calibration file.");
this.buttonChooseCalibrationFile.UseVisualStyleBackColor = true;
- this.buttonChooseCalibrationFile.Click += new System.EventHandler(this.ButtonClick);
+ this.buttonChooseCalibrationFile.Click += new System.EventHandler(this.ChooseCalibrationFile_Click);
//
// panelProbe
//
@@ -207,7 +223,7 @@ private void InitializeComponent()
this.panelProbe.Location = new System.Drawing.Point(3, 2);
this.panelProbe.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panelProbe.Name = "panelProbe";
- this.panelProbe.Size = new System.Drawing.Size(828, 551);
+ this.panelProbe.Size = new System.Drawing.Size(828, 555);
this.panelProbe.TabIndex = 1;
//
// panelTrackBar
@@ -216,8 +232,8 @@ private void InitializeComponent()
this.panelTrackBar.Controls.Add(label6);
this.panelTrackBar.Controls.Add(label7);
this.panelTrackBar.Controls.Add(this.trackBarProbePosition);
- this.panelTrackBar.Location = new System.Drawing.Point(775, -3);
- this.panelTrackBar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.panelTrackBar.Location = new System.Drawing.Point(775, -1);
+ this.panelTrackBar.Margin = new System.Windows.Forms.Padding(4);
this.panelTrackBar.Name = "panelTrackBar";
this.panelTrackBar.Size = new System.Drawing.Size(49, 559);
this.panelTrackBar.TabIndex = 30;
@@ -260,9 +276,20 @@ private void InitializeComponent()
this.panelChannelOptions.Location = new System.Drawing.Point(837, 2);
this.panelChannelOptions.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panelChannelOptions.Name = "panelChannelOptions";
- this.panelChannelOptions.Size = new System.Drawing.Size(272, 551);
+ this.panelChannelOptions.Size = new System.Drawing.Size(272, 555);
this.panelChannelOptions.TabIndex = 1;
//
+ // textBoxGainCorrection
+ //
+ this.textBoxGainCorrection.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.textBoxGainCorrection.Location = new System.Drawing.Point(106, 68);
+ this.textBoxGainCorrection.Name = "textBoxGainCorrection";
+ this.textBoxGainCorrection.ReadOnly = true;
+ this.textBoxGainCorrection.Size = new System.Drawing.Size(151, 22);
+ this.textBoxGainCorrection.TabIndex = 36;
+ this.textBoxGainCorrection.TabStop = false;
+ //
// textBoxProbeCalibrationFile
//
this.textBoxProbeCalibrationFile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@@ -310,12 +337,12 @@ private void InitializeComponent()
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
- this.buttonCancel.Click += new System.EventHandler(this.ButtonClick);
//
// buttonOkay
//
this.buttonOkay.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonOkay.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOkay.Location = new System.Drawing.Point(873, 2);
this.buttonOkay.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOkay.Name = "buttonOkay";
@@ -323,7 +350,6 @@ private void InitializeComponent()
this.buttonOkay.TabIndex = 0;
this.buttonOkay.Text = "OK";
this.buttonOkay.UseVisualStyleBackColor = true;
- this.buttonOkay.Click += new System.EventHandler(this.ButtonClick);
//
// tableLayoutPanel1
//
@@ -336,14 +362,14 @@ private void InitializeComponent()
this.tableLayoutPanel1.Controls.Add(this.panelProbe, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 30);
- this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 26);
+ this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 45F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
- this.tableLayoutPanel1.Size = new System.Drawing.Size(1112, 600);
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(1112, 604);
this.tableLayoutPanel1.TabIndex = 3;
//
// flowLayoutPanel1
@@ -353,32 +379,12 @@ private void InitializeComponent()
this.flowLayoutPanel1.Controls.Add(this.buttonOkay);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
- this.flowLayoutPanel1.Location = new System.Drawing.Point(4, 559);
- this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.flowLayoutPanel1.Location = new System.Drawing.Point(4, 563);
+ this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(1104, 37);
this.flowLayoutPanel1.TabIndex = 2;
//
- // label1
- //
- label1.AutoSize = true;
- label1.Location = new System.Drawing.Point(15, 63);
- label1.Name = "label1";
- label1.Size = new System.Drawing.Size(71, 32);
- label1.TabIndex = 35;
- label1.Text = "Gain\r\nCorrection:";
- //
- // textBoxGainCorrection
- //
- this.textBoxGainCorrection.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.textBoxGainCorrection.Location = new System.Drawing.Point(106, 68);
- this.textBoxGainCorrection.Name = "textBoxGainCorrection";
- this.textBoxGainCorrection.ReadOnly = true;
- this.textBoxGainCorrection.Size = new System.Drawing.Size(151, 22);
- this.textBoxGainCorrection.TabIndex = 36;
- this.textBoxGainCorrection.TabStop = false;
- //
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
@@ -391,13 +397,6 @@ private void InitializeComponent()
this.statusStrip1.TabIndex = 3;
this.statusStrip1.Text = "statusStrip1";
//
- // toolStripLabelGainCalibrationSN
- //
- toolStripLabelGainCalibrationSN.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
- toolStripLabelGainCalibrationSN.Name = "toolStripLabelGainCalibrationSN";
- toolStripLabelGainCalibrationSN.Size = new System.Drawing.Size(153, 20);
- toolStripLabelGainCalibrationSN.Text = "Gain Calibration SN: ";
- //
// toolStripGainCalSN
//
this.toolStripGainCalSN.AutoSize = false;
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs
index 6fac57c..d747bdb 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs
@@ -1,5 +1,4 @@
using System;
-using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
@@ -83,10 +82,10 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2QuadShankProbeConfigu
comboBoxReference.DataSource = Enum.GetValues(typeof(NeuropixelsV2QuadShankReference));
comboBoxReference.SelectedItem = ProbeConfiguration.Reference;
- comboBoxReference.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxReference.SelectedIndexChanged += SelectedReferenceChanged;
comboBoxChannelPresets.DataSource = Enum.GetValues(typeof(ChannelPreset));
- comboBoxChannelPresets.SelectedIndexChanged += SelectedIndexChanged;
+ comboBoxChannelPresets.SelectedIndexChanged += SelectedChannelPresetChanged;
CheckForExistingChannelPreset();
CheckStatus();
@@ -118,20 +117,18 @@ private void ResizeTrackBar(object sender, EventArgs e)
}
}
- private void SelectedIndexChanged(object sender, EventArgs e)
+ private void SelectedReferenceChanged(object sender, EventArgs e)
{
- var comboBox = sender as ComboBox;
+ ProbeConfiguration.Reference = (NeuropixelsV2QuadShankReference)((ComboBox)sender).SelectedItem;
+ }
- if (comboBox.Name == nameof(comboBoxReference))
- {
- ProbeConfiguration.Reference = (NeuropixelsV2QuadShankReference)comboBox.SelectedItem;
- }
- else if (comboBox.Name == nameof(comboBoxChannelPresets))
+ private void SelectedChannelPresetChanged(object sender, EventArgs e)
+ {
+ var channelPreset = (ChannelPreset)((ComboBox)sender).SelectedItem;
+
+ if (channelPreset != ChannelPreset.None)
{
- if ((ChannelPreset)comboBox.SelectedItem != ChannelPreset.None)
- {
- SetChannelPreset((ChannelPreset)comboBox.SelectedItem);
- }
+ SetChannelPreset(channelPreset);
}
}
@@ -511,67 +508,66 @@ private void OnFileLoadEvent(object sender, EventArgs e)
private void FileTextChanged(object sender, EventArgs e)
{
- if (sender is TextBox textBox && textBox != null && textBox.Name == nameof(textBoxProbeCalibrationFile))
- {
- CheckStatus();
- }
+ CheckStatus();
}
private void CheckStatus()
{
- var gainCorrection = NeuropixelsV2Helper.TryParseGainCalibrationFile(textBoxProbeCalibrationFile.Text);
+ NeuropixelsV2GainCorrection? gainCorrection;
+
+ try
+ {
+ gainCorrection = NeuropixelsV2Helper.TryParseGainCalibrationFile(textBoxProbeCalibrationFile.Text);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"An error occurred while parsing {textBoxProbeCalibrationFile.Text}. Check the error log below." +
+ $"\n\n" + ex.Message);
+ return;
+ }
panelProbe.Visible = gainCorrection.HasValue;
- textBoxGainCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.GainCorrectionFactor.ToString() : "";
- toolStripGainCalSN.Text = gainCorrection.HasValue ? gainCorrection.Value.SerialNumber.ToString() :
- string.IsNullOrEmpty(textBoxProbeCalibrationFile.Text) ? "No file found." : "Invalid file.";
+
+ textBoxGainCorrection.Text = gainCorrection.HasValue
+ ? gainCorrection.Value.GainCorrectionFactor.ToString()
+ : "";
+
+ toolStripGainCalSN.Text = gainCorrection.HasValue
+ ? gainCorrection.Value.SerialNumber.ToString()
+ : string.IsNullOrEmpty(textBoxProbeCalibrationFile.Text) ? "No file found." : "Invalid file.";
}
- internal void ButtonClick(object sender, EventArgs e)
+ internal void ChooseCalibrationFile_Click(object sender, EventArgs e)
{
- if (sender is Button button && button != null)
- {
- if (button.Name == nameof(buttonOkay))
- {
- DialogResult = DialogResult.OK;
- }
- else if (button.Name == nameof(buttonChooseCalibrationFile))
- {
- var ofd = new OpenFileDialog()
- {
- CheckFileExists = true,
- Filter = "Gain calibration files (*_gainCalValues.csv)|*_gainCalValues.csv|All Files|*.*",
- FilterIndex = 0
- };
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- textBoxProbeCalibrationFile.Text = ofd.FileName;
- }
- }
- else if (button.Name == nameof(buttonResetZoom))
- {
- ResetZoom();
- }
- else if (button.Name == nameof(buttonClearSelections))
- {
- ChannelConfiguration.SetAllSelections(false);
- ChannelConfiguration.HighlightEnabledContacts();
- ChannelConfiguration.HighlightSelectedContacts();
- ChannelConfiguration.UpdateContactLabels();
- ChannelConfiguration.RefreshZedGraph();
- }
- else if (button.Name == nameof(buttonEnableContacts))
- {
- EnableSelectedContacts();
-
- ChannelConfiguration.SetAllSelections(false);
- ChannelConfiguration.HighlightEnabledContacts();
- ChannelConfiguration.HighlightSelectedContacts();
- ChannelConfiguration.UpdateContactLabels();
- ChannelConfiguration.RefreshZedGraph();
- }
+ var ofd = new OpenFileDialog()
+ {
+ CheckFileExists = true,
+ Filter = "Gain calibration files (*_gainCalValues.csv)|*_gainCalValues.csv|All Files|*.*",
+ FilterIndex = 0
+ };
+
+ if (ofd.ShowDialog() == DialogResult.OK)
+ {
+ textBoxProbeCalibrationFile.Text = ofd.FileName;
}
+
+ CheckStatus();
+ }
+
+ internal void ResetZoom_Click(object sender, EventArgs e)
+ {
+ ResetZoom();
+ }
+
+ internal void ClearSelection_Click(object sender, EventArgs e)
+ {
+ DeselectContacts();
+ }
+
+ internal void EnableContacts_Click(object sender, EventArgs e)
+ {
+ EnableSelectedContacts();
+ DeselectContacts();
}
private void EnableSelectedContacts()
@@ -586,6 +582,15 @@ private void EnableSelectedContacts()
CheckForExistingChannelPreset();
}
+ private void DeselectContacts()
+ {
+ ChannelConfiguration.SetAllSelections(false);
+ ChannelConfiguration.HighlightEnabledContacts();
+ ChannelConfiguration.HighlightSelectedContacts();
+ ChannelConfiguration.UpdateContactLabels();
+ ChannelConfiguration.RefreshZedGraph();
+ }
+
private void ResetZoom()
{
ChannelConfiguration.ResetZoom();
@@ -601,13 +606,8 @@ private void MoveToVerticalPosition(float relativePosition)
private void TrackBarScroll(object sender, EventArgs e)
{
- if (sender is TrackBar trackBar && trackBar != null)
- {
- if (trackBar.Name == nameof(trackBarProbePosition))
- {
- MoveToVerticalPosition((float)trackBar.Value / trackBar.Maximum);
- }
- }
+ var trackBar = (TrackBar)sender;
+ MoveToVerticalPosition((float)trackBar.Value / trackBar.Maximum);
}
private void UpdateTrackBarLocation(object sender, EventArgs e)
diff --git a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.resx b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.resx
index c28f9c0..3c32c40 100644
--- a/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.resx
+++ b/OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.resx
@@ -132,21 +132,21 @@
False
+
+ False
+
+
+ False
+
17, 17
274, 17
-
- False
-
382, 17
-
- False
-
diff --git a/OpenEphys.Onix1/NeuropixelsV1Helper.cs b/OpenEphys.Onix1/NeuropixelsV1Helper.cs
index aa85edb..7344e2d 100644
--- a/OpenEphys.Onix1/NeuropixelsV1Helper.cs
+++ b/OpenEphys.Onix1/NeuropixelsV1Helper.cs
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
-using Bonsai.Expressions;
namespace OpenEphys.Onix1
{
@@ -10,8 +9,8 @@ namespace OpenEphys.Onix1
///
public static class NeuropixelsV1Helper
{
- internal const int NumberOfGains = 8;
- internal const int NumberOfAdcs = 8;
+ internal const int NumberOfGainFactors = 8;
+ internal const int NumberOfAdcParameters = 8;
///
/// Tries to parse the ADC calibration file.
@@ -33,55 +32,52 @@ public static class NeuropixelsV1Helper
{
if (!File.Exists(adcCalibrationFile)) return null;
- string[] lines;
+ var lines = File.ReadLines(adcCalibrationFile);
- try { lines = File.ReadAllLines(adcCalibrationFile); }
- catch { return null; }
-
- if (lines.Length != NeuropixelsV1e.AdcCount + 1) return null;
+ if (lines.Count() != NeuropixelsV1e.AdcCount + 1) return null;
if (!ulong.TryParse(lines.ElementAt(0), out var serialNumber)) return null;
if (!lines
.Skip(1)
.Select(l =>
{
- var values = l.Split(',');
- if (values.Length != NumberOfAdcs + 1) return -1;
- var s = values[0];
- if (!int.TryParse(s, out int adcNumber)) return -1;
- return adcNumber;
+ var ok = int.TryParse(l.Split(',')[0], out int adcNumber);
+ return (Ok: ok, AdcNumber: adcNumber);
})
+ .Where(l => l.Ok)
+ .Select(l => l.AdcNumber)
.SequenceEqual(Enumerable.Range(0, NeuropixelsV1e.AdcCount))) return null;
- var adcs = lines.Skip(1)
- .Select(l =>
- {
- const int tryParseFailed = -1;
- var calibrationValues = l.Split(',')
- .Skip(1)
- .Select(e =>
- {
- if (!int.TryParse(e, out int result)) result = tryParseFailed;
- return result;
- });
-
- if (calibrationValues.Count() != NumberOfAdcs || calibrationValues.Any(val => val == tryParseFailed)) return null;
- return new NeuropixelsV1eAdc
- {
- CompP = calibrationValues.ElementAt(0),
- CompN = calibrationValues.ElementAt(1),
- Slope = calibrationValues.ElementAt(2),
- Coarse = calibrationValues.ElementAt(3),
- Fine = calibrationValues.ElementAt(4),
- Cfix = calibrationValues.ElementAt(5),
- Offset = calibrationValues.ElementAt(6),
- Threshold = calibrationValues.ElementAt(7)
- };
- });
-
- if (adcs.Any(adc => adc == null)) return null;
-
- return new(serialNumber, adcs.ToArray());
+ var adcs = lines
+ .Skip(1)
+ .Select(l =>
+ {
+ var calibrationValues = l
+ .Split(',')
+ .Skip(1)
+ .Select(p =>
+ {
+ var ok = int.TryParse(p, out int param);
+ return (Ok: ok, Param: param);
+ })
+ .Where(l => l.Ok)
+ .Select(l => l.Param);
+
+ return calibrationValues.Count() == NumberOfAdcParameters
+ ? null
+ : new NeuropixelsV1eAdc {
+ CompP = calibrationValues.ElementAt(0),
+ CompN = calibrationValues.ElementAt(1),
+ Slope = calibrationValues.ElementAt(2),
+ Coarse = calibrationValues.ElementAt(3),
+ Fine = calibrationValues.ElementAt(4),
+ Cfix = calibrationValues.ElementAt(5),
+ Offset = calibrationValues.ElementAt(6),
+ Threshold = calibrationValues.ElementAt(7)
+ };
+ });
+
+ return adcs.Any(adc => adc == null) ? null : new(serialNumber, adcs.ToArray());
}
///
@@ -107,53 +103,69 @@ public static class NeuropixelsV1Helper
{
if (!File.Exists(gainCalibrationFile)) return null;
- string[] lines;
-
- try { lines = File.ReadAllLines(gainCalibrationFile); }
- catch { return null; }
+ var lines = File.ReadLines(gainCalibrationFile);
- if (lines.Length != NeuropixelsV1e.ElectrodeCount + 1) return null;
+ if (lines.Count() != NeuropixelsV1e.ElectrodeCount + 1) return null;
if (!ulong.TryParse(lines.ElementAt(0), out var serialNumber)) return null;
if (!lines
.Skip(1)
.Select(l =>
{
- var values = l.Split(',');
- if (values.Length != NumberOfGains * 2 + 1) return -1;
- var s = values[0];
- int.TryParse(s, out var channel);
- return channel;
+ var ok = int.TryParse(l.Split(',')[0], out var channel);
+ return (Ok: ok, Channel: channel);
})
+ .Where(l => l.Ok)
+ .Select(l => l.Channel)
.SequenceEqual(Enumerable.Range(0, NeuropixelsV1e.ElectrodeCount))) return null;
- var apIndex = Array.IndexOf(Enum.GetValues(typeof(NeuropixelsV1Gain)), apGain) + 1;
- var apGainCorrections = lines.Skip(1)
- .Select(l =>
- {
- var s = l.Split(',')[apIndex];
- double.TryParse(s, out double gainCorrection);
- return gainCorrection;
- })
- .Distinct();
-
- if (apGainCorrections.Count() == 2) apGainCorrections = apGainCorrections.Where(val => val != 1.0);
- if (apGainCorrections.Count() != 1) return null;
-
- var lfpIndex = Array.IndexOf(Enum.GetValues(typeof(NeuropixelsV1Gain)), lfpGain) + 1 + NumberOfGains;
- var lfpGainCorrections = lines.Skip(1)
- .Select(l =>
- {
- var s = l.Split(',')[lfpIndex];
- double.TryParse(s, out double gainCorrection);
- return gainCorrection;
- })
- .Distinct();
-
- if (lfpGainCorrections.Count() == 2) lfpGainCorrections = lfpGainCorrections.Where(val => val != 1.0);
- if (lfpGainCorrections.Count() != 1) return null;
-
- return new(serialNumber, apGainCorrections.First(), lfpGainCorrections.First());
+ var apIndex = Array.IndexOf(Enum.GetValues(typeof(NeuropixelsV1Gain)), apGain);
+ var apGainCorrections = lines
+ .Skip(1)
+ .Select(l =>
+ {
+ var corrections = l
+ .Split(',')
+ .Skip(1)
+ .Select(s =>
+ {
+ var ok = double.TryParse(s, out var correction);
+ return (Ok: ok, Correction: correction);
+ })
+ .Where(l => l.Ok)
+ .Select(l => l.Correction);
+
+ return corrections.Count() == NumberOfGainFactors * 2 ? corrections.ElementAt(apIndex) : null;
+ })
+ .Distinct();
+
+ if (apGainCorrections.Count() == 2) apGainCorrections = apGainCorrections.Where(val => val != 1.0); // NB: Reference contacts are always 1.0. Filter this out.
+
+ var lfpIndex = Array.IndexOf(Enum.GetValues(typeof(NeuropixelsV1Gain)), lfpGain) + NumberOfGainFactors;
+ var lfpGainCorrections = lines
+ .Skip(1)
+ .Select(l =>
+ {
+ var corrections = l
+ .Split(',')
+ .Skip(1)
+ .Select(s =>
+ {
+ var ok = double.TryParse(s, out var correction);
+ return (Ok: ok, Correction: correction);
+ })
+ .Where(l => l.Ok)
+ .Select(l => l.Correction);
+
+ return corrections.Count() == NumberOfGainFactors * 2 ? corrections.ElementAt(lfpIndex) : null;
+ })
+ .Distinct();
+
+ if (lfpGainCorrections.Count() == 2) lfpGainCorrections = lfpGainCorrections.Where(val => val != 1.0); // NB: Reference contacts are always 1.0. Filter this out.
+
+ return (apGainCorrections.Count() != 1 || lfpGainCorrections.Count() != 1)
+ ? null
+ : new(serialNumber, apGainCorrections.First().Value, lfpGainCorrections.First().Value);
}
///
@@ -188,7 +200,7 @@ public static NeuropixelsV1eAdcCalibration ParseAdcCalibrationFile(StreamReader
for (var i = 0; i < NeuropixelsV1e.AdcCount; i++)
{
var adcCal = file.ReadLine().Split(',').Skip(1);
- if (adcCal.Count() != NumberOfAdcs)
+ if (adcCal.Count() != NumberOfAdcParameters)
{
throw new InvalidOperationException("Incorrectly formatted ADC calibration file.");
}
@@ -240,7 +252,7 @@ public static NeuropixelsV1eGainCorrection ParseGainCalibrationFile(StreamReader
var gainCorrections = file.ReadLine().Split(',').Skip(1);
- if (gainCorrections.Count() != 2 * NumberOfGains)
+ if (gainCorrections.Count() != 2 * NumberOfGainFactors)
throw new InvalidOperationException("Incorrectly formatted gain correction calibration file.");
var ap = double.Parse(gainCorrections.ElementAt(Array.IndexOf(Enum.GetValues(typeof(NeuropixelsV1Gain)), apGain)));
diff --git a/OpenEphys.Onix1/NeuropixelsV2Helper.cs b/OpenEphys.Onix1/NeuropixelsV2Helper.cs
index 6264837..9915f4d 100644
--- a/OpenEphys.Onix1/NeuropixelsV2Helper.cs
+++ b/OpenEphys.Onix1/NeuropixelsV2Helper.cs
@@ -27,33 +27,33 @@ public class NeuropixelsV2Helper
{
if (!File.Exists(gainCalibrationFile)) return null;
- string[] lines;
- try { lines = File.ReadAllLines(gainCalibrationFile); }
- catch { return null; }
+ var lines = File.ReadLines(gainCalibrationFile);
- if (lines.Length != NeuropixelsV2.ChannelCount + 1) return null;
+ if (lines.Count() != NeuropixelsV2.ChannelCount + 1) return null;
if (!ulong.TryParse(lines.ElementAt(0), out var serialNumber)) return null;
if (!lines
.Skip(1)
.Select(l =>
{
- var values = l.Split(',');
- if (values.Length != 2) return -1;
- var s = values[0];
- int.TryParse(s, out var channel);
- return channel;
+ var s = l.Split(',')[0];
+ var ok = int.TryParse(s, out var channel);
+ return (Ok: ok, Channel: channel);
})
+ .Where(l => l.Ok)
+ .Select(l => l.Channel)
.SequenceEqual(Enumerable.Range(0, NeuropixelsV2.ChannelCount))) return null;
- var gains = lines.Skip(1)
- .Select(l =>
- {
- var s = l.Split(',')[1];
- double.TryParse(s, out var gainCorrection);
- return gainCorrection;
- })
- .Distinct();
+ var gains = lines
+ .Skip(1)
+ .Select(l =>
+ {
+ var ok = double.TryParse(l.Split(',')[1], out var gainCorrection);
+ return (Ok: ok, GainCorrection: gainCorrection);
+ })
+ .Where(l => l.Ok)
+ .Select(l => l.GainCorrection)
+ .Distinct();
return gains.Count() == 1 ? new(serialNumber, gains.First()) : null;
}