CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Data2D.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2014 by Federico Marulli and Alfonso Veropalumbo *
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__
34 #define __DATA2D__
35 
36 #include "Data.h"
37 
38 namespace cbl {
39 
40  namespace data {
41 
50  class Data2D : public Data
51  {
52  protected:
53 
58 
60  std::vector<double> m_x;
61 
63  std::vector<double> m_y;
64 
66  int m_xsize;
67 
69  int m_ysize;
70 
72 
73  public:
74 
79 
83  Data2D ()
84  : Data(DataType::_2D_) {}
85 
122  Data2D (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={})
124  { read(input_file, skip_nlines, column, column_data, column_errors, column_edges); }
125 
139  Data2D (const std::vector<double> x, const std::vector<double> y, const std::vector<std::vector<double>> data, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={});
140 
157  Data2D (const std::vector<double> x, const std::vector<double> y, const std::vector<std::vector<double>> data, const std::vector<std::vector<double>> error, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={});
158 
175  Data2D (const std::vector<double> x, const std::vector<double> y, const std::vector<double> data, const std::vector<double> error, const std::vector<double> bin_edges_x={}, const std::vector<double> bin_edges_y={});
176 
193  Data2D (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<double> bin_edges_x={}, const std::vector<double> bin_edges_y={});
194 
198  ~Data2D () = default;
199 
205  std::shared_ptr<Data> as_factory ();
206 
208 
214 
219  int xsize () const override
220  { return m_xsize; }
221 
226  int ysize () const override
227  { return m_ysize; }
228 
234  double xx (const int i) const override
235  { return m_x[i]; }
236 
241  std::vector<double> xx () const override { return m_x; }
242 
248  double yy (const int i) const override
249  { return m_y[i]; }
250 
255  std::vector<double> yy () const override
256  { return m_y; }
257 
270  std::vector<std::vector<double>> IndipendentVariable (const int i=-1, const int j=-1) const override
271  { (void)i; (void)j; return {m_x, m_y}; }
272 
279  double data (const int i, const int j) const override
280  { return m_data[j+i*m_ysize]; }
281 
286  void get_data (std::vector<std::vector<double>> &data) const override;
287 
294  double error (const int i, const int j) const override
295  { return m_error[j+i*m_ysize]; }
296 
301  void get_error (std::vector<std::vector<double>> &error) const override;
302 
304 
305 
310 
315  void set_xx (const std::vector<double> x) override { m_x = x; m_xsize = m_x.size();}
316 
321  void set_yy (const std::vector<double> y) override { m_y = y; m_ysize = m_y.size(); }
322 
327  void set_edges_xx (const std::vector<double> edges) override { m_edges_xx = edges; }
328 
333  void set_edges_yy (const std::vector<double> edges) override { m_edges_yy = edges; }
334 
336 
337 
342 
379  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;
380 
386  virtual void Print (const int precision=4) const override;
387 
408  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;
409 
419  void write_covariance (const std::string dir, const std::string file, const int precision=10) const override;
420 
422 
428 
437  std::shared_ptr<Data> cut (const double xmin, const double xmax, const double ymin, const double ymax) const;
438 
440 
441  };
442 
443  }
444 }
445 
446 #endif
The class Data.
The class Data2D.
Definition: Data2D.h:51
void set_edges_xx(const std::vector< double > edges) override
set interval variable m_edges_xx
Definition: Data2D.h:327
int m_xsize
number of points along x
Definition: Data2D.h:66
double data(const int i, const int j) const override
get data at index i,j
Definition: Data2D.h:279
double yy(const int i) const override
get the value of y at index i
Definition: Data2D.h:248
void write_covariance(const std::string dir, const std::string file, const int precision=10) const override
write the covariance
Definition: Data2D.cpp:406
std::vector< double > m_y
ordered y axis points
Definition: Data2D.h:63
int xsize() const override
get the number of points along x
Definition: Data2D.h:219
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
write the data
Definition: Data2D.cpp:345
void set_yy(const std::vector< double > y) override
set interval variable m_y
Definition: Data2D.h:321
std::vector< double > xx() const override
get the x vector
Definition: Data2D.h:241
std::vector< double > yy() const override
get the y vector
Definition: Data2D.h:255
int ysize() const override
get the number of points along y
Definition: Data2D.h:226
std::vector< double > m_x
ordered x axis points
Definition: Data2D.h:60
Data2D()
default constructor
Definition: Data2D.h:83
std::shared_ptr< Data > cut(const double xmin, const double xmax, const double ymin, const double ymax) const
cut the data
Definition: Data2D.cpp:442
virtual void Print(const int precision=4) const override
print the data on screen
Definition: Data2D.cpp:329
Data2D(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.h:122
std::vector< std::vector< double > > IndipendentVariable(const int i=-1, const int j=-1) const override
get the independet variable, to be used in model computation
Definition: Data2D.h:270
void get_error(std::vector< std::vector< double >> &error) const override
get error
Definition: Data2D.cpp:187
int m_ysize
number of points along y
Definition: Data2D.h:69
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
Definition: Data2D.cpp:201
double error(const int i, const int j) const override
get error at index i,j
Definition: Data2D.h:294
double xx(const int i) const override
get the value of x at index i
Definition: Data2D.h:234
std::shared_ptr< Data > as_factory()
static factory used to construct objects of class Data2D
Definition: Data2D.cpp:491
void set_xx(const std::vector< double > x) override
set interval variable m_x
Definition: Data2D.h:315
void get_data(std::vector< std::vector< double >> &data) const override
get data
Definition: Data2D.cpp:173
~Data2D()=default
default destructor
void set_edges_yy(const std::vector< double > edges) override
set interval variable m_edges_yy
Definition: Data2D.h:333
The class Data.
Definition: Data.h:89
std::vector< double > m_edges_yy
bin edges for the y variable
Definition: Data.h:109
virtual std::vector< double > data() const
get data
Definition: Data.h:376
std::vector< double > m_error
standard deviations
Definition: Data.h:103
std::vector< double > m_data
data values
Definition: Data.h:100
Data()=default
default constructor
std::vector< double > m_edges_xx
bin edges for the x variable
Definition: Data.h:106
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
DataType
the data type
Definition: Data.h:53
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38