Exemplo n.º 1
0
 private void ClearResults_Click(object sender, EventArgs e)
 {
     mRelativeIntegralList.Clear();
     ErrorsText.Clear();
     UpdateChart();
 }
Exemplo n.º 2
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            if (MatrixRanges.Items.Count == 0)
            {
                MessageBox.Show("You must add integration intervals for matrix first!");
                return;
            }
            if (MaterialRanges.Items.Count == 0)
            {
                MessageBox.Show("You must add integration intervals for material first!");
                return;
            }

            ErrorsText.Clear();
            mRelativeIntegralList.Clear();

            var measurements = AutomatedLIBS.MainWindow.mExperiments;

            for (int measurementNum = 0; measurementNum < measurements.Count; ++measurementNum)
            {
                RelativeIntegralList intList = new RelativeIntegralList();

                var spectrums = measurements[measurementNum].mSpectra;
                for (int spectrumNum = 0; spectrumNum < spectrums.Count; ++spectrumNum)
                {
                    var spectrum = spectrums[spectrumNum];

                    // calculate matrix integral
                    double matrixIntegral = 0.0f;
                    for (int i = 0; i < MatrixRanges.Items.Count; ++i)
                    {
                        var range = (Range)MatrixRanges.Items[i];
                        if (range.mSingleLine)
                        {
                            int index = GetClosestWavelengthMatchIndex(range.from);
                            matrixIntegral += spectrum.mAbsoluteIntensities.Value[index];
                        }
                        else
                        {
                            matrixIntegral += CalculateIntegral(spectrum, range.from, range.to);
                        }
                    }

                    // calculate material integral
                    double materialIntegral = 0.0f;
                    for (int i = 0; i < MaterialRanges.Items.Count; ++i)
                    {
                        var range = (Range)MaterialRanges.Items[i];
                        if (range.mSingleLine)
                        {
                            int index = GetClosestWavelengthMatchIndex(range.from);
                            materialIntegral += spectrum.mAbsoluteIntensities.Value[index];
                        }
                        else
                        {
                            materialIntegral += CalculateIntegral(spectrum, range.from, range.to);
                        }
                    }

                    // calculate relative integral
                    double relativeIntegral = materialIntegral / matrixIntegral;

                    // IntegralResults.Text += relativeIntegral.ToString() + '\n';

                    intList.mElements.Add(new RelativeIntegral(relativeIntegral, spectrum.mIntegrationDelayMicroSec, spectrum.mName));
                }

                if (intList.mElements.Count > 0)
                {
                    intList.mMeasurementNumber = measurementNum + 1;
                    mRelativeIntegralList.Add(intList);

                    ///////////////////////
                    // calculate error

                    // calculate average
                    intList.mAverage = 0.0;
                    for (int i = 0; i < intList.mElements.Count; ++i)
                    {
                        intList.mAverage += intList.mElements[i].mIntegral;
                    }
                    if (intList.mElements.Count > 0)
                    {
                        intList.mAverage /= intList.mElements.Count;
                    }

                    // calculate standard deviation
                    intList.mStandardDeviation = 0.0;
                    for (int i = 0; i < intList.mElements.Count; ++i)
                    {
                        intList.mStandardDeviation += Math.Pow(intList.mElements[i].mIntegral - intList.mAverage, 2);
                    }
                    if (intList.mElements.Count > 1)
                    {
                        intList.mStandardDeviation /= intList.mElements.Count - 1;
                        intList.mStandardDeviation  = Math.Sqrt(intList.mStandardDeviation);
                    }

                    ErrorsText.Text += "M" + measurementNum + " - μ: " + Math.Round(intList.mAverage, 4) + "; σ: " + Math.Round(intList.mStandardDeviation, 4) + Environment.NewLine;
                }
            }

            UpdateChart();
        }