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