Skip to content

Commit

Permalink
Add validation of gain calibration files for Neuropixels
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
- Refactored code to return a nullable type instead of following the conventional TryParse pattern
- 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
- 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
- Added status strip for Neuropixels V1e
  • Loading branch information
bparks13 committed Sep 6, 2024
1 parent 8ded0ba commit a7328e0
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 252 deletions.
316 changes: 226 additions & 90 deletions OpenEphys.Onix1.Design/NeuropixelsV1eDialog.Designer.cs

Large diffs are not rendered by default.

79 changes: 75 additions & 4 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;
CheckStatus();
}
else if (comboBox.Name == nameof(comboBoxLfpGain))
{
ConfigureNode.ProbeConfiguration.LfpAmplifierGain = (NeuropixelsV1Gain)comboBox.SelectedItem;
CheckStatus();
}
else if (comboBox.Name == nameof(comboBoxReference))
{
Expand Down Expand Up @@ -239,13 +242,45 @@ private void OnFileLoadEvent(object sender, EventArgs e)

private void CheckStatus()
{
if (File.Exists(ConfigureNode.AdcCalibrationFile) && File.Exists(ConfigureNode.GainCalibrationFile))
const string NoFileSelected = "No file selected.";
const string InvalidFile = "Invalid file.";

var adcCalibration = NeuropixelsV1Helper.TryParseAdcCalibrationFile(ConfigureNode.AdcCalibrationFile);

Adcs = adcCalibration.HasValue ? adcCalibration.Value.Adcs : null;
buttonViewAdcs.Enabled = adcCalibration.HasValue;
toolStripAdcCalSN.Text = adcCalibration.HasValue ? adcCalibration.Value.SN.ToString() :
string.IsNullOrEmpty(ConfigureNode.AdcCalibrationFile) ? NoFileSelected : InvalidFile;

var gainCorrection = NeuropixelsV1Helper.TryParseGainCalibrationFile(ConfigureNode.GainCalibrationFile, ConfigureNode.ProbeConfiguration.SpikeAmplifierGain,
ConfigureNode.ProbeConfiguration.LfpAmplifierGain);

toolStripGainCalSN.Text = gainCorrection.HasValue ? gainCorrection.Value.SN.ToString() :
string.IsNullOrEmpty(ConfigureNode.GainCalibrationFile) ? NoFileSelected : InvalidFile;
textBoxApCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.AP.ToString() : "";
textBoxLfpCorrection.Text = gainCorrection.HasValue ? gainCorrection.Value.LFP.ToString() : "";

panelProbe.Visible = adcCalibration.HasValue && gainCorrection.HasValue;

if (toolStripAdcCalSN.Text == NoFileSelected || toolStripGainCalSN.Text == NoFileSelected)
{
toolStripStatus.Image = Properties.Resources.StatusRefreshImage;
toolStripStatus.Text = "Select files.";
}
else if (toolStripAdcCalSN.Text == InvalidFile || toolStripGainCalSN.Text == InvalidFile)
{
toolStripStatus.Image = Properties.Resources.StatusCriticalImage;
toolStripStatus.Text = "Invalid files.";
}
else if (toolStripAdcCalSN.Text != toolStripGainCalSN.Text)
{
panelProbe.Visible = true;
toolStripStatus.Image = Properties.Resources.StatusBlockedImage;
toolStripStatus.Text = "Serial number mismatch.";
}
else
{
panelProbe.Visible = false;
toolStripStatus.Image = Properties.Resources.StatusReadyImage;
toolStripStatus.Text = "Ready.";
}
}

Expand Down Expand Up @@ -306,6 +341,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 a7328e0

Please sign in to comment.