SourceXtractorPlusPlus  0.16
Please provide a description of the project.
DetectionImageConfig.cpp
Go to the documentation of this file.
1 
23 
27 
29 
31 
32 using namespace Euclid::Configuration;
33 namespace po = boost::program_options;
34 
35 namespace SourceXtractor {
36 
37 static const std::string DETECTION_IMAGE { "detection-image" };
38 static const std::string DETECTION_IMAGE_GAIN { "detection-image-gain" };
39 static const std::string DETECTION_IMAGE_FLUX_SCALE {"detection-image-flux-scale"};
40 static const std::string DETECTION_IMAGE_SATURATION { "detection-image-saturation" };
41 static const std::string DETECTION_IMAGE_INTERPOLATION { "detection-image-interpolation" };
42 static const std::string DETECTION_IMAGE_INTERPOLATION_GAP { "detection-image-interpolation-gap" };
43 
44 DetectionImageConfig::DetectionImageConfig(long manager_id) : Configuration(manager_id),
45  m_gain(0), m_saturation(0), m_flux_scale(1.0), m_interpolation_gap(0) {
46 }
47 
49  return { {"Detection image", {
50  {DETECTION_IMAGE.c_str(), po::value<std::string>(),
51  "Path to a fits format image to be used as detection image."},
52  {DETECTION_IMAGE_GAIN.c_str(), po::value<double>(),
53  "Detection image gain in e-/ADU (0 = infinite gain)"},
54  {DETECTION_IMAGE_FLUX_SCALE.c_str(), po::value<double>(),
55  "Detection image flux scale"},
56  {DETECTION_IMAGE_SATURATION.c_str(), po::value<double>(),
57  "Detection image saturation level (0 = no saturation)"},
58  {DETECTION_IMAGE_INTERPOLATION.c_str(), po::value<bool>()->default_value(true),
59  "Interpolate bad pixels in detection image"},
60  {DETECTION_IMAGE_INTERPOLATION_GAP.c_str(), po::value<int>()->default_value(5),
61  "Maximum number if pixels to interpolate over"}
62  }}};
63 }
64 
66  // Normally we would define this one as required, but then --list-output-properties would be
67  // unusable unless we also specify --detection-image, which is not very intuitive.
68  // For this reason, we check for its existence here
69  if (args.find(DETECTION_IMAGE) == args.end()) {
70  throw Elements::Exception() << "'--" << DETECTION_IMAGE << "' is required but missing";
71  }
72 
74  auto fits_image_source = std::make_shared<FitsImageSource>(m_detection_image_path, 0, ImageTile::FloatImage);
75  m_image_source = fits_image_source;
77  m_coordinate_system = std::make_shared<WCS>(*fits_image_source);
78 
79  double detection_image_gain = 0, detection_image_saturate = 0;
80  auto img_metadata = m_image_source->getMetadata();
81 
82  if (img_metadata.count("GAIN")){
83  // read the keyword GAIN from the metadata
84  if (double* double_gain = boost::get<double>(&img_metadata.at("GAIN").m_value)){
85  detection_image_gain = *double_gain;
86  } else if (int64_t *int64_gain = boost::get<int64_t>(&img_metadata.at("GAIN").m_value)){
87  detection_image_gain = (double) *int64_gain;
88  }
89  else {
90  throw Elements::Exception() << "Keyword GAIN must be either float or int!";
91  }
92  }
93 
94  if (img_metadata.count("SATURATE")){
95  // read the keyword SATURATE from the metadata
96  if (double* double_saturate = boost::get<double>(&img_metadata.at("SATURATE").m_value)){
97  detection_image_saturate = *double_saturate;
98  } else if (int64_t *int64_saturate = boost::get<int64_t>(&img_metadata.at("SATURATE").m_value)){
99  detection_image_saturate = (double) *int64_saturate;
100  }
101  else {
102  throw Elements::Exception() << "Keyword SATURATE must be either float or int!";
103  }
104  }
105 
106  if (args.find(DETECTION_IMAGE_FLUX_SCALE) != args.end()) {
107  m_flux_scale = args.find(DETECTION_IMAGE_FLUX_SCALE)->second.as<double>();
108  }
109  else if (img_metadata.count("FLXSCALE")) {
110  // read the keyword FLXSCALE from the metadata
111  if (double* f_scale = boost::get<double>(&img_metadata.at("FLXSCALE").m_value)){
112  m_flux_scale = *f_scale;
113  } else if (int64_t *int64_f_scale = boost::get<int64_t>(&img_metadata.at("FLXSCALE").m_value)){
114  m_flux_scale = (double) *int64_f_scale;
115  }
116  else {
117  throw Elements::Exception() << "Keyword FLXSCALE must be either float or int!";
118  }
119  }
120 
121  if (args.find(DETECTION_IMAGE_GAIN) != args.end()) {
122  m_gain = args.find(DETECTION_IMAGE_GAIN)->second.as<double>();
123  }
124  else {
125  m_gain = detection_image_gain;
126  }
127 
128  if (args.find(DETECTION_IMAGE_SATURATION) != args.end()) {
129  m_saturation = args.find(DETECTION_IMAGE_SATURATION)->second.as<double>();
130  }
131  else {
132  m_saturation = detection_image_saturate;
133  }
134 
135  m_interpolation_gap = args.find(DETECTION_IMAGE_INTERPOLATION)->second.as<bool>() ?
136  std::max(0, args.find(DETECTION_IMAGE_INTERPOLATION_GAP)->second.as<int>()) : 0;
137 
138  // Adapt image and parameters to take flux_scale into consideration
139  if (m_flux_scale != 1.0) {
141  m_gain /= m_flux_scale;
143  }
144 }
145 
147  return m_detection_image_path;
148 }
149 
152  throw Elements::Exception() << "getDetectionImage() call on not initialized DetectionImageConfig";
153  }
154  return m_detection_image;
155 }
156 
159  throw Elements::Exception() << "getCoordinateSystem() call on not initialized DetectionImageConfig";
160  }
161  return m_coordinate_system;
162 }
163 
164 } // SourceXtractor namespace
165 
166 
167 
T c_str(T... args)
static std::shared_ptr< BufferedImage< T > > create(std::shared_ptr< const ImageSource > source, std::shared_ptr< TileManager > tile_manager=TileManager::getInstance())
std::shared_ptr< DetectionImage > m_detection_image
std::shared_ptr< CoordinateSystem > getCoordinateSystem() const
std::shared_ptr< CoordinateSystem > m_coordinate_system
void initialize(const UserValues &args) override
std::shared_ptr< DetectionImage > getDetectionImage() const
std::shared_ptr< ImageSource > m_image_source
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)
T end(T... args)
T find(T... args)
T max(T... args)
static const std::string DETECTION_IMAGE_GAIN
static const std::string DETECTION_IMAGE_INTERPOLATION_GAP
static const std::string DETECTION_IMAGE_INTERPOLATION
static const std::string DETECTION_IMAGE_FLUX_SCALE
static const std::string DETECTION_IMAGE
static const std::string DETECTION_IMAGE_SATURATION