33 arma::vec region = X.subvec(min_index, max_index);
35 double start = X(min_index);
36 double end = X(max_index);
38 if (correct_baseline){baseline = arma::linspace(start, end, region.n_elem);}
39 else{baseline = arma::zeros(region.n_elem);}
41 double baseline_area = sum(baseline) / abscissa_step;
42 double region_area = sum(region) / abscissa_step;
43 double value = (correct_baseline ? region_area - baseline_area : region_area);
59 double delta = std::abs(abscissa(1) - abscissa(0));
60 arma::uvec left_bound = find(((min-delta) <= abscissa) && (abscissa <= (min+delta)));
61 arma::uvec right_bound = find(((max-delta) <= abscissa) && (abscissa <= (max+delta)));
63 arma::uword min_index = left_bound(0);
64 arma::uword max_index = right_bound(0);
65 min = abscissa(min_index);
66 max = abscissa(max_index);
67 boundaries << min_index << arma::endr << max_index;
68 arma::vec results(X.n_cols);
69 baselines.set_size(X.col(0).subvec(min_index, max_index).n_elem, X.n_cols);
70 arma::vec baseline(baselines.n_cols);
71 for (arma::uword i = 0; i < X.n_cols; ++i){
72 results(i) =
IntegratePeak(X.col(i), min_index, max_index, delta, baseline, correct_baseline);
73 baselines.col(i) = baseline;
91 arma::mat
Vespucci::Math::Quantification::IntegratePeaksMat(
const arma::mat &X,
const arma::vec &abscissa,
double &first_min,
double &first_max,
double &second_min,
double &second_max, arma::mat &first_baselines, arma::mat &second_baselines, arma::uvec &boundaries)
93 double delta = std::abs(abscissa(1) - abscissa(0));
94 arma::uvec first_left_bound = find(((first_min-delta) <= abscissa) && (abscissa <= (first_min+delta)));
95 arma::uvec first_right_bound = find(((first_max-delta) <= abscissa) && (abscissa <= (first_max+delta)));
96 arma::uvec second_left_bound = find(((second_min-delta) <= abscissa) && (abscissa <= (second_min+delta)));
97 arma::uvec second_right_bound = find(((second_max-delta) <= abscissa) && (abscissa <= (second_max+delta)));
99 arma::uword first_min_index = first_left_bound(0);
100 arma::uword first_max_index = first_right_bound(0);
101 arma::uword second_min_index = second_left_bound(0);
102 arma::uword second_max_index = second_right_bound(0);
104 first_min = abscissa(first_min_index);
105 first_max = abscissa(first_max_index);
106 second_min = abscissa(second_min_index);
107 second_max = abscissa(second_max_index);
109 boundaries.set_size(4);
110 boundaries(0) = first_min_index;
111 boundaries(1) = first_max_index;
112 boundaries(2) = second_min_index;
113 boundaries(3) = second_max_index;
119 first_baselines.set_size(X.col(0).subvec(first_min_index, first_max_index).n_elem, X.n_cols);
120 arma::vec first_baseline(first_baselines.n_cols);
121 second_baselines.set_size(X.col(0).subvec(second_min_index, second_max_index).n_elem, X.n_cols);
122 arma::vec second_baseline(second_baselines.n_cols);
124 arma::mat results (X.n_cols, 2);
125 for (arma::uword i = 0; i < X.n_cols; ++i){
126 results(i, 0) =
IntegratePeak(X.col(i), first_min_index, first_max_index, delta, first_baseline,
true);
127 first_baselines.col(i) = first_baseline;
129 for (arma::uword i = 0; i < X.n_cols; ++i){
130 results(i, 1) =
IntegratePeak(X.col(i), second_min_index, second_max_index, delta, second_baseline,
true);
131 second_baselines.col(i) = second_baseline;
149 arma::field<arma::vec> &baselines,
150 arma::uvec &boundaries, arma::uword bound_window,
bool correct_baseline)
152 arma::vec results(X.n_cols);
153 double delta = std::abs(abscissa(1) - abscissa(0));
154 arma::uvec left_bound = find(((min-delta) <= abscissa) && (abscissa <= (min+delta)));
155 arma::uvec right_bound = find(((max-delta) <= abscissa) && (abscissa <= (max+delta)));
158 arma::uword min_index = left_bound(0);
159 arma::uword max_index = right_bound(0);
160 min = abscissa(min_index);
161 max = abscissa(max_index);
163 arma::uword min_start = min_index - bound_window;
164 arma::uword min_end = min_index + bound_window;
165 min_end = (min_end >= abscissa.n_rows ? abscissa.n_rows - 1 : min_end);
167 arma::uword max_start = max_index - bound_window;
168 arma::uword max_end = max_index + bound_window;
169 max_end = (max_end >= abscissa.n_rows ? abscissa.n_rows - 1 : max_end);
171 baselines.set_size(X.n_cols);
172 for (arma::uword i = 0; i < X.n_cols; ++i){
173 arma::vec spectrum = X.col(i);
174 arma::vec min_window = spectrum.rows(min_start, min_end);
175 arma::vec max_window = spectrum.rows(max_start, max_end);
178 arma::vec baseline(spectrum.rows(min_index, max_index).n_rows);
179 results(i) =
IntegratePeak(spectrum, min_index, max_index, delta, baseline, correct_baseline);
180 baselines(i) = baseline;
200 double &first_min,
double &first_max,
201 double &second_min,
double &second_max,
202 arma::field<arma::vec> &first_baselines, arma::field<arma::vec> &second_baselines,
203 arma::uvec &boundaries, arma::uword bound_window)
205 arma::mat results(X.n_cols, 2);
206 double delta = std::abs(abscissa(1) - abscissa(0));
207 arma::uvec first_left_bound = find(((first_min-delta) <= abscissa) && (abscissa <= (first_min+delta)));
208 arma::uvec first_right_bound = find(((first_max-delta) <= abscissa) && (abscissa <= (first_max+delta)));
209 arma::uvec second_left_bound = find(((second_min-delta) <= abscissa) && (abscissa <= (second_min+delta)));
210 arma::uvec second_right_bound = find(((second_max-delta) <= abscissa) && (abscissa <= (second_max+delta)));
212 arma::uword first_min_index = first_left_bound(0);
213 arma::uword first_max_index = first_right_bound(0);
214 arma::uword second_min_index = second_left_bound(0);
215 arma::uword second_max_index = second_right_bound(0);
217 first_min = abscissa(first_min_index);
218 first_max = abscissa(first_max_index);
219 second_min = abscissa(second_min_index);
220 second_max = abscissa(second_max_index);
222 arma::uword first_min_start = first_min_index - bound_window;
223 arma::uword first_min_end = first_min_index + bound_window;
224 first_min_end = (first_min_end >= abscissa.n_rows ? abscissa.n_rows - 1 : first_min_end);
225 arma::uword second_min_start = second_min_index - bound_window;
226 arma::uword second_min_end = second_min_index + bound_window;
227 second_min_end = (second_min_end >= abscissa.n_rows ? abscissa.n_rows - 1 : second_min_end);
229 arma::uword first_max_start = first_max_index - bound_window;
230 arma::uword first_max_end = first_max_index + bound_window;
231 first_max_end = (first_max_end >= abscissa.n_rows ? abscissa.n_rows - 1 : first_max_end);
232 arma::uword second_max_start = second_max_index - bound_window;
233 arma::uword second_max_end = second_max_index + bound_window;
234 second_max_end = (second_max_end >= abscissa.n_rows ? abscissa.n_rows - 1 : second_max_end);
236 first_baselines.set_size(X.n_cols);
237 second_baselines.set_size(X.n_cols);
239 for (arma::uword i = 0; i < X.n_cols; ++i){
240 arma::vec spectrum = X.col(i);
242 arma::vec first_min_window = spectrum.rows(first_min_start, first_min_end);
243 arma::vec first_max_window = spectrum.rows(first_max_start, first_max_end);
246 arma::vec first_baseline(spectrum.rows(first_min_index, first_max_index).n_rows);
247 results(i, 0) =
IntegratePeak(spectrum, first_min_index, first_max_index, delta, first_baseline,
true);
248 first_baselines(i) = first_baseline;
250 arma::vec second_min_window = spectrum.rows(second_min_start, second_min_end);
251 arma::vec second_max_window = spectrum.rows(second_max_start, second_max_end);
254 arma::vec second_baseline(spectrum.rows(second_min_index, second_max_index).n_rows);
255 results(i, 1) =
IntegratePeak(spectrum, second_min_index, second_max_index, delta, second_baseline,
true);
256 second_baselines(i) = second_baseline;
259 boundaries.set_size(4);
260 boundaries(0) = first_min_index;
261 boundaries(1) = first_max_index;
262 boundaries(2) = second_min_index;
263 boundaries(3) = second_max_index;
VESPUCCI_EXPORT arma::vec IntegratePeakMat(const arma::mat &X, const arma::vec &abscissa, double &min, double &max, arma::mat &baselines, arma::uvec &boundaries, bool correct_baseline)
Vespucci::Math::Quantification::IntegratePeakMat.
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
VESPUCCI_EXPORT arma::uword LocalMinimum(const arma::mat &X, double &value)
Vespucci::Math::LocalMinimum.
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
VESPUCCI_EXPORT arma::mat IntegratePeaksMat(const arma::mat &X, const arma::vec &abscissa, double &first_min, double &first_max, double &second_min, double &second_max, arma::mat &first_baselines, arma::mat &second_baselines, arma::uvec &boundaries)
Vespucci::Math::Quantification::IntegratePeaksMat.
VESPUCCI_EXPORT double IntegratePeak(const arma::vec &X, arma::uword min_index, arma::uword max_index, double abscissa_step, arma::vec &baseline, bool correct_baseline)
Vespucci::Math::Quantification::IntegratePeak.