/// <summary>计算峰列表中峰对象所对应的物质的量</summary> /// <param name="peak_list">峰对象列表</param> /// <param name="capacity">物质的量</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo Quantitate(List <Peak> peak_list, PeakQuantificationMethod pqm) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; double _capacity = 0.0; if (pqm.Calibration_Method != PeakQuantificationMethod.CalibrationMethod.cm_ExternalStandard) { return(QualitativeErrorInfo.CalibrationMethodError); } //外标定量 foreach (Peak _p in peak_list) { if (!CPeakFilter.FindCheckedPeak(_p)) { continue; } _capacity = 0.0; _rc = GetCapacity(_p, pqm, ref _capacity); if (_rc == QualitativeErrorInfo.Success) { _p.Capacity = _capacity; } } return(_rc); }
/// <summary>归一法</summary> /// <param name="std_peak_list">峰对象列表</param> /// <param name="qm">定量参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo Quantitate(List <Peak> peak_list, PeakQuantificationMethod pqm) { if (peak_list == null) { return(QualitativeErrorInfo.PeakListError); } QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; double _sum = GetResponseSum(peak_list, pqm.Qualitative_Method, PeakQuantificationMethod.SumMethod.sm_absolute_adjust); if (_sum == 0) { return(QualitativeErrorInfo.CapacityError); } //归一法首先需要定性,以确定校准因子 foreach (Peak _p in peak_list) { if (!CPeakFilter.FindCheckedPeak(_p)) { continue; } _p.Capacity = _p.AdjustFactor * GetResponseValue(_p, pqm.Qualitative_Method) / _sum; } return(_rc); }
/// <summary>计算峰列表中每个有效峰的校正因子</summary> /// <param name="std_peak_list">峰对象列表</param> /// <param name="qm">响应值类型选择</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo GetAdjustFactor(List <Peak> std_peak_list, PeakQuantificationMethod.QualitativeMethod qm) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; try { List <Peak> _valid_peaks = std_peak_list.FindAll(CPeakFilter.FindCheckedPeak); if (_valid_peaks != null) { foreach (Peak _p in _valid_peaks) { double _factor = 0.0; _rc = ComputeAbsoluteAdjustFactor(_p, qm, ref _factor); if (_rc == QualitativeErrorInfo.Success) { _p.AdjustFactor = _factor; } } } } catch (System.Exception ex) { Debug.WriteLine(ex.Message); _rc = QualitativeErrorInfo.PeakListError; } return(_rc); }
/// <summary>计算指定峰的物质的量</summary> /// <param name="p">峰对象</param> /// <param name="internal_standard_peak">内标峰</param> /// <param name="pqm">定量参数</param> /// <param name="capacity">物质的量</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo Capacity(Peak p, double response, PeakQuantificationMethod.CurveFittingMethod cfm, ref double capacity) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; if ((p.Coefficient == null) || (p.Coefficient.Count < 2)) { capacity = p.AdjustFactor * response; } else { switch (cfm) { case PeakQuantificationMethod.CurveFittingMethod.cfm_linear: case PeakQuantificationMethod.CurveFittingMethod.cfm_quadratic: case PeakQuantificationMethod.CurveFittingMethod.cfm_cubic: capacity = 0; for (int k = 0; k < p.Coefficient.Count; k++) { capacity += p.Coefficient[k] * Math.Pow(response, k); } break; case PeakQuantificationMethod.CurveFittingMethod.cfm_log: capacity = Math.Pow(10, (p.Coefficient[0] + p.Coefficient[1] * Math.Log10(response))); break; default: _rc = QualitativeErrorInfo.CurveFitMethodError; break; } } return(_rc); }
/// <summary>百分比法</summary> /// <param name="std_peak_list">峰对象列表</param> /// <param name="qm">定量参数</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo Quantitate(List <Peak> peak_list, PeakQuantificationMethod pqm) { if (peak_list == null) { return(QualitativeErrorInfo.PeakListError); } QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; double _sum = GetResponseSum(peak_list, pqm.Qualitative_Method, PeakQuantificationMethod.SumMethod.sm_normal); if (_sum == 0) { return(QualitativeErrorInfo.ResponseValueError); } foreach (Peak _p in peak_list) { if (!CPeakFilter.FindNaturalPeak(_p)) { continue; } _p.Checked = true; _p.Capacity = GetResponseValue(_p, pqm.Qualitative_Method) / _sum; } return(_rc); }
/// <summary>计算指定峰绝对校正因子</summary> /// <param name="std_peak">峰对象</param> /// <param name="qm">响应值类型选择</param> /// <param name="adjust_factor">校正因子</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo ComputeAbsoluteAdjustFactor(Peak std_peak, PeakQuantificationMethod.QualitativeMethod qm, ref double adjust_factor) { QualitativeErrorInfo _rc = QualitativeErrorInfo.CapacityError; if (std_peak.Capacity >= 0 && !double.IsNaN(std_peak.Capacity)) { adjust_factor = std_peak.Capacity / GetResponseValue(std_peak, qm); _rc = QualitativeErrorInfo.Success; } 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="std_peak_list">标准峰对象列表</param> /// <param name="qm">响应值类型选择</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo GetAdjustFactor(List <Peak> std_peak_list, PeakQuantificationMethod.QualitativeMethod qm) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; double _factor = 0.0; if (std_peak_list == null) { return(QualitativeErrorInfo.PeakListError); } //至少包含一个内标物和被测物 if (std_peak_list.Count < 2) { return(QualitativeErrorInfo.PeakListError); } //查找内标物 Peak _internal_standard_peak = std_peak_list.Find(CPeakFilter.FindInternalStandardPeak); if (_internal_standard_peak == null) { return(QualitativeErrorInfo.InternalStandardError); } //计算内标物的绝对校正因子 _rc = CQuantificationBase.ComputeAbsoluteAdjustFactor(_internal_standard_peak, qm, ref _factor); if (_rc != QualitativeErrorInfo.Success) { return(QualitativeErrorInfo.InternalStandardError); } _internal_standard_peak.AdjustFactor = _factor; //计算未知物的校正因子(注意未知物列表要剔除内标物) foreach (Peak _p in std_peak_list) { if (!CPeakFilter.FindCheckedPeak(_p) || ((_p.InternalStandard != null) && (_p.InternalStandard != ""))) { continue; } _factor = 0.0; _rc = CQuantificationBase.ComputeRelativeAdjustFactor(_p, _internal_standard_peak, qm, ref _factor); if (_rc == QualitativeErrorInfo.Success) { _p.AdjustFactor = _factor; } } return(_rc); }
public static QualitativeErrorInfo QA_CreateCalibrationCoeff(List <PeakAndPointList> standard_papl, List <Peak> peak_param, AnalyzerMethod am) { if ((standard_papl == null) || (standard_papl.Count == 0) || (peak_param == null) || (peak_param.Count == 0)) { return(QualitativeErrorInfo.PeakListError); } QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; //计算标样的峰信息 foreach (PeakAndPointList _papl in standard_papl) { _rc = CCalculationFactory.ComputePeakInfo(_papl.PeakList, _papl.PointList, am.CalculationMethod); if (_rc != QualitativeErrorInfo.Success) { continue; } CIdentificationFactory.Identify(peak_param, _papl.PeakList, am.IdentificationMethod); } foreach (Peak _p in peak_param) { List <Peak> _peak_list = CQuantificationFactory.GetStandardPeakList(standard_papl, _p.Name, am.QuantificationMethod); if (_peak_list == null) { continue; } _p.Coefficient = CQuantificationFactory.GetCoefficient(_peak_list, am.QuantificationMethod); if (_p.Coefficient == null) { continue; } string _fitting_formula = CQuantificationFactory.GetFittingFormula(_p.Coefficient, am.QuantificationMethod); foreach (Peak _p0 in _peak_list) { if ((_p0.InternalStandard == null) || _p0.InternalStandard.Trim() == "") { _p0.Coefficient = _p.Coefficient.GetRange(0, _p.Coefficient.Count); _p0.FittingFormula = _fitting_formula; } } } return(_rc); }
/// <summary>计算指定峰相对对校正因子</summary> /// <param name="std_peak">标准峰对象</param> /// <param name="internal_standard_peak">内标峰对象</param> /// <param name="qm">响应值类型选择</param> /// <param name="adjust_factor">校正因子</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo ComputeRelativeAdjustFactor(Peak std_peak, Peak internal_standard_peak, PeakQuantificationMethod.QualitativeMethod qm, ref double adjust_factor) { double _absolute_adjust_factor = 0.0; QualitativeErrorInfo _rc = CQuantificationExternal.ComputeAbsoluteAdjustFactor(std_peak, qm, ref _absolute_adjust_factor); if (_rc != QualitativeErrorInfo.Success) { return(_rc); } if (internal_standard_peak.AdjustFactor == 0) { return(QualitativeErrorInfo.InternalStandardError); } adjust_factor = _absolute_adjust_factor / internal_standard_peak.AdjustFactor; return(_rc); }
/// <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="peak_list">峰对象列表</param> /// <param name="capacity">物质的量</param> /// <returns>QualitativeErrorInfo枚举值</returns> public static QualitativeErrorInfo Quantitate(List <Peak> peak_list, PeakQuantificationMethod pqm) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; double _capacity = 0.0; if (pqm.Calibration_Method != PeakQuantificationMethod.CalibrationMethod.cm_InternalStandard) { return(QualitativeErrorInfo.CalibrationMethodError); } //内标定量 Peak _internal_standard_peak = peak_list.Find(CPeakFilter.FindInternalStandardPeak); //if ((_internal_standard_peak == null) || (_internal_standard_peak.AdjustFactor == 0)) if (_internal_standard_peak == null) { return(QualitativeErrorInfo.InternalStandardError); } foreach (Peak _p in peak_list) { if (!CPeakFilter.FindCheckedPeak(_p) || ((_p.InternalStandard != null) && (_p.InternalStandard != ""))) { continue; } _capacity = 0.0; _rc = GetCapacity(_p, _internal_standard_peak, pqm, ref _capacity); if (_rc == QualitativeErrorInfo.Success) { _p.Capacity = _capacity; } } return(_rc); }
/// <summary>计算峰信息</summary> /// <param name="peak">峰对象</param> /// <param name="dead_time">死时间</param> /// <param name="curve_point">峰曲线列表</param> /// <returns>QualitativeErrorInfo枚举</returns> private QualitativeErrorInfo ComputePeakInfo(Peak peak, double dead_time, List <PointF> peak_group_curve) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; if ((peak == null) || (peak_group_curve == null)) { return(QualitativeErrorInfo.PeakObjectError); } List <PointF> _peak_curve = GetPeakCurve(peak, peak_group_curve); if (_peak_curve == null) { Debug.WriteLine("Peak_" + peak.Index + " can't be calculated !"); return(QualitativeErrorInfo.PeakCurveError); } //计算容量因子,组分在两相中的总量之比称分配比,又称容量因子,k = (Tr - T0)/T0 peak.CapacityFactor = (dead_time == 0) ? (-1) : ((peak.PeakPoint.X - dead_time) / dead_time); //计算峰面积 peak.PeakArea = ComputePeakArea(peak, _peak_curve); //计算峰高 //peak.PeakHeight = ComputePeakHeight(peak.PeakPoint, GetPeakStartPoint(peak), GetPeakEndPoint(peak)); peak.PeakHeight = ComputePeakHeight(peak); peak.PeakWidth1 = peak.PeakWidth2 = peak.PeakWidth4 = -1; peak.PlateIdealNum = peak.PlateRealNum = -1; peak.TailingFactor = peak.AsymmetricDegree = -1; List <PointF> _point_line = GetWidthOfAnyPeakHeight(peak, _peak_curve, peak.PeakHeight / 2); if ((_point_line == null) || (_point_line.Count < 2)) { return(QualitativeErrorInfo.ComputePeakInfoError); } //peak.PeakWidth2 = ComputeDistance(_point_line[0], _point_line[1]); peak.PeakWidth2 = Math.Abs(_point_line[0].X - _point_line[1].X); peak.PeakWidth1 = peak.PeakWidth2 * 4 / 2.35; _point_line = GetWidthOfAnyPeakHeight(peak, _peak_curve, peak.PeakHeight / 4); if ((_point_line == null) || (_point_line.Count < 2)) { return(QualitativeErrorInfo.ComputePeakInfoError); } //peak.PeakWidth4 = ComputeDistance(_point_line[0], _point_line[1]); peak.PeakWidth4 = Math.Abs(_point_line[0].X - _point_line[1].X); peak.PlateIdealNum = ComputeTheoreticalPlates(peak); peak.PlateRealNum = ComputeEffectivePlates(peak, dead_time); peak.TailingFactor = ComputeTailingFactor(peak, _peak_curve); peak.AsymmetricDegree = ComputeSymmetryFactor(peak, _peak_curve); #region OLD_CODE ////计算半高峰宽 //peak.PeakWidth2 = (peak.PeakArea / peak.PeakHeight / 1.065); ////计算峰宽 //peak.PeakWidth1 = peak.PeakWidth2 * 4 / 2.35; ////计算四分之一峰宽 //double _height = Double.Parse((peak.PeakPoint.Y - peak.StartPoint.Y).ToString("f3")); //peak.PeakWidth4 = Double.Parse(ComputeAnyHeightWidth(_height / 4, _peak_curve, peak).ToString("f3")); ////计算理论塔板数 //peak.PlateIdealNum = ComputeTheoreticalPlates(peak); ////计算有效塔板数 //peak.PlateRealNum = ComputeEffectivePlates(peak, dead_time); ////计算拖尾因子,5%高度处全峰宽与左峰宽两倍的比值 //peak.TailingFactor = ComputeTailingFactor(peak, peak_group_curve); ////计算不对称度,10%高度处左峰宽与右峰宽的比值 //peak.AsymmetricDegree = ComputeSymmetryFactor(peak, peak_group_curve); #endregion return(_rc); }
private static List <Peak> GetAverStandardPeakList(List <PeakAndPointList> unknown_std_papl, List <Peak> standard_list, PeakIdentificationMethod pim, PeakQuantificationMethod pqm) { QualitativeErrorInfo _rc = QualitativeErrorInfo.Success; if ((unknown_std_papl == null) || (unknown_std_papl.Count == 0) || (standard_list == null) || (standard_list.Count == 0)) { return(null); } int[] _std_count = new int[standard_list.Count]; double[] _std_rt = new double[standard_list.Count]; List <Peak> _aver_std_list = new List <Peak>(); for (int i = 0; i < standard_list.Count; i++) { _std_count[i] = 0; _std_rt[i] = 0; Peak _p = new Peak(); _p.Name = standard_list[i].Name; _p.Checked = true; _p.Index = i; _aver_std_list.Add(_p); } foreach (PeakAndPointList _papl in unknown_std_papl) { List <Peak> _unknown_std_list = _papl.PeakList.FindAll(CPeakFilter.FindNaturalPeak); if (_unknown_std_list == null) { continue; } //定性标样峰 List <Peak> _target_list = CIdentificationFactory.Identify(standard_list, _unknown_std_list, pim); if (_target_list == null) { continue; } _rc = CQuantificationFactory.GetAdjustFactor(_target_list, pqm); //计算校正因子 if (_rc != QualitativeErrorInfo.Success) { continue; } foreach (Peak _p in _aver_std_list) { foreach (Peak _p0 in _target_list) { if (_p.Name == _p0.Name) { _p.Capacity += _p0.Capacity; _p.PeakHeight += _p0.PeakHeight; _p.PeakArea += _p0.PeakArea; _p.AdjustFactor += _p0.AdjustFactor; _std_count[_p.Index]++; _std_rt[_p.Index] += _p0.PeakPoint.X; _target_list.Remove(_p0); break; } } } } foreach (Peak _p in _aver_std_list) { int _count = _std_count[_p.Index]; _std_rt[_p.Index] /= _count; _p.Capacity /= _count; _p.PeakHeight /= _count; _p.PeakArea /= _count; _p.AdjustFactor /= _count; _p.PeakPoint = new PointF((float)_std_rt[_p.Index], 0); } return((_aver_std_list.Count > 0) ? _aver_std_list : null); }