LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
gslsersicmixinterpolator.cc
Go to the documentation of this file.
1#ifdef LSST_GAUSS2D_FIT_HAS_GSL
2
3#include <algorithm>
4#include <stdexcept>
5#include <string>
6#include <vector>
7
10
13
14namespace lsst::gauss2d::fit {
15
16GSLSersicMixInterpolator::GSLSersicMixInterpolator(unsigned short order, const InterpType interp_type_)
17 : _interp_type(interp_type_),
18 _order(order),
20 _sersicindex_min(_knots[0].sersicindex),
21 _sersicindex_max(_knots.back().sersicindex) {
22 _interps.reserve(order);
23 std::vector<double> sersics;
26 const size_t n_knots = _knots.size();
27 sersics.reserve(n_knots);
28 integrals.resize(order);
29 sigmas.resize(order);
30 for (size_t iord = 0; iord < _order; ++iord) {
31 integrals[iord].reserve(n_knots);
32 sigmas[iord].reserve(n_knots);
33 }
34 for (const auto& knot : _knots) {
35 sersics.push_back(knot.sersicindex);
36 for (size_t iord = 0; iord < _order; ++iord) {
37 const auto& integralsize = knot.values[iord];
38 integrals[iord].push_back(integralsize.integral);
39 sigmas[iord].push_back(integralsize.sigma);
40 }
41 }
42 for (size_t iord = 0; iord < _order; ++iord) {
43 _interps.push_back({std::make_unique<GSLInterpolator>(sersics, integrals[iord], _interp_type),
44 std::make_unique<GSLInterpolator>(sersics, sigmas[iord], _interp_type)});
45 }
46}
47
48GSLSersicMixInterpolator::~GSLSersicMixInterpolator() {}
49
50double GSLSersicMixInterpolator::get_final_correction() const { return _final_correction; }
51
52std::vector<IntegralSize> GSLSersicMixInterpolator::get_integralsizes(double sersicindex) const {
53 if (!((sersicindex >= _sersicindex_min) && (sersicindex <= _sersicindex_max))) {
54 throw std::invalid_argument("sersicindex=" + to_string_float(sersicindex)
55 + " not between min=" + to_string_float(_sersicindex_min)
56 + " and max=" + to_string_float(_sersicindex_max));
57 }
58
60 result.reserve(_order);
61 double sum = 0;
62 size_t max_ord = _order - correct_final_integral;
63 for (size_t i = 0; i < max_ord; ++i) {
64 const auto& interp = _interps[i];
65 double integral = interp.first->eval(sersicindex);
66 sum += integral;
67 result.push_back(IntegralSize(integral, interp.second->eval(sersicindex)));
68 }
69 if (correct_final_integral) {
70 const auto& interp = _interps[_order - 1];
71 double integral = 1.0 - sum;
72 double integral_interp = interp.first->eval(sersicindex);
73 bool interp_eq_zero = integral_interp == 0;
74 _final_correction = integral * (!interp_eq_zero) / (integral_interp + interp_eq_zero);
75 if (!(integral >= 0)) {
76 throw std::logic_error(this->str() + ".get_integralsizes(" + to_string_float(sersicindex)
77 + ") got correction=" + to_string_float(_final_correction)
78 + " from integral=" + to_string_float(integral) + " !>=0)");
79 }
80 result.push_back(IntegralSize(integral, interp.second->eval(sersicindex)));
81 } else {
82 // An overly cautious reset of the value since the option is mutable.
83 _final_correction = 1.;
84 }
85
86 return result;
87}
88
89std::vector<IntegralSize> GSLSersicMixInterpolator::get_integralsizes_derivs(double sersicindex) const {
90 if (!((sersicindex >= _sersicindex_min) && (sersicindex <= _sersicindex_max))) {
91 throw std::invalid_argument("sersicindex=" + to_string_float(sersicindex)
92 + " not between min=" + to_string_float(_sersicindex_min)
93 + " and max=" + to_string_float(_sersicindex_max));
94 }
95
97 result.reserve(_order);
98 size_t max_ord = _order - correct_final_integral;
99 for (size_t i = 0; i < max_ord; ++i) {
100 const auto& interp = _interps[i];
101 result.push_back(
102 IntegralSize(interp.first->eval_deriv(sersicindex), interp.second->eval_deriv(sersicindex)));
103 }
104 if (correct_final_integral) {
105 const auto& interp = _interps[max_ord];
106 result.push_back(IntegralSize(correct_final_integral * interp.first->eval_deriv(sersicindex),
107 interp.second->eval_deriv(sersicindex)));
108 } else {
109 _final_correction = 1.;
110 }
111
112 return result;
113}
114
115InterpType GSLSersicMixInterpolator::get_interptype() const { return _interp_type; }
116
117const std::vector<SersicMixValues>& GSLSersicMixInterpolator::get_knots() const { return _knots; }
118
119unsigned short GSLSersicMixInterpolator::get_order() const { return _order; }
120
121double GSLSersicMixInterpolator::get_sersicindex_min() const { return _sersicindex_min; }
122double GSLSersicMixInterpolator::get_sersicindex_max() const { return _sersicindex_max; }
123
124std::string GSLSersicMixInterpolator::repr(bool name_keywords, std::string_view namespace_separator) const {
125 return std::string("GSLSersicMixInterpolator(") + (name_keywords ? "order=" : "") + std::to_string(_order)
126 + ")";
127}
128
129std::string GSLSersicMixInterpolator::str() const {
130 return "GSLSersicMixInterpolator(order=" + std::to_string(_order) + ")";
131}
132} // namespace lsst::gauss2d::fit
133
134#endif // #ifdef LSST_GAUSS2D_FIT_HAS_GSL
py::object result
Definition _schema.cc:429
const std::vector< SersicMixValues > & get_sersic_mix_knots(unsigned short order)
Definition sersicmix.cc:50
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)
Definition to_string.h:15
T push_back(T... args)
T reserve(T... args)
T resize(T... args)
T size(T... args)
T to_string(T... args)
table::Key< int > order