SourceXtractorPlusPlus  0.16
Please provide a description of the project.
SourcePsfTask.cpp
Go to the documentation of this file.
1 
18 #include <numeric>
24 
25 namespace SourceXtractor {
26 
27 static double getCoordX(SourceXtractor::SourceInterface& source, unsigned instance) {
28  auto& pixel_centroid = source.getProperty<MeasurementFramePixelCentroid>(instance);
29  return pixel_centroid.getCentroidX();
30 }
31 
32 static double getCoordY(SourceXtractor::SourceInterface& source, unsigned instance) {
33  auto& pixel_centroid = source.getProperty<MeasurementFramePixelCentroid>(instance);
34  return pixel_centroid.getCentroidY();
35 }
36 
38  {"X_IMAGE", getCoordX},
39  {"Y_IMAGE", getCoordY},
40  {"XWIN_IMAGE", getCoordX},
41  {"YWIN_IMAGE", getCoordY},
42  {"XPEAK_IMAGE", getCoordX},
43  {"YPEAK_IMAGE", getCoordY},
44  {"XMODEL_IMAGE", getCoordX},
45  {"YMODEL_IMAGE", getCoordY}
46 };
47 
48 SourcePsfTask::SourcePsfTask(unsigned instance, const std::shared_ptr<Psf> &vpsf)
49  : m_instance(instance), m_vpsf(vpsf) {
50 }
51 
53  std::vector<double> component_values;
54 
55  for (auto component : m_vpsf->getComponents()) {
56  component_values.push_back(component_value_getters[component](source, m_instance));
57  }
58 
59  auto psf = m_vpsf->getPsf(component_values);
60  // The result may not be normalized!
61  auto psf_sum = std::accumulate(psf->getData().begin(), psf->getData().end(), 0.);
62  auto psf_normalized = VectorImage<SeFloat>::create(*MultiplyImage<SeFloat>::create(psf, 1. / psf_sum));
63  source.setIndexedProperty<SourcePsfProperty>(m_instance, m_vpsf->getPixelSampling(), psf_normalized);
64 
65  // Check image
66  auto check_image = CheckImages::getInstance().getPsfImage(m_instance);
67  if (check_image) {
68  auto x = component_value_getters["X_IMAGE"](source, m_instance);
69  auto y = component_value_getters["Y_IMAGE"](source, m_instance);
70 
72  check_image, psf_normalized, m_vpsf->getPixelSampling(), x, y);
73  }
74 }
75 
76 }
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T accumulate(T... args)
std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > getPsfImage(unsigned int frame_number)
static CheckImages & getInstance()
Definition: CheckImages.h:138
SeFloat getCentroidY() const
Y coordinate of centroid.
SeFloat getCentroidX() const
X coordinate of centroid.
Processes two images to create a third combining them by using any function.
The SourceInterface is an abstract "source" that has properties attached to it.
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
static std::map< std::string, ValueGetter > component_value_getters
Definition: SourcePsfTask.h:35
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
std::shared_ptr< Psf > m_vpsf
Definition: SourcePsfTask.h:39
SourcePsfTask(unsigned instance, const std::shared_ptr< Psf > &vpsf)
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:100
static double getCoordX(SourceXtractor::SourceGroupInterface &group, unsigned instance)
Definition: PsfTask.cpp:33
static double getCoordY(SourceXtractor::SourceGroupInterface &group, unsigned instance)
Definition: PsfTask.cpp:39
T push_back(T... args)
static void addImageToImage(ImageType &image1, const ImageType &image2, double scale, double x, double y)