43 const arma::vec &abscissa,
46 arma::uword bound_window,
47 arma::mat &total_baseline,
48 arma::mat &inflection_baseline)
50 arma::rowvec results(8);
55 arma::vec abscissa_part = abscissa.rows(min_index, max_index);
56 arma::vec spectrum_part = spectrum.rows(min_index, max_index);
58 min = abscissa(min_index);
59 max = abscissa(max_index);
61 arma::uword min_start = min_index - bound_window;
62 arma::uword min_end = min_index + bound_window;
63 min_end = (min_end >= abscissa.n_rows ? abscissa.n_rows - 1 : min_end);
65 arma::uword max_start = max_index - bound_window;
66 arma::uword max_end = max_index + bound_window;
67 max_end = (max_end >= abscissa.n_rows ? abscissa.n_rows - 1 : max_end);
69 double total_area = arma::as_scalar(arma::trapz(abscissa_part, spectrum_part));
71 arma::uword window_size = max_index - min_index + 1;
72 total_baseline = arma::linspace(spectrum(min_index), spectrum(max_index), window_size);
73 arma::vec total_abscissa = abscissa.rows(min_index, max_index);
74 arma::uvec positive_indices = arma::find(spectrum_part > total_baseline);
75 double positive_area = arma::as_scalar(arma::trapz(abscissa_part.rows(positive_indices), spectrum_part.rows(positive_indices)));
76 double baseline_area = arma::as_scalar(arma::trapz(abscissa_part.rows(positive_indices), total_baseline.rows(positive_indices)));
77 total_baseline = arma::join_horiz(total_abscissa, total_baseline);
79 arma::vec min_window = spectrum.rows(min_start, min_end);
80 arma::vec max_window = spectrum.rows(max_start, max_end);
84 abscissa_part = abscissa.rows(inflection_min_index, inflection_max_index);
85 spectrum_part = spectrum.rows(inflection_min_index, inflection_max_index);
87 double area_between_inflection;
89 area_between_inflection = arma::as_scalar(arma::trapz(abscissa_part, spectrum_part));
90 }
catch(std::exception e){
91 std::cout <<
"Exception: invalid inflection points found" << std::endl;
92 area_between_inflection = std::nan(
"");
93 inflection_min_index = min_index;
94 inflection_max_index = max_index;
97 window_size = inflection_max_index - inflection_min_index + 1;
98 inflection_baseline = arma::linspace(spectrum(inflection_min_index), spectrum(inflection_max_index), window_size);
99 double inf_baseline_area = arma::as_scalar(arma::trapz(abscissa_part, inflection_baseline));
100 inflection_baseline = join_horiz(abscissa.rows(inflection_min_index, inflection_max_index), inflection_baseline);
105 arma::uword search_min_index = (inflection_min_index < min_index ? min_index : inflection_min_index);
106 arma::uword search_max_index = (inflection_max_index > max_index ? max_index : inflection_max_index);
107 arma::vec region = spectrum.rows(search_min_index, search_max_index);
108 arma::vec region_abscissa = abscissa.rows(search_min_index, search_max_index);
110 double maximum = region.max();
111 arma::uword max_pos = region.index_max();
112 arma::vec search_baseline = arma::linspace(region(0), region(region.n_rows - 1), region.n_rows);
113 double peak_center = region_abscissa(max_pos);
114 double adj_maximum = maximum - search_baseline(max_pos);
116 double half_maximum = adj_maximum / 2.0;
119 arma::vec bandwidth_region = spectrum.rows(search_min_index, search_max_index);
120 arma::vec bandwidth_baseline = arma::linspace(bandwidth_region(0), bandwidth_region(bandwidth_region.n_rows - 1), bandwidth_region.n_rows);
121 bandwidth_region = bandwidth_region - bandwidth_baseline;
122 arma::vec bandwidth_abscissa = abscissa.rows(search_min_index, search_max_index);
123 bandwidth_region = bandwidth_region - half_maximum * arma::ones(bandwidth_region.n_rows);
126 while (i < bandwidth_region.n_rows && bandwidth_region(i) < 0){++i;}
127 arma::uword left = (i >= bandwidth_region.n_rows ? bandwidth_region.n_rows - 1 : i);
130 while (i < bandwidth_region.n_rows && bandwidth_region(i) >= 0){++i;}
131 arma::uword right = (i >= bandwidth_region.n_rows ? bandwidth_region.n_rows - 1 : i);
133 if (bandwidth_region.n_rows > left)
134 left = std::fabs(bandwidth_region(left)) < std::fabs(bandwidth_region(left + 1)) ? left : left + 1;
136 right = std::fabs(bandwidth_region(right)) < std::fabs(bandwidth_region(right - 1)) ? right : right - 1;
139 double fwhm = bandwidth_abscissa(right) - bandwidth_abscissa(left);
141 results(0) = peak_center;
142 results(1) = maximum;
143 results(2) = adj_maximum;
144 results(3) = total_area;
145 results(4) = positive_area - baseline_area;
146 results(5) = area_between_inflection;
147 results(6) = area_between_inflection - inf_baseline_area;
155 arma::mat results(spectra.n_cols, 8);
156 inflection_baselines.clear();
157 total_baselines.clear();
159 inflection_baselines.set_size(spectra.n_cols);
160 arma::field<arma::mat> total_baselines_tmp(spectra.n_cols);
163 #pragma omp parallel for default(none) \ 164 shared(spectra, inflection_baselines, total_baselines_tmp, results, min, max, bound_window, abscissa) 165 for (intmax_t i = 0; i < (intmax_t) spectra.n_cols; ++i)
167 #pragma omp parallel for default(none) \ 168 shared(spectra, inflection_baselines, total_baselines_tmp, results, min, max, bound_window, abscissa) 169 for (
size_t i = 0; i < spectra.n_cols; ++ i)
172 double temp_min =
min;
173 double temp_max =
max;
174 arma::mat total_baseline;
175 arma::mat inflection_baseline;
177 inflection_baselines(i) = inflection_baseline;
178 total_baselines_tmp(i) = total_baseline;
181 for (
size_t i = 0; i < total_baselines_tmp.n_rows; ++i){
182 if (total_baselines.n_rows){
183 total_baselines = arma::join_horiz(total_baselines, total_baselines_tmp(i).col(1));
186 total_baselines = total_baselines_tmp(i);
200 arma::vec all_abscissa = inflection_baselines(0).col(0);
202 for (arma::uword i = 0; i < inflection_baselines.n_elem; ++i){
203 arma::vec current_baseline = inflection_baselines(i).col(0);
204 all_abscissa = arma::join_vert(all_abscissa, current_baseline);
206 arma::vec abscissa = arma::unique(all_abscissa);
207 abscissa = arma::sort(abscissa);
208 arma::mat baseline_matrix(abscissa.n_rows, inflection_baselines.n_elem);
210 for (arma::uword j = 0; j < inflection_baselines.n_elem; ++j){
211 arma::vec current_baseline = inflection_baselines(j).col(1);
212 arma::vec current_abscissa = inflection_baselines(j).col(0);
213 for (arma::uword i = 0; i < abscissa.n_rows; ++i){
214 arma::uvec indices = arma::find(current_abscissa == abscissa(i));
215 baseline_matrix(i, j) = (indices.n_rows > 0 ?
216 current_baseline(indices(0)) :
220 baseline_matrix = arma::join_horiz(abscissa, baseline_matrix);
221 return baseline_matrix;
276 return arma::rowvec();
391 return arma::rowvec();
521 return arma::rowvec();
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
VESPUCCI_EXPORT arma::mat FitGaussianPeakMat(const arma::mat &spectra, const arma::vec &abscissa, double &min, double &max, arma::mat &baselines, arma::mat &fits, arma::mat ¶ms, arma::mat &residuals)
VESPUCCI_EXPORT arma::rowvec FitLorentzianPeak(const arma::vec &spectrum, const arma::vec &abscissa, double &min, double &max, arma::mat &baseline, arma::mat &fit, arma::rowvec ¶ms, arma::mat residuals)
Vespucci::Math::Quantification::FitLorentzianPeak.
VESPUCCI_EXPORT arma::uword LocalMinimum(const arma::mat &X, double &value)
Vespucci::Math::LocalMinimum.
VESPUCCI_EXPORT arma::rowvec FitGaussianPeak(const arma::vec &spectrum, const arma::vec &abscissa, double &min, double &max, arma::mat &baseline, arma::mat &fit, arma::rowvec ¶ms, arma::mat residuals)
Vespucci::Math::Quantification::FitGaussianPeak Fit and analyze data with a Gaussian function...
VESPUCCI_EXPORT arma::rowvec QuantifyPeak(const arma::vec &spectrum, const arma::vec &abscissa, double &min, double &max, arma::uword bound_window, arma::mat &total_baseline, arma::mat &inflection_baseline)
Vespucci::Math::Quantification::QuantifyPeak Performs empirical analysis of peak shape and magnitude...
VESPUCCI_EXPORT arma::rowvec FitVoigtPeak(const arma::vec &spectrum, const arma::vec &abscissa, double &min, double &max, arma::mat &baseline, arma::mat &fit, arma::rowvec ¶ms, arma::mat residuals)
Vespucci::Math::Quantification::FitVoigtPeak.
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
VESPUCCI_EXPORT arma::mat ConvertInflectionBaselines(const arma::field< arma::mat > &inflection_baselines)
Vespucci::Math::Quantification::ConvertInflectionBaselines.
VESPUCCI_EXPORT arma::uword ClosestIndex(double value, const arma::vec &vector)
Vespucci::Math::ClosestIndex.
VESPUCCI_EXPORT arma::mat FitVoigtPeakMat(const arma::mat &spectra, const arma::vec &abscissa, double &min, double &max, arma::mat &baselines, arma::mat &fits, arma::mat ¶ms, arma::mat &residuals)
Vespucci::Math::Quantification::FitVoigtPeakMat.
VESPUCCI_EXPORT arma::mat QuantifyPeakMat(const arma::mat &spectra, const arma::vec &abscissa, double &min, double &max, arma::uword bound_window, arma::mat &total_baselines, arma::field< arma::mat > &inflection_baselines)
VESPUCCI_EXPORT arma::mat FitLorentzianPeakMat(const arma::mat &spectra, const arma::vec &abscissa, double &min, double &max, arma::mat &baselines, arma::mat &fits, arma::mat ¶ms, arma::mat &residuals)
Vespucci::Math::Quantification::FitLorentzianPeakMat.