26 #include <boost/regex.hpp>
31 using boost::regex_match;
33 #include <boost/algorithm/string.hpp>
39 namespace po = boost::program_options;
40 namespace fs = boost::filesystem;
43 namespace Configuration {
54 {
"Input catalog options",
56 "The file containing the photometry mapping of the catalog columns"},
58 "A list of filters to ignore"}}}};
63 if (mapping_file.is_relative()) {
64 mapping_file = base_dir / mapping_file;
66 if (!fs::exists(mapping_file)) {
67 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" does not exist";
69 if (fs::is_directory(mapping_file)) {
70 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" is not a file";
78 PhotometricBandMappingConfig::MappingMap filter_name_mapping{};
79 PhotometricBandMappingConfig::UpperLimitThresholdMap threshold_mapping{};
84 bool header_found =
false;
85 int filtr_column_index = 0;
86 int flux_column_index = 1;
87 int error_column_index = 2;
88 int upper_limit_column_index = 3;
89 int convertion_column_index = 4;
91 std::vector<std::string> expected_column_name {
"Filter",
"Flux Column",
"Error Column",
"Upper Limit/error ratio",
"Convert from MAG"};
99 boost::trim(trimmed_line);
102 boost::split(strs, trimmed_line, boost::is_any_of(
","));
104 for (
size_t index = 0; index < expected_column_name.size(); ++index) {
105 for (
size_t index_string = 0; index_string < strs.
size(); ++index_string) {
108 if (item==expected_column_name[index]){
109 proposed_column_index[index] = index_string;
114 if (proposed_column_index[0] >= 0 && proposed_column_index[1] >= 0 && proposed_column_index[2] >=0) {
116 filtr_column_index = proposed_column_index[0];
117 flux_column_index = proposed_column_index[1];
118 error_column_index = proposed_column_index[2];
119 upper_limit_column_index = proposed_column_index[3];
120 convertion_column_index = proposed_column_index[4];
131 if (
int(cells.
size()) <= filtr_column_index ||
132 int(cells.
size()) <= flux_column_index ||
133 int(cells.
size()) <= error_column_index ) {
136 std::string filter_value = cells[filtr_column_index];
137 boost::trim(filter_value);
139 boost::trim(flux_value);
140 std::string error_value = cells[error_column_index];
141 boost::trim(error_value);
143 filter_name_mapping.emplace_back(filter_value,
std::make_pair(flux_value, error_value));
145 if (upper_limit_column_index > 0 &&
int(cells.
size()) > upper_limit_column_index && cells[upper_limit_column_index] !=
"" ) {
146 float n =
std::stof(cells[upper_limit_column_index]);
147 threshold_mapping.emplace_back(filter_value, n);
149 threshold_mapping.emplace_back(filter_value, 3.0);
152 if (convertion_column_index > 0 &&
int(cells.
size()) > convertion_column_index && cells[convertion_column_index] !=
"") {
153 bool f =
std::stoi(cells[convertion_column_index]);
154 convert_from_mag_mapping.emplace_back(filter_value, f);
156 convert_from_mag_mapping.emplace_back(filter_value,
false);
159 logger.
error() <<
"Syntax error in " << filename <<
": " << line <<
" => " << e.
what();;
163 return std::make_tuple(filter_name_mapping, threshold_mapping, convert_from_mag_mapping);
171 auto all_filter_name_mapping = std::get<0>(parsed);
172 auto all_threshold_mapping = std::get<1>(parsed);
173 auto all_convert_mapping = std::get<2>(parsed);
179 for (
auto& pair : all_threshold_mapping) {
180 if (exclude_filters.count(pair.first) == 0) {
185 for (
auto& pair : all_convert_mapping) {
186 if (exclude_filters.count(pair.first) == 0) {
191 for (
auto& pair : all_filter_name_mapping) {
192 if (exclude_filters.count(pair.first) > 0) {
193 exclude_filters.erase(pair.first);
199 if (!exclude_filters.empty()) {
201 for (
auto& f : exclude_filters) {
202 wrong_filters << f <<
" ";
210 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
218 <<
"PhotometricBandMappingConfig";
223 const PhotometricBandMappingConfig::UpperLimitThresholdMap&
227 <<
"PhotometricBandMappingConfig";
235 <<
"PhotometricBandMappingConfig";
244 <<
"PhotometricBandMappingConfig";
ConvertFromMagMap m_convert_from_mag_map
ELEMENTS_API auto split(Args &&...args) -> decltype(splitPath(std::forward< Args >(args)...))
Superclass of all configuration classes.
const ConvertFromMagMap & getConvertFromMagMapping()
Returns the mapping of the flag indicating if the photometry has to be computed from a MAG_AB...
void setBaseDir(const boost::filesystem::path &base_dir)
Sets the directory used when resolving relative paths.
static const std::string FILTER_MAPPING_FILE
State & getCurrentState()
Returns the current state of the configuration.
void initialize(const UserValues &args) override
It initializes the photometric bands list.
const boost::filesystem::path getMappingFile()
Returns the mapping file to be used by other configuration class.
static const std::string EXCLUDE_FILTER
PhotometricBandMappingConfig(long manager_id)
Constructs a new PhotometricBandMappingConfig object.
static fs::path getMappingFileFromOptions(const Configuration::UserValues &args, const fs::path &base_dir)
UpperLimitThresholdMap m_threshold_map
static Elements::Logging logger
boost::filesystem::path m_base_dir
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the PhotometryCatalogConfig.
const UpperLimitThresholdMap & getUpperLimitThresholdMapping()
Returns the mapping of threshold used in the upper limit computation which will be red from the catal...
const MappingMap & getPhotometricBandMapping()
Returns the list of the photometric band mapping which will be red from the catalog.
std::vector< std::pair< std::string, std::pair< std::string, std::string >>> MappingMap
void error(const std::string &logMessage)
static std::tuple< PhotometricBandMappingConfig::MappingMap, PhotometricBandMappingConfig::UpperLimitThresholdMap, PhotometricBandMappingConfig::ConvertFromMagMap > parseFile(fs::path filename)
boost::filesystem::path m_mapping_file
std::vector< std::pair< std::string, float >> UpperLimitThresholdMap
static Logging getLogger(const std::string &name="")
The initialize() method has been called.