24 #include <boost/algorithm/string.hpp>
25 #include <boost/timer/timer.hpp>
46 namespace po = boost::program_options;
47 namespace timer = boost::timer;
71 {
"simple", Algorithm::SIMPLE},
72 {
"se2", Algorithm::SE2},
81 auto i = args.
find(var);
85 auto basename = input.leaf();
86 while (!basename.extension().empty())
87 basename = basename.stem();
89 auto output_area = boost::filesystem::path(args.
at(
"output-area").as<
std::string>());
90 auto output = output_area / boost::filesystem::path(basename.native() +
"_" + algo +
"_" + default_suffix);
91 output.replace_extension(
"fits");
92 return output.native();
97 switch (m_algorithm) {
98 case Algorithm::SIMPLE:
99 return Euclid::make_unique<SimpleBackgroundAnalyzer>();
101 return Euclid::make_unique<SE2BackgroundLevelAnalyzer>(m_cell_size, m_smooth, m_weight_config.
getWeightType());
103 return Euclid::make_unique<SEBackgroundLevelAnalyzer>(m_cell_size, m_smooth, m_weight_config.
getWeightType());
114 po::options_description options;
120 options.add(config_manager.closeRegistration());
121 options.add_options()
122 (
"output", po::value<std::string>(),
"Output image for the background")
123 (
"output-variance", po::value<std::string>(),
"Output image for the variance")
124 (
"output-area", po::value<std::string>()->default_value(boost::filesystem::temp_directory_path().native()),
"Output area")
125 (
"algorithm", po::value<std::string>()->required(),
"Algorithm to use: Simple, SE2")
126 (
"cell-size", po::value<std::string>()->default_value(
"64"),
"Cell size for the histogram")
127 (
"smooth-size", po::value<std::string>()->default_value(
"3"),
"Box size for the median filtering")
128 (
"no-write", po::bool_switch(),
"Do not write the image (skip interpolation)")
129 (
"tile-size", po::value<int>()->default_value(512),
"Tile size")
130 (
"tile-memory", po::value<int>()->default_value(2048),
"Tile memory limit");
137 config_manager.initialize(args);
142 m_output_bg = getOutputPath(args,
"output",
"background");
143 m_output_var = getOutputPath(args,
"output-variance",
"variance");
146 boost::to_lower(algorithm_str);
147 if (s_algo_map.count(algorithm_str) > 0)
148 m_algorithm = s_algo_map[algorithm_str];
152 m_cell_size = stringToVector<int>(args.
at(
"cell-size").as<
std::string>());
153 m_smooth = stringToVector<int>(args.
at(
"smooth-size").as<
std::string>());
155 auto tile_size = args.
at(
"tile-size").as<
int>();
156 auto tile_memory = args.
at(
"tile-memory").as<
int>();
157 TileManager::getInstance()->setOptions(tile_size, tile_size, tile_memory);
164 logger.
info() <<
"Destination background image: " << m_output_bg;
165 logger.
info() <<
"Destination variance image: " << m_output_var;
167 auto bg_analyzer = getBackgroundAnalyzer();
168 assert (bg_analyzer !=
nullptr);
178 logger.
info() <<
"Weight image " << weight_image->getRepr();
182 timer::cpu_timer timer;
183 auto bg_model = bg_analyzer->analyzeBackground(image, weight_image, mask, threshold);
185 if (!args.
at(
"no-write").as<
bool>()) {
187 FitsWriter::writeFile(*bg_model.getLevelMap(), m_output_bg, m_detection_config.
getCoordinateSystem());
189 FitsWriter::writeFile(*bg_model.getVarianceMap(), m_output_var, m_detection_config.
getCoordinateSystem());
197 TileManager::getInstance()->saveAllTiles();
198 FitsFileManager::getInstance()->closeAllFiles();
200 return Elements::ExitCode::OK;