Esempio n. 1
0
        private void SaveSummaryButton_click(object sender, EventArgs e)
        {
            if (names.Count == 0)
            {
                MessageBox.Show(this, "Cannot save summary without any files loaded", "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "CSV (*.csv)|*.csv|All Files (*.*)|*.*";
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            try {
                using (StreamWriter tw = new StreamWriter(sfd.FileName)) {
                    string[] headers = new string[] {
                        "TF Pathname", "name", "Zmin", "Zmax", "Integral(TF TF*)"
                    };
                    tw.WriteLine(String.Join(",", headers));
                    for (int i = 0; i < names.Count; i++)
                    {
                        tw.WriteLine(String.Join(",", new string[] {
                            names[i],
                            Path.GetFileNameWithoutExtension(names[i]),
                            ZList[i].Minimum().ToString(),
                            ZList[i].Maximum().ToString(),
                            DataProcessing.Integrate(
                                ZList[i],
                                SrList[i].Map(x => x.Magnitude).Map(x => x * x)
                                ).ToString()
                        }));
                    }
                }
            }
            catch (IOException ex) {
                MessageBox.Show(this, "An IO error happened during saving: " + Environment.NewLine + Environment.NewLine +
                                ex.Message, "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 2
0
        private void AnalyzeButton_Click(object sender, EventArgs e)
        {
            int           numSkipped    = 0;
            int           numValid      = 0;
            List <ETan>   ETans         = new List <ETan>();
            List <double> measuredVals  = new List <double>();
            List <double> predictedVals = new List <double>();

            foreach (ETan etanRow in ETanFilesListBox.Items)
            {
                foreach (MeasSummary.SummaryRow sumrow in etanRow.summrow)
                {
                    if (etanRow.summrow == null ||
                        (VoltageMode && Double.IsNaN(sumrow.PeakHeaderVoltage)) ||
                        (!VoltageMode && Double.IsNaN(sumrow.MeasuredTemperature))
                        )
                    {
                        numSkipped++;
                        continue;
                    }
                    var scaledEtanRms = etanRow.rms.Multiply(sumrow.ETanScalingFactor);
                    if (sumrow.Conjugate)
                    {
                        scaledEtanRms = scaledEtanRms.Conjugate();
                    }

                    if (VoltageMode && !Double.IsNaN(sumrow.CrestFactor))
                    {
                        scaledEtanRms = scaledEtanRms.Multiply(sumrow.CrestFactor);
                    }

                    double Z = DataProcessing.TFInt(
                        ETan_Z: etanRow.z, ETan_RMS: scaledEtanRms,
                        TF_Z: TFz, TF_Sr: TFSr);

                    if (VoltageMode)
                    {
                        Z = Math.Sqrt(Z);
                    }

                    ETans.Add(etanRow);
                    double measuredVal;
                    if (VoltageMode)
                    {
                        measuredVal = sumrow.PeakHeaderVoltage;
                    }
                    else
                    {
                        measuredVal = sumrow.MeasuredTemperature;
                    }
                    measuredVals.Add(measuredVal);
                    predictedVals.Add(Z);
                    numValid++;
                }
            }

            if (numValid == 0)
            {
                MessageBox.Show(this, "No valid data was found.",
                                "No Data",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (numSkipped > 0)
            {
                MessageBox.Show(this, numSkipped.ToString() + " Etan files were skipped " +
                                "because a cooresponding row in the measurement summary file was not found.",
                                "Skipped ETan Files", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            double scaleFactor;
            // TODO: Are these two things reversed? I need another person to double-check.
            //var A = CreateMatrix.DenseOfColumns(new IEnumerable<double>[] { measuredVals });
            //var B = CreateVector.DenseOfEnumerable(predictedVals);
            var A = CreateMatrix.DenseOfColumns(new IEnumerable <double>[] { predictedVals });
            var B = CreateVector.DenseOfEnumerable(measuredVals);

            var X = A.QR().Solve(B); // A*X = B

            scaleFactor = 1.0 / X[0];
            double TFScaleFactor = VoltageMode ? scaleFactor : Math.Sqrt(scaleFactor); // Scalefactor used for scaling the TF

            // Save things
            SaveScaledTF(TFScaleFactor);
            if (saveSummaryFileCheckbox.Checked)
            {
                SaveSummaryTable(ETans, predictedVals, scaleFactor);
            }

            TFFitPlotForm tffpf = new TFFitPlotForm();

            tffpf.AddData(
                predicted: predictedVals,
                measured: measuredVals,
                varName: VoltageMode ? "V" : "dT",
                title: TransferFunctionFilenameLabel.Text
                );
            tffpf.AddFit(1.0 / scaleFactor, 0, Color.Red);

            tffpf.Show(this);
        }
Esempio n. 3
0
        private void ProcessTempDataButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title       = "Select input data files...";
            ofd.Multiselect = true;
            double interval = 0.0;

            if (HeaderToolRadioButton.Checked)
            {
                ofd.Filter = "Excel Files (*.xls, *.xlsx)|*.xls;*.xlsx|All Files (*.*)|*.*";
            }
            else
            {
                if (TemperatureModeRadioButton.Checked)
                {
                    if (!Double.TryParse(TempMeasIntervalTextBox.Text, out interval))
                    {
                        MessageBox.Show(this, "The entered time interval is not a valid number.",
                                        "Data Processing Error");
                        return;
                    }
                }
                if (VoltageModeRadioButton.Checked && CRMRadioButton.Checked)
                {
                    ofd.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*";
                }
                else
                {
                    ofd.Filter = "CSV (*.csv)|*.csv|All Files (*.*)|*.*";
                }
            }
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string         sourcedir = Path.GetDirectoryName(ofd.FileNames[0]);
            SaveFileDialog sfd       = new SaveFileDialog();

            //sfd.InitialDirectory = @"C:\Users\ConraN01\Documents\Spyder_WS\MRI_RF_TF_Tool_Project\Test Files for Python Utility\Raw Neuro Header Voltage Data Files";
            sfd.Filter = "CSV (*.csv)|*.csv|All Files (*.*)|*.*";
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            try
            {
                if (HeaderToolRadioButton.Checked)
                {
                    DataProcessing.ProcessHeaderToolVoltage(ofd.FileNames, sfd.FileName);
                }
                else
                {
                    if (VoltageModeRadioButton.Checked)
                    {
                        if (NeuroRadioButton.Checked)
                        {
                            DataProcessing.ProcessNeuroHeaderVoltage(ofd.FileNames, sfd.FileName);
                        }
                        else
                        {
                            DataProcessing.ProcessCRMHeaderVoltage(ofd.FileNames, sfd.FileName);
                        }
                    }
                    else
                    {
                        if (NeuroRadioButton.Checked)
                        { // Neuro Temp Data
                            DataProcessing.ProcessNeuroTempData(ofd.FileNames, sfd.FileName, interval,
                                                                doPlots: DoDataProcessingPlotsCheckBox.Checked);
                        }
                        else
                        {
                            DataProcessing.ProcessCRMTempData(ofd.FileNames, sfd.FileName, interval,
                                                              doPlots: DoDataProcessingPlotsCheckBox.Checked);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Data Processing Error");
                return;
            }
            MessageBox.Show(this, "Done");
        }