25 #include <boost/algorithm/string.hpp> 26 #include <boost/python/extract.hpp> 27 #include <boost/tokenizer.hpp> 45 using namespace Euclid::Configuration;
46 namespace fs = boost::filesystem;
47 namespace py = boost::python;
51 MeasurementImageConfig::MeasurementImageConfig(
long manager_id) :
Configuration(manager_id) {
52 declareDependency<PythonConfig>();
53 declareDependency<WeightImageConfig>();
54 declareDependency<DetectionImageConfig>();
70 void validateImagePaths(
const PyMeasurementImage& image) {
71 if (!fs::exists(image.file)) {
74 if (image.weight_file !=
"" && !fs::exists(image.weight_file)) {
77 if (image.psf_file !=
"" && !fs::exists(image.psf_file)) {
83 auto fits_image_source = std::make_shared<FitsImageSource<DetectionImage::PixelType>>(py_image.file, py_image.image_hdu);
85 if (py_image.flux_scale != 1.) {
93 auto weight_type_name = boost::to_upper_copy(type_string);
94 if (weight_type_map.find(weight_type_name) == weight_type_map.end()) {
95 throw Elements::Exception() <<
"Unknown weight map type for measurement weight image " << file_name <<
": "<< type_string;
98 return weight_type_map[weight_type_name];
102 auto weight_type = getWeightType(py_image.weight_type, py_image.weight_file);
105 if (py_image.weight_file ==
"") {
108 throw Elements::Exception() <<
"Weight type '" << py_image.weight_type <<
"' is meaningless without a weight image";
116 throw Elements::Exception() <<
"Please give an appropriate weight type for image: " << py_image.weight_file;
119 auto weight_image_source =
120 std::make_shared<FitsImageSource<DetectionImage::PixelType>>(py_image.weight_file, py_image.weight_hdu);
123 logger.
debug() <<
"w: " << weight_map->getWidth() <<
" h: " << weight_map->getHeight()
124 <<
" t: " << py_image.weight_type <<
" s: " << py_image.weight_scaling;
131 if (!py_image.has_weight_threshold) {
135 auto weight_type_name = boost::to_upper_copy(py_image.weight_type);
136 switch (weight_type_map[weight_type_name]) {
140 threshold = threshold * threshold;
146 threshold = 1.0 / threshold;
157 auto images = getDependency<PythonConfig>().getInterpreter().getMeasurementImages();
158 auto groups = getDependency<PythonConfig>().getInterpreter().getMeasurementGroups();
161 boost::char_separator<char> line_sep{
"\n"};
162 for (
auto &
g : groups) {
164 std::string group_str = py::extract<std::string>(
g.attr(
"__str__")());
165 boost::tokenizer<decltype(line_sep)> tok(group_str, line_sep);
166 for (
auto &l : tok) {
171 if (images.size() > 0) {
172 for (
auto& p : images) {
174 validateImagePaths(py_image);
203 auto weight_map = createWeightMap(py_image);
205 if (weight_map !=
nullptr && flux_scale != 1. && py_image.
weight_absolute) {
221 logger.
debug() <<
"No measurement image provided, using the detection image for measurements";
223 auto detection_image = getDependency<DetectionImageConfig>();
224 auto weight_image = getDependency<WeightImageConfig>();
229 detection_image.getDetectionImagePath(),
232 detection_image.getDetectionImage(),
233 detection_image.getCoordinateSystem(),
234 weight_image.getWeightImage(),
235 weight_image.getWeightType(),
237 weight_image.isWeightAbsolute(),
238 weight_image.getWeightThreshold(),
239 (
SeFloat) detection_image.getGain(),
240 (
SeFloat) detection_image.getSaturation(),
void info(const std::string &logMessage)
void debug(const std::string &logMessage)
static Logging getLogger(const std::string &name="")