IODA Bundle
GetValuesPost.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2020-2020 UCAR.
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  * In applying this licence, ECMWF does not waive the privileges and immunities
8  * granted to it by virtue of its status as an intergovernmental organisation nor
9  * does it submit to any jurisdiction.
10  */
11 
12 #ifndef OOPS_BASE_GETVALUESPOST_H_
13 #define OOPS_BASE_GETVALUESPOST_H_
14 
15 #include <algorithm>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 #include "oops/base/ObsSpaces.h"
21 #include "oops/base/PostBase.h"
22 #include "oops/base/State.h"
23 #include "oops/base/State4D.h"
24 #include "oops/base/Variables.h"
25 #include "oops/interface/GeoVaLs.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/Duration.h"
30 #include "oops/util/Logger.h"
31 
32 namespace eckit {
33  class Configuration;
34 }
35 
36 namespace oops {
37 
38 /// \brief Fills GeoVaLs with requested variables at requested locations:
39 /// - as a postprocessor during model run.
40 /// - as a method fill() on State4D
41 template <typename MODEL, typename OBS>
42 class GetValuesPost : public PostBase<State<MODEL>> {
49 
50  typedef std::vector<std::unique_ptr<GetValues_>> GetValuesVec_;
51  typedef std::vector<std::unique_ptr<GeoVaLs_>> GeoVaLsVec_;
52  typedef std::vector<std::unique_ptr<Locations_>> LocationsVec_;
53 
54  public:
55 /// \brief Saves Locations and Variables to be processed
56  GetValuesPost(const ObsSpaces_ &,
57  const LocationsVec_ &, const std::vector<Variables> &,
58  const std::vector<eckit::LocalConfiguration> &);
59 
60 /// \brief Returns geovals filled in during the model run
61  const GeoVaLsVec_ & geovals() const {return geovals_;}
62 
63 /// \brief fills in GeoVaLs looping through State4D
64  void fill(const State4D_ &);
65 
66  private:
67 /// \brief initialization before model run: sets up GetValues and allocate GeoVaLs
68  void doInitialize(const State_ &, const util::DateTime &, const util::Duration &) override;
69 /// \brief called at each model step: fill in GeoVaLs for the current time slot
70  void doProcessing(const State_ &) override;
71 
72 // Data
73  util::DateTime winbgn_; /// Begining of assimilation window
74  util::DateTime winend_; /// End of assimilation window
75  util::Duration hslot_; /// Half time slot
76 
77  const LocationsVec_ & locations_; /// locations of observations
78  const std::vector<Variables> geovars_; /// Variables needed from model
79  GetValuesVec_ getvals_; /// GetValues used to fill in GeoVaLs
80  GeoVaLsVec_ geovals_; /// GeoVaLs that are filled in
81  const std::vector<eckit::LocalConfiguration> getvalsconfs_; /// configuration object
82 };
83 
84 // -----------------------------------------------------------------------------
85 
86 template <typename MODEL, typename OBS>
88  const LocationsVec_ & locations,
89  const std::vector<Variables> & vars,
90  const std::vector<eckit::LocalConfiguration> & confs)
91  : PostBase<State_>(),
92  winbgn_(obsdb.windowStart()), winend_(obsdb.windowEnd()), hslot_(),
93  locations_(locations), geovars_(vars), getvalsconfs_(confs)
94 {
95  Log::trace() << "GetValuesPost::GetValuesPost" << std::endl;
96 }
97 
98 // -----------------------------------------------------------------------------
99 template <typename MODEL, typename OBS>
101  Log::trace() << "GetValuesPost::fill start" << std::endl;
102  const size_t nstates = xx.size();
103  util::Duration tstep = winend_ - winbgn_; // for a single state
104  // if using several states, compute the timestep and check that it's the same
105  // for all states
106  if (nstates > 1) {
107  tstep = xx[1].validTime() - xx[0].validTime();
108  for (size_t ii = 1; ii < nstates; ++ii) {
109  ASSERT(tstep == (xx[ii].validTime() - xx[ii-1].validTime()));
110  }
111  }
112  // run GetValues postprocessor looping through all the states
113  doInitialize(xx[0], xx[nstates-1].validTime(), tstep);
114  for (size_t ii = 0; ii < nstates; ++ii) {
115  doProcessing(xx[ii]);
116  }
117  Log::trace() << "GetValuesPost::fill done" << std::endl;
118 }
119 
120 // -----------------------------------------------------------------------------
121 
122 template <typename MODEL, typename OBS>
123 void GetValuesPost<MODEL, OBS>::doInitialize(const State_ & xx, const util::DateTime & end,
124  const util::Duration & tstep) {
125  Log::trace() << "GetValuesPost::doInitialize start" << std::endl;
126  hslot_ = tstep/2;
127 
128  for (size_t jj = 0; jj < locations_.size(); ++jj) {
129  getvals_.emplace_back(new GetValues_(xx.geometry(), *locations_[jj], getvalsconfs_[jj]));
130  geovals_.emplace_back(new GeoVaLs_(*locations_[jj], geovars_[jj],
131  xx.geometry().variableSizes(geovars_[jj])));
132  }
133 
134  Log::trace() << "GetValuesPost::doInitialize done" << std::endl;
135 }
136 
137 // -----------------------------------------------------------------------------
138 
139 template <typename MODEL, typename OBS>
141  Log::trace() << "GetValuesPost::doProcessing start" << std::endl;
142  util::DateTime t1 = std::max(xx.validTime()-hslot_, winbgn_);
143  util::DateTime t2 = std::min(xx.validTime()+hslot_, winend_);
144 
145 // Get state variables at obs locations
146  for (size_t jj = 0; jj < getvals_.size(); ++jj) {
147  getvals_[jj]->fillGeoVaLs(xx, t1, t2, *geovals_[jj]);
148  }
149  Log::trace() << "GetValuesPost::doProcessing done" << std::endl;
150 }
151 
152 // -----------------------------------------------------------------------------
153 
154 } // namespace oops
155 
156 #endif // OOPS_BASE_GETVALUESPOST_H_
Gets values from model State to observation locations (fills GeoVaLs)
Fills GeoVaLs with requested variables at requested locations:
Definition: GetValuesPost.h:42
ObsSpaces< OBS > ObsSpaces_
Definition: GetValuesPost.h:45
GeoVaLs< OBS > GeoVaLs_
Definition: GetValuesPost.h:43
GetValuesVec_ getvals_
Variables needed from model.
Definition: GetValuesPost.h:79
const GeoVaLsVec_ & geovals() const
Returns geovals filled in during the model run.
Definition: GetValuesPost.h:61
std::vector< std::unique_ptr< GetValues_ > > GetValuesVec_
Definition: GetValuesPost.h:50
util::Duration hslot_
End of assimilation window.
Definition: GetValuesPost.h:75
std::vector< std::unique_ptr< Locations_ > > LocationsVec_
Definition: GetValuesPost.h:52
Locations< OBS > Locations_
Definition: GetValuesPost.h:44
void doProcessing(const State_ &) override
called at each model step: fill in GeoVaLs for the current time slot
State4D< MODEL > State4D_
Definition: GetValuesPost.h:47
GetValues< MODEL, OBS > GetValues_
Definition: GetValuesPost.h:48
GetValuesPost(const ObsSpaces_ &, const LocationsVec_ &, const std::vector< Variables > &, const std::vector< eckit::LocalConfiguration > &)
Saves Locations and Variables to be processed.
Definition: GetValuesPost.h:87
const LocationsVec_ & locations_
Half time slot.
Definition: GetValuesPost.h:77
const std::vector< Variables > geovars_
locations of observations
Definition: GetValuesPost.h:78
void doInitialize(const State_ &, const util::DateTime &, const util::Duration &) override
initialization before model run: sets up GetValues and allocate GeoVaLs
std::vector< std::unique_ptr< GeoVaLs_ > > GeoVaLsVec_
Definition: GetValuesPost.h:51
util::DateTime winbgn_
Definition: GetValuesPost.h:73
void fill(const State4D_ &)
fills in GeoVaLs looping through State4D
State< MODEL > State_
Definition: GetValuesPost.h:46
const std::vector< eckit::LocalConfiguration > getvalsconfs_
GeoVaLs that are filled in.
Definition: GetValuesPost.h:81
GeoVaLsVec_ geovals_
GetValues used to fill in GeoVaLs.
Definition: GetValuesPost.h:80
util::DateTime winend_
Begining of assimilation window.
Definition: GetValuesPost.h:74
Locations of observations for observation operator.
Handles post-processing of model fields.
Definition: PostBase.h:33
Four dimensional state (vector of 3D States)
Definition: State4D.h:29
size_t size() const
Get 3D model state.
Definition: State4D.h:43
State class used in oops; subclass of interface class interface::State.
std::vector< size_t > variableSizes(const Variables &) const
Geometry_ geometry() const
Accessor to geometry associated with this State.
const util::DateTime validTime() const
Accessor to the time of this State.
The namespace for the main oops code.