19 #include <boost/algorithm/string.hpp>
21 #include <CCfits/CCfits>
37 using namespace Euclid::Configuration;
38 namespace po = boost::program_options;
40 namespace SourceXtractor {
74 std::make_pair(
"UNMATCHED", AssocModeConfig::AssocFilter::UNMATCHED)
89 for (
auto& part : parts) {
91 column_list.
emplace_back(boost::lexical_cast<int>(part)-1);
105 declareDependency<DetectionImageConfig>();
106 declareDependency<PartitionStepConfig>();
111 return { {
"Assoc config", {
113 "Assoc catalog file"},
115 "Assoc columns to specify x/ra,y/dec[,weight] (the index of the first column is 1)"},
116 {
ASSOC_MODE.
c_str(), po::value<std::string>()->default_value(
"NEAREST"),
117 "Assoc mode [FIRST, NEAREST, MEAN, MAG_MEAN, SUM, MAG_SUM, MIN, MAX]"},
119 "Assoc radius (Always in pixels of the detection image)"},
121 "Assoc catalog filter setting: ALL, MATCHED, UNMATCHED"},
123 "List of columns indices in the assoc catalog to copy on match (the index of the first column is 1). "},
125 "Assoc coordinates type: PIXEL, WORLD"},
136 if (assoc_filter_table.find(filter) != assoc_filter_table.end()) {
137 auto assoc_filter = assoc_filter_table.at(filter);
139 getDependency<PartitionStepConfig>().addPartitionStepCreator(
141 return std::make_shared<AssocModePartitionStep>(
true);
145 getDependency<PartitionStepConfig>().addPartitionStepCreator(
147 return std::make_shared<AssocModePartitionStep>(
false);
157 if (assoc_mode_table.find(assoc_mode) != assoc_mode_table.end()) {
169 if (columns.size() < 2) {
170 throw Elements::Exception() <<
"At least 2 columns must be specified for x,y coordinates in the assoc catalog";
172 if (columns.size() > 3) {
173 throw Elements::Exception() <<
"Maximum 3 columns for x, y and weight must be specified in the assoc catalog";
181 if (assoc_coord_type_table.find(assoc_coord_type_str) != assoc_coord_type_table.end()) {
182 assoc_coord_type = assoc_coord_type_table.at(assoc_coord_type_str);
184 throw Elements::Exception() <<
"Invalid association coordinate type: " << assoc_coord_type_str;
193 reader = std::make_shared<Euclid::Table::FitsReader>(
filename);
196 reader = std::make_shared<Euclid::Table::AsciiReader>(
filename);
198 auto table = reader->read();
200 for (
size_t i = 0; i < getDependency<DetectionImageConfig>().getExtensionsNb(); i++) {
202 auto coordinate_system = getDependency<DetectionImageConfig>().getCoordinateSystem(i);
215 if (assoc_coord_type ==
AssocCoordType::PIXEL && getDependency<DetectionImageConfig>().getExtensionsNb() > 1) {
217 "Using Assoc catalog matching in pixel coordinates with multiple detection images";
227 for (
auto& row : table) {
231 if (coordinate_system !=
nullptr) {
237 coord = coordinate_system->worldToImage(world_coord);
245 if (columns.
size() == 3 && columns.
at(2) >= 0) {
246 catalog.
back().
weight = boost::get<double>(row[columns.
at(2)]);
248 for (
auto column : copy_columns) {
249 if (column >= static_cast<int>(row.size())) {
252 if (row[column].type() ==
typeid(
int)) {
254 }
else if (row[column].type() ==
typeid(
double)) {
256 }
else if (row[column].type() ==
typeid(
int64_t)) {
258 }
else if (row[column].type() ==
typeid(
SeFloat)) {
ELEMENTS_API auto split(Args &&...args) -> decltype(splitPath(std::forward< Args >(args)...))
static ConfigManager & getInstance(long id)
void registerDependency()
static Elements::Logging logger
static Logging getLogger(const std::string &name="")