FV3 Bundle
ObsErrorDiag.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_GENERIC_OBSERRORDIAG_H_
12 #define OOPS_GENERIC_OBSERRORDIAG_H_
13 
14 #include <sstream>
15 #include <string>
16 
17 #include <boost/scoped_ptr.hpp>
18 
20 #include "oops/util/Logger.h"
21 
22 namespace eckit {
23  class Configuration;
24 }
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 /// Diagonal observation error covariance matrix.
30 
31 template<typename MODEL>
32 class ObsErrorDiag : public ObsErrorBase<MODEL> {
33  typedef typename MODEL::ObsSpace ObsSpace_;
34  typedef typename MODEL::ObsVector ObsVector_;
35 
36  public:
37  ObsErrorDiag(const ObsSpace_ &, const eckit::Configuration &);
38  ~ObsErrorDiag();
39 
40 /// Linearize and reset for inner loop (nothing in this simple case)
41  void linearize(const ObsVector_ &) {}
42 
43 /// Multiply a Departure by \f$R\f$
44  ObsVector_ * multiply(const ObsVector_ &) const;
45 
46 /// Multiply a Departure by \f$R^{-1}\f$
47  ObsVector_ * inverseMultiply(const ObsVector_ &) const;
48 
49 /// Generate random perturbation
50  void randomize(ObsVector_ &) const;
51 
52 /// Get mean error for Jo table
53  double getRMSE() const {return stddev_->rms();}
54 
55  private:
56  void print(std::ostream &) const;
57 
58  boost::scoped_ptr<ObsVector_> stddev_;
59  boost::scoped_ptr<ObsVector_> inverseVariance_;
60 };
61 
62 // =============================================================================
63 
64 template<typename MODEL>
65 ObsErrorDiag<MODEL>::ObsErrorDiag(const ObsSpace_ & obsgeom, const eckit::Configuration & config)
66  : stddev_(), inverseVariance_()
67 {
68  stddev_.reset(new ObsVector_(obsgeom));
69  const std::string col = config.getString("obserror");
70  stddev_->read(col);
71 
72  inverseVariance_.reset(new ObsVector_(*stddev_));
74  inverseVariance_->invert();
75 
76  Log::trace() << "ObsErrorDiag:ObsErrorDiag constructed" << std::endl;
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template<typename MODEL>
83  Log::trace() << "ObsErrorDiag:~ObsErrorDiag destructed" << std::endl;
84 }
85 
86 // -----------------------------------------------------------------------------
87 
88 template<typename MODEL>
89 typename MODEL::ObsVector * ObsErrorDiag<MODEL>::multiply(const ObsVector_ & dy) const {
90  ObsVector_ * res = new ObsVector_(dy);
91  *res /= *inverseVariance_;
92  return res;
93 }
94 
95 // -----------------------------------------------------------------------------
96 
97 template<typename MODEL>
98 typename MODEL::ObsVector * ObsErrorDiag<MODEL>::inverseMultiply(const ObsVector_ & dy) const {
99  ObsVector_ * res = new ObsVector_(dy);
100  *res *= *inverseVariance_;
101  return res;
102 }
103 
104 // -----------------------------------------------------------------------------
105 
106 template<typename MODEL>
108  dy.random();
109  dy *= *stddev_;
110 }
111 
112 // -----------------------------------------------------------------------------
113 
114 template<typename MODEL>
115 void ObsErrorDiag<MODEL>::print(std::ostream & os) const {
116  os << "ObsErrorDiag<MODEL>::print not implemeted yet";
117 }
118 
119 // -----------------------------------------------------------------------------
120 
121 
122 } // namespace oops
123 
124 #endif // OOPS_GENERIC_OBSERRORDIAG_H_
double getRMSE() const
Get mean error for Jo table.
Definition: ObsErrorDiag.h:53
boost::scoped_ptr< ObsVector_ > inverseVariance_
Definition: ObsErrorDiag.h:59
MODEL::ObsSpace ObsSpace_
Definition: ObsErrorDiag.h:33
MODEL::ObsVector ObsVector_
Definition: ObsErrorDiag.h:34
ObsErrorDiag(const ObsSpace_ &, const eckit::Configuration &)
Definition: ObsErrorDiag.h:65
The namespace for the main oops code.
void randomize(ObsVector_ &) const
Generate random perturbation.
Definition: ObsErrorDiag.h:107
void print(std::ostream &) const
Definition: ObsErrorDiag.h:115
ObsVector_ * inverseMultiply(const ObsVector_ &) const
Multiply a Departure by .
Definition: ObsErrorDiag.h:98
Diagonal observation error covariance matrix.
Definition: ObsErrorDiag.h:32
ObsVector_ * multiply(const ObsVector_ &) const
Multiply a Departure by .
Definition: ObsErrorDiag.h:89
Base class for observation error covariance matrices.
Definition: ObsErrorBase.h:39
void linearize(const ObsVector_ &)
Linearize and reset for inner loop (nothing in this simple case)
Definition: ObsErrorDiag.h:41
boost::scoped_ptr< ObsVector_ > stddev_
Definition: ObsErrorDiag.h:58