Skip to content

Commit

Permalink
Add validation of gain calibration files
Browse files Browse the repository at this point in the history
- Refactored code (moved to helper class) and made names consistent
- Added TryParse for NeuropixelsV2e and NeuropixelsV1e calibration files
- Added dialog elements that displays the current gain correction value from the gain calibration file
- Added V2 gain correction class for easier passing of correction and SN
- Only print errors during a workflow run; from the dialogs, do not print errors
- Display the serial number after parsing calibration files
- Add a button to open a new window for the ADC values in NeuropixelsV1eDialog
- Small update to size of controls and panels
  • Loading branch information
bparks13 committed Sep 5, 2024
1 parent 3bdadf5 commit d8385b0
Show file tree
Hide file tree
Showing 14 changed files with 853 additions and 249 deletions.
304 changes: 214 additions & 90 deletions OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs

Large diffs are not rendered by default.

76 changes: 74 additions & 2 deletions OpenEphys.Onix1.Design/NeuropixelsV1eDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;

Expand All @@ -13,6 +12,8 @@ public partial class NeuropixelsV1eDialog : Form
{
readonly NeuropixelsV1eChannelConfigurationDialog ChannelConfiguration;

private NeuropixelsV1eAdc[] Adcs = null;

private enum ChannelPreset
{
BankA,
Expand Down Expand Up @@ -134,10 +135,12 @@ private void SelectedIndexChanged(object sender, EventArgs e)
if (comboBox.Name == nameof(comboBoxApGain))
{
ConfigureNode.ProbeConfiguration.SpikeAmplifierGain = (NeuropixelsV1Gain)comboBox.SelectedItem;
UpdateCorrectionValues();
}
else if (comboBox.Name == nameof(comboBoxLfpGain))
{
ConfigureNode.ProbeConfiguration.LfpAmplifierGain = (NeuropixelsV1Gain)comboBox.SelectedItem;
UpdateCorrectionValues();
}
else if (comboBox.Name == nameof(comboBoxReference))
{
Expand All @@ -160,6 +163,35 @@ private void SelectedIndexChanged(object sender, EventArgs e)
}
}

private void UpdateCorrectionValues()
{
if (NeuropixelsV1Helper.TryParseAdcCalibrationFile(ConfigureNode.AdcCalibrationFile, null, out var adcCalibration) && adcCalibration.HasValue)
{
Adcs = adcCalibration.Value.Adcs;
toolStripAdcCalSN.Text = adcCalibration.Value.SN.ToString();
buttonViewAdcs.Enabled = true;
}
else
{
Adcs = null;
toolStripAdcCalSN.Text = string.IsNullOrEmpty(ConfigureNode.AdcCalibrationFile) ? "No file selected." : "Invalid file.";
buttonViewAdcs.Enabled = false;
}

if (NeuropixelsV1Helper.TryParseGainCalibrationFile(ConfigureNode.GainCalibrationFile, null, ConfigureNode.ProbeConfiguration.SpikeAmplifierGain,
ConfigureNode.ProbeConfiguration.LfpAmplifierGain, out var gainCorrection) && gainCorrection.HasValue)
{
toolStripGainCalSN.Text = gainCorrection.Value.SN.ToString();
}
else
{
toolStripGainCalSN.Text = string.IsNullOrEmpty(ConfigureNode.GainCalibrationFile) ? "No file selected." : "Invalid file";
}

textBoxApCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.AP.ToString() : "";
textBoxLfpCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.LFP.ToString() : "";
}

private void SetChannelPreset(ChannelPreset preset)
{
var probeConfiguration = ChannelConfiguration.ProbeConfiguration;
Expand Down Expand Up @@ -239,14 +271,18 @@ private void OnFileLoadEvent(object sender, EventArgs e)

private void CheckStatus()
{
if (File.Exists(ConfigureNode.AdcCalibrationFile) && File.Exists(ConfigureNode.GainCalibrationFile))
if (NeuropixelsV1Helper.TryParseAdcCalibrationFile(ConfigureNode.AdcCalibrationFile, null, out _) &&
NeuropixelsV1Helper.TryParseGainCalibrationFile(ConfigureNode.GainCalibrationFile, null, ConfigureNode.ProbeConfiguration.SpikeAmplifierGain,
ConfigureNode.ProbeConfiguration.LfpAmplifierGain, out _))
{
panelProbe.Visible = true;
}
else
{
panelProbe.Visible = false;
}

UpdateCorrectionValues();
}

private void ButtonClick(object sender, EventArgs e)
Expand Down Expand Up @@ -306,6 +342,42 @@ private void ButtonClick(object sender, EventArgs e)
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();
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions OpenEphys.Onix1.Design/NeuropixelsV1eDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,27 @@
<metadata name="label1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="label2.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="label4.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripLabelAdcCalibrationSN.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripLabelGainCalibrationSn.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>365, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>473, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>41</value>
</metadata>
Expand Down
70 changes: 36 additions & 34 deletions OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8385b0

Please sign in to comment.