OOPS
ObsTable.h
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 #ifndef LORENZ95_OBSTABLE_H_
12 #define LORENZ95_OBSTABLE_H_
13 
14 #include <fstream>
15 #include <map>
16 #include <ostream>
17 #include <string>
18 #include <vector>
19 
20 #include "eckit/mpi/Comm.h"
21 #include "oops/base/ObsSpaceBase.h"
22 #include "oops/base/Variables.h"
23 #include "oops/util/DateTime.h"
24 #include "oops/util/ObjectCounter.h"
25 #include "oops/util/parameters/OptionalParameter.h"
26 #include "oops/util/parameters/Parameters.h"
27 #include "oops/util/parameters/RequiredParameter.h"
28 
29 namespace lorenz95 {
30  class ObsIterator;
31 
32 // -----------------------------------------------------------------------------
33 /// Options controlling generation of artificial observations.
34 class ObsGenerateParameters : public oops::Parameters {
35  OOPS_CONCRETE_PARAMETERS(ObsGenerateParameters, Parameters)
36 
37  public:
38  oops::RequiredParameter<util::Duration> begin{"begin", this};
39  oops::OptionalParameter<util::Duration> end{"end", this};
40  oops::RequiredParameter<util::Duration> obsFrequency{"obs_frequency", this};
41  /// Number of observations to generate in each time slot.
42  oops::RequiredParameter<int> obsDensity{"obs_density", this};
43  oops::RequiredParameter<double> obsError{"obs_error", this};
44 };
45 
46 // -----------------------------------------------------------------------------
47 /// \brief Configuration parameters for the L95 model's ObsSpace.
49  OOPS_CONCRETE_PARAMETERS(ObsTableParameters, ObsSpaceParametersBase)
50 
51  public:
52  /// File from which to load observations.
53  oops::OptionalParameter<std::string> obsdatain{"obsdatain", this};
54  /// File to which to save observations and analysis.
55  oops::OptionalParameter<std::string> obsdataout{"obsdataout", this};
56  /// Options controlling generation of artificial observations.
57  oops::OptionalParameter<ObsGenerateParameters> generate{"generate", this};
58 };
59 
60 // -----------------------------------------------------------------------------
61 /// A Simple Observation Data Handler
62 /*!
63  * ObsTable defines a simple observation handler
64  * that mimicks the interfaces required from ODB.
65  */
67  private util::ObjectCounter<ObsTable> {
68  public:
69  static const std::string classname() {return "lorenz95::ObsTable";}
70 
72 
73  ObsTable(const Parameters_ &, const eckit::mpi::Comm &,
74  const util::DateTime &, const util::DateTime &, const eckit::mpi::Comm &);
75  ~ObsTable();
76 
77  void save() const;
78 
79  void putdb(const std::string &, const std::vector<int> &) const;
80  void putdb(const std::string &, const std::vector<float> &) const;
81  void putdb(const std::string &, const std::vector<double> &) const;
82  void getdb(const std::string &, std::vector<int> &) const;
83  void getdb(const std::string &, std::vector<float> &) const;
84  void getdb(const std::string &, std::vector<double> &) const;
85 
86  bool has(const std::string & col) const;
87  void generateDistribution(const ObsGenerateParameters & params);
88  void random(std::vector<double> &) const;
89  unsigned int nobs() const {return times_.size();}
90  const std::vector<double> & locations() const { return locations_; }
91  const std::vector<util::DateTime> & times() const { return times_; }
92  const oops::Variables & obsvariables() const { return obsvars_; }
93  const std::string & obsname() const {return obsname_;}
94 
95  /// iterator to the first observation
96  ObsIterator begin() const;
97  /// iterator to the observation past-the-last
98  ObsIterator end() const;
99 
100  private:
101  void print(std::ostream &) const;
102  void otOpen(const std::string &);
103  void otWrite(const std::string &) const;
104 
105  const util::DateTime winbgn_;
106  const util::DateTime winend_;
107 
108  std::vector<util::DateTime> times_;
109  std::vector<double> locations_;
110  mutable std::map<std::string, std::vector<double> > data_;
111 
112  const eckit::mpi::Comm & comm_;
114  std::string nameIn_;
115  std::string nameOut_;
116  const std::string obsname_ = "Lorenz 95";
117 };
118 // -----------------------------------------------------------------------------
119 } // namespace lorenz95
120 
121 #endif // LORENZ95_OBSTABLE_H_
Options controlling generation of artificial observations.
Definition: ObsTable.h:34
oops::RequiredParameter< util::Duration > begin
Definition: ObsTable.h:38
oops::RequiredParameter< util::Duration > obsFrequency
Definition: ObsTable.h:40
oops::RequiredParameter< int > obsDensity
Number of observations to generate in each time slot.
Definition: ObsTable.h:42
oops::OptionalParameter< util::Duration > end
Definition: ObsTable.h:39
oops::RequiredParameter< double > obsError
Definition: ObsTable.h:43
Iterator over all observations.
A Simple Observation Data Handler.
Definition: ObsTable.h:67
void random(std::vector< double > &) const
Definition: ObsTable.cc:228
ObsTableParameters Parameters_
Definition: ObsTable.h:71
const std::vector< double > & locations() const
Definition: ObsTable.h:90
std::vector< double > locations_
Definition: ObsTable.h:109
static const std::string classname()
Definition: ObsTable.h:69
void print(std::ostream &) const
Definition: ObsTable.cc:353
std::string nameIn_
Definition: ObsTable.h:114
bool has(const std::string &col) const
Definition: ObsTable.cc:78
void getdb(const std::string &, std::vector< int > &) const
Definition: ObsTable.cc:128
const std::string obsname_
Definition: ObsTable.h:116
unsigned int nobs() const
Definition: ObsTable.h:89
void otWrite(const std::string &) const
Definition: ObsTable.cc:288
const oops::Variables obsvars_
Definition: ObsTable.h:113
const eckit::mpi::Comm & comm_
Definition: ObsTable.h:112
ObsIterator begin() const
iterator to the first observation
Definition: ObsTable.cc:344
const util::DateTime winbgn_
Definition: ObsTable.h:105
void save() const
Definition: ObsTable.cc:72
void generateDistribution(const ObsGenerateParameters &params)
Definition: ObsTable.cc:176
const util::DateTime winend_
Definition: ObsTable.h:106
std::map< std::string, std::vector< double > > data_
Definition: ObsTable.h:110
const std::string & obsname() const
Definition: ObsTable.h:93
const oops::Variables & obsvariables() const
Definition: ObsTable.h:92
ObsIterator end() const
iterator to the observation past-the-last
Definition: ObsTable.cc:348
std::string nameOut_
Definition: ObsTable.h:115
const std::vector< util::DateTime > & times() const
Definition: ObsTable.h:91
std::vector< util::DateTime > times_
Definition: ObsTable.h:108
void otOpen(const std::string &)
Definition: ObsTable.cc:237
void putdb(const std::string &, const std::vector< int > &) const
Definition: ObsTable.cc:84
ObsTable(const Parameters_ &, const eckit::mpi::Comm &, const util::DateTime &, const util::DateTime &, const eckit::mpi::Comm &)
Definition: ObsTable.cc:42
Configuration parameters for the L95 model's ObsSpace.
Definition: ObsTable.h:48
oops::OptionalParameter< std::string > obsdatain
File from which to load observations.
Definition: ObsTable.h:53
oops::OptionalParameter< std::string > obsdataout
File to which to save observations and analysis.
Definition: ObsTable.h:55
oops::OptionalParameter< ObsGenerateParameters > generate
Options controlling generation of artificial observations.
Definition: ObsTable.h:57
Base class for observation spaces.
Definition: ObsSpaceBase.h:47
Base class for configuration parameters of observation spaces.
Definition: ObsSpaceBase.h:30
The namespace for the L95 model.