SourceXtractorPlusPlus  0.12
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 
35  {"X_IMAGE", [](SourceXtractor::SourceGroupInterface &group, unsigned instance){
36  auto& measurement_frame_group = group.getProperty<MeasurementFrameGroupRectangle>(instance);
37  double top_x = measurement_frame_group.getTopLeft().m_x;
38  return top_x + measurement_frame_group.getWidth() / 2.;
39  }},
40  {"Y_IMAGE", [](SourceXtractor::SourceGroupInterface &group, unsigned instance){
41  auto& measurement_frame_group = group.getProperty<MeasurementFrameGroupRectangle>(instance);
42  double top_y = measurement_frame_group.getTopLeft().m_y;
43  return top_y + measurement_frame_group.getHeight() / 2.;
44  }}
45 };
46 
47 PsfTask::PsfTask(unsigned instance, const std::shared_ptr<VariablePsf> &vpsf)
48  : m_instance(instance), m_vpsf(vpsf) {
49 }
50 
52  std::vector<double> component_values;
53 
54  for (auto c : m_vpsf->getComponents()) {
55  component_values.push_back(component_value_getters[c.name](group, m_instance));
56  }
57 
58  auto psf = m_vpsf->getPsf(component_values);
59  // The result may not be normalized!
60  auto psf_sum = std::accumulate(psf->getData().begin(), psf->getData().end(), 0.);
61  auto psf_normalized = VectorImage<SeFloat>::create(*MultiplyImage<SeFloat>::create(psf, 1. / psf_sum));
62  group.setIndexedProperty<PsfProperty>(m_instance, m_vpsf->getPixelSampling(), psf_normalized);
63 
64  // Check image
65  if (group.size()) {
66  auto check_image = CheckImages::getInstance().getPsfImage(m_instance);
67  if (check_image) {
68  auto x = component_value_getters["X_IMAGE"](group, m_instance);
69  auto y = component_value_getters["Y_IMAGE"](group, m_instance);
70 
72  check_image, psf_normalized, m_vpsf->getPixelSampling(), x, y);
73  }
74  }
75 }
76 
77 }
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)
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:34
PsfTask(unsigned instance, const std::shared_ptr< VariablePsf > &vpsf)
Definition: PsfTask.cpp:47
std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > getPsfImage(unsigned int frame_number)
Defines the interface used to group sources.
virtual void computeProperties(SourceGroupInterface &source) const override
Computes one or more properties for the SourceGroup and/or the Sources it contains.
Definition: PsfTask.cpp:51
T accumulate(T...args)
virtual unsigned int size() const =0
Processes two images to create a third combining them by using any function.