SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
VariablePsf.cpp
Go to the documentation of this file.
1
17/*
18 * VariablePsf.cpp
19 *
20 * Created on: Jun 25, 2018
21 * Author: Alejandro Álvarez Ayllón
22 */
23
24#include <ElementsKernel/Exception.h>
25#include <algorithm>
27
28
29namespace SourceXtractor {
30
41
48
50 return m_coefficients[0]->getWidth();
51}
52
54 return m_coefficients[0]->getHeight();
55}
56
58 return m_pixel_sampling;
59}
60
64
66{
68
69 // Initialize with the constant component
71
72 // Add the rest of the components
73 for (auto i = 1u; i < m_coefficients.size(); ++i) {
74 const auto& exp = m_exponents[i];
75 const auto& coef = m_coefficients[i];
76
77 double acc = 1.;
78 for (auto j = 0u; j < scaled_props.size(); ++j) {
80 }
81
82 for (auto x = 0; x < getWidth(); ++x) {
83 for (auto y = 0; y < getHeight(); ++y) {
84 result->at(x, y) += acc * coef->at(x, y);
85 }
86 }
87 }
88
89 return result;
90}
91
93 // Pre-condition: There is at least a constant component
94 if (m_coefficients.size() == 0) {
95 throw Elements::Exception() << "A variable PSF needs at least one set of coefficients";
96 }
97
98 // Pre-condition: There is a degree value per unique group
100 for (auto& component : m_components) {
101 if (component.group_id >= (int) m_group_degrees.size()) {
102 throw Elements::Exception() << "Component group out of range for " << component.name;
103 }
105 }
106
107 // Pre-condition: There are enough coefficients - (n+d)!/(n!d!) per group
108 unsigned int n_coefficients = 1;
109 for (unsigned int g = 0; g < n_component_per_group.size(); ++g) {
110 int dmax = m_group_degrees[g];
111 int n = n_component_per_group[g];
112 int d = std::min<int>(dmax, n);
113 int num, den;
114
115 for (num = 1, den = 1; d > 0; num *= (n+dmax--), den*= d--);
116
118 }
119
120 if (n_coefficients != m_coefficients.size()) {
121 throw Elements::Exception() << "Invalid number of coefficients. Got " << m_coefficients.size()
122 << " expected " << n_coefficients;
123 }
124
125 // Pre-condition: All components have the same size
126 auto psf_width = m_coefficients[0]->getWidth();
127 auto psf_height = m_coefficients[0]->getHeight();
128
129 for (auto coeff : m_coefficients) {
130 if (coeff->getWidth() != psf_width || coeff->getHeight() != psf_height) {
131 throw Elements::Exception() << "Malformed variable PSF, coefficient matrices do not have the same dimensions";
132 }
133 }
134}
135
137{
138 if (values.size() != m_components.size()) {
139 throw Elements::Exception()
140 << "Expecting " << m_components.size() << " values, got " << values.size();
141 }
143 for (auto i = 0u; i < values.size(); ++i) {
144 scaled[i] = (values[i] - m_components[i].offset) / m_components[i].scale;
145 }
146 return scaled;
147}
148
152
154 if (m_components.empty()) {
155 return;
156 }
157
158 // Constant
160 --group_exponents[m_components[0].group_id];
161
162 // Polynomial
163 exp[0] = 1;
164 for (auto e = m_exponents.begin() + 1; e != m_exponents.end(); ++e) {
165 *e = exp;
166
167 size_t ei = 0;
168 for (auto component : m_components) {
169 if (group_exponents[component.group_id] > 0) {
170 --group_exponents[component.group_id];
171 ++exp[ei];
172 break;
173 }
174 else {
175 group_exponents[component.group_id] = exp[ei];
176 exp[ei++] = 0;
177 }
178 }
179 }
180}
181
182} // end SourceXtractor
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T back_inserter(T... args)
T begin(T... args)
std::shared_ptr< VectorImage< SeFloat > > getPsf(const std::vector< double > &values) const override
int getHeight() const override
std::vector< std::string > m_component_names
double getPixelSampling() const override
std::vector< double > scaleProperties(const std::vector< double > &values) const
Normalizes the values.
std::vector< std::vector< int > > m_exponents
std::vector< std::shared_ptr< VectorImage< SeFloat > > > m_coefficients
int getWidth() const override
std::vector< Component > m_components
const std::vector< std::string > & getComponents() const override
std::vector< int > m_group_degrees
VariablePsf(double pixel_sampling, const std::vector< Component > &components, const std::vector< int > &group_degrees, const std::vector< std::shared_ptr< VectorImage< SeFloat > > > &coefficients)
void selfTest()
Verify that the preconditions of getPsf are met at construction time.
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
T end(T... args)
T exp(T... args)
T pow(T... args)
T resize(T... args)
T size(T... args)
T transform(T... args)