FV3 Bundle
EnsHofX.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018 UCAR
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  */
7 
8 #ifndef OOPS_RUNS_ENSHOFX_H_
9 #define OOPS_RUNS_ENSHOFX_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include <boost/scoped_ptr.hpp>
15 #include <boost/shared_ptr.hpp>
16 
17 #include "eckit/config/LocalConfiguration.h"
19 #include "oops/base/ObsEnsemble.h"
20 #include "oops/base/Observations.h"
21 #include "oops/base/Observer.h"
22 #include "oops/base/ObsFilters.h"
23 #include "oops/base/ObsOperators.h"
24 #include "oops/base/ObsSpaces.h"
26 #include "oops/base/StateInfo.h"
28 #include "oops/interface/Model.h"
31 #include "oops/interface/State.h"
32 #include "oops/runs/Application.h"
33 #include "oops/util/DateTime.h"
34 #include "oops/util/Duration.h"
35 #include "oops/util/Logger.h"
36 
37 namespace oops {
38 
39 template <typename MODEL> class EnsHofX : public Application {
50 
51  public:
52 // -----------------------------------------------------------------------------
53  EnsHofX() {
54  instantiateFilterFactory<MODEL>();
55  }
56 // -----------------------------------------------------------------------------
57  virtual ~EnsHofX() {}
58 // -----------------------------------------------------------------------------
59  int execute(const eckit::Configuration & fullConfig) const {
60 // Setup observation window
61  const eckit::LocalConfiguration windowConf(fullConfig, "Assimilation Window");
62  const util::Duration winlen(windowConf.getString("Length"));
63  const util::DateTime winbgn(windowConf.getString("Begin"));
64  const util::DateTime winend(winbgn + winlen);
65  Log::info() << "Observation window is:" << windowConf << std::endl;
66 
67 // Setup resolution
68  const eckit::LocalConfiguration resolConfig(fullConfig, "Geometry");
69  const Geometry_ resol(resolConfig);
70 
71 // Setup Model
72  const eckit::LocalConfiguration modelConfig(fullConfig, "Model");
73  const Model_ model(resol, modelConfig);
74 
75 // Setup observation bias
76  eckit::LocalConfiguration biasConf;
77  fullConfig.get("ObsBias", biasConf);
78  ObsAuxCtrl_ ybias(biasConf);
79 
80 // Setup observations
81  eckit::LocalConfiguration obsconf(fullConfig, "Observations");
82  Log::debug() << "Observations configuration is:" << obsconf << std::endl;
83  ObsSpace_ obsdb(obsconf, winbgn, winend);
84  ObsOperator_ hop(obsdb);
85 
86 // Setup QC filters
87  eckit::LocalConfiguration filterConf;
88  obsconf.get("ObsFilters", filterConf);
89  ObsFilters_ filter(obsdb, obsconf);
90 
91 // Setup initial states
92  const eckit::LocalConfiguration initialConfig(fullConfig, "Initial Condition");
93  std::vector<eckit::LocalConfiguration> members;
94  initialConfig.get("state", members);
95  Log::debug() << "EnsHofX: using " << members.size() << " states." << std::endl;
96 
97 // Setup ObsEnsemble
98  ObsEnsemble_ obsens(obsdb, members.size());
99 // Loop on all ensemble members
100  for (unsigned jj = 0; jj < members.size(); ++jj) {
101 // Setup initial state for jj-th member
102  Log::info() << jj << " member initial configuration is:" << members[jj] << std::endl;
103  State_ xx(resol, model.variables(), members[jj]);
104  Log::test() << jj << " member initial state: " << xx << std::endl;
105 
106 // Setup augmented state
107  ModelAux_ moderr(resol, members[jj]);
108 
109 // Setup postprocessor: forecast outputs
111  eckit::LocalConfiguration prtConf;
112  fullConfig.get("Prints", prtConf);
113  post.enrollProcessor(new StateInfo<State_>("fc", prtConf));
114 
115 // Setup postprocessor: Observer
116  boost::shared_ptr<Observer<MODEL, State_> >
117  pobs(new Observer<MODEL, State_>(obsdb, hop, ybias, filter));
118  post.enrollProcessor(pobs);
119 
120 // Compute H(x)
121  model.forecast(xx, moderr, winlen, post);
122  Log::info() << jj << " member: finished observation computation" << std::endl;
123  Log::test() << jj << " member final state: " << xx << std::endl;
124 
125 // Save H(x)
126  boost::scoped_ptr<Observations_> yobs(pobs->release());
127  Log::test() << jj << " member H(x): " << *yobs << std::endl;
128  obsens[jj] = *yobs;
129  obsens[jj].save("hofx_"+std::to_string(jj+1));
130  }
131 
132  return 0;
133  }
134 // -----------------------------------------------------------------------------
135  private:
136  std::string appname() const {
137  return "oops::EnsHofX<" + MODEL::name() + ">";
138  }
139 // -----------------------------------------------------------------------------
140 };
141 
142 } // namespace oops
143 
144 #endif // OOPS_RUNS_ENSHOFX_H_
Observations< MODEL > Observations_
Definition: EnsHofX.h:44
ObsOperators< MODEL > ObsOperator_
Definition: EnsHofX.h:47
ObsSpaces< MODEL > ObsSpace_
Definition: EnsHofX.h:48
ModelAuxControl< MODEL > ModelAux_
Definition: EnsHofX.h:42
ObsFilters< MODEL > ObsFilters_
Definition: EnsHofX.h:46
Geometry< MODEL > Geometry_
Definition: EnsHofX.h:40
int execute(const eckit::Configuration &fullConfig) const
Definition: EnsHofX.h:59
Encapsulates the model state.
Observations Class.
Definition: Observations.h:36
program test
ObsAuxControl< MODEL > ObsAuxCtrl_
Definition: EnsHofX.h:43
character(len=32) name
The namespace for the main oops code.
logical debug
Definition: mpp.F90:1297
Handles writing-out of forecast fields.
Definition: StateInfo.h:28
subroutine, public info(self)
State< MODEL > State_
Definition: EnsHofX.h:49
Model< MODEL > Model_
Definition: EnsHofX.h:41
virtual ~EnsHofX()
Definition: EnsHofX.h:57
Encapsulates the nonlinear forecast model.
std::string appname() const
Definition: EnsHofX.h:136
Computes observation equivalent during model run.
Definition: Observer.h:43
ObsEnsemble< MODEL > ObsEnsemble_
Definition: EnsHofX.h:45
Control model post processing.
Definition: PostProcessor.h:31
Ensemble.
Definition: ObsEnsemble.h:23
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:39
std::size_t size() const
Access.
Definition: ObsSpaces.h:51