Alexandria  2.14.1
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PhotometryAttributeFromRow.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
26 #include <typeindex>
27 #include <cmath>
28 #include "ElementsKernel/Real.h"
30 
31 #include "../../SourceCatalog/PhotometryParsingException.h"
33 #include "ElementsKernel/Real.h"
34 #include "Table/CastVisitor.h"
35 
36 
37 using namespace std;
38 
39 namespace Euclid {
40 namespace SourceCatalog {
41 
42 PhotometryAttributeFromRow::PhotometryAttributeFromRow(
44  const vector<pair<string, std::pair<string, string>>>& filter_name_mapping,
45  const bool missing_photometry_enabled,
46  const double missing_photometry_flag,
47  const bool upper_limit_enabled) :
48  m_missing_photometry_enabled(missing_photometry_enabled),
49  m_missing_photometry_flag(missing_photometry_flag),
50  m_upper_limit_enabled(upper_limit_enabled){
51 
52  unique_ptr<size_t> flux_column_index_ptr;
53  unique_ptr<size_t> error_column_index_ptr;
54 
55  for (auto filter_name_pair : filter_name_mapping) {
56  flux_column_index_ptr = column_info_ptr->find(filter_name_pair.second.first);
57  error_column_index_ptr = column_info_ptr->find(filter_name_pair.second.second);
58 
59  if (flux_column_index_ptr == nullptr) {
60  throw Elements::Exception() << "Column info does not have the flux column "
61  << filter_name_pair.second.first;
62  }
63  if (error_column_index_ptr == nullptr) {
64  throw Elements::Exception() << "Column info does not have the flux error column "
65  << filter_name_pair.second.second;
66  }
67  m_table_index_vector.push_back(make_pair(*(flux_column_index_ptr), *(error_column_index_ptr)));
68  }
69 
70  // create and filled the shared pointer to the filter name vector
72  for(auto a_filter_name_map: filter_name_mapping) {
73  m_filter_name_vector_ptr->push_back(a_filter_name_map.first);
74  }
75 
76 }
77 
79  // @todo Auto-generated destructor stub
80 }
81 
83  const Euclid::Table::Row& row) {
84 
85  vector<FluxErrorPair> photometry_vector {};
86 
87  for (auto& filter_index_pair : m_table_index_vector) {
88  Euclid::Table::Row::cell_type flux_cell = row[filter_index_pair.first];
89  Euclid::Table::Row::cell_type error_cell = row[filter_index_pair.second];
90 
91  double flux = boost::apply_visitor(Table::CastVisitor<double>{}, flux_cell);
92  double error = boost::apply_visitor(Table::CastVisitor<double>{}, error_cell);
93 
94  bool missing_data = false;
95  bool upper_limit = false;
96  if (std::isinf(flux)){
98  "Infinite flux encountered when parsing the Photometry",
99  flux,
100  error);
101  }
104  missing_data = Elements::isEqual(flux, m_missing_photometry_flag) || std::isnan(flux);
105  if (missing_data){
106  error=0;
107  } else {
108  if (m_upper_limit_enabled) {
110  if (error==0.){
112  "Zero error encountered when parsing the Photometry with 'missing data' and 'upper limit' enabled",
113  flux,
114  error);
115  }
116  if (error<0){
118  upper_limit=true;
119  if (flux<=0){
121  "Negative or Zero flux encountered when parsing the Photometry in the context of an 'upper limit'",
122  flux,
123  error);
124  }
125  error=std::abs(error);
126  }
127  } else {
129  if (error<=0){
131  "Negative or Zero error encountered when parsing the Photometry with 'missing data' enabled and 'upper limit' disabled",
132  flux,
133  error);
134  }
135  }
136  }
137  } else {
138 
140  if (std::isnan(flux)){
142  "NAN flux encountered when parsing the Photometry with 'missing data' disabled",
143  flux,
144  error);
145  }
146 
147  if (m_upper_limit_enabled) {
149  if (error==0.){
151  "Zero error encountered when parsing the Photometry with 'missing data' disabled and 'upper limit' enabled",
152  flux,
153  error);
154  }
155  if (error<0){
157  upper_limit=true;
158  if (flux<=0){
160  "Negative or Zero flux encountered when parsing the Photometry in the context of an 'upper limit'",
161  flux,
162  error);
163  }
164  error=std::abs(error);
165 
166  }
167 
168  } else {
170  if (error<=0){
172  "Negative or Zero error encountered when parsing the Photometry with 'missing data' and 'upper limit' disabled",
173  flux,
174  error);
175  }
176  }
177  }
178 
179 
180 
181 
182  photometry_vector.push_back(FluxErrorPair{flux, error, missing_data, upper_limit});
183  }//Eof for
184 
185  unique_ptr<Attribute> photometry_ptr { new Photometry{m_filter_name_vector_ptr, photometry_vector } };
186 
187  return photometry_ptr;
188 }
189 
190 } // namespace SourceCatalog
191 } // end of namespace Euclid
192 
boost::variant< bool, int32_t, int64_t, float, double, std::string, std::vector< bool >, std::vector< int32_t >, std::vector< int64_t >, std::vector< float >, std::vector< double >, NdArray::NdArray< bool >, NdArray::NdArray< int32_t >, NdArray::NdArray< int64_t >, NdArray::NdArray< float >, NdArray::NdArray< double > > cell_type
The possible cell types.
Definition: Row.h:84
std::unique_ptr< Attribute > createAttribute(const Euclid::Table::Row &row) override
Create a photometricAttribute from a Table row.
T push_back(T...args)
std::vector< std::pair< size_t, size_t > > m_table_index_vector
T make_pair(T...args)
Represents one row of a Table.
Definition: Row.h:64
STL class.
STL class.
std::shared_ptr< std::vector< std::string > > m_filter_name_vector_ptr
bool isEqual(const RawType &left, const RawType &right)
T isnan(T...args)
T isinf(T...args)