36namespace Calibration {
39 const auto N =
Index(pc.size());
47 const auto N =
Index(pc.size());
55 assert(first_c_index >= 0);
69 const Index start = first_c_index - ((first_c_index > 1) ? 2 : 0);
70 const Index cpos = first_c_index % 4;
71 const Index hpos = cpos + ((cpos < 2) ? 2 : -2);
74 const Vector * pc =
nullptr;
75 const Vector * pa =
nullptr;
76 const Vector * ph =
nullptr;
85 const Index pos = i % 4;
91 }
else if (pos == hpos) {
102 if ((pos == cpos or pos == hpos) and pc and pa and ph) {
103 out.emplace_back(
calibration(*pc, *pa, *ph, tc, th));
115 const Index end = end_tmp >= 0 ? end_tmp : 1 + ys.
nelem() + end_tmp;
124 for (
Index k=start; k<end; k++)
126 y[i] += ys[k][i] * scale;
133 const Index end = end_tmp >= 0 ? end_tmp : 1 + ys.
nelem() + end_tmp;
141 for (
Index k=start; k<end; k++) {
152 y[i] = std::numeric_limits<Numeric>::quiet_NaN();
162 const Index end = end_tmp >= 0 ? end_tmp : 1 + ys.
nelem() + end_tmp;
171 for (
Index k=start; k<end; k++)
180 const Index end = end_tmp >= 0 ? end_tmp : 1 + ys.
nelem() + end_tmp;
188 for (
Index k=start; k<end; k++) {
199 var[i] = std::numeric_limits<Numeric>::quiet_NaN();
207 var(
std, y, ys, start, end_tmp);
222 const Index end = end_tmp >= 0 ? end_tmp : 1 + ys.
nelem() + end_tmp;
231 for (
Index k=start; k<end; k++)
234 cov(i, j) += (ys[k][i] - y[i]) * (ys[k][j] - y[j]) * scale;
245 for (
Index i=0; i<n; i++)
252 std::sort(calc.begin(), calc.end());
257 return (calc[(n-1)/2] + calc[n/2]) / 2;
267 for (
Index i=0; i<n; i++) {
276 std::sort(calc.begin(), calc.end());
279 auto newend = std::remove_if(calc.begin(), calc.end(), [](
auto x){return not isnormal_or_zero(x);});
280 const Index numnormal = n -
Index(calc.end() - newend);
285 return calc[numnormal/2];
286 return (calc[(numnormal-1)/2] + calc[numnormal/2]) / 2;
289 return std::numeric_limits<Numeric>::quiet_NaN();
300 const Index p = 1 +
Index(std::abs(X - X0) / DX);
301 Index this_scale = 0;
302 while ((p >> this_scale) > 1) this_scale++;
303 return 1 << this_scale;
306 for (
Index i=0; i<x.
size(); i++) scale[i] = scaling(x[i], x0, dx);
317 first = std::min(i, first);
321 assert(first <=
last);
322 return {first,
last};
328 Index first_i, last_i;
334 std::vector<Numeric> out;
335 for (
Index i=firstone; i<=lastone; i++) out.emplace_back(x[i]);
338 first_i = lastone + 1;
339 while (first_i not_eq
N) {
340 last_i = first_i + scaling[first_i];
341 if (last_i >
N) last_i =
N;
342 out.emplace_back(
mean(x[
Range(first_i, last_i-first_i)]));
347 std::vector<Numeric> fx(0);
350 first_i = last_i - scaling[last_i];
351 if (first_i < 0) first_i = 0;
352 out.insert(out.begin(),
mean(x[
Range(first_i, last_i-first_i)]));
362 Index first_i, last_i;
368 std::vector<Numeric> out;
369 for (
Index i=firstone; i<=lastone; i++) {
371 out.emplace_back(x[i]);
373 out.emplace_back(std::numeric_limits<Numeric>::quiet_NaN());
378 first_i = lastone + 1;
379 while (first_i not_eq
N) {
380 last_i = first_i + scaling[first_i];
381 if (last_i >
N) last_i =
N;
382 out.emplace_back(
nanmean(x[
Range(first_i, last_i-first_i)]));
387 std::vector<Numeric> fx(0);
390 first_i = last_i - scaling[last_i];
391 if (first_i < 0) first_i = 0;
392 out.insert(out.begin(),
nanmean(x[
Range(first_i, last_i-first_i)]));
403 std::vector<bool>
mask(x.
size(),
false);
413 x[i] = std::numeric_limits<Numeric>::quiet_NaN();
418namespace Correction {
424 const Numeric t = std::exp(-tau);
425 if (std::isnormal(t)) {
427 bt += trop_bt * std::expm1(-tau) / t;
TimeStep mean(const ArrayOfTimeStep &dt)
Returns the mean time step.
Index nelem() const ARTS_NOEXCEPT
A constant view of a Vector.
Index nelem() const noexcept
Returns the number of elements.
Index size() const noexcept
Iterator1D begin() ARTS_NOEXCEPT
Return iterator to first element.
Iterator1D end() ARTS_NOEXCEPT
Return iterator behind last element.
void Reduce(Numeric &o, const Vector &i, const Verbosity &)
WORKSPACE METHOD: Reduce.
Numeric last(ConstVectorView x)
last
Numeric nanmean(const ConstVectorView &x) ARTS_NOEXCEPT
Mean function, vector version ignoring nans and infs.
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
constexpr auto pow2(auto x) noexcept
power of two
VectorView avg(VectorView y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the average of the ranged ys.
MatrixView cov(MatrixView cov, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the covariance matrix of the ranged ys.
VectorView nanvar(VectorView var, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the variance of the ranged ys ignoring all non-normal values.
VectorView var(VectorView var, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the variance of the ranged ys.
Numeric nanmedian(const ConstVectorView &v, const ArrayOfIndex &pos)
Get the median of the vector in the range ignoring all non-normal values.
VectorView nanavg(VectorView y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the average of the ranged ys ignoring all non-normal values.
VectorView std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys.
VectorView nanstd(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys ignoring all non-normal values.
Numeric median(const ConstVectorView &v, const ArrayOfIndex &pos)
Get the median of the vector in the range.
ArrayOfVector caha(const ArrayOfVector &data, const Vector &tcvec, const Vector &thvec, const Index first_c_index)
Calibrate the data by CAHA.
Vector systemtemp(const Vector &pc, const Vector &ph, Numeric tc, Numeric th) noexcept
Computes the linear receiver temperature formula elementwise.
Vector calibration(const Vector &pc, const Vector &pa, const Vector &ph, Numeric tc, Numeric th) noexcept
Computes the linear calibration formula elementwise.
VectorView naive_tropospheric(VectorView bt, const Numeric tau, const Numeric trop_bt)
Apply tropospheric correction.
Numeric naive_tropospheric_singletau_median(const ConstVectorView &bt, const Numeric trop_bt, const Numeric target_bt)
Naive tropospheric correction parameterization.
std::vector< bool > out_of_bounds(const Vector &x, const Numeric xmin, const Numeric xmax)
Masks values that are out of bounds in x.
VectorView mask(VectorView x, const std::vector< bool > &masking)
Masks all true entries of masking in x by turning them into NaN.
Vector nanfocus(const Vector &x, const ArrayOfIndex &scaling)
Returns the re-averaged values of x according to scaling ignoring all non-normal values.
std::pair< Index, Index > find_first_and_last_1(const ArrayOfIndex &x)
ArrayOfIndex focus_doublescaling(const Vector &x, const Numeric x0, const Numeric dx)
Returns the relative position scale for each value in x.
Vector focus(const Vector &x, const ArrayOfIndex &scaling)
Returns the re-averaged values of x according to scaling.
constexpr bool isnormal_or_zero(T x) noexcept
Stuff related to generating y-data from raw data.