/// <summary> /// 定量计算 /// </summary> /// <param name="cm">定量方法</param> /// <param name="qm">定量依据</param> /// <param name="cp">计算参数</param> /// <param name="stdsample">标样列表</param> public static bool Calculate(PeakAndPointList test, CalculateMethods cm, QualitativeMode qm, CalculateParameter cp, List <PeakAndPointList> stdsample) { try { AnalyzerMethod am = Graph.FormatAnalyzerMethod(qm, cp, stdsample); switch (cm) { case CalculateMethods.cm_Normalizing: //QualitativeAnalyzer.ComputeNormalization(test, qm,false); QualitativeAnalyzer.QA_ComputePeakInfo(test, am); QualitativeAnalyzer.QA_Normalization(test, am); break; case CalculateMethods.cm_CNormalizing: if (stdsample == null || stdsample.Count == 0) { return(false); } //QualitativeAnalyzer.ComputeAjustNormalization(stdsample[0], test, qm, deltatime); ClearPeakText(test.PeakList); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //20141221:校正归一计算中,计算Dll中根据参数选择调用函数 am.QuantificationMethod.Calibration_Method = PeakQuantificationMethod.CalibrationMethod.cm_CorrectedNormalization; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QualitativeAnalyzer.QA_CorrectedNormalization(stdsample[0], test, am); UnCalculatePeak(stdsample[0], test); break; case CalculateMethods.cm_SCorrection: if (stdsample == null || stdsample.Count == 0) { return(false); } //QualitativeAnalyzer.SinglePointFitting(stdsample[0], test, qm, deltatime); ClearPeakText(test.PeakList); QualitativeAnalyzer.QA_SinglePointFitting(stdsample, test, am); UnCalculatePeak(stdsample[0], test); break; case CalculateMethods.cm_MCorrection: if (stdsample == null || stdsample.Count <= 1) { return(false); } //QualitativeAnalyzer.MultiPointFitting(stdsample, test, qm, deltatime, cp.Degree, cp.ZeroPoint, cp.Logarithm); ClearPeakText(test.PeakList); QualitativeAnalyzer.QA_MultiPointFitting(stdsample, test, am); UnCalculatePeak(stdsample[0], test); break; } return(true); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }
/// <summary> /// 计算后未处理的标样峰 /// </summary> /// <param name="stdsample"></param> /// <param name="test"></param> /// <returns></returns> private static bool UnCalculatePeak(PeakAndPointList stdsample, PeakAndPointList test) { try { bool flag = false; Peak pk = null; for (int i = 0; i < test.PeakList.Count; i++) { test.PeakList[i].Description = null; } for (int i = 0; i < stdsample.PeakList.Count; i++) { if (stdsample.PeakList[i].PeakState == Peak.PeakStates.ps_natural && stdsample.PeakList[i].Checked && stdsample.PeakList[i].Name != "") { flag = false; pk = null; for (int j = 0; j < test.PeakList.Count; j++) { if (stdsample.PeakList[i].Name == test.PeakList[j].Name && test.PeakList[j].Checked) { flag = true; break; } if (test.PeakList[j].PeakPoint.X > stdsample.PeakList[i].StartPoint.X && test.PeakList[j].PeakPoint.X < stdsample.PeakList[i].EndPoint.X) { if (pk != null && Math.Abs(stdsample.PeakList[i].PeakPoint.X - test.PeakList[j].PeakPoint.X) < Math.Abs(stdsample.PeakList[i].PeakPoint.X - pk.PeakPoint.X)) { pk = test.PeakList[j]; } if (pk == null) { pk = test.PeakList[j]; } } } if (!flag && pk != null && pk.PeakState != Peak.PeakStates.ps_natural) { //test.PeakList[pk.Index].Name = stdsample.PeakList[i].Name + ":" + stdsample.PeakList[i].PeakPoint.X.ToString(); //20140430 test.PeakList[pk.Index].Description = stdsample.PeakList[i].Name + ":" + stdsample.PeakList[i].PeakPoint.X.ToString(); //test.PeakList[pk.Index].PeakState = Peak.PeakStates.ps_natural; test.PeakList[pk.Index].Checked = true; } } } return(true); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }
/// <summary>百分比法</summary> /// <param name="unknown_papl">PeakAndPointList对象</param> /// <param name="pcm">计算方法参数</param> /// <param name="pqm">定量方法参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo QA_Normalization(PeakAndPointList unknown_papl, AnalyzerMethod am, bool bfilter) { ClearPeakResult(unknown_papl.PeakList); am.QuantificationMethod.Calibration_Method = PeakQuantificationMethod.CalibrationMethod.cm_Normalization; if (bfilter) { CCalculationFactory.ComputePeakInfo(unknown_papl.PeakList, unknown_papl.PointList, am.CalculationMethod); } return(CQuantificationFactory.Quantitate(unknown_papl.PeakList, am.QuantificationMethod)); }
/// <summary> /// 定量计算 /// </summary> /// <param name="cm">定量方法</param> /// <param name="qm">定量依据</param> /// <param name="cp">计算参数</param> /// <param name="stdsample">标样列表</param> public bool Calculate(CalculateMethods cm, QualitativeMode qm, CalculateParameter cp, List <PeakAndPointList> stdsample) { try { //if (cm== CalculateMethods.cm_Normalizing && !Calculated) return true; PeakAndPointList test = new PeakAndPointList(_peakhelper.Peaks, _datahelper.List); bool rs = Calculate(test, cm, qm, cp, stdsample); //FormatPeakList(test.PeakList, WaveCanvas.VerticalCoordinate.DataMultiple); Calculated = false; return(rs); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }
/// <summary> /// 获取谱图图形数据 /// </summary> /// <param name="filename">图谱文件名</param> /// <returns></returns> public static PeakAndPointList GetGraphData(string filename) { try { //open points DataHelper dh = new DataHelper(); //open peaks PeakHelper ph = new PeakHelper(); DoOpen(filename, dh, ph, null); PeakAndPointList lst = new PeakAndPointList(); lst.PeakList = ph.Peaks; lst.PointList = dh.List; return(lst); } catch (Exception ex) { LogHelper.WriteError(ex); return(null); } }
/// <summary>归一化法</summary> /// <param name="std_papl">标准样品</param> /// <param name="unknown_papl">未知样品</param> /// <param name="pcm">计算方法参数</param> /// <param name="pqm">定量方法参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo QA_CorrectedNormalization(PeakAndPointList std_papl, PeakAndPointList unknown_papl, AnalyzerMethod am) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; //计算标样峰信息 _rc = CCalculationFactory.ComputePeakInfo(std_papl.PeakList, std_papl.PointList, am.CalculationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } //计算标样校正因子 _rc = CQuantificationFactory.GetAdjustFactor(std_papl.PeakList, am.QuantificationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } ResetPeakList(unknown_papl.PeakList); //计算未知样峰信息 _rc = CCalculationFactory.ComputePeakInfo(unknown_papl.PeakList, unknown_papl.PointList, am.CalculationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } //定性未知样 List <Peak> _target_list = CIdentificationFactory.Identify(std_papl.PeakList, unknown_papl.PeakList, am.IdentificationMethod); if (_target_list == null) { return(QualitativeErrorInfo.IdentifyPeakError); } //未知样定量 _rc = CQuantificationFactory.Quantitate(_target_list, am.QuantificationMethod); return(_rc); }
/// <summary>根据标样曲线,进行多点校正/// </summary> /// <param name="std_papl">标样列表</param> /// <param name="unknown_papl">未知样品</param> /// <param name="am">分析参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo QA_MultiPointFitting(List <PeakAndPointList> std_papl, PeakAndPointList unknown_papl, AnalyzerMethod am) { if (std_papl == null || std_papl.Count <= 0 || unknown_papl == null) { return(QualitativeErrorInfo.PeakListError); } QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; //检查标样的浓度是否正常 if (SampleIsError(std_papl)) { Debug.WriteLine("The sample doesn't meet the requirements for calculation."); return(QualitativeErrorInfo.ConcentrationEmpty); } //计算标样的峰信息 _rc = CCalculationFactory.ComputePeakInfo(std_papl[0].PeakList, std_papl[0].PointList, am.CalculationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } List <Peak> _valid_standard_list = std_papl[0].PeakList.FindAll(CPeakFilter.FindCheckedPeak); if (_valid_standard_list == null) { return(QualitativeErrorInfo.StandardSampleError); } //计算校准曲线 //List<PeakAndPointList> _unknown_std_papl = std_papl.GetRange(1, std_papl.Count - 1); //_rc = QA_CreateCalibrationCoeff(_unknown_std_papl, _valid_standard_list, am); _rc = QA_CreateCalibrationCoeff(std_papl, _valid_standard_list, am); //计算未知样的峰信息 ResetPeakList(unknown_papl.PeakList); _rc = CCalculationFactory.ComputePeakInfo(unknown_papl.PeakList, unknown_papl.PointList, am.CalculationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } //定性未知峰 List <Peak> _target_list = CIdentificationFactory.Identify(_valid_standard_list, unknown_papl.PeakList, am.IdentificationMethod); if (_target_list == null) { return(QualitativeErrorInfo.IdentifyPeakError); } //定量 _rc = CQuantificationFactory.Quantitate(_target_list, am.QuantificationMethod); return(_rc); }
/// <summary>单点校正函数,此单点校正有不止一个标样,按多个标样的平均值计算。</summary> /// <param name="std_papl">标样列表</param> /// <param name="unknown_papl">未知样品</param> /// <param name="am">分析参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo QA_SinglePointFitting(List <PeakAndPointList> std_papl, PeakAndPointList unknown_papl, AnalyzerMethod am) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; if (std_papl == null || std_papl.Count <= 0) { return(QualitativeErrorInfo.PeakListError); } //计算标样的峰信息 foreach (PeakAndPointList _papl in std_papl) { CCalculationFactory.ComputePeakInfo(_papl.PeakList, _papl.PointList, am.CalculationMethod); } List <Peak> _std_list = std_papl[0].PeakList.FindAll(CPeakFilter.FindCheckedPeak); if (_std_list == null) { return(QualitativeErrorInfo.StandardSampleError); } _rc = CQuantificationFactory.GetAdjustFactor(_std_list, am.QuantificationMethod); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } //如果存在多组标样,需要首先定性这些标样 if (std_papl.Count > 1) { List <Peak> _aver_std_list = GetAverStandardPeakList(std_papl, _std_list, am.IdentificationMethod, am.QuantificationMethod); if (_aver_std_list != null) { _std_list = _aver_std_list; } } //计算未知峰信息 ResetPeakList(unknown_papl.PeakList); CCalculationFactory.ComputePeakInfo(unknown_papl.PeakList, unknown_papl.PointList, am.CalculationMethod); //定性未知样 List <Peak> _target_list = CIdentificationFactory.Identify(_std_list, unknown_papl.PeakList, am.IdentificationMethod); if (_target_list == null) { return(QualitativeErrorInfo.IdentifyPeakError); } //定量未知样 _rc = CQuantificationFactory.Quantitate(_target_list, am.QuantificationMethod); return(_rc); }
/// <summary>百分比法</summary> /// <param name="unknown_papl">PeakAndPointList对象</param> /// <param name="pcm">计算方法参数</param> /// <param name="pqm">定量方法参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo QA_Normalization(PeakAndPointList unknown_papl, AnalyzerMethod am) { return(QA_Normalization(unknown_papl, am, true)); }
public static QualitativeErrorInfo QA_ComputePeakInfo(PeakAndPointList unknown_papl, AnalyzerMethod am) { ClearPeakResult(unknown_papl.PeakList); return(CCalculationFactory.ComputePeakInfo(unknown_papl.PeakList, unknown_papl.PointList, am.CalculationMethod, CPeakFilter.FindValidPeak)); }
/// <summary> /// 打开一组谱图 /// </summary> /// <param name="index"></param> /// <param name="filenames"></param> /// <param name="colors"></param> /// <returns></returns> public bool Open(List <string> filenames, List <Color> colors) { try { GroupGraph = true; //get all pointf collect List <List <PointF> > pts = new List <List <PointF> >(); List <List <Peak> > pks = new List <List <Peak> >(); List <PointF> xrect = new List <PointF>(); List <PointF> yrect = new List <PointF>(); DataHelper dh = new DataHelper(); for (int i = 0; i < filenames.Count; i++) { string[] name = filenames[i].Split(','); PeakAndPointList ppl = Graph.GetGraphData(name[0]); List <PointF> pt = ppl.PointList; List <Peak> pk = ppl.PeakList; if (pt == null || pt.Count <= 0) { continue; } pts.Add(pt); pks.Add(pk); //20130823采用查询方式获取限值 //xrect.Add(new PointF(pt[0].X, pt[pt.Count - 1].X)); //yrect.Add(new PointF(pt.Min(ymin => ymin.Y), pt.Max(ymax => ymax.Y))); xrect.Add(new PointF(pt.Min(xmin => xmin.X), pt.Max(xmax => xmax.X))); yrect.Add(new PointF(pt.Min(ymin => ymin.Y), pt.Max(ymax => ymax.Y))); //20130823 if (name.GetLength(0) > 1) { _graphname += name[1] + ";"; } else { _graphname += System.IO.Path.GetFileNameWithoutExtension(name[0]) + ";"; } //2013-06-18谱图重叠时显示一条谱图的峰信息 //2013-08-21打开谱图时获取数据单位 //if (i == 0) DoOpen(name[0], null, _peakhelper, null); if (i == 0) { DoOpen(name[0], dh, _peakhelper, null); _datahelper.DataUnit = dh.DataUnit; } //2013-06-18 } _peakhelper.GroupList = pks; _datahelper.GroupList = pts; //get data rect _datahelper.XLimitValue = new PointF(xrect.Min(xmin => xmin.X), xrect.Max(xmax => xmax.Y)); _datahelper.YLimitValue = new PointF(yrect.Min(ymin => ymin.X), yrect.Max(ymax => ymax.Y)); //colors _graphcolors = colors; return(true); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }