OOPS
oops/interface/ObsErrorCovariance.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_INTERFACE_OBSERRORCOVARIANCE_H_
12 #define OOPS_INTERFACE_OBSERRORCOVARIANCE_H_
13 
14 #include <memory>
15 #include <string>
16 
17 
18 #include "oops/base/ObsErrorBase.h"
21 
22 namespace eckit {
23  class Configuration;
24 }
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 /// Observation error covariance matrix
30 /*!
31  * This class provides the operations associated with the observation
32  * error covariance matrix. It wraps model specific observation error covariances.
33  */
34 
35 template <typename OBS, typename OBSERR>
39 
40  public:
41  static const std::string classname() {return "oops::ObsErrorCovariance";}
42 
43  ObsErrorCovariance(const eckit::Configuration &, const ObsSpace_ &, const Variables &);
45 
46 /// Multiply a Departure by \f$R\f$ and \f$R^{-1}\f$
47  void multiply(ObsVector_ &) const;
48  void inverseMultiply(ObsVector_ &) const;
49 
50 /// Generate random perturbation
51  void randomize(ObsVector_ &) const;
52 
53 /// Get mean error for Jo table
54  double getRMSE() const;
55 
56  private:
57  void print(std::ostream &) const;
58  std::unique_ptr<OBSERR> covar_;
59 };
60 
61 // ====================================================================================
62 
63 template <typename OBS, typename OBSERR>
64 ObsErrorCovariance<OBS, OBSERR>::ObsErrorCovariance(const eckit::Configuration & conf,
65  const ObsSpace_ & obsdb,
66  const Variables & obsvar) : covar_() {
67  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::ObsErrorCovariance starting" << std::endl;
68  util::Timer timer(classname(), "ObsErrorCovariance");
69  covar_.reset(new OBSERR(conf, obsdb, obsvar));
70  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::ObsErrorCovariance done" << std::endl;
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 template <typename OBS, typename OBSERR>
77  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::~ObsErrorCovariance starting" << std::endl;
78  util::Timer timer(classname(), "~ObsErrorCovariance");
79  covar_.reset();
80  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::~ObsErrorCovariance done" << std::endl;
81 }
82 
83 // -----------------------------------------------------------------------------
84 
85 template <typename OBS, typename OBSERR>
87  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::multiply starting" << std::endl;
88  util::Timer timer(classname(), "multiply");
89  covar_->multiply(dy.obsvector());
90  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::multiply done" << std::endl;
91 }
92 
93 // -----------------------------------------------------------------------------
94 
95 template <typename OBS, typename OBSERR>
97  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::inverseMultiply starting" << std::endl;
98  util::Timer timer(classname(), "inverseMultiply");
99  covar_->inverseMultiply(dy.obsvector());
100  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::inverseMultiply done" << std::endl;
101 }
102 
103 // -----------------------------------------------------------------------------
104 
105 template <typename OBS, typename OBSERR>
107  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::randomize starting" << std::endl;
108  util::Timer timer(classname(), "randomize");
109  covar_->randomize(dy.obsvector());
110  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::randomize done" << std::endl;
111 }
112 
113 // -----------------------------------------------------------------------------
114 
115 template <typename OBS, typename OBSERR>
117  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::getRMSE starting" << std::endl;
118  util::Timer timer(classname(), "getRMSE");
119  double zz = covar_->getRMSE();
120  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::getRMSE done" << std::endl;
121  return zz;
122 }
123 
124 // -----------------------------------------------------------------------------
125 
126 template<typename OBS, typename OBSERR>
127 void ObsErrorCovariance<OBS, OBSERR>::print(std::ostream & os) const {
128  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::print starting" << std::endl;
129  util::Timer timer(classname(), "print");
130  os << *covar_;
131  Log::trace() << "ObsErrorCovariance<OBS, OBSERR>::print done" << std::endl;
132 }
133 
134 // -----------------------------------------------------------------------------
135 
136 } // namespace oops
137 
138 #endif // OOPS_INTERFACE_OBSERRORCOVARIANCE_H_
oops::ObsVector::obsvector
ObsVector_ & obsvector()
Interfacing.
Definition: oops/interface/ObsVector.h:54
oops::ObsErrorCovariance::~ObsErrorCovariance
~ObsErrorCovariance()
Definition: oops/interface/ObsErrorCovariance.h:76
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::ObsErrorCovariance::multiply
void multiply(ObsVector_ &) const
Multiply a Departure by and .
Definition: oops/interface/ObsErrorCovariance.h:86
oops::ObsSpace
Definition: oops/interface/ObsSpace.h:42
oops::ObsErrorBase
Base class for observation error covariance matrices.
Definition: ObsErrorBase.h:32
oops::ObsErrorCovariance::inverseMultiply
void inverseMultiply(ObsVector_ &) const
Multiply a Departure dy by .
Definition: oops/interface/ObsErrorCovariance.h:96
oops::ObsErrorCovariance::print
void print(std::ostream &) const
Definition: oops/interface/ObsErrorCovariance.h:127
oops::ObsErrorCovariance::ObsErrorCovariance
ObsErrorCovariance(const eckit::Configuration &, const ObsSpace_ &, const Variables &)
Definition: oops/interface/ObsErrorCovariance.h:64
oops::ObsErrorCovariance
Observation error covariance matrix.
Definition: oops/interface/ObsErrorCovariance.h:36
oops::ObsVector
Definition: oops/interface/ObsSpace.h:36
eckit
Definition: FieldL95.h:22
oops::ObsErrorCovariance::ObsSpace_
ObsSpace< OBS > ObsSpace_
Definition: oops/interface/ObsErrorCovariance.h:37
oops::ObsErrorCovariance::randomize
void randomize(ObsVector_ &) const
Generate random perturbation.
Definition: oops/interface/ObsErrorCovariance.h:106
ObsSpace.h
oops::ObsErrorCovariance::getRMSE
double getRMSE() const
Get mean error for Jo table.
Definition: oops/interface/ObsErrorCovariance.h:116
oops::ObsErrorCovariance::classname
static const std::string classname()
Definition: oops/interface/ObsErrorCovariance.h:41
oops::Variables
Definition: oops/base/Variables.h:23
ObsVector.h
ObsErrorBase.h
oops::ObsErrorCovariance::covar_
std::unique_ptr< OBSERR > covar_
Definition: oops/interface/ObsErrorCovariance.h:58
oops::ObsErrorCovariance::ObsVector_
ObsVector< OBS > ObsVector_
Definition: oops/interface/ObsErrorCovariance.h:38