OOPS
qg/model/ObsBias.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 
11 #include "model/ObsBias.h"
12 
13 #include <cmath>
14 #include <iostream>
15 #include <sstream>
16 #include <string>
17 
18 #include "eckit/config/Configuration.h"
19 #include "model/ObsBiasIncrement.h"
20 #include "oops/base/Variables.h"
21 #include "oops/util/Logger.h"
22 
23 // -----------------------------------------------------------------------------
24 namespace qg {
25 // -----------------------------------------------------------------------------
26 ObsBias::ObsBias(const ObsSpaceQG &, const eckit::Configuration & conf)
27  : bias_(ntypes, 0.0), active_(false), geovars_(), hdiags_() {
28  oops::Log::info() << "ObsBias: conf = " << conf << std::endl;
29  eckit::LocalConfiguration biasconf;
30  if (conf.has("obs bias")) {
31  conf.get("obs bias", biasconf);
32  active_ = biasconf.has("stream") || biasconf.has("uwind") ||
33  biasconf.has("vwind") || biasconf.has("wspeed");
34  }
35  if (active_) {
36  if (biasconf.has("stream")) bias_[0] = biasconf.getDouble("stream");
37  if (biasconf.has("uwind")) bias_[1] = biasconf.getDouble("uwind");
38  if (biasconf.has("vwind")) bias_[2] = biasconf.getDouble("vwind");
39  if (biasconf.has("wspeed")) bias_[3] = biasconf.getDouble("wspeed");
40  std::string strn = "";
41  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
42  if (jj > 0) strn += ", ";
43  std::ostringstream strs;
44  strs << bias_[jj];
45  strn += strs.str();
46  }
47  oops::Log::info() << "ObsBias::ObsBias created, bias = " << strn << std::endl;
48  }
49 }
50 // -----------------------------------------------------------------------------
51 ObsBias::ObsBias(const ObsBias & other, const bool copy)
52  : bias_(ntypes, 0.0), active_(other.active_),
53  geovars_(other.geovars_), hdiags_(other.hdiags_)
54 {
55  if (active_ && copy) {
56  for (unsigned int jj = 0; jj < ntypes; ++jj) bias_[jj] = other.bias_[jj];
57  }
58 }
59 // -----------------------------------------------------------------------------
61  if (active_) {
62  for (unsigned int jj = 0; jj < ntypes; ++jj) bias_[jj] += dx[jj];
63  }
64  return *this;
65 }
66 // -----------------------------------------------------------------------------
68  if (active_) {
69  for (unsigned int jj = 0; jj < ntypes; ++jj) bias_[jj] = rhs.bias_[jj];
70  }
71  return *this;
72 }
73 // -----------------------------------------------------------------------------
74 double ObsBias::norm() const {
75  double zz = 0.0;
76  if (active_) {
77  double ztmp = 0.0;
78  std::size_t ii = 0;
79  for (unsigned int jj = 0; jj < ntypes; ++jj) {
80  ztmp = bias_[jj]*bias_[jj];
81  zz += ztmp;
82  if (ztmp > 0.0) ++ii;
83  }
84  zz = std::sqrt(zz/ii);
85  }
86  return zz;
87 }
88 // -----------------------------------------------------------------------------
89 void ObsBias::print(std::ostream & os) const {
90  if (active_) {
91  std::string strn = "";
92  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
93  if (jj > 0) strn += ", ";
94  std::ostringstream strs;
95  strs << bias_[jj];
96  strn += strs.str();
97  }
98  os << std::endl << "ObsBias = " << strn;
99  }
100 }
101 // -----------------------------------------------------------------------------
102 } // namespace qg
103 
qg
The namespace for the qg model.
Definition: qg/model/AnalyticInit.cc:13
ObsBiasIncrement.h
qg::ObsBias::norm
double norm() const
Definition: qg/model/ObsBias.cc:74
qg::ObsBias::bias_
std::vector< double > bias_
Definition: qg/model/ObsBias.h:66
qg::ObsBias
Class to handle observation bias parameters.
Definition: qg/model/ObsBias.h:37
qg::ObsSpaceQG
ObsSpace for QG model.
Definition: ObsSpaceQG.h:44
qg::ObsBias::ObsBias
ObsBias(const ObsSpaceQG &, const eckit::Configuration &)
Definition: qg/model/ObsBias.cc:26
ObsBias.h
qg::ObsBias::operator+=
ObsBias & operator+=(const ObsBiasIncrement &)
Definition: qg/model/ObsBias.cc:60
qg::ObsBias::ntypes
static const unsigned int ntypes
Definition: qg/model/ObsBias.h:39
qg::ObsBias::active_
bool active_
Definition: qg/model/ObsBias.h:67
qg::ObsBiasIncrement
Definition: ObsBiasIncrement.h:31
qg::ObsBias::print
void print(std::ostream &) const
Definition: qg/model/ObsBias.cc:89
Variables.h
qg::ObsBias::operator=
ObsBias & operator=(const ObsBias &)
Definition: qg/model/ObsBias.cc:67