SABER
EstimateParams.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 SABER_OOPS_ESTIMATEPARAMS_H_
12 #define SABER_OOPS_ESTIMATEPARAMS_H_
13 
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 #include "eckit/config/Configuration.h"
21 #include "oops/base/IncrementEnsemble.h"
22 #include "oops/interface/Increment.h"
23 #include "oops/interface/State.h"
24 #include "oops/mpi/mpi.h"
25 #include "oops/runs/Application.h"
26 #include "oops/util/Logger.h"
27 
30 
31 namespace eckit {
32  class Configuration;
33 }
34 
35 namespace oops {
36  class Variables;
37 }
38 
39 namespace saber {
40 
41 template <typename MODEL> class EstimateParams : public oops::Application {
42  typedef oops::Geometry<MODEL> Geometry_;
43  typedef oops::Increment<MODEL> Increment_;
44  typedef oops::State<MODEL> State_;
46  typedef oops::IncrementEnsemble<MODEL> Ensemble_;
47  typedef std::shared_ptr<oops::IncrementEnsemble<MODEL>> EnsemblePtr_;
48 
49  public:
50 // -----------------------------------------------------------------------------
51  static const std::string classname() {return "saber::EstimateParams";}
52  explicit EstimateParams(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {
53  instantiateCovarFactory<MODEL>();
54  }
55 // -----------------------------------------------------------------------------
56  virtual ~EstimateParams() {}
57 // -----------------------------------------------------------------------------
58  int execute(const eckit::Configuration & fullConfig) const {
59  util::Timer timer(classname(), "write");
60 
61  // Setup resolution
62  const eckit::LocalConfiguration resolConfig(fullConfig, "geometry");
63  const Geometry_ resol(resolConfig, this->getComm());
64 
65  // Setup variables
66  const oops::Variables vars(fullConfig, "input variables");
67 
68  // Setup background state
69  const eckit::LocalConfiguration backgroundConfig(fullConfig, "background");
70  State_ xx(resol, backgroundConfig);
71 
72  // Setup time
73  const util::DateTime time = xx.validTime();
74 
75  // Setup ensemble 1
76  EnsemblePtr_ ens1 = NULL;
77  if (fullConfig.has("ensemble")) {
78  const eckit::LocalConfiguration ensembleConfig(fullConfig, "ensemble");
79  ens1.reset(new Ensemble_(ensembleConfig, xx, xx, resol, vars));
80  for (size_t ie = 0; ie < ens1->size(); ++ie) {
81  (*ens1)[ie].toAtlas();
82  }
83  }
84 
85  // Setup ensemble 2
86  EnsemblePtr_ ens2 = NULL;
87  if (fullConfig.has("covariance")) {
88  const eckit::LocalConfiguration covarConfig(fullConfig, "covariance");
89  int ens2_ne = covarConfig.getInt("pseudoens_size");
90  ens2.reset(new Ensemble_(resol, vars, time, ens2_ne));
91  // One time-slot only
92  std::unique_ptr<oops::ModelSpaceCovarianceBase<MODEL>>
93  cov(oops::CovarianceFactory<MODEL>::create(covarConfig, resol, vars, xx, xx));
94  for (int ie = 0; ie < ens2_ne; ++ie) {
95  oops::Log::info() << "Generate pseudo ensemble member " << ie+1 << " / "
96  << ens2_ne << std::endl;
97 
98  // Compute a pseudo ensemble using randomization
99  Increment_ incr(resol, vars, time);
100  cov->randomize(incr);
101  (*ens2)[ie] = incr;
102  (*ens2)[ie].toAtlas();
103  }
104  }
105 
106  // Setup parameters
107  ParametersBUMP_ param(resol, vars, time, fullConfig, ens1, ens2);
108 
109  // Write parameters
110  param.write();
111 
112  return 0;
113  }
114 // -----------------------------------------------------------------------------
115  private:
116  std::string appname() const {
117  return "saber::EstimateParams<" + MODEL::name() + ">";
118  }
119 // -----------------------------------------------------------------------------
120 };
121 
122 } // namespace saber
123 #endif // SABER_OOPS_ESTIMATEPARAMS_H_
saber::EstimateParams
Definition: EstimateParams.h:41
oops
Definition: ErrorCovarianceBUMP.h:33
saber::ParametersBUMP
BUMP parameters.
Definition: ParametersBUMP.h:43
saber::EstimateParams::Increment_
oops::Increment< MODEL > Increment_
Definition: EstimateParams.h:43
saber::EstimateParams::ParametersBUMP_
ParametersBUMP< MODEL > ParametersBUMP_
Definition: EstimateParams.h:45
saber::EstimateParams::classname
static const std::string classname()
Definition: EstimateParams.h:51
ParametersBUMP.h
saber
Definition: type_bump.h:22
saber::ParametersBUMP::write
void write() const
Definition: ParametersBUMP.h:165
eckit
Definition: type_bump.h:18
saber::EstimateParams::Geometry_
oops::Geometry< MODEL > Geometry_
Definition: EstimateParams.h:42
saber::EstimateParams::execute
int execute(const eckit::Configuration &fullConfig) const
Definition: EstimateParams.h:58
saber::EstimateParams::~EstimateParams
virtual ~EstimateParams()
Definition: EstimateParams.h:56
instantiateCovarFactory.h
saber::EstimateParams::EstimateParams
EstimateParams(const eckit::mpi::Comm &comm=oops::mpi::world())
Definition: EstimateParams.h:52
saber::EstimateParams::Ensemble_
oops::IncrementEnsemble< MODEL > Ensemble_
Definition: EstimateParams.h:46
saber::EstimateParams::State_
oops::State< MODEL > State_
Definition: EstimateParams.h:44
saber::EstimateParams::EnsemblePtr_
std::shared_ptr< oops::IncrementEnsemble< MODEL > > EnsemblePtr_
Definition: EstimateParams.h:47
saber::EstimateParams::appname
std::string appname() const
Definition: EstimateParams.h:116