SourceXtractorPlusPlus 0.19.2
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
FluxRadiusTask.cpp
Go to the documentation of this file.
1
18#include <algorithm>
19#include <NdArray/NdArray.h>
24
25using namespace Euclid::NdArray;
26
27namespace SourceXtractor {
28
30 : m_instances{instances}, m_flux_fraction{flux_frac} {
31}
32
35
36 for (size_t i = 0; i < m_instances.size(); ++i) {
37 auto& growth_curve_prop = source.getProperty<GrowthCurve>(m_instances[i]);
38 auto& growth_curve = growth_curve_prop.getCurve();
39 auto step_size = growth_curve_prop.getStepSize();
40
41 std::vector<double> steps(growth_curve.size());
42 for (size_t s = 0; s < steps.size(); ++s) {
43 steps[s] = (s + 1) * step_size;
44 }
45
46 for (size_t j = 0; j < m_flux_fraction.size(); ++j) {
47 auto target_flux = std::max(0., growth_curve.back() * m_flux_fraction[j]);
48
49 // We can not use Alexandria's interpolation because the accumulated flux is not
50 // strictly increasing, so we search for the first bin where the accumulated flux is
51 // >= the target flux, and interpolate with the previous one
52 auto next = std::find_if(std::begin(growth_curve), std::end(growth_curve),
53 std::bind2nd(std::greater_equal<double>(), target_flux));
54 if (next == std::end(growth_curve)) {
55 --next;
56 }
57 size_t next_i = std::distance(std::begin(growth_curve), next);
58
59 SeFloat y0, y1;
61
62 x1 = *next;
63 y1 = steps[next_i];
64 if (next_i > 0) {
65 x0 = *(next - 1);
66 y0 = steps[next_i - 1];
67 }
68 else {
69 x0 = 0;
70 y0 = 0;
71 }
72
73 SeFloat slope = (y1 - y0) / (x1 - x0);
74 SeFloat target_radius = y0 + (target_flux - x0) * slope;
75 radii.at(i, j) = std::min(target_radius, static_cast<SeFloat>(steps.back()));
76 }
77 }
78 source.setProperty<FluxRadius>(std::move(radii));
79}
80
81} // end of namespace SourceXtractor
T at(T... args)
T back(T... args)
T begin(T... args)
std::vector< SeFloat > m_flux_fraction
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
FluxRadiusTask(const std::vector< unsigned > &instances, const std::vector< SeFloat > &flux_frac)
std::vector< unsigned > m_instances
const std::vector< double > & getCurve() const
Definition GrowthCurve.h:38
The SourceInterface is an abstract "source" that has properties attached to it.
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
T distance(T... args)
T end(T... args)
T find_if(T... args)
T max(T... args)
T min(T... args)
T move(T... args)
constexpr double s
SeFloat32 SeFloat
Definition Types.h:32
Euclid::NdArray::NdArray< T > NdArray
T next(T... args)
T size(T... args)