OOPS
ObsData1D.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef LORENZ95_OBSDATA1D_H_
9 #define LORENZ95_OBSDATA1D_H_
10 
11 #include <cmath>
12 #include <ostream>
13 #include <string>
14 #include <vector>
15 
16 #include "eckit/exception/Exceptions.h"
17 
18 #include "oops/base/Variables.h"
19 #include "oops/util/Logger.h"
20 #include "oops/util/missingValues.h"
21 #include "oops/util/ObjectCounter.h"
22 #include "oops/util/Printable.h"
23 
24 #include "lorenz95/ObsTableView.h"
25 
26 namespace lorenz95 {
27 
28 // -----------------------------------------------------------------------------
29 /// Data in observation space
30 
31 template<typename DATATYPE>
32 class ObsData1D : public util::Printable,
33  private util::ObjectCounter<ObsData1D<DATATYPE> > {
34  public:
35  static const std::string classname() {return "lorenz95::ObsData1D";}
36 
37  ObsData1D(const ObsTableView &, const oops::Variables &, const std::string &);
38  ObsData1D(const ObsData1D &);
40 
41  ObsData1D & operator= (const ObsData1D &);
42 
43  void zero();
44  void mask(const ObsData1D<int> &);
45 
46  size_t nobs() const {return data_.size();}
47  DATATYPE & operator[] (const size_t ii) {return data_.at(ii);}
48  const DATATYPE & operator[] (const size_t ii) const {return data_.at(ii);}
49 
50 // I/O
51  void save(const std::string &) const;
52 
53  private:
54  void print(std::ostream &) const;
55 
57  std::vector<DATATYPE> data_;
58 };
59 
60 //-----------------------------------------------------------------------------
61 
62 template<typename DATATYPE>
64  const std::string & name)
65  : obsdb_(ot), data_(ot.nobs())
66 {
67  this->zero();
68  if (!name.empty()) obsdb_.getdb(name, data_);
69 }
70 // -----------------------------------------------------------------------------
71 template<typename DATATYPE>
73  : obsdb_(other.obsdb_), data_(other.data_)
74 {}
75 // -----------------------------------------------------------------------------
76 template<typename DATATYPE>
78  ASSERT(data_.size() == rhs.data_.size());
79  data_ = rhs.data_;
80  return *this;
81 }
82 // -----------------------------------------------------------------------------
83 template<typename DATATYPE>
85  for (size_t jj = 0; jj < data_.size(); ++jj) {
86  data_.at(jj) = static_cast<DATATYPE>(0);
87  }
88 }
89 // -----------------------------------------------------------------------------
90 template<typename DATATYPE>
92  DATATYPE missing = util::missingValue(missing);
93  for (size_t jj = 0; jj < data_.size(); ++jj) {
94  if (mask[jj]) data_.at(jj) = missing;
95  }
96 }
97 // -----------------------------------------------------------------------------
98 template<typename DATATYPE>
99 void ObsData1D<DATATYPE>::save(const std::string & name) const {
100  obsdb_.putdb(name, data_);
101 }
102 // -----------------------------------------------------------------------------
103 template<typename DATATYPE>
104 void ObsData1D<DATATYPE>::print(std::ostream & os) const {
105  ASSERT(data_.size() > 0);
106  DATATYPE zmin = data_.at(0);
107  DATATYPE zmax = data_.at(0);
108  for (size_t jj = 0; jj < data_.size(); ++jj) {
109  if (data_.at(jj) < zmin) zmin = data_.at(jj);
110  if (data_.at(jj) > zmax) zmax = data_.at(jj);
111  }
112  os << "Lorenz 95 nobs= " << data_.size() << " Min=" << zmin << ", Max=" << zmax;
113 }
114 // -----------------------------------------------------------------------------
115 } // namespace lorenz95
116 
117 #endif // LORENZ95_OBSDATA1D_H_
ObsTableView.h
lorenz95::ObsData1D::mask
void mask(const ObsData1D< int > &)
Definition: ObsData1D.h:91
lorenz95::ObsData1D::obsdb_
const ObsTableView & obsdb_
Definition: ObsData1D.h:56
lorenz95::ObsData1D::operator=
ObsData1D & operator=(const ObsData1D &)
Definition: ObsData1D.h:77
lorenz95::ObsData1D::nobs
size_t nobs() const
Definition: ObsData1D.h:46
lorenz95::ObsTableView::getdb
void getdb(const std::string &, std::vector< int > &) const
Definition: ObsTableView.cc:115
lorenz95::ObsData1D::operator[]
DATATYPE & operator[](const size_t ii)
Definition: ObsData1D.h:47
lorenz95::ObsData1D::print
void print(std::ostream &) const
Definition: ObsData1D.h:104
lorenz95::ObsData1D::zero
void zero()
Definition: ObsData1D.h:84
lorenz95::ObsData1D::save
void save(const std::string &) const
Definition: ObsData1D.h:99
lorenz95::ObsData1D::ObsData1D
ObsData1D(const ObsTableView &, const oops::Variables &, const std::string &)
Definition: ObsData1D.h:63
lorenz95::ObsData1D::~ObsData1D
~ObsData1D()
Definition: ObsData1D.h:39
lorenz95::ObsData1D::data_
std::vector< DATATYPE > data_
Definition: ObsData1D.h:57
lorenz95::ObsData1D
Data in observation space.
Definition: BackgroundCheck.h:24
lorenz95::ObsTableView
A Simple Observation Data Handler.
Definition: ObsTableView.h:38
oops::Variables
Definition: oops/base/Variables.h:23
lorenz95
The namespace for the L95 model.
Definition: l95/src/lorenz95/AnalyticInit.cc:17
lorenz95::ObsData1D::classname
static const std::string classname()
Definition: ObsData1D.h:35
Variables.h