/// <summary>
 /// Serializer for storing a spike detector to disk.
 /// </summary>
 /// <param name="filename">Full path of spike detector file.</param>
 /// <param name="detectorToSerialize"> The SpikeSorter object to be saved.</param>
 public void SerializeObject(string filename, SpikeDetectorParameters detectorToSerialize)
 {
     Stream stream = File.Open(filename, FileMode.Create);
     BinaryFormatter bFormatter = new BinaryFormatter();
     bFormatter.Serialize(stream, detectorToSerialize);
     stream.Close();
 }
示例#2
0
        /// <summary>
        /// Serializer for storing a spike detector to disk.
        /// </summary>
        /// <param name="filename">Full path of spike detector file.</param>
        /// <param name="detectorToSerialize"> The SpikeSorter object to be saved.</param>
        public void SerializeObject(string filename, SpikeDetectorParameters detectorToSerialize)
        {
            Stream          stream     = File.Open(filename, FileMode.Create);
            BinaryFormatter bFormatter = new BinaryFormatter();

            bFormatter.Serialize(stream, detectorToSerialize);
            stream.Close();
        }
        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);
                }
            }
        }
示例#4
0
        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);
                }
            }
        }