CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Data2D_extra.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2014 by Federico Marulli *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
33 #ifndef __DATA2D_EXTRA__
34 #define __DATA2D_EXTRA__
35 
36 #include "Data2D.h"
37 
38 namespace cbl {
39 
40  namespace data {
41 
51  class Data2D_extra : public Data2D
52  {
53 
54  protected:
55 
60 
62  std::vector<std::vector<double>> m_extra_info;
63 
65 
66 
67  public:
68 
73 
78 
117  Data2D_extra (const int n_extra_info, const std::string input_file, const int skip_nlines=0, const std::vector<int> column={1, 2}, const std::vector<int> column_data={}, const std::vector<int> column_errors={}, const std::vector<int> column_edges={})
118  : Data2D()
119  { m_extra_info.resize(n_extra_info); read(input_file, skip_nlines, column, column_data, column_errors, column_edges); set_dataType(DataType::_2D_extra_); }
120 
137  Data2D_extra (const std::vector<double> x, const std::vector<double> y, const std::vector<std::vector<double>> data, const std::vector<std::vector<double>> extra_info, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={})
138  : Data2D(x, y, data, bin_edges_x, bin_edges_y), m_extra_info(extra_info) { set_dataType(DataType::_2D_extra_); }
139 
159  Data2D_extra (const std::vector<double> x, const std::vector<double> y, const std::vector<double> data, const std::vector<double> error, const std::vector<std::vector<double>> extra_info, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={}) : Data2D(x, y, data, error, bin_edges_x, bin_edges_y), m_extra_info(extra_info) { set_dataType(DataType::_2D_extra_); }
160 
180  Data2D_extra (const std::vector<double> x, const std::vector<double> y, const std::vector<std::vector<double>> data, const std::vector<std::vector<double>> covariance, const std::vector<std::vector<double>> extra_info, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={}) : Data2D(x, y, data, covariance, bin_edges_x, bin_edges_y), m_extra_info(extra_info) { set_dataType(DataType::_2D_extra_); }
181 
201  Data2D_extra (const std::vector<double> x, const std::vector<double> y, const std::vector<double> data, const std::vector<std::vector<double>> covariance, const std::vector<std::vector<double>> extra_info, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={}) : Data2D(x, y, data, covariance, bin_edges_x, bin_edges_y), m_extra_info(extra_info) { set_dataType(DataType::_2D_extra_); }
202 
206  virtual ~Data2D_extra () = default;
207 
214  std::shared_ptr<Data> as_factory () { return move(std::unique_ptr<Data2D_extra>(this)); }
215 
217 
218 
223 
230  double extra_info (const int i, const int j) const { return m_extra_info[i][j]; }
231 
236  std::vector<std::vector<double>> extra_info () const { return m_extra_info; }
237 
250  std::vector<std::vector<double>> IndipendentVariable (const int i=-1, const int j=-1) const
251  {
252  std::vector<std::vector<double>> iv;
253  iv.push_back(((i>0) ? m_extra_info[i] : m_x));
254  iv.push_back(((j>0) ? m_extra_info[i] : m_y));
255  return iv;
256  }
257 
259 
260 
265 
270  void set_extra_info (const std::vector<std::vector<double>> extra_info) { m_extra_info = extra_info; }
271 
273 
274 
279 
316  virtual void read (const std::string input_file, const int skip_nlines=0, const std::vector<int> column={1, 2}, const std::vector<int> column_data={}, const std::vector<int> column_errors={}, const std::vector<int> column_edges={}) override;
317 
323  virtual void Print (const int precision=4) const override;
324 
339  virtual void write (const std::string dir, const std::string file, const std::string header, const bool full, const int prec=4, const int ww=8, const int rank=0) const override;
340 
342 
343 
349 
358  std::shared_ptr<Data> cut (const double xmin, const double xmax, const double ymin, const double ymax) const;
359 
361 
362  };
363 
364  }
365 }
366 
367 #endif
The class Data2D.
The class Data2D_extra.
Definition: Data2D_extra.h:52
virtual ~Data2D_extra()=default
default destructor
Data2D_extra(const std::vector< double > x, const std::vector< double > y, const std::vector< std::vector< double >> data, const std::vector< std::vector< double >> extra_info, const std::vector< double > bin_edges_x={}, const std::vector< double > bin_edges_y={})
constructor which gets the data from an input matrix
Definition: Data2D_extra.h:137
Data2D_extra()
default constructor
Definition: Data2D_extra.h:77
virtual void read(const std::string input_file, const int skip_nlines=0, const std::vector< int > column={1, 2}, const std::vector< int > column_data={}, const std::vector< int > column_errors={}, const std::vector< int > column_edges={}) override
read the data
Data2D_extra(const std::vector< double > x, const std::vector< double > y, const std::vector< double > data, const std::vector< std::vector< double >> covariance, const std::vector< std::vector< double >> extra_info, const std::vector< double > bin_edges_x={}, const std::vector< double > bin_edges_y={})
constructor which gets both the data and the covariance matrix from input matrices
Definition: Data2D_extra.h:201
std::vector< std::vector< double > > extra_info() const
return the m_exta_info vector
Definition: Data2D_extra.h:236
Data2D_extra(const std::vector< double > x, const std::vector< double > y, const std::vector< std::vector< double >> data, const std::vector< std::vector< double >> covariance, const std::vector< std::vector< double >> extra_info, const std::vector< double > bin_edges_x={}, const std::vector< double > bin_edges_y={})
constructor which gets both the data and the covariance matrix from input matrices
Definition: Data2D_extra.h:180
Data2D_extra(const int n_extra_info, const std::string input_file, const int skip_nlines=0, const std::vector< int > column={1, 2}, const std::vector< int > column_data={}, const std::vector< int > column_errors={}, const std::vector< int > column_edges={})
constructor which reads the data from file
Definition: Data2D_extra.h:117
std::shared_ptr< Data > as_factory()
static factory used to construct objects of class Data2D_extra
Definition: Data2D_extra.h:214
std::shared_ptr< Data > cut(const double xmin, const double xmax, const double ymin, const double ymax) const
cut the data
virtual void write(const std::string dir, const std::string file, const std::string header, const bool full, const int prec=4, const int ww=8, const int rank=0) const override
write the data
std::vector< std::vector< double > > IndipendentVariable(const int i=-1, const int j=-1) const
get the independet variable, to be used in model computation
Definition: Data2D_extra.h:250
double extra_info(const int i, const int j) const
return the value of the extra information at index i,j
Definition: Data2D_extra.h:230
std::vector< std::vector< double > > m_extra_info
extra information
Definition: Data2D_extra.h:62
Data2D_extra(const std::vector< double > x, const std::vector< double > y, const std::vector< double > data, const std::vector< double > error, const std::vector< std::vector< double >> extra_info, const std::vector< double > bin_edges_x={}, const std::vector< double > bin_edges_y={})
constructor which gets both the data and the errors from input matrices
Definition: Data2D_extra.h:159
virtual void Print(const int precision=4) const override
print the data on screen
void set_extra_info(const std::vector< std::vector< double >> extra_info)
set the extra info
Definition: Data2D_extra.h:270
The class Data2D.
Definition: Data2D.h:51
std::vector< double > m_y
ordered y axis points
Definition: Data2D.h:63
std::vector< double > m_x
ordered x axis points
Definition: Data2D.h:60
Data2D()
default constructor
Definition: Data2D.h:83
void set_dataType(const DataType dataType)
set the data type
Definition: Data.h:121
virtual std::vector< double > data() const
get data
Definition: Data.h:376
virtual std::vector< double > error() const
get standard deviation
Definition: Data.h:389
virtual std::vector< std::vector< double > > covariance() const
get the m_covariance vector
Definition: Data.h:403
@ _2D_extra_
2D dataset with extra information
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38