SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FluxMeasurement.cpp
Go to the documentation of this file.
1 
17 /*
18  * FluxMeasurement.cpp
19  *
20  * Created on: Oct 19, 2018
21  * Author: Alejandro Alvarez
22  */
23 
25 
26 
27 namespace SourceXtractor {
28 
30 
31 
32 FluxMeasurement measureFlux(const std::shared_ptr<Aperture> &aperture, SeFloat centroid_x, SeFloat centroid_y,
33  const std::shared_ptr<Image<SeFloat>> &img,
34  const std::shared_ptr<Image<SeFloat>> &variance_map, SeFloat variance_threshold,
35  bool use_symmetry) {
36  auto min_pixel = aperture->getMinPixel(centroid_x, centroid_y);
37  auto max_pixel = aperture->getMaxPixel(centroid_x, centroid_y);
38 
39  FluxMeasurement measurement;
40 
41  // Skip if the full source is outside the frame
42  if (max_pixel.m_x < 0 || max_pixel.m_y < 0 || min_pixel.m_x >= img->getWidth() ||
43  min_pixel.m_y >= img->getHeight()) {
44  measurement.m_flags = Flags::OUTSIDE;
45  return measurement;
46  }
47 
48  // iterate over the aperture pixels
49  for (int pixel_y = min_pixel.m_y; pixel_y <= max_pixel.m_y; pixel_y++) {
50  for (int pixel_x = min_pixel.m_x; pixel_x <= max_pixel.m_x; pixel_x++) {
51  SeFloat pixel_value = 0;
52  SeFloat pixel_variance = 0;
53  SeFloat variance_tmp = 0;
54 
55  // get the area coverage and continue if there is overlap
56  auto area = aperture->getArea(centroid_x, centroid_y, pixel_x, pixel_y);
57  if (area > 0) {
58 
59  measurement.m_total_area += area;
60 
61  // make sure the pixel is inside the image
62  if (pixel_x >= 0 && pixel_y >= 0 && pixel_x < img->getWidth() && pixel_y < img->getHeight()) {
63 
64  variance_tmp = variance_map ? variance_map->getValue(pixel_x, pixel_y) : 1;
65  if (variance_tmp > variance_threshold) {
66 
67  measurement.m_bad_area += 1;
68 
69  // try using the mirror pixel
70  if (use_symmetry) {
71  // get the mirror pixel
72  auto mirror_x = 2 * centroid_x - pixel_x + 0.49999;
73  auto mirror_y = 2 * centroid_y - pixel_y + 0.49999;
74  if (mirror_x >= 0 && mirror_y >= 0 && mirror_x < img->getWidth() && mirror_y < img->getHeight()) {
75  variance_tmp = variance_map ? variance_map->getValue(mirror_x, mirror_y) : 1;
76  if (variance_tmp < variance_threshold) {
77  // mirror pixel is OK: take the value
78  pixel_value = img->getValue(mirror_x, mirror_y);
79  pixel_variance = variance_tmp;
80  }
81  }
82  }
83  } else {
84  pixel_value = img->getValue(pixel_x, pixel_y);
85  pixel_variance = variance_tmp;
86  }
87 
88  measurement.m_flux += pixel_value * area;
89  measurement.m_variance += pixel_variance * area;
90  } else {
91  measurement.m_flags |= Flags::BOUNDARY;
92  }
93  }
94  }
95  }
96 
97  // check/set the bad area flag
98  if (measurement.m_total_area > 0) {
99  if (measurement.m_bad_area / measurement.m_total_area > BADAREA_THRESHOLD_APER) {
100  measurement.m_flags |= Flags::BIASED;
101  }
102  }
103 
104  return measurement;
105 }
106 
107 } // end SourceXtractor
The object is completely outside of the measurement frame.
SeFloat32 SeFloat
Definition: Types.h:32
The object is truncated (too close to an image boundary)
The object has bad pixels.
Interface representing an image.
Definition: Image.h:43
const SeFloat BADAREA_THRESHOLD_APER
FluxMeasurement measureFlux(const std::shared_ptr< Aperture > &aperture, SeFloat centroid_x, SeFloat centroid_y, const std::shared_ptr< Image< SeFloat >> &img, const std::shared_ptr< Image< SeFloat >> &variance_map, SeFloat variance_threshold, bool use_symmetry)