SourceXtractorPlusPlus  0.11
Please provide a description of the project.
FluxRadiusTask.cpp
Go to the documentation of this file.
1 
18 #include <algorithm>
19 #include <NdArray/NdArray.h>
24 
25 using namespace Euclid::NdArray;
26 
27 namespace SourceXtractor {
28 
29 FluxRadiusTask::FluxRadiusTask(const std::vector<unsigned>& instances, const std::vector<SeFloat>& flux_frac)
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 distance(T... args)
constexpr double s
SeFloat32 SeFloat
Definition: Types.h:32
T end(T... args)
T min(T... args)
std::vector< unsigned > m_instances
T next(T... args)
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
T max(T... args)
T move(T... args)
const std::vector< double > & getCurve() const
Definition: GrowthCurve.h:38
std::vector< SeFloat > m_flux_fraction
T find_if(T... args)
T size(T... args)
T begin(T... args)
The SourceInterface is an abstract "source" that has properties attached to it.
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.