SourceXtractorPlusPlus  0.14
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PsfTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * PsfTask.cpp
19  *
20  * Created on: Jun 25, 2018
21  * Author: Alejandro Alvarez Ayllon
22  */
23 
24 #include <numeric>
30 
31 namespace SourceXtractor {
32 
33 static double getCoordX(SourceXtractor::SourceGroupInterface& group, unsigned instance) {
34  auto& measurement_frame_group = group.getProperty<MeasurementFrameGroupRectangle>(instance);
35  double top_x = measurement_frame_group.getTopLeft().m_x;
36  return top_x + measurement_frame_group.getWidth() / 2.;
37 }
38 
39 static double getCoordY(SourceXtractor::SourceGroupInterface& group, unsigned instance) {
40  auto& measurement_frame_group = group.getProperty<MeasurementFrameGroupRectangle>(instance);
41  double top_y = measurement_frame_group.getTopLeft().m_y;
42  return top_y + measurement_frame_group.getHeight() / 2.;
43 }
44 
46  {"X_IMAGE", getCoordX},
47  {"Y_IMAGE", getCoordY},
48  {"XWIN_IMAGE", getCoordX},
49  {"YWIN_IMAGE", getCoordY},
50  {"XPEAK_IMAGE", getCoordX},
51  {"YPEAK_IMAGE", getCoordY},
52  {"XMODEL_IMAGE", getCoordX},
53  {"YMODEL_IMAGE", getCoordY}
54 };
55 
56 PsfTask::PsfTask(unsigned instance, const std::shared_ptr<VariablePsf> &vpsf)
57  : m_instance(instance), m_vpsf(vpsf) {
58 }
59 
61  std::vector<double> component_values;
62 
63  for (auto c : m_vpsf->getComponents()) {
64  component_values.push_back(component_value_getters[c.name](group, m_instance));
65  }
66 
67  auto psf = m_vpsf->getPsf(component_values);
68  // The result may not be normalized!
69  auto psf_sum = std::accumulate(psf->getData().begin(), psf->getData().end(), 0.);
70  auto psf_normalized = VectorImage<SeFloat>::create(*MultiplyImage<SeFloat>::create(psf, 1. / psf_sum));
71  group.setIndexedProperty<PsfProperty>(m_instance, m_vpsf->getPixelSampling(), psf_normalized);
72 
73  // Check image
74  if (group.size()) {
75  auto check_image = CheckImages::getInstance().getPsfImage(m_instance);
76  if (check_image) {
77  auto x = component_value_getters["X_IMAGE"](group, m_instance);
78  auto y = component_value_getters["Y_IMAGE"](group, m_instance);
79 
81  check_image, psf_normalized, m_vpsf->getPixelSampling(), x, y);
82  }
83  }
84 }
85 
86 }
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
static void addImageToImage(ImageType &image1, const ImageType &image2, double scale, double x, double y)
void setIndexedProperty(std::size_t index, Args...args)
Convenience template method to call setProperty() with a more user-friendly syntax.
static std::shared_ptr< VectorImage< T > > create(Args &&...args)
Definition: VectorImage.h:89
STL class.
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T push_back(T...args)
static double getCoordY(SourceXtractor::SourceGroupInterface &group, unsigned instance)
Definition: PsfTask.cpp:39
std::shared_ptr< VariablePsf > m_vpsf
Definition: PsfTask.h:45
static CheckImages & getInstance()
Definition: CheckImages.h:136
std::map< std::string, ValueGetter > component_value_getters
Definition: PsfTask.cpp:45
PsfTask(unsigned instance, const std::shared_ptr< VariablePsf > &vpsf)
Definition: PsfTask.cpp:56
std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > getPsfImage(unsigned int frame_number)
Defines the interface used to group sources.
static double getCoordX(SourceXtractor::SourceGroupInterface &group, unsigned instance)
Definition: PsfTask.cpp:33
virtual void computeProperties(SourceGroupInterface &source) const override
Computes one or more properties for the SourceGroup and/or the Sources it contains.
Definition: PsfTask.cpp:60
T accumulate(T...args)
virtual unsigned int size() const =0
Processes two images to create a third combining them by using any function.