/// <summary> /// Serializer for storing a spike sorter to disk. /// </summary> /// <param name="filename">Full path of spike sorter file.</param> /// <param name="sorterToSerialize"> The SpikeSorter object to be saved.</param> public void SerializeObject(string filename, SpikeSorter sorterToSerialize) { Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, sorterToSerialize); stream.Close(); }
internal SpikeDetectorParameters(SerializationInfo info, StreamingContext ctxt) { this.ss = (SpikeSorter)info.GetValue("ss", typeof(SpikeSorter)); this.threshold = (decimal)info.GetValue("threshold", typeof(decimal)); this.deadTime = (decimal)info.GetValue("deadTime", typeof(decimal)); this.maxSpikeAmp = (decimal)info.GetValue("maxSpikeAmp", typeof(decimal)); this.minSpikeSlope = (decimal)info.GetValue("minSpikeSlope", typeof(decimal)); this.minSpikeWidth = (decimal)info.GetValue("minSpikeWidth", typeof(decimal)); this.maxSpikeWidth = (decimal)info.GetValue("maxSpikeWidth", typeof(decimal)); this.numPre = (decimal)info.GetValue("numPre", typeof(decimal)); this.numPost = (decimal)info.GetValue("numPost", typeof(decimal)); this.spikeDetectionLag = (decimal)info.GetValue("spikeDetectionLag", typeof(decimal)); this.detectorType = (int)info.GetValue("detectorType", typeof(int)); this.noiseAlgType = (int)info.GetValue("noiseAlgType", typeof(int)); this.thresholdPolarity = (int)info.GetValue("thresholdPolarity", typeof(int)); }
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); } } }
private void button_HoardSpikes_Click(object sender, EventArgs e) { if (!isHoarding) { // Make sure they want to kill the current sorter if (spikeSorter != null) { if (MessageBox.Show("Do you want to overwrite the current spike sorter?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } // Update the UI to reflect the state of things Flush(); // Reset the sorter completely isTrained = false; isEngaged = false; hasData = false; isHoarding = true; spikeSorter = null; // Create the appropriate sorter switch (comboBox_ProjectionType.SelectedItem.ToString()) { case "Maximum Voltage Inflection": { spikeSorter = new SpikeSorter( numChannels, (int)numericUpDown_maxK.Value, (int)numericUpDown_MinSpikesToTrain.Value, (double)numericUpDown_MinClassificationProb.Value, comboBox_ProjectionType.SelectedItem.ToString()); break; } case "Double Voltage Inflection": { spikeSorter = new SpikeSorter( numChannels, (int)numericUpDown_maxK.Value, (int)numericUpDown_MinSpikesToTrain.Value, (double)numericUpDown_MinClassificationProb.Value, comboBox_ProjectionType.SelectedItem.ToString()); break; } case "PCA": { spikeSorter = new SpikeSorter( numChannels, (int)numericUpDown_maxK.Value, (int)numericUpDown_MinSpikesToTrain.Value, (double)numericUpDown_MinClassificationProb.Value, (int)numericUpDown_ProjDim.Value, comboBox_ProjectionType.SelectedItem.ToString()); break; } } // Update hoard button button_HoardSpikes.Text = "Stop"; } else { isHoarding = false; hasData = true; button_TrainSorter.Enabled = true; button_HoardSpikes.Text = "Hoard"; } // Update wrapper detectorParameters.SS = spikeSorter; }