FV3 Bundle
qg/model/ObsBiasCovariance.cc
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 
12 
13 #include <cmath>
14 #include <iostream>
15 #include <random>
16 #include <sstream>
17 #include <string>
18 #include <vector>
19 
20 #include "eckit/config/LocalConfiguration.h"
21 #include "model/ObsBias.h"
22 #include "model/ObsBiasIncrement.h"
23 #include "oops/util/Logger.h"
24 
25 // -----------------------------------------------------------------------------
26 namespace qg {
27 // -----------------------------------------------------------------------------
28 ObsBiasCovariance::ObsBiasCovariance(const eckit::Configuration & conf)
29  : conf_(conf), variance_(ObsBias::ntypes, 0.0)
30 {
31 // if (!conf.empty()) {
32  std::vector<double> zz(4, 0.0);
33  if (conf.has("stream")) zz[0] = conf.getDouble("stream");
34  if (conf.has("uwind")) zz[1] = conf.getDouble("uwind");
35  if (conf.has("vwind")) zz[2] = conf.getDouble("vwind");
36  if (conf.has("wspeed")) zz[3] = conf.getDouble("wspeed");
37 
38  std::string strn = "";
39  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
40  if (jj > 0) strn += ", ";
41  if (std::abs(zz[jj]) > 1.0e-8) {
42  variance_[jj] = zz[jj] * zz[jj];
43  std::ostringstream strs;
44  strs << variance_[jj];
45  strn += strs.str();
46  } else {
47  variance_[jj] = 0.0;
48  strn += "0.0";
49  }
50  }
51  oops::Log::info() << "ObsBiasCovariance created, variances = " << strn << std::endl;
52 // }
53 }
54 // -----------------------------------------------------------------------------
56  ObsBiasIncrement & dxout) const {
57  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
58  if (variance_[jj] > 0.0) {
59  dxout[jj] = dxin[jj] * variance_[jj];
60  } else {
61  dxout[jj] = 0.0;
62  }
63  }
64 }
65 // -----------------------------------------------------------------------------
67  ObsBiasIncrement & dxout) const {
68  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
69  if (variance_[jj] > 0.0) {
70  dxout[jj] = dxin[jj] / variance_[jj];
71  } else {
72  dxout[jj] = 0.0;
73  }
74  }
75 }
76 // -----------------------------------------------------------------------------
78  static std::mt19937 generator(4);
79  static std::normal_distribution<double> distribution(0.0, 1.0);
80  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
81  if (variance_[jj] > 0.0) {
82  double zz = distribution(generator);
83  dx[jj] = zz * std::sqrt(variance_[jj]);
84  } else {
85  dx[jj] = 0.0;
86  }
87  }
88 }
89 // -----------------------------------------------------------------------------
90 void ObsBiasCovariance::print(std::ostream & os) const {
91  os << "ObsBiasCovariance::print not implemented";
92 }
93 // -----------------------------------------------------------------------------
94 } // namespace qg
void print(std::ostream &) const
Definition: conf.py:1
void multiply(const ObsBiasIncrement &, ObsBiasIncrement &) const
void randomize(ObsBiasIncrement &) const
Class to handle observation bias parameters.
real(fp), parameter, public e
ObsBiasCovariance(const eckit::Configuration &)
Constructor, destructor.
void inverseMultiply(const ObsBiasIncrement &, ObsBiasIncrement &) const
subroutine, public info(self)
static const unsigned int ntypes
The namespace for the qg model.