FV3 Bundle
Observations.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_OBSERVATIONS_H_
12 #define OOPS_BASE_OBSERVATIONS_H_
13 
14 #include <cstddef>
15 #include <ostream>
16 #include <string>
17 #include <vector>
18 
19 #include <boost/ptr_container/ptr_vector.hpp>
20 #include <boost/shared_ptr.hpp>
21 
22 #include "eckit/config/Configuration.h"
23 #include "oops/base/Departures.h"
24 #include "oops/base/ObsSpaces.h"
25 #include "oops/interface/GeoVaLs.h"
29 #include "oops/util/abor1_cpp.h"
30 #include "oops/util/DateTime.h"
31 #include "oops/util/Logger.h"
32 #include "oops/util/Printable.h"
33 
34 namespace oops {
35 
36 template<typename MODEL> class Observations;
37 
38 /// Observations Class.
39 /*!
40  * Contains observed values or their model equivalents and the associated
41  * observation operator.
42  */
43 
44 // -----------------------------------------------------------------------------
45 template <typename MODEL> class Observations : public util::Printable {
52 
53  public:
54  explicit Observations(const ObsSpace_ &);
55  explicit Observations(const Observations &);
56  ~Observations();
58 
59 /// Access
60  std::size_t size() const {return obs_.size();}
61  ObsVector_ & operator[](const std::size_t ii) {return obs_.at(ii);}
62  const ObsVector_ & operator[](const std::size_t ii) const {return obs_.at(ii);}
63 
64 /// Interactions with Departures
65  std::vector<boost::shared_ptr<ObsVector_> > operator-(const Observations & other) const;
67 
68 /// Save observations values
69  void save(const std::string &) const;
70  void read(const eckit::Configuration &);
71 
72  private:
73  void print(std::ostream &) const;
74 
75  boost::ptr_vector<ObsVector_> obs_;
76 };
77 
78 // =============================================================================
79 
80 template <typename MODEL>
82 {
83  for (std::size_t jj = 0; jj < obsdb.size(); ++jj) {
84  obs_.push_back(new ObsVector_(obsdb[jj]));
85  }
86  Log::trace() << "Observations created" << std::endl;
87 }
88 // -----------------------------------------------------------------------------
89 template <typename MODEL>
90 Observations<MODEL>::Observations(const Observations & other): obs_(other.obs_)
91 {
92  Log::trace() << "Observations copy-created" << std::endl;
93 }
94 // -----------------------------------------------------------------------------
95 template <typename MODEL>
97  Log::trace() << "Observations destructed" << std::endl;
98 }
99 // -----------------------------------------------------------------------------
100 template <typename MODEL>
102  for (std::size_t jj = 0; jj < obs_.size(); ++jj) {
103  obs_[jj] = rhs.obs_[jj];
104  }
105  return *this;
106 }
107 // -----------------------------------------------------------------------------
108 template <typename MODEL>
109 std::vector<boost::shared_ptr<ObsVector<MODEL> > >
111  std::vector<boost::shared_ptr<ObsVector_> > out;
112  for (std::size_t jj = 0; jj < obs_.size(); ++jj) {
113  boost::shared_ptr<ObsVector_> ovec(new ObsVector_(obs_[jj], true));
114  *ovec -= other.obs_[jj];
115  out.push_back(ovec);
116  }
117  return out;
118 }
119 // -----------------------------------------------------------------------------
120 template <typename MODEL>
122  for (std::size_t jj = 0; jj < obs_.size(); ++jj) {
123  obs_[jj] += dy[jj];
124  }
125  return *this;
126 }
127 // -----------------------------------------------------------------------------
128 template <typename MODEL>
129 void Observations<MODEL>::save(const std::string & name) const {
130  for (std::size_t jj = 0; jj < obs_.size(); ++jj) {
131  obs_[jj].save(name);
132  }
133 }
134 // -----------------------------------------------------------------------------
135 template <typename MODEL>
136 void Observations<MODEL>::read(const eckit::Configuration & config) {
137  std::vector<eckit::LocalConfiguration> conf;
138  config.get("ObsTypes", conf);
139  for (std::size_t jj = 0; jj < obs_.size(); ++jj) {
140  const std::string name = conf[jj].getString("ObsData.obsvalue");
141  obs_[jj].read(name);
142  }
143  Log::trace() << "Observations:Observations have been read" << std::endl;
144 }
145 // -----------------------------------------------------------------------------
146 template <typename MODEL>
147 void Observations<MODEL>::print(std::ostream & os) const {
148  for (std::size_t jj = 0; jj < obs_.size(); ++jj) os << obs_[jj];
149 }
150 // -----------------------------------------------------------------------------
151 } // namespace oops
152 
153 #endif // OOPS_BASE_OBSERVATIONS_H_
std::size_t size() const
Access.
Definition: Observations.h:60
ObsVector< MODEL > ObsVector_
Definition: Observations.h:51
boost::ptr_vector< ObsVector_ > obs_
Definition: Observations.h:75
Difference between two observation vectors.
Definition: Departures.h:36
Definition: conf.py:1
Departures< MODEL > Departures_
Definition: Observations.h:46
Observations Class.
Definition: Observations.h:36
character(len=32) name
The namespace for the main oops code.
Observations & operator+=(const Departures_ &)
Definition: Observations.h:121
Observations & operator=(const Observations &)
Definition: Observations.h:101
ObsAuxControl< MODEL > ObsAuxCtrl_
Definition: Observations.h:48
void save(const std::string &) const
Save observations values.
Definition: Observations.h:129
ObsOperator< MODEL > ObsOperator_
Definition: Observations.h:49
ObsSpaces< MODEL > ObsSpace_
Definition: Observations.h:50
void read(const eckit::Configuration &)
Definition: Observations.h:136
GeoVaLs< MODEL > GeoVaLs_
Definition: Observations.h:47
std::vector< boost::shared_ptr< ObsVector_ > > operator-(const Observations &other) const
Interactions with Departures.
Definition: Observations.h:110
void print(std::ostream &) const
Definition: Observations.h:147
Observations(const ObsSpace_ &)
Definition: Observations.h:81
const ObsVector_ & operator[](const std::size_t ii) const
Definition: Observations.h:62
std::size_t size() const
Access.
Definition: ObsSpaces.h:51
ObsVector_ & operator[](const std::size_t ii)
Definition: Observations.h:61