OOPS
ObsSpaceQG.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2017-2020 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 #ifndef QG_MODEL_OBSSPACEQG_H_
13 #define QG_MODEL_OBSSPACEQG_H_
14 
15 #include <map>
16 #include <memory>
17 #include <ostream>
18 #include <string>
19 #include <vector>
20 
21 #include "eckit/geometry/Point2.h"
22 #include "eckit/mpi/Comm.h"
23 
24 #include "oops/base/ObsSpaceBase.h"
25 #include "oops/base/Variables.h"
26 #include "oops/util/DateTime.h"
27 #include "oops/util/parameters/OptionalParameter.h"
28 #include "oops/util/parameters/Parameters.h"
29 #include "oops/util/parameters/RequiredParameter.h"
30 
31 #include "oops/qg/LocationsQG.h"
32 #include "oops/qg/ObsIteratorQG.h"
33 #include "oops/qg/QgFortran.h"
34 
35 namespace qg {
36  class ObsIteratorQG;
37 
38 /// Contents of the `obsdatain` or `obsdataout` YAML section.
39 class ObsDataParameters : public oops::Parameters {
40  OOPS_CONCRETE_PARAMETERS(ObsDataParameters, Parameters)
41 
42  public:
43  /// File path.
44  oops::RequiredParameter<std::string> obsfile{"obsfile", this};
45 };
46 
47 /// Options controlling generation of artificial observations.
48 class ObsGenerateParameters : public oops::Parameters {
49  OOPS_CONCRETE_PARAMETERS(ObsGenerateParameters, Parameters)
50 
51  public:
52  oops::RequiredParameter<util::Duration> begin{"begin", this};
53  oops::RequiredParameter<util::Duration> obsPeriod{"obs_period", this};
54  /// Number of observations to generate in each time slot.
55  oops::RequiredParameter<int> obsDensity{"obs_density", this};
56  oops::RequiredParameter<int> nval{"nval", this};
57  oops::RequiredParameter<double> obsError{"obs_error", this};
58 };
59 
60 /// \brief Configuration parameters for the QG model's ObsSpace.
62  OOPS_CONCRETE_PARAMETERS(ObsSpaceQGParameters, ObsSpaceParametersBase)
63 
64  public:
65  /// Type of observations.
66  oops::RequiredParameter<std::string> obsType{"obs type", this};
67  /// File from which to load observations.
68  oops::OptionalParameter<ObsDataParameters> obsdatain{"obsdatain", this};
69  /// File to which to save observations and analysis.
70  oops::OptionalParameter<ObsDataParameters> obsdataout{"obsdataout", this};
71  /// Options controlling generation of artificial observations.
72  oops::OptionalParameter<ObsGenerateParameters> generate{"generate", this};
73 };
74 
75 /// \brief ObsSpace for QG model
76 /// \details ObsSpaceQG is created for each obs type. The underlying Fortran
77 /// structure (key_) is created for each matching input-output filename pair
78 /// (i.e. different obstypes can be stored in the same Fortran structure).
79 /// For mapping between ObsSpaceQG and Fortran structures,
80 /// ObsSpaceQG::theObsFileRegister_ map is used
82  public:
84 
85  /// create full ObsSpace (read or generate data)
86  ObsSpaceQG(const Parameters_ &, const eckit::mpi::Comm &,
87  const util::DateTime &, const util::DateTime &, const eckit::mpi::Comm &);
88  ~ObsSpaceQG();
89 
90  /// save and close file
91  void save() const;
92 
93  /// read data or metadata
94  void getdb(const std::string &, int &) const;
95  /// save data or metadata
96  void putdb(const std::string &, const int &) const;
97 
98  /// create locations for the whole time window
99  std::unique_ptr<LocationsQG> locations() const;
100 
101  /// return number of observations (unique locations)
102  int nobs() const;
103 
104  /// return variables simulated by ObsOperators
105  const oops::Variables & obsvariables() const { return obsvars_; }
106 
107  /// observation type
108  const std::string & obsname() const {return obsname_;}
109 
110  /// iterator to the first observation
111  ObsIteratorQG begin() const;
112  /// iterator to the observation past-the-last
113  ObsIteratorQG end() const;
114 
115  /// interface with Fortran
116  const F90odb & toFortran() const {return key_;}
117 
118  private:
119  void print(std::ostream &) const;
120 
121  mutable F90odb key_; // pointer to Fortran structure
122  const std::string obsname_; // corresponds with obstype
123  const util::DateTime winbgn_; // window for the observations
124  const util::DateTime winend_;
125  oops::Variables obsvars_; // variables simulated by ObsOperators
126 
127  // defines mapping for Fortran structures
128  static std::map < std::string, F90odb > theObsFileRegister_;
129  static int theObsFileCount_; // number of files used
130 };
131 
132 } // namespace qg
133 
134 #endif // QG_MODEL_OBSSPACEQG_H_
Base class for observation spaces.
Definition: ObsSpaceBase.h:47
Base class for configuration parameters of observation spaces.
Definition: ObsSpaceBase.h:30
Contents of the obsdatain or obsdataout YAML section.
Definition: ObsSpaceQG.h:39
oops::RequiredParameter< std::string > obsfile
File path.
Definition: ObsSpaceQG.h:44
Options controlling generation of artificial observations.
Definition: ObsSpaceQG.h:48
oops::RequiredParameter< double > obsError
Definition: ObsSpaceQG.h:57
oops::RequiredParameter< util::Duration > obsPeriod
Definition: ObsSpaceQG.h:53
oops::RequiredParameter< int > nval
Definition: ObsSpaceQG.h:56
oops::RequiredParameter< util::Duration > begin
Definition: ObsSpaceQG.h:52
oops::RequiredParameter< int > obsDensity
Number of observations to generate in each time slot.
Definition: ObsSpaceQG.h:55
Iterator over all observations.
Definition: ObsIteratorQG.h:28
ObsSpace for QG model.
Definition: ObsSpaceQG.h:81
const F90odb & toFortran() const
interface with Fortran
Definition: ObsSpaceQG.h:116
void print(std::ostream &) const
Definition: ObsSpaceQG.cc:165
oops::Variables obsvars_
Definition: ObsSpaceQG.h:125
const std::string obsname_
Definition: ObsSpaceQG.h:122
const std::string & obsname() const
observation type
Definition: ObsSpaceQG.h:108
ObsSpaceQGParameters Parameters_
Definition: ObsSpaceQG.h:83
const util::DateTime winend_
Definition: ObsSpaceQG.h:124
const util::DateTime winbgn_
Definition: ObsSpaceQG.h:123
void getdb(const std::string &, int &) const
read data or metadata
Definition: ObsSpaceQG.cc:127
const oops::Variables & obsvariables() const
return variables simulated by ObsOperators
Definition: ObsSpaceQG.h:105
static int theObsFileCount_
Definition: ObsSpaceQG.h:129
std::unique_ptr< LocationsQG > locations() const
create locations for the whole time window
Definition: ObsSpaceQG.cc:139
ObsIteratorQG end() const
iterator to the observation past-the-last
Definition: ObsSpaceQG.cc:160
void putdb(const std::string &, const int &) const
save data or metadata
Definition: ObsSpaceQG.cc:133
void save() const
save and close file
Definition: ObsSpaceQG.cc:116
ObsIteratorQG begin() const
iterator to the first observation
Definition: ObsSpaceQG.cc:156
ObsSpaceQG(const Parameters_ &, const eckit::mpi::Comm &, const util::DateTime &, const util::DateTime &, const eckit::mpi::Comm &)
create full ObsSpace (read or generate data)
Definition: ObsSpaceQG.cc:39
static std::map< std::string, F90odb > theObsFileRegister_
Definition: ObsSpaceQG.h:128
int nobs() const
return number of observations (unique locations)
Definition: ObsSpaceQG.cc:148
Configuration parameters for the QG model's ObsSpace.
Definition: ObsSpaceQG.h:61
oops::OptionalParameter< ObsDataParameters > obsdataout
File to which to save observations and analysis.
Definition: ObsSpaceQG.h:70
oops::RequiredParameter< std::string > obsType
Type of observations.
Definition: ObsSpaceQG.h:66
oops::OptionalParameter< ObsDataParameters > obsdatain
File from which to load observations.
Definition: ObsSpaceQG.h:68
oops::OptionalParameter< ObsGenerateParameters > generate
Options controlling generation of artificial observations.
Definition: ObsSpaceQG.h:72
The namespace for the qg model.
int F90odb
Definition: QgFortran.h:55