UFO
src/ufo/GeoVaLs.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2021 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 UFO_GEOVALS_H_
9 #define UFO_GEOVALS_H_
10 
11 #include <memory>
12 #include <ostream>
13 #include <string>
14 #include <vector>
15 
16 #include "oops/base/Variables.h"
17 #include "oops/util/ObjectCounter.h"
18 #include "oops/util/Printable.h"
19 
20 #include "ufo/GeoVaLs.interface.h"
21 
22 namespace eckit {
23  class Configuration;
24 }
25 
26 namespace ioda {
27  class ObsSpace;
28  class Distribution;
29 }
30 
31 namespace ufo {
32  class Locations;
33 
34 // -----------------------------------------------------------------------------
35 
36 /// GeoVaLs: geophysical values at locations
37 
38 class GeoVaLs : public util::Printable,
39  private util::ObjectCounter<GeoVaLs> {
40  public:
41  static const std::string classname() {return "ufo::GeoVaLs";}
42 
43  GeoVaLs(std::shared_ptr<const ioda::Distribution>, const oops::Variables &);
44  GeoVaLs(const Locations &, const oops::Variables &);
45 
46  GeoVaLs(const Locations & locs, const oops::Variables & vars,
47  const std::vector<size_t> & nlevs);
48 
49  GeoVaLs(const eckit::Configuration &, const ioda::ObsSpace &,
50  const oops::Variables &);
51  GeoVaLs(const GeoVaLs &, const int &);
52  GeoVaLs(const GeoVaLs &);
53 
54  ~GeoVaLs();
55 
56  GeoVaLs & operator = (const GeoVaLs &);
57  GeoVaLs & operator *= (const double);
58  GeoVaLs & operator *= (const std::vector<float> &);
59  GeoVaLs & operator += (const GeoVaLs &);
60  GeoVaLs & operator -= (const GeoVaLs &);
61  GeoVaLs & operator *= (const GeoVaLs &);
62  double dot_product_with(const GeoVaLs &) const;
63  void split(GeoVaLs &, GeoVaLs &) const;
64  void merge(const GeoVaLs &, const GeoVaLs &);
65 
66  /// \brief Deprecated method. Allocates GeoVaLs for \p vars variables with
67  /// \p nlev number of levels
68  /// \details Please do not use in any new code. This method is currently
69  /// only used for ObsDiagnostics and will be removed soon. Rely on
70  /// GeoVaLs(const Locations &, const oops::Variables &, const std::vector<size_t> &)
71  /// to allocate GeoVaLs correctly.
72  /// Fails if at least one of the \p vars doesn't exist in GeoVaLs.
73  /// Only allocates variables that haven't been allocated before.
74  /// Fails if one of \p vars is already allocated with number of levels
75  /// different than \p nlev; doesn't reallocate variables that are already
76  /// allocated with \p nlev.
77  void allocate(const int & nlev, const oops::Variables & vars);
78 
79  void zero();
80  void reorderzdir(const std::string &, const std::string &);
81  void random();
82  double rms() const;
83  double normalizedrms(const GeoVaLs &) const;
84 
85  bool has(const std::string & var) const {return vars_.has(var);}
86  const oops::Variables & getVars() const {return vars_;}
87 
88  size_t nlevs(const std::string & var) const;
89  /// Get 2D GeoVaLs for variable \p var (fails for 3D GeoVaLs)
90  void get(std::vector<double> &, const std::string & var) const;
91  /// Get 2D GeoVaLs for variable \p var (fails for 3D GeoVaLs), and convert to float
92  void get(std::vector<float> &, const std::string & var) const;
93  /// Get 2D GeoVaLs for variable \p var (fails for 3D GeoVaLs), and convert to int
94  void get(std::vector<int> &, const std::string & var) const;
95 
96  /// Get GeoVaLs at a specified level
97  void getAtLevel(std::vector<double> &, const std::string &, const int) const;
98  /// Get GeoVaLs at a specified level and convert to float
99  void getAtLevel(std::vector<float> &, const std::string &, const int) const;
100  /// Get GeoVaLs at a specified level and convert to int
101  void getAtLevel(std::vector<int> &, const std::string &, const int) const;
102 
103  /// Get GeoVaLs at a specified location
104  void getAtLocation(std::vector<double> &, const std::string &, const int) const;
105  /// Get GeoVaLs at a specified location and convert to float
106  void getAtLocation(std::vector<float> &, const std::string &, const int) const;
107  /// Get GeoVaLs at a specified location and convert to int
108  void getAtLocation(std::vector<int> &, const std::string &, const int) const;
109 
110  /// Put GeoVaLs for double variable \p var at level \p lev.
111  void putAtLevel(const std::vector<double> & vals, const std::string & var, const int lev) const;
112  /// Put GeoVaLs for float variable \p var at level \p lev.
113  void putAtLevel(const std::vector<float> & vals, const std::string & var, const int lev) const;
114  /// Put GeoVaLs for int variable \p var at level \p lev.
115  void putAtLevel(const std::vector<int> & vals, const std::string & var, const int lev) const;
116 
117  /// Put GeoVaLs for double variable \p var at location \p loc.
118  void putAtLocation(const std::vector<double> & vals, const std::string & var,
119  const int loc) const;
120  /// Put GeoVaLs for float variable \p var at location \p loc.
121  void putAtLocation(const std::vector<float> & vals, const std::string & var, const int loc) const;
122  /// Put GeoVaLs for int variable \p var at location \p loc.
123  void putAtLocation(const std::vector<int> & vals, const std::string & var, const int loc) const;
124 
125  void read(const eckit::Configuration &, const ioda::ObsSpace &);
126  void write(const eckit::Configuration &) const;
127  size_t nlocs() const;
128 
129  int & toFortran() {return keyGVL_;}
130  const int & toFortran() const {return keyGVL_;}
131 
132  private:
133  void print(std::ostream &) const;
134 
136  oops::Variables vars_;
137  std::shared_ptr<const ioda::Distribution> dist_; /// observations MPI distribution
138 };
139 
140 // -----------------------------------------------------------------------------
141 
142 } // namespace ufo
143 
144 #endif // UFO_GEOVALS_H_
GeoVaLs: geophysical values at locations.
GeoVaLs & operator+=(const GeoVaLs &)
Add another GeoVaLs.
Definition: GeoVaLs.cc:205
size_t nlevs(const std::string &var) const
Return number of levels for a specified variable.
Definition: GeoVaLs.cc:310
bool has(const std::string &var) const
std::shared_ptr< const ioda::Distribution > dist_
const int & toFortran() const
void split(GeoVaLs &, GeoVaLs &) const
Split two GeoVaLs.
Definition: GeoVaLs.cc:259
void zero()
Zero out the GeoVaLs.
Definition: GeoVaLs.cc:136
void print(std::ostream &) const
Output GeoVaLs to a stream.
Definition: GeoVaLs.cc:275
void reorderzdir(const std::string &, const std::string &)
Reorder GeoVaLs in vertical dimension based on vertical coordinate variable.
Definition: GeoVaLs.cc:143
GeoVaLs & operator*=(const double)
Multiply by a constant scalar.
Definition: GeoVaLs.cc:177
oops::Variables vars_
double dot_product_with(const GeoVaLs &) const
Scalar product of two GeoVaLs.
Definition: GeoVaLs.cc:229
void write(const eckit::Configuration &) const
Write GeoVaLs to the file.
Definition: GeoVaLs.cc:495
double rms() const
Calculate rms.
Definition: GeoVaLs.cc:151
GeoVaLs(std::shared_ptr< const ioda::Distribution >, const oops::Variables &)
Deprecated default constructor - does not allocate fields.
Definition: GeoVaLs.cc:35
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
Definition: GeoVaLs.cc:330
void putAtLocation(const std::vector< double > &vals, const std::string &var, const int loc) const
Put GeoVaLs for double variable var at location loc.
Definition: GeoVaLs.cc:451
size_t nlocs() const
Return the number of geovals.
Definition: GeoVaLs.cc:502
GeoVaLs & operator-=(const GeoVaLs &)
Subtract another GeoVaLs.
Definition: GeoVaLs.cc:213
void read(const eckit::Configuration &, const ioda::ObsSpace &)
Read GeoVaLs from the file.
Definition: GeoVaLs.cc:487
const oops::Variables & getVars() const
void allocate(const int &nlev, const oops::Variables &vars)
Deprecated method. Allocates GeoVaLs for vars variables with nlev number of levels.
Definition: GeoVaLs.cc:128
double normalizedrms(const GeoVaLs &) const
Calculate normalized rms.
Definition: GeoVaLs.cc:160
void get(std::vector< double > &, const std::string &var) const
Get 2D GeoVaLs for variable var (fails for 3D GeoVaLs)
Definition: GeoVaLs.cc:359
void merge(const GeoVaLs &, const GeoVaLs &)
Merge two GeoVaLs.
Definition: GeoVaLs.cc:267
void putAtLevel(const std::vector< double > &vals, const std::string &var, const int lev) const
Put GeoVaLs for double variable var at level lev.
Definition: GeoVaLs.cc:414
void random()
Randomize GeoVaLs.
Definition: GeoVaLs.cc:170
void getAtLocation(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified location.
Definition: GeoVaLs.cc:380
GeoVaLs & operator=(const GeoVaLs &)
Copy operator.
Definition: GeoVaLs.cc:197
static const std::string classname()
Locations class to handle simple lat-lon-time locations.
Forward declarations.
Definition: ObsAodExt.h:21
Forward declarations.
Definition: ObsAodExt.h:25
Definition: RunCRTM.h:27
int F90goms
Definition: Fortran.h:16