SourceXtractorPlusPlus  0.13
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
65 void DetectionImageConfig::initialize(const UserValues& args) {
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  detection_image_gain = boost::get<double>(img_metadata.at("GAIN").m_value);
84  if (img_metadata.count("SATURATE"))
85  detection_image_saturate = boost::get<double>(img_metadata.at("SATURATE").m_value);
86 
87  if (args.find(DETECTION_IMAGE_FLUX_SCALE) != args.end()) {
88  m_flux_scale = args.find(DETECTION_IMAGE_FLUX_SCALE)->second.as<double>();
89  }
90  else if (img_metadata.count("FLXSCALE")) {
91  m_flux_scale = boost::get<double>(img_metadata.at("FLXSCALE").m_value);
92  }
93 
94  if (args.find(DETECTION_IMAGE_GAIN) != args.end()) {
95  m_gain = args.find(DETECTION_IMAGE_GAIN)->second.as<double>();
96  }
97  else {
98  m_gain = detection_image_gain;
99  }
100 
101  if (args.find(DETECTION_IMAGE_SATURATION) != args.end()) {
102  m_saturation = args.find(DETECTION_IMAGE_SATURATION)->second.as<double>();
103  }
104  else {
105  m_saturation = detection_image_saturate;
106  }
107 
108  m_interpolation_gap = args.find(DETECTION_IMAGE_INTERPOLATION)->second.as<bool>() ?
109  std::max(0, args.find(DETECTION_IMAGE_INTERPOLATION_GAP)->second.as<int>()) : 0;
110 
111  // Adapt image and parameters to take flux_scale into consideration
112  if (m_flux_scale != 1.0) {
114  m_gain /= m_flux_scale;
116  }
117 }
118 
120  return m_detection_image_path;
121 }
122 
124  if (getCurrentState() < State::INITIALIZED) {
125  throw Elements::Exception() << "getDetectionImage() call on not initialized DetectionImageConfig";
126  }
127  return m_detection_image;
128 }
129 
131  if (getCurrentState() < State::INITIALIZED) {
132  throw Elements::Exception() << "getCoordinateSystem() call on not initialized DetectionImageConfig";
133  }
134  return m_coordinate_system;
135 }
136 
137 } // SourceXtractor namespace
138 
139 
140 
static const std::string DETECTION_IMAGE_INTERPOLATION
static const std::string DETECTION_IMAGE_FLUX_SCALE
std::shared_ptr< CoordinateSystem > m_coordinate_system
static const std::string DETECTION_IMAGE_GAIN
std::shared_ptr< DetectionImage > getDetectionImage() const
std::shared_ptr< CoordinateSystem > getCoordinateSystem() const
static const std::string DETECTION_IMAGE_SATURATION
STL class.
static const std::string DETECTION_IMAGE_INTERPOLATION_GAP
STL class.
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
void initialize(const UserValues &args) override
T max(T...args)
std::shared_ptr< ImageSource > m_image_source
T find(T...args)
T c_str(T...args)
static const std::string DETECTION_IMAGE
std::shared_ptr< DetectionImage > m_detection_image
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)
static std::shared_ptr< BufferedImage< T > > create(std::shared_ptr< const ImageSource > source, std::shared_ptr< TileManager > tile_manager=TileManager::getInstance())