SourceXtractorPlusPlus  0.13
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 
32 getMirrorPixel(SeFloat centroid_x, SeFloat centroid_y, int pixel_x, int pixel_y,
33  const std::shared_ptr<Image<SeFloat>>& img,
34  const std::shared_ptr<Image<SeFloat>>& variance_map,
35  SeFloat variance_threshold) {
36  // get the mirror pixel
37  auto mirror_x = 2 * centroid_x - pixel_x + 0.49999;
38  auto mirror_y = 2 * centroid_y - pixel_y + 0.49999;
39  if (img->isInside(mirror_x, mirror_y)) {
40  auto variance_tmp = variance_map->getValue(mirror_x, mirror_y);
41  if (variance_tmp < variance_threshold) {
42  // mirror pixel is OK: take the value
43  return std::make_pair(img->getValue(mirror_x, mirror_y), variance_tmp);
44  }
45  }
46  return std::make_pair(0., 0.);
47 }
48 
49 FluxMeasurement measureFlux(const std::shared_ptr<Aperture> &aperture, SeFloat centroid_x, SeFloat centroid_y,
50  const std::shared_ptr<Image<SeFloat>> &img,
51  const std::shared_ptr<Image<SeFloat>> &variance_map, SeFloat variance_threshold,
52  bool use_symmetry) {
53  auto min_pixel = aperture->getMinPixel(centroid_x, centroid_y);
54  auto max_pixel = aperture->getMaxPixel(centroid_x, centroid_y);
55 
56  FluxMeasurement measurement;
57 
58  // Skip if the full source is outside the frame
59  if (max_pixel.m_x < 0 || max_pixel.m_y < 0 || min_pixel.m_x >= img->getWidth() ||
60  min_pixel.m_y >= img->getHeight()) {
61  measurement.m_flags = Flags::OUTSIDE;
62  return measurement;
63  }
64 
65  // iterate over the aperture pixels
66  for (int pixel_y = min_pixel.m_y; pixel_y <= max_pixel.m_y; pixel_y++) {
67  for (int pixel_x = min_pixel.m_x; pixel_x <= max_pixel.m_x; pixel_x++) {
68  SeFloat pixel_value = 0;
69  SeFloat pixel_variance = 0;
70 
71  // get the area coverage and continue if there is overlap
72  auto area = aperture->getArea(centroid_x, centroid_y, pixel_x, pixel_y);
73  if (area == 0) {
74  continue;
75  }
76 
77  measurement.m_total_area += area;
78 
79  // make sure the pixel is inside the image
80  if (img->isInside(pixel_x, pixel_y)) {
81 
82  SeFloat variance_tmp = variance_map->getValue(pixel_x, pixel_y);
83  if (variance_tmp > variance_threshold) {
84  measurement.m_bad_area += 1;
85  if (use_symmetry) {
86  std::tie(pixel_value, pixel_variance) = getMirrorPixel(
87  centroid_x, centroid_y, pixel_x, pixel_y, img, variance_map, variance_threshold);
88  }
89  }
90  else {
91  pixel_value = img->getValue(pixel_x, pixel_y);
92  pixel_variance = variance_tmp;
93  }
94 
95  measurement.m_flux += pixel_value * area;
96  measurement.m_variance += pixel_variance * area;
97  } else {
98  measurement.m_flags |= Flags::BOUNDARY;
99  }
100  }
101  }
102 
103  // check/set the bad area flag
104  bool is_biased = measurement.m_total_area > 0 && measurement.m_bad_area / measurement.m_total_area > BADAREA_THRESHOLD_APER;
105  measurement.m_flags |= Flags::BIASED * is_biased;
106  return measurement;
107 }
108 
109 } // end SourceXtractor
static std::tuple< SeFloat, SeFloat > getMirrorPixel(SeFloat centroid_x, SeFloat centroid_y, int pixel_x, int pixel_y, const std::shared_ptr< Image< SeFloat >> &img, const std::shared_ptr< Image< SeFloat >> &variance_map, SeFloat variance_threshold)
T tie(T...args)
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)
T make_pair(T...args)
The object has bad pixels.
Interface representing an image.
Definition: Image.h:43
const SeFloat BADAREA_THRESHOLD_APER
Definition: Flagging.cpp:25
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)