IODA Bundle
ObsErrors.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_BASE_OBSERRORS_H_
12 #define OOPS_BASE_OBSERRORS_H_
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include <boost/noncopyable.hpp>
19 
20 #include "oops/base/Departures.h"
21 #include "oops/base/ObsError.h"
22 #include "oops/base/ObsSpaces.h"
23 #include "oops/util/Logger.h"
24 #include "oops/util/Printable.h"
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 /// \brief Container for ObsErrors for all observation types that are used in DA
30 template <typename OBS>
31 class ObsErrors : public util::Printable,
32  private boost::noncopyable {
36 
37  public:
38  static const std::string classname() {return "oops::ObsErrors";}
39 
40  ObsErrors(const eckit::Configuration &, const ObsSpaces_ &);
41 
42 /// Accessor and size
43  size_t size() const {return err_.size();}
44  ObsError_ & operator[](const size_t ii) {return err_.at(ii);}
45  const ObsError_ & operator[](const size_t ii) const {return err_.at(ii);}
46 
47 /// Multiply a Departure by \f$R\f$
48  void multiply(Departures_ &) const;
49 /// Multiply a Departure by \f$R^{-1}\f$
50  void inverseMultiply(Departures_ &) const;
51 
52 /// Generate random perturbation
53  void randomize(Departures_ &) const;
54 
55 /// Save obs errors
56  void save(const std::string &) const;
57 
58  /// returns inverse of observation error variance
60 
61  private:
62  void print(std::ostream &) const override;
63  std::vector<ObsError_> err_;
64  const ObsSpaces_ & os_;
65 };
66 
67 // -----------------------------------------------------------------------------
68 
69 template <typename OBS>
70 ObsErrors<OBS>::ObsErrors(const eckit::Configuration & config,
71  const ObsSpaces_ & os) : err_(), os_(os) {
72  std::vector<eckit::LocalConfiguration> obsconf = config.getSubConfigurations();
73  for (size_t jj = 0; jj < os.size(); ++jj) {
74  eckit::LocalConfiguration conf = obsconf[jj].getSubConfiguration("obs error");
75  err_.emplace_back(conf, os[jj]);
76  }
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template <typename OBS>
83  for (size_t jj = 0; jj < err_.size(); ++jj) {
84  err_[jj].multiply(dy[jj]);
85  }
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 template <typename OBS>
92  for (size_t jj = 0; jj < err_.size(); ++jj) {
93  err_[jj].inverseMultiply(dy[jj]);
94  }
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 template <typename OBS>
101  for (size_t jj = 0; jj < err_.size(); ++jj) {
102  err_[jj].randomize(dy[jj]);
103  }
104 }
105 
106 // -----------------------------------------------------------------------------
107 
108 template <typename OBS>
109 void ObsErrors<OBS>::save(const std::string & name) const {
110  for (const auto & err : err_) {
111  err.save(name);
112  }
113 }
114 
115 // -----------------------------------------------------------------------------
116 
117 template <typename OBS>
119  Departures_ invvar(os_);
120  for (size_t jj = 0; jj < err_.size(); ++jj) {
121  invvar[jj] = err_[jj].inverseVariance();
122  }
123  return invvar;
124 }
125 
126 // -----------------------------------------------------------------------------
127 
128 template<typename OBS>
129 void ObsErrors<OBS>::print(std::ostream & os) const {
130  for (size_t jj = 0; jj < err_.size(); ++jj) os << err_[jj] << std::endl;
131 }
132 
133 // -----------------------------------------------------------------------------
134 
135 } // namespace oops
136 
137 #endif // OOPS_BASE_OBSERRORS_H_
Difference between two observation vectors.
Definition: Departures.h:44
Observation error covariance matrix of observations from a single ObsSpace.
Definition: ObsError.h:29
Container for ObsErrors for all observation types that are used in DA.
Definition: ObsErrors.h:32
ObsError< OBS > ObsError_
Definition: ObsErrors.h:34
ObsErrors(const eckit::Configuration &, const ObsSpaces_ &)
Definition: ObsErrors.h:70
void save(const std::string &) const
Save obs errors.
Definition: ObsErrors.h:109
void inverseMultiply(Departures_ &) const
Multiply a Departure by .
Definition: ObsErrors.h:91
void multiply(Departures_ &) const
Multiply a Departure by .
Definition: ObsErrors.h:82
ObsSpaces< OBS > ObsSpaces_
Definition: ObsErrors.h:35
size_t size() const
Accessor and size.
Definition: ObsErrors.h:43
const ObsError_ & operator[](const size_t ii) const
Definition: ObsErrors.h:45
Departures< OBS > Departures_
Definition: ObsErrors.h:33
Departures_ inverseVariance() const
returns inverse of observation error variance
Definition: ObsErrors.h:118
const ObsSpaces_ & os_
Definition: ObsErrors.h:64
void randomize(Departures_ &) const
Generate random perturbation.
Definition: ObsErrors.h:100
void print(std::ostream &) const override
Definition: ObsErrors.h:129
static const std::string classname()
Definition: ObsErrors.h:38
std::vector< ObsError_ > err_
Definition: ObsErrors.h:63
ObsError_ & operator[](const size_t ii)
Definition: ObsErrors.h:44
std::size_t size() const
Access.
Definition: ObsSpaces.h:53
The namespace for the main oops code.