private void saveSpikeFilterToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveSDDialog = new SaveFileDialog(); saveSDDialog.DefaultExt = "*.nrsd"; saveSDDialog.Filter = "NeuroRighter Spike Detector|*.nrsd"; saveSDDialog.Title = "Save NeuroRighter Spike Detector"; if (saveSDDialog.ShowDialog() == DialogResult.OK && saveSDDialog.FileName != "") { try { SpikeDetectorSerializer spikeDetSerializer = new SpikeDetectorSerializer(); spikeDetSerializer.SerializeObject(saveSDDialog.FileName, detectorParameters); } catch (Exception ex) { MessageBox.Show("Error: Could not write file to disk. Original error: " + ex.Message); } } }
private void loadSpikeFilterToolStripMenuItem_Click(object sender, EventArgs e) { // Make sure they want to kill the current sorter if (spikeSorter != null) { if (MessageBox.Show("This will overwrite the current spike sorter. Do you want to continue?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } // Disengage any current sorter isEngaged = false; button_EngageSpikeSorter.Text = "Engage Spike Sorter"; label_SorterEngaged.Text = "Sorter is not engaged"; label_SorterEngaged.ForeColor = Color.Red; // Deserialize your saved sorter OpenFileDialog openSDDialog = new OpenFileDialog(); openSDDialog.DefaultExt = "*.nrsd"; openSDDialog.Filter = "NeuroRighter Spike Detectpr|*.nrsd"; openSDDialog.Title = "Load NeuroRighter Spike Detector"; openSDDialog.InitialDirectory = Properties.Settings.Default.spikeSorterDir; if (openSDDialog.ShowDialog() == DialogResult.OK) { try { SpikeDetectorSerializer spikeDetSerializer = new SpikeDetectorSerializer(); detectorParameters = spikeDetSerializer.DeSerializeObject(openSDDialog.FileName); Properties.Settings.Default.spikeSorterDir = new FileInfo(openSDDialog.FileName).DirectoryName; // Detector parameters comboBox_noiseEstAlg.SelectedIndex = detectorParameters.NoiseAlgType; comboBox_spikeDetAlg.SelectedIndex = detectorParameters.DetectorType; thresholdMultiplier.Value = detectorParameters.Threshold; numericUpDown_DeadTime.Value = detectorParameters.DeadTime; numericUpDown_MaxSpkAmp.Value = detectorParameters.MaxSpikeAmp; numericUpDown_MinSpikeSlope.Value = detectorParameters.MinSpikeSlope; numericUpDown_MinSpikeWidth.Value = detectorParameters.MinSpikeWidth; numericUpDown_MaxSpikeWidth.Value = detectorParameters.MaxSpikeWidth; numPreSamples.Value = detectorParameters.NumPre; numPostSamples.Value = detectorParameters.NumPost; comboBox_ThresholdPolarity.SelectedIndex = detectorParameters.ThresholdPolarity; if (detectorParameters.SS != null) { // Deserialize the sorter spikeSorter = detectorParameters.SS; // Update the number of spikes you have trained with UpdateCollectionBar(); // Sorter Parameters switch (spikeSorter.projectionType) { case "Maximum Voltage Inflection": comboBox_ProjectionType.SelectedIndex = 0; break; case "Double Voltage Inflection": comboBox_ProjectionType.SelectedIndex = 1; break; case "PCA": comboBox_ProjectionType.SelectedIndex = 2; break; } numericUpDown_ProjDim.Value = (decimal)spikeSorter.projectionDimension; numericUpDown_MinClassificationProb.Value = (decimal)spikeSorter.pValue; numericUpDown_MinSpikesToTrain.Value = (decimal)spikeSorter.minSpikes; numericUpDown_maxK.Value = (decimal)spikeSorter.maxK; // Update UI to reflect the state of things if (spikeSorter.trained) { // Tell the user the the sorter is trained label_Trained.Text = "Spike sorter is trained."; label_Trained.ForeColor = Color.Green; button_EngageSpikeSorter.Enabled = true; button_TrainSorter.Enabled = true; isTrained = true; ReportTrainingResults(); } else { label_Trained.Text = "Spike sorter is not trained."; label_Trained.ForeColor = Color.Red; button_EngageSpikeSorter.Enabled = false; button_TrainSorter.Enabled = true; isTrained = false; } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }