25#include <boost/algorithm/string.hpp>
26#include <boost/regex.hpp>
28using boost::regex_match;
44namespace po = boost::program_options;
57 m_weight_type(
WeightType::WEIGHT_TYPE_FROM_BACKGROUND),
58 m_absolute_weight(false),
60 m_weight_threshold(0),
61 m_symmetry_usage(true) {
63 declareDependency<DetectionImageConfig>();
67 return { {
"Weight image", {
69 "Path to a fits format image to be used as weight image."},
71 "Is the weight map provided as absolute values or relative to background."},
73 "Weight image type [none|background|rms|variance|weight]."},
75 "Weight map scaling factor."},
77 "Threshold for pixels to be considered bad pixels. In same units as weight map."},
79 "Use object symmetry to replace pixels above the weight threshold for photometry."},
86 switch (weight_type) {
88 case WeightType::WEIGHT_TYPE_FROM_BACKGROUND:
89 case WeightType::WEIGHT_TYPE_RMS:
90 return threshold * threshold;
91 case WeightType::WEIGHT_TYPE_VARIANCE:
93 case WeightType::WEIGHT_TYPE_WEIGHT:
95 return 1.0 / threshold;
117 auto weight_iter = WEIGHT_MAP.find(weight_type_name);
118 if (weight_iter == WEIGHT_MAP.end()) {
133 throw Elements::Exception() <<
"Please give an appropriate weight type for image: " << weight_image_filename;
135 throw Elements::Exception() <<
"Please give an appropriate weight type for image: " << weight_image_filename;
137 throw Elements::Exception() <<
"Setting absolute weight but providing *no* weight image does not make sense.";
139 if (weight_image_filename !=
"") {
140 boost::regex hdu_regex(
".*\\[[0-9]*\\]$");
142 for (
int i=0;; i++) {
144 if (boost::regex_match(weight_image_filename, hdu_regex)) {
146 fits_image_source = std::make_shared<FitsImageSource>(weight_image_filename, 0,
ImageTile::FloatImage);
152 fits_image_source = std::make_shared<FitsImageSource>(weight_image_filename, i+1,
ImageTile::FloatImage);
170 auto flux_scale = getDependency<DetectionImageConfig>().getOriginalFluxScale(
m_weight_images.size());
177 scaled_weight_threshold *= flux_scale * flux_scale;
201 auto image_chunk = image->getChunk(
x,
y, width, height);
221 auto& tile_image = *tile.
getImage();
222 for (
int iy = 0; iy < height; iy++) {
223 for (
int ix = 0; ix < width; ix++) {
226 tile_image.setValue(ix, iy, 1.0 / value);
237 auto& tile_image = *tile.
getImage();
238 for (
int iy = 0; iy < height; iy++) {
239 for (
int ix = 0; ix < width; ix++) {
241 tile_image.setValue(ix, iy, value);
248 auto& tile_image = *tile.
getImage();
249 for (
int iy = 0; iy < height; iy++) {
250 for (
int ix = 0; ix < width; ix++) {
252 tile_image.setValue(ix, iy, value * value);
275 std::make_shared<WeightMapImageSource>(weight_image, weight_type, scaling));
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T emplace_back(T... args)