LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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