OOPS
Observers.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_OBSERVERS_H_
12 #define OOPS_BASE_OBSERVERS_H_
13 
14 #include <algorithm>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
20 #include "oops/base/Observations.h"
21 #include "oops/base/Observer.h"
22 #include "oops/base/ObsSpaces.h"
23 #include "oops/base/PostBase.h"
24 #include "oops/base/QCData.h"
25 #include "oops/interface/State.h"
26 #include "oops/util/DateTime.h"
27 #include "oops/util/Duration.h"
28 #include "oops/util/Logger.h"
29 
30 namespace oops {
31 
32 /// Computes observation equivalent during model run.
33 
34 // -----------------------------------------------------------------------------
35 
36 template <typename MODEL, typename OBS>
37 class Observers : public PostBase<State<MODEL>> {
45 
46  public:
47  Observers(const eckit::Configuration &, const ObsSpaces_ & obsdb, const ObsAuxCtrls_ &,
48  QCData_ &);
50 
51  const Observations_ & hofx() {return yobs_;}
52 
53  private:
54 // Methods
55  void doInitialize(const State_ &, const util::DateTime &, const util::Duration &) override;
56  void doProcessing(const State_ &) override;
57  void doFinalize(const State_ &) override;
58 
59 // Data
62 
63  util::DateTime winbgn_; //!< Begining of assimilation window
64  util::DateTime winend_; //!< End of assimilation window
65  util::Duration hslot_; //!< Half time slot
66 
67  std::vector<std::shared_ptr<Observer_>> observers_;
68 };
69 
70 // -----------------------------------------------------------------------------
71 
72 template <typename MODEL, typename OBS>
73 Observers<MODEL, OBS>::Observers(const eckit::Configuration & conf, const ObsSpaces_ & obsdb,
74  const ObsAuxCtrls_ & ybias, QCData_ & qc)
75  : PostBase<State_>(),
76  obspace_(obsdb), yobs_(obsdb),
77  winbgn_(obsdb.windowStart()), winend_(obsdb.windowEnd()), hslot_(0), observers_(0)
78 {
79  Log::trace() << "Observers::Observers starting" << std::endl;
80 
81  const int iterout = conf.getInt("iteration", 0);
82  std::vector<eckit::LocalConfiguration> typeconf;
83  conf.get("observations", typeconf);
84  ASSERT(obsdb.size() == typeconf.size());
85  observers_.reserve(obsdb.size());
86  for (size_t jj = 0; jj < obsdb.size(); ++jj) {
87  typeconf[jj].set("iteration", iterout);
88  observers_.emplace_back(new Observer_(typeconf[jj], obsdb[jj],
89  ybias[jj], yobs_[jj], qc.qcFlags(jj), qc.obsErrors(jj)));
90  }
91  Log::trace() << "Observers::Observers done" << std::endl;
92 }
93 
94 // -----------------------------------------------------------------------------
95 
96 template <typename MODEL, typename OBS>
97 void Observers<MODEL, OBS>::doInitialize(const State_ & xx, const util::DateTime & end,
98  const util::Duration & tstep) {
99  Log::trace() << "Observers::doInitialize start" << std::endl;
100  const util::DateTime bgn(xx.validTime());
101  hslot_ = tstep/2;
102 
103  for (size_t jj = 0; jj < observers_.size(); ++jj) {
104  observers_[jj]->doInitialize(xx, winbgn_, winend_);
105  }
106  Log::trace() << "Observers::doInitialize done" << std::endl;
107 }
108 
109 // -----------------------------------------------------------------------------
110 
111 template <typename MODEL, typename OBS>
113  Log::trace() << "Observers::doProcessing start" << std::endl;
114  util::DateTime t1 = std::max(xx.validTime()-hslot_, winbgn_);
115  util::DateTime t2 = std::min(xx.validTime()+hslot_, winend_);
116 
117 // Get state variables at obs locations
118  for (size_t jj = 0; jj < observers_.size(); ++jj) {
119  observers_[jj]->doProcessing(xx, t1, t2);
120  }
121  Log::trace() << "Observers::doProcessing done" << std::endl;
122 }
123 
124 // -----------------------------------------------------------------------------
125 
126 template <typename MODEL, typename OBS>
128  Log::trace() << "Observers::doFinalize start" << std::endl;
129  for (size_t jj = 0; jj < observers_.size(); ++jj) {
130  observers_[jj]->doFinalize();
131  }
132  Log::trace() << "Observers::doFinalize done" << std::endl;
133 }
134 
135 // -----------------------------------------------------------------------------
136 
137 } // namespace oops
138 
139 #endif // OOPS_BASE_OBSERVERS_H_
oops::State::validTime
const util::DateTime validTime() const
Time.
Definition: oops/interface/State.h:60
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::QCData
container for QC-related things (flags & obserrors)
Definition: QCData.h:24
oops::Observers::ObsAuxCtrls_
ObsAuxControls< OBS > ObsAuxCtrls_
Definition: Observers.h:39
oops::Observers::yobs_
Observations_ yobs_
Definition: Observers.h:61
oops::ObsAuxControls
Definition: ObsAuxControls.h:26
oops::Observers::winend_
util::DateTime winend_
End of assimilation window.
Definition: Observers.h:64
QCData.h
ObsSpaces.h
Observer.h
oops::Observers::Observers
Observers(const eckit::Configuration &, const ObsSpaces_ &obsdb, const ObsAuxCtrls_ &, QCData_ &)
Definition: Observers.h:73
oops::Observers::Observer_
Observer< MODEL, OBS > Observer_
Definition: Observers.h:41
oops::Observers::winbgn_
util::DateTime winbgn_
Begining of assimilation window.
Definition: Observers.h:63
oops::Observers::ObsSpaces_
ObsSpaces< OBS > ObsSpaces_
Definition: Observers.h:42
oops::Observers
Computes observation equivalent during model run.
Definition: Observers.h:37
oops::Observers::QCData_
QCData< OBS > QCData_
Definition: Observers.h:43
oops::Observers::doInitialize
void doInitialize(const State_ &, const util::DateTime &, const util::Duration &) override
Definition: Observers.h:97
oops::Observers::~Observers
~Observers()
Definition: Observers.h:49
PostBase.h
ObsAuxControls.h
oops::Observers::State_
State< MODEL > State_
Definition: Observers.h:44
oops::ObsSpaces::size
std::size_t size() const
Access.
Definition: ObsSpaces.h:57
Observations.h
oops::PostBase
Handles post-processing of model fields.
Definition: PostBase.h:33
oops::Observers::obspace_
ObsSpaces_ obspace_
Definition: Observers.h:60
oops::Observers::hofx
const Observations_ & hofx()
Definition: Observers.h:51
oops::Observers::doProcessing
void doProcessing(const State_ &) override
Actual processing.
Definition: Observers.h:112
oops::Observers::doFinalize
void doFinalize(const State_ &) override
Definition: Observers.h:127
oops::Observer
Computes observation equivalent for a single ObsType.
Definition: Observer.h:39
oops::Observations
Observations Class.
Definition: oops/base/Departures.h:30
oops::QCData::obsErrors
const ObsDataPtr_< float > obsErrors(const size_t ii) const
accessor to Obs errors
Definition: QCData.h:37
oops::State
Encapsulates the model state.
Definition: CostJbState.h:28
oops::Observers::Observations_
Observations< OBS > Observations_
Definition: Observers.h:40
oops::Observers::observers_
std::vector< std::shared_ptr< Observer_ > > observers_
Definition: Observers.h:67
State.h
oops::ObsSpaces
Definition: ObsSpaces.h:41
oops::Observers::hslot_
util::Duration hslot_
Half time slot.
Definition: Observers.h:65
oops::GeoVaLs
Definition: oops/interface/GeoVaLs.h:32
oops::Observers::GeoVaLs_
GeoVaLs< OBS > GeoVaLs_
Definition: Observers.h:38
oops::QCData::qcFlags
const ObsDataPtr_< int > qcFlags(const size_t ii) const
accessor to QC flag
Definition: QCData.h:35