SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
FluxRadiusTask.cpp
Go to the documentation of this file.
1
17
18#include <algorithm>
19#include <functional>
20
21#include <NdArray/NdArray.h>
26
27using namespace Euclid::NdArray;
28
29namespace SourceXtractor {
30
32 : m_instances{instances}, m_flux_fraction{flux_frac} {
33}
34
36 NdArray<SeFloat> radii{m_instances.size(), m_flux_fraction.size()};
37
38 for (size_t i = 0; i < m_instances.size(); ++i) {
39 auto& growth_curve_prop = source.getProperty<GrowthCurve>(m_instances[i]);
40 auto& growth_curve = growth_curve_prop.getCurve();
41 auto step_size = growth_curve_prop.getStepSize();
42
43 std::vector<double> steps(growth_curve.size());
44 for (size_t s = 0; s < steps.size(); ++s) {
45 steps[s] = (s + 1) * step_size;
46 }
47
48 for (size_t j = 0; j < m_flux_fraction.size(); ++j) {
49 auto target_flux = std::max(0., growth_curve.back() * m_flux_fraction[j]);
50
51 // We can not use Alexandria's interpolation because the accumulated flux is not
52 // strictly increasing, so we search for the first bin where the accumulated flux is
53 // >= the target flux, and interpolate with the previous one
54 auto next = std::find_if(std::begin(growth_curve), std::end(growth_curve),
55 std::bind(std::greater_equal<double>(), std::placeholders::_1, target_flux));
56 if (next == std::end(growth_curve)) {
57 --next;
58 }
59 size_t next_i = std::distance(std::begin(growth_curve), next);
60
61 SeFloat y0, y1;
63
64 x1 = *next;
65 y1 = steps[next_i];
66 if (next_i > 0) {
67 x0 = *(next - 1);
68 y0 = steps[next_i - 1];
69 }
70 else {
71 x0 = 0;
72 y0 = 0;
73 }
74
75 SeFloat slope = (y1 - y0) / (x1 - x0);
76 SeFloat target_radius = y0 + (target_flux - x0) * slope;
77 radii.at(i, j) = std::min(target_radius, static_cast<SeFloat>(steps.back()));
78 }
79 }
80 source.setProperty<FluxRadius>(std::move(radii));
81}
82
83} // end of namespace SourceXtractor
T back(T... args)
T begin(T... args)
T bind(T... args)
T & at(const std::vector< size_t > &coords)
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)
SeFloat32 SeFloat
Definition Types.h:32
T next(T... args)
T size(T... args)