SourceXtractorPlusPlus  0.10
Please provide a description of the project.
KronRadiusTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * KronRadiusTask.cpp
19  *
20  * Created on: Sep 12, 2016
21  * Author: mkuemmel@usm.lmu.de
22  */
23 #include <math.h>
24 #include <iostream>
25 
29 
38 
39 namespace SourceXtractor {
40 
41 namespace {
42  // the typical radius for determining the Kron-radius
43  const SeFloat KRON_NRADIUS = 3*2.0;
44  const SeFloat CROWD_THRESHOLD_KRON = 0.1;
45  const SeFloat BADAREA_THRESHOLD_KRON = 0.1;
46 }
47 
49 
52 
53  // get the detection frame
54  const auto& detection_frame = source.getProperty<DetectionFrame>().getFrame();
55 
56  // get the images and image information from the frame
57  const auto& detection_image = detection_frame->getSubtractedImage();
58  const auto& detection_variance = detection_frame->getVarianceMap();
59  const auto& variance_threshold = detection_frame->getVarianceThreshold();
60  const auto& threshold_image = detection_frame->getThresholdedImage();
61 
62  // get the object center
63  const auto& centroid_x = source.getProperty<PixelCentroid>().getCentroidX();
64  const auto& centroid_y = source.getProperty<PixelCentroid>().getCentroidY();
65 
66  // get the shape parameters
67  const auto& cxx = source.getProperty<ShapeParameters>().getEllipseCxx();
68  const auto& cyy = source.getProperty<ShapeParameters>().getEllipseCyy();
69  const auto& cxy = source.getProperty<ShapeParameters>().getEllipseCxy();
70 
71  // create the elliptical aperture
72  auto ell_aper = std::make_shared<EllipticalAperture>(cxx, cyy, cxy, KRON_NRADIUS);
73 
74  // get the aperture borders on the image
75  const auto& min_pixel = ell_aper->getMinPixel(centroid_x, centroid_y);
76  const auto& max_pixel = ell_aper->getMaxPixel(centroid_x, centroid_y);
77 
78 // get the pixel list
79  const auto& pix_list = source.getProperty<PixelCoordinateList>().getCoordinateList();
80 
81  // get the neighbourhood information
82  NeighbourInfo neighbour_info(min_pixel, max_pixel, pix_list, threshold_image);
83 
84  SeFloat radius_flux_sum=0.;
85  SeFloat flux_sum=0.;
86  long int area_sum=0;
87  long int area_bad=0;
88  long int area_full=0;
89  long int flag=0;
90 
91  // iterate over the aperture pixels
92  for (int pixel_y = min_pixel.m_y; pixel_y <= max_pixel.m_y; pixel_y++) {
93  for (int pixel_x = min_pixel.m_x; pixel_x <= max_pixel.m_x; pixel_x++) {
94  SeFloat value = 0;
95  SeFloat pixel_variance = 0;
96 
97  // check whether the current pixel is inside
98  if (ell_aper->getArea(centroid_x, centroid_y, pixel_x, pixel_y) > 0){
99 
100  // make sure the pixel is inside the image
101  if (pixel_x >=0 && pixel_y >=0 && pixel_x < detection_image->getWidth() && pixel_y < detection_image->getHeight()) {
102 
103  // enhance the area
104  area_sum += 1;
105 
106  // get the variance value
107  pixel_variance = detection_variance ? detection_variance->getValue(pixel_x, pixel_y) : 1;
108 
109  // check whether the pixel is good
110  if (pixel_variance < variance_threshold) {
111  value = detection_image->getValue(pixel_x, pixel_y);
112  }
113  else {
114  // set bad pixel values to zero
115  value=0.0;
116  pixel_variance=0.0;
117  area_bad += 1;
118  }
119 
120  // check whether the pixel is part of another object
121  if (neighbour_info.isNeighbourObjectPixel(pixel_x, pixel_y)) {
122  area_full += 1;
123  }
124  else {
125  // add the pixel quantity
126  radius_flux_sum += value*sqrt(ell_aper->getRadiusSquared(centroid_x, centroid_y, pixel_x, pixel_y));
127  flux_sum += value;
128  }
129  }
130  else {
131  // set the border flag
132  flag |= 0x0008;
133  }
134  }
135  }
136  }
137 
138  if (area_sum>0) {
139  // check/set the bad area flag
140  if ((SeFloat)area_bad/(SeFloat)area_sum > BADAREA_THRESHOLD_KRON)
141  flag |= 0x0001;
142 
143  // check/set the crowded area flag
144  if ((SeFloat)area_full/(SeFloat)area_sum > CROWD_THRESHOLD_KRON)
145  flag |= 0x0002;
146  }
147 
148  // set the property
149  if (flux_sum>0){
150  source.setProperty<KronRadius>(radius_flux_sum/flux_sum, flag);
151  }
152  else {
153  // the default value
154  source.setProperty<KronRadius>(0.0, flag);
155  }
156 }
157 }
158 
PixelCoordinateList.h
SourceXtractor::PixelCoordinateList
Definition: PixelCoordinateList.h:30
std::lock
T lock(T... args)
SourceXtractor::KronRadiusTask::computeProperties
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition: KronRadiusTask.cpp:50
SourceXtractor::PixelCentroid
The centroid of all the pixels in the source, weighted by their DetectionImage pixel values.
Definition: PixelCentroid.h:37
SourceXtractor::SeFloat
SeFloat32 SeFloat
Definition: Types.h:32
AutoPhotometryTask.h
SourceXtractor::KronRadius
Kron radius.
Definition: KronRadius.h:36
DetectionFrame.h
std::lock_guard
STL class.
SourceXtractor::MultithreadedMeasurement::g_global_mutex
static std::recursive_mutex g_global_mutex
Definition: MultithreadedMeasurement.h:54
SourceXtractor::NeighbourInfo::isNeighbourObjectPixel
bool isNeighbourObjectPixel(int x, int y) const
Definition: NeighbourInfo.cpp:69
std::sqrt
T sqrt(T... args)
EllipticalAperture.h
NeighbourInfo.h
SourceXtractor
Definition: Aperture.h:30
AperturePhotometryTask.h
SourceXtractor::NeighbourInfo
Definition: NeighbourInfo.h:34
SourceXtractor::DetectionFrame
Definition: DetectionFrame.h:33
MultithreadedMeasurement.h
SourceXtractor::SourceInterface::getProperty
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
Definition: SourceInterface.h:57
ShapeParameters.h
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
SourceXtractor::SourceInterface::setProperty
void setProperty(Args... args)
Definition: SourceInterface.h:72
SourceXtractor::ShapeParameters
Definition: ShapeParameters.h:32
PixelCentroid.h
KronRadiusTask.h
KronRadius.h