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
FluxRadius.h
Euclid::NdArray
std::move
T move(T... args)
SourceXtractor::Image< SeFloat >::PixelType
SeFloat PixelType
Definition: Image.h:47
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition: Types.h:32
std::vector< unsigned >
std::find_if
T find_if(T... args)
std::vector::size
T size(T... args)
SourceXtractor::FluxRadiusTask::m_flux_fraction
std::vector< SeFloat > m_flux_fraction
Definition: FluxRadiusTask.h:36
std::distance
T distance(T... args)
Euclid::NdArray::NdArray< SeFloat >
std::vector::back
T back(T... args)
SourceXtractor
Definition: Aperture.h:30
std::vector::at
T at(T... args)
std::greater_equal
Image.h
std::min
T min(T... args)
NdArray.h
SourceXtractor::FluxRadiusTask::computeProperties
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition: FluxRadiusTask.cpp:33
SourceXtractor::GrowthCurve::getCurve
const std::vector< double > & getCurve() const
Definition: GrowthCurve.h:38
GrowthCurve.h
SourceXtractor::GrowthCurve
Definition: GrowthCurve.h:30
std::begin
T begin(T... args)
s
constexpr double s
SourceXtractor::FluxRadius
Definition: FluxRadius.h:27
FluxRadiusTask.h
SourceXtractor::SourceInterface::getProperty
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
Definition: SourceInterface.h:57
SourceXtractor::FluxRadiusTask::m_instances
std::vector< unsigned > m_instances
Definition: FluxRadiusTask.h:35
std::end
T end(T... args)
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
std::max
T max(T... args)
SourceXtractor::SourceInterface::setProperty
void setProperty(Args... args)
Definition: SourceInterface.h:72
std::next
T next(T... args)