SourceXtractorPlusPlus  0.13
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  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 
125  throw Elements::Exception() << "getDetectionImage() call on not initialized DetectionImageConfig";
126  }
127  return m_detection_image;
128 }
129 
132  throw Elements::Exception() << "getCoordinateSystem() call on not initialized DetectionImageConfig";
133  }
134  return m_coordinate_system;
135 }
136 
137 } // SourceXtractor namespace
138 
139 
140 
SourceXtractor::DetectionImageConfig::m_coordinate_system
std::shared_ptr< CoordinateSystem > m_coordinate_system
Definition: DetectionImageConfig.h:74
SourceXtractor::DETECTION_IMAGE
static const std::string DETECTION_IMAGE
Definition: DetectionImageConfig.cpp:37
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::DETECTION_IMAGE_INTERPOLATION
static const std::string DETECTION_IMAGE_INTERPOLATION
Definition: DetectionImageConfig.cpp:41
SourceXtractor::DetectionImageConfig::getDetectionImagePath
std::string getDetectionImagePath() const
Definition: DetectionImageConfig.cpp:119
Euclid::Configuration::Configuration::getCurrentState
State & getCurrentState()
std::map::find
T find(T... args)
SourceXtractor::DetectionImageConfig::getProgramOptions
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
Definition: DetectionImageConfig.cpp:48
SourceXtractor::DetectionImageConfig::getCoordinateSystem
std::shared_ptr< CoordinateSystem > getCoordinateSystem() const
Definition: DetectionImageConfig.cpp:130
SourceXtractor::DetectionImageConfig::m_flux_scale
double m_flux_scale
Definition: DetectionImageConfig.h:79
SourceXtractor::DetectionImageConfig::m_gain
double m_gain
Definition: DetectionImageConfig.h:76
SourceXtractor::DetectionImageConfig::getDetectionImage
std::shared_ptr< DetectionImage > getDetectionImage() const
Definition: DetectionImageConfig.cpp:123
SourceXtractor::BufferedImage::create
static std::shared_ptr< BufferedImage< T > > create(std::shared_ptr< const ImageSource > source, std::shared_ptr< TileManager > tile_manager=TileManager::getInstance())
Definition: BufferedImage.cpp:34
Euclid::Configuration
SourceXtractor::DetectionImageConfig::m_image_source
std::shared_ptr< ImageSource > m_image_source
Definition: DetectionImageConfig.h:75
SourceXtractor::DetectionImageConfig::m_saturation
double m_saturation
Definition: DetectionImageConfig.h:77
SourceXtractor::DetectionImageConfig::initialize
void initialize(const UserValues &args) override
Definition: DetectionImageConfig.cpp:65
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::DetectionImageConfig::m_detection_image
std::shared_ptr< DetectionImage > m_detection_image
Definition: DetectionImageConfig.h:73
WCS.h
BufferedImage.h
std::string::c_str
T c_str(T... args)
SourceXtractor::DETECTION_IMAGE_GAIN
static const std::string DETECTION_IMAGE_GAIN
Definition: DetectionImageConfig.cpp:38
Elements::Exception
ProcessedImage.h
std::map
STL class.
DetectionImageConfig.h
SourceXtractor::ProcessedImage::create
static std::shared_ptr< ProcessedImage< T, P > > create(std::shared_ptr< const Image< T >> image_a, std::shared_ptr< const Image< T >> image_b)
Definition: ProcessedImage.h:54
SourceXtractor::DETECTION_IMAGE_FLUX_SCALE
static const std::string DETECTION_IMAGE_FLUX_SCALE
Definition: DetectionImageConfig.cpp:39
SourceXtractor::DetectionImageConfig::m_detection_image_path
std::string m_detection_image_path
Definition: DetectionImageConfig.h:72
SourceXtractor::DETECTION_IMAGE_SATURATION
static const std::string DETECTION_IMAGE_SATURATION
Definition: DetectionImageConfig.cpp:40
SourceXtractor::DETECTION_IMAGE_INTERPOLATION_GAP
static const std::string DETECTION_IMAGE_INTERPOLATION_GAP
Definition: DetectionImageConfig.cpp:42
Euclid::Configuration::Configuration
std::map::end
T end(T... args)
std::max
T max(T... args)
SourceXtractor::DetectionImageConfig::m_interpolation_gap
int m_interpolation_gap
Definition: DetectionImageConfig.h:81
ConfigManager.h
FitsImageSource.h
Euclid::Configuration::Configuration::State::INITIALIZED
@ INITIALIZED
SourceXtractor::ImageTile::FloatImage
@ FloatImage
Definition: ImageTile.h:39