OOPS
ObsVecQG.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2017-2019 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 #include <math.h>
13 
14 #include "oops/util/Logger.h"
15 
16 #include "model/ObsSpaceQG.h"
17 #include "model/ObsVecQG.h"
18 #include "model/QgFortran.h"
19 
20 #include "eckit/exception/Exceptions.h"
21 
22 namespace qg {
23 // -----------------------------------------------------------------------------
25  const std::string & name, const bool fail)
26  : obsdb_(obsdb), keyOvec_(0)
27 {
28  qg_obsvec_setup_f90(keyOvec_, obsdb.obsvariables().size(), obsdb.nobs());
29  if (!name.empty()) {
30  if (fail || obsdb_.has(name)) obsdb_.getdb(name, keyOvec_);
31  }
32 }
33 // -----------------------------------------------------------------------------
35  : obsdb_(other.obsdb_), keyOvec_(0) {
38 }
39 // -----------------------------------------------------------------------------
40 ObsVecQG::ObsVecQG(const ObsSpaceQG & obsdb, const ObsVecQG & other)
41  : obsdb_(obsdb), keyOvec_(0)
42 {
43  qg_obsvec_setup_f90(keyOvec_, obsdb.obsvariables().size(), obsdb.nobs());
44  qg_obsvec_copy_local_f90(keyOvec_, other.keyOvec_, obsdb.localobs().size(),
45  obsdb.localobs().data());
46 }
47 // -----------------------------------------------------------------------------
50 }
51 // -----------------------------------------------------------------------------
53  ASSERT(nobs() == rhs.nobs());
54  const int keyOvecRhs = rhs.keyOvec_;
55  qg_obsvec_copy_f90(keyOvec_, keyOvecRhs);
56  return *this;
57 }
58 // -----------------------------------------------------------------------------
59 ObsVecQG & ObsVecQG::operator*= (const double & zz) {
61  return *this;
62 }
63 // -----------------------------------------------------------------------------
65  ASSERT(nobs() == rhs.nobs());
66  const int keyOvecRhs = rhs.keyOvec_;
67  qg_obsvec_add_f90(keyOvec_, keyOvecRhs);
68  return *this;
69 }
70 // -----------------------------------------------------------------------------
72  ASSERT(nobs() == rhs.nobs());
73  const int keyOvecRhs = rhs.keyOvec_;
74  qg_obsvec_sub_f90(keyOvec_, keyOvecRhs);
75  return *this;
76 }
77 // -----------------------------------------------------------------------------
79  ASSERT(nobs() == rhs.nobs());
80  const int keyOvecRhs = rhs.keyOvec_;
81  qg_obsvec_mul_f90(keyOvec_, keyOvecRhs);
82  return *this;
83 }
84 // -----------------------------------------------------------------------------
86  ASSERT(nobs() == rhs.nobs());
87  const int keyOvecRhs = rhs.keyOvec_;
88  qg_obsvec_div_f90(keyOvec_, keyOvecRhs);
89  return *this;
90 }
91 // -----------------------------------------------------------------------------
94 }
95 // -----------------------------------------------------------------------------
96 void ObsVecQG::axpy(const double & zz, const ObsVecQG & rhs) {
97  ASSERT(nobs() == rhs.nobs());
98  const int keyOvecRhs = rhs.keyOvec_;
99  qg_obsvec_axpy_f90(keyOvec_, zz, keyOvecRhs);
100 }
101 // -----------------------------------------------------------------------------
104 }
105 // -----------------------------------------------------------------------------
108 }
109 // -----------------------------------------------------------------------------
110 double ObsVecQG::dot_product_with(const ObsVecQG & other) const {
111  ASSERT(nobs() == other.nobs());
112  const int keyOvecOther = other.keyOvec_;
113  double zz;
114  qg_obsvec_dotprod_f90(keyOvec_, keyOvecOther, zz);
115  return zz;
116 }
117 // -----------------------------------------------------------------------------
118 double ObsVecQG::rms() const {
119  int iobs;
121  double zz = 0.0;
122  if (iobs > 0) {
124  zz = sqrt(zz/iobs);
125  }
126  return zz;
127 }
128 // -----------------------------------------------------------------------------
129 void ObsVecQG::save(const std::string & name) const {
130  obsdb_.putdb(name, keyOvec_);
131 }
132 // -----------------------------------------------------------------------------
133 Eigen::VectorXd ObsVecQG::packEigen() const {
134  Eigen::VectorXd vec(nobs());
135  double val;
136  for (unsigned int ii = 0; ii < nobs(); ++ii) {
138  vec(ii) = val;
139  }
140  return vec;
141 }
142 // -----------------------------------------------------------------------------
143 void ObsVecQG::read(const std::string & name) {
144  obsdb_.getdb(name, keyOvec_);
145 }
146 // -----------------------------------------------------------------------------
147 void ObsVecQG::print(std::ostream & os) const {
148  double scaling, zmin, zmax, zavg;
149  qg_obsvec_stats_f90(keyOvec_, scaling, zmin, zmax, zavg);
150  std::ios_base::fmtflags f(os.flags());
151  os << obsdb_.obsname() << " nobs= " << nobs()
152  << " Scaling=" << std::setprecision(4) << std::setw(7) << scaling
153  << ", Min=" << std::fixed << std::setprecision(4) << std::setw(12) << zmin
154  << ", Max=" << std::fixed << std::setprecision(4) << std::setw(12) << zmax
155  << ", Average=" << std::fixed << std::setprecision(4) << std::setw(12) << zavg;
156  os.flags(f);
157 }
158 // -----------------------------------------------------------------------------
159 unsigned int ObsVecQG::nobs() const {
160  int iobs;
162  unsigned int nobs(iobs);
163  return nobs;
164 }
165 // -----------------------------------------------------------------------------
166 } // namespace qg
qg::ObsVecQG::~ObsVecQG
~ObsVecQG()
Definition: ObsVecQG.cc:48
qg::qg_obsvec_delete_f90
void qg_obsvec_delete_f90(F90ovec &)
qg::ObsVecQG::read
void read(const std::string &)
Definition: ObsVecQG.cc:143
qg::ObsVecQG::dot_product_with
double dot_product_with(const ObsVecQG &) const
Definition: ObsVecQG.cc:110
ObsSpaceQG.h
qg
The namespace for the qg model.
Definition: qg/model/AnalyticInit.cc:13
QgFortran.h
qg::ObsSpaceQG::obsname
const std::string & obsname() const
observation type
Definition: ObsSpaceQG.h:75
qg::qg_obsvec_setup_f90
void qg_obsvec_setup_f90(F90ovec &, const int &, const int &)
qg::ObsVecQG::print
void print(std::ostream &) const
Definition: ObsVecQG.cc:147
qg::ObsVecQG::random
void random()
Definition: ObsVecQG.cc:106
qg::ObsVecQG::obsdb_
const ObsSpaceQG & obsdb_
Definition: ObsVecQG.h:71
qg::ObsVecQG::keyOvec_
F90ovec keyOvec_
Definition: ObsVecQG.h:72
qg::qg_obsvec_sub_f90
void qg_obsvec_sub_f90(const F90ovec &, const F90ovec &)
qg::ObsSpaceQG::obsvariables
const oops::Variables & obsvariables() const
return variables simulated by ObsOperators
Definition: ObsSpaceQG.h:72
qg::ObsSpaceQG
ObsSpace for QG model.
Definition: ObsSpaceQG.h:44
qg::qg_obsvec_div_f90
void qg_obsvec_div_f90(const F90ovec &, const F90ovec &)
qg::ObsVecQG::zero
void zero()
Definition: ObsVecQG.cc:92
qg::ObsSpaceQG::nobs
int nobs() const
return number of observations (unique locations)
Definition: ObsSpaceQG.cc:199
oops::Variables::size
size_t size() const
Definition: oops/base/Variables.h:37
qg::qg_obsvec_invert_f90
void qg_obsvec_invert_f90(const F90ovec &)
ObsVecQG.h
qg::qg_obsvec_random_f90
void qg_obsvec_random_f90(const ObsSpaceQG &, const F90ovec &)
qg::ObsVecQG::nobs
unsigned int nobs() const
Definition: ObsVecQG.cc:159
qg::ObsVecQG::ObsVecQG
ObsVecQG(const ObsSpaceQG &, const std::string &name="", const bool fail=true)
Definition: ObsVecQG.cc:24
qg::ObsVecQG::invert
void invert()
Definition: ObsVecQG.cc:102
qg::ObsVecQG::rms
double rms() const
Definition: ObsVecQG.cc:118
qg::ObsVecQG::axpy
void axpy(const double &, const ObsVecQG &)
Definition: ObsVecQG.cc:96
qg::ObsVecQG::operator+=
ObsVecQG & operator+=(const ObsVecQG &)
Definition: ObsVecQG.cc:64
qg::qg_obsvec_mul_scal_f90
void qg_obsvec_mul_scal_f90(const F90ovec &, const double &)
qg::qg_obsvec_mul_f90
void qg_obsvec_mul_f90(const F90ovec &, const F90ovec &)
qg::ObsVecQG::packEigen
Eigen::VectorXd packEigen() const
Definition: ObsVecQG.cc:133
qg::ObsVecQG::save
void save(const std::string &) const
Definition: ObsVecQG.cc:129
qg::qg_obsvec_axpy_f90
void qg_obsvec_axpy_f90(const F90ovec &, const double &, const F90ovec &)
qg::ObsVecQG::operator*=
ObsVecQG & operator*=(const double &)
Definition: ObsVecQG.cc:59
qg::ObsSpaceQG::localobs
const std::vector< int > & localobs() const
local observations indices
Definition: ObsSpaceQG.h:78
qg::ObsVecQG::operator/=
ObsVecQG & operator/=(const ObsVecQG &)
Definition: ObsVecQG.cc:85
qg::qg_obsvec_copy_local_f90
void qg_obsvec_copy_local_f90(const F90ovec &, const F90ovec &, const int &, const int *)
qg::ObsVecQG
ObsVecQG class to handle vectors in observation space for QG model.
Definition: ObsVecQG.h:34
run_time_test.val
val
Definition: run_time_test.py:28
qg::qg_obsvec_getat_f90
void qg_obsvec_getat_f90(const F90ovec &, const int &, double &)
qg::qg_obsvec_zero_f90
void qg_obsvec_zero_f90(const F90ovec &)
qg::ObsSpaceQG::getdb
void getdb(const std::string &, int &) const
read data or metadata
Definition: ObsSpaceQG.cc:155
qg::ObsSpaceQG::has
bool has(const std::string &col) const
check if variable is in ObsSpace
Definition: ObsSpaceQG.cc:174
qg::qg_obsvec_add_f90
void qg_obsvec_add_f90(const F90ovec &, const F90ovec &)
qg::qg_obsvec_nobs_f90
void qg_obsvec_nobs_f90(const F90ovec &, int &)
qg::qg_obsvec_copy_f90
void qg_obsvec_copy_f90(const F90ovec &, const F90ovec &)
qg::qg_obsvec_stats_f90
void qg_obsvec_stats_f90(const F90ovec &, double &, double &, double &, double &)
qg::qg_obsvec_dotprod_f90
void qg_obsvec_dotprod_f90(const F90ovec &, const F90ovec &, double &)
qg::ObsVecQG::operator=
ObsVecQG & operator=(const ObsVecQG &)
Definition: ObsVecQG.cc:52
qg::qg_obsvec_clone_f90
void qg_obsvec_clone_f90(F90ovec &, const F90ovec &)
qg::ObsSpaceQG::putdb
void putdb(const std::string &, const int &) const
save data or metadata
Definition: ObsSpaceQG.cc:166
qg::ObsVecQG::operator-=
ObsVecQG & operator-=(const ObsVecQG &)
Definition: ObsVecQG.cc:71