27 #include <boost/algorithm/string.hpp>
35 namespace po = boost::program_options;
36 namespace fs = boost::filesystem;
39 namespace Configuration {
50 {
"Input catalog options",
52 "The file containing the photometry mapping of the catalog columns"},
54 "A list of filters to ignore"}}}};
59 if (mapping_file.is_relative()) {
60 mapping_file = base_dir / mapping_file;
62 if (!fs::exists(mapping_file)) {
63 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" does not exist";
65 if (fs::is_directory(mapping_file)) {
66 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" is not a file";
74 PhotometricBandMappingConfig::MappingMap filter_name_mapping{};
75 PhotometricBandMappingConfig::UpperLimitThresholdMap threshold_mapping{};
80 bool header_found =
false;
81 int filtr_column_index = 0;
82 int flux_column_index = 1;
83 int error_column_index = 2;
84 int upper_limit_column_index = 3;
85 int convertion_column_index = 4;
95 boost::trim(trimmed_line);
100 for (
size_t index = 0; index < expected_column_name.size(); ++index) {
101 for (
size_t index_string = 0; index_string < strs.
size(); ++index_string) {
104 if (item == expected_column_name[index]) {
105 proposed_column_index[index] = index_string;
110 if (proposed_column_index[0] >= 0 && proposed_column_index[1] >= 0 && proposed_column_index[2] >= 0) {
112 filtr_column_index = proposed_column_index[0];
113 flux_column_index = proposed_column_index[1];
114 error_column_index = proposed_column_index[2];
115 upper_limit_column_index = proposed_column_index[3];
116 convertion_column_index = proposed_column_index[4];
126 if (
int(cells.
size()) <= filtr_column_index ||
int(cells.
size()) <= flux_column_index ||
127 int(cells.
size()) <= error_column_index) {
130 std::string filter_value = cells[filtr_column_index];
131 boost::trim(filter_value);
133 boost::trim(flux_value);
134 std::string error_value = cells[error_column_index];
135 boost::trim(error_value);
137 filter_name_mapping.emplace_back(filter_value,
std::make_pair(flux_value, error_value));
139 if (upper_limit_column_index > 0 &&
int(cells.
size()) > upper_limit_column_index &&
140 cells[upper_limit_column_index] !=
"") {
141 float n =
std::stof(cells[upper_limit_column_index]);
142 threshold_mapping.emplace_back(filter_value, n);
144 threshold_mapping.emplace_back(filter_value, 3.0);
147 if (convertion_column_index > 0 &&
int(cells.
size()) > convertion_column_index &&
148 cells[convertion_column_index] !=
"") {
149 bool f =
std::stoi(cells[convertion_column_index]);
150 convert_from_mag_mapping.emplace_back(filter_value, f);
152 convert_from_mag_mapping.emplace_back(filter_value,
false);
155 logger.
error() <<
"Syntax error in " << filename <<
": " << line <<
" => " << e.
what();
160 return std::make_tuple(filter_name_mapping, threshold_mapping, convert_from_mag_mapping);
168 auto all_filter_name_mapping = std::get<0>(parsed);
169 auto all_threshold_mapping = std::get<1>(parsed);
170 auto all_convert_mapping = std::get<2>(parsed);
176 for (
auto& pair : all_threshold_mapping) {
177 if (exclude_filters.count(pair.first) == 0) {
182 for (
auto& pair : all_convert_mapping) {
183 if (exclude_filters.count(pair.first) == 0) {
188 for (
auto& pair : all_filter_name_mapping) {
189 if (exclude_filters.count(pair.first) > 0) {
190 exclude_filters.erase(pair.first);
196 if (!exclude_filters.empty()) {
198 for (
auto& f : exclude_filters) {
199 wrong_filters << f <<
" ";
207 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
215 <<
"PhotometricBandMappingConfig";
220 const PhotometricBandMappingConfig::UpperLimitThresholdMap&
224 <<
"PhotometricBandMappingConfig";
232 <<
"PhotometricBandMappingConfig";
240 <<
"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.