UFO
ProfileCheckBase.h
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2020, Met Office
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_PROFILE_PROFILECHECKBASE_H_
9 #define UFO_PROFILE_PROFILECHECKBASE_H_
10 
11 #include <algorithm>
12 #include <cmath>
13 #include <functional>
14 #include <map>
15 #include <memory>
16 #include <ostream>
17 #include <string>
18 #include <vector>
19 
20 #include "eckit/exception/Exceptions.h"
21 #include "eckit/types/FloatCompare.h"
22 
23 #include "oops/util/CompareNVectors.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/missingValues.h"
26 #include "oops/util/PropertiesOfNVectors.h"
27 
29 
32 
34 
35 namespace ufo {
36 
37  /// \brief Profile QC checker base class
39  public:
41 
42  virtual ~ProfileCheckBase() {}
43 
44  /// Run check
45  virtual void runCheck(ProfileDataHandler &profileDataHandler) = 0;
46 
47  /// Fill variables in validator using a ProfileDataHandler.
48  /// This function will only be called for subclasses of ProfileCheckBase
49  /// whose runOnEntireSample() implementation returns false.
50  /// If runOnEntireSample() returns true, the subclass needs
51  /// to handle the storage of validation data on its own.
52  /// For an example see the ProfileAveragePressure class.
53  virtual void fillValidationData(ProfileDataHandler &profileDataHandler) {}
54 
55  /// Get result of check (default fail)
56  virtual bool getResult() {return false;}
57 
58  /// Run this check on the entire sample?
59  virtual bool runOnEntireSample() {return false;}
60 
61  /// List of names of required GeoVaLs.
62  virtual oops::Variables getGeoVaLNames() {return oops::Variables();}
63 
64  /// List of names of GeoVaLs used in check validation.
65  virtual oops::Variables getValidationGeoVaLNames() {return oops::Variables();}
66 
67  /// List of names of required obs diagnostics.
68  virtual oops::Variables getObsDiagNames() {return oops::Variables();}
69 
70  protected: // functions
71  /// Apply correction to vector of values
72  template <typename T>
73  void correctVector(const std::vector <T> &v1,
74  const std::vector <T> &v2,
75  std::vector <T> &vout)
76  {
77  ASSERT(v1.size() == v2.size());
78  vout.assign(v1.size(), 0);
79  std::transform(v1.begin(), v1.end(), v2.begin(), vout.begin(), std::plus<T>());
80  }
81 
82  /// Set a QC flag on one profile level.
83  /// This is the base case for one vector.
84  template <typename T>
85  void SetQCFlag(const int& flag,
86  const size_t& jlev,
87  std::vector <T> &vec)
88  {
89  if (vec.size() > jlev) vec[jlev] |= flag;
90  }
91 
92  /// Set a QC flag on one profile level.
93  /// This is the recursive case that accepts an arbitrary number of vectors
94  /// using a variadic template.
95  template <typename T, typename... Args>
96  void SetQCFlag(const int& flag,
97  const size_t& jlev,
98  std::vector <T> &vec1,
99  Args&... vecs)
100  {
101  if (vec1.size() > jlev) vec1[jlev] |= flag;
102  SetQCFlag(flag, jlev, vecs...);
103  }
104 
105  protected: // variables
106  /// Configurable parameters
108 
109  /// Missing value (int)
110  const int missingValueInt = util::missingValue(1);
111 
112  /// Missing value (float)
113  const float missingValueFloat = util::missingValue(1.0f);
114  };
115 
116  /// Profile check factory
118  {
119  public:
120  static std::unique_ptr<ProfileCheckBase> create(const std::string&,
122  virtual ~ProfileCheckFactory() = default;
123  protected:
124  explicit ProfileCheckFactory(const std::string &);
125  private:
126  virtual std::unique_ptr<ProfileCheckBase> make
128 
129  static std::map <std::string, ProfileCheckFactory*> & getMakers()
130  {
131  static std::map <std::string, ProfileCheckFactory*> makers_;
132  return makers_;
133  }
134  };
135 
136  template<class T>
138  {
139  virtual std::unique_ptr<ProfileCheckBase>
141  {
142  return std::unique_ptr<ProfileCheckBase>(new T(options));
143  }
144  public:
145  explicit ProfileCheckMaker(const std::string & name)
146  : ProfileCheckFactory(name) {}
147  };
148 } // namespace ufo
149 
150 #endif // UFO_PROFILE_PROFILECHECKBASE_H_
Options controlling the operation of the ConventionalProfileProcessing filter.
Profile QC checker base class.
const float missingValueFloat
Missing value (float)
virtual oops::Variables getValidationGeoVaLNames()
List of names of GeoVaLs used in check validation.
const ConventionalProfileProcessingParameters & options_
Configurable parameters.
ProfileCheckBase(const ConventionalProfileProcessingParameters &options)
void SetQCFlag(const int &flag, const size_t &jlev, std::vector< T > &vec)
void SetQCFlag(const int &flag, const size_t &jlev, std::vector< T > &vec1, Args &... vecs)
void correctVector(const std::vector< T > &v1, const std::vector< T > &v2, std::vector< T > &vout)
Apply correction to vector of values.
virtual void runCheck(ProfileDataHandler &profileDataHandler)=0
Run check.
virtual bool runOnEntireSample()
Run this check on the entire sample?
virtual void fillValidationData(ProfileDataHandler &profileDataHandler)
virtual bool getResult()
Get result of check (default fail)
virtual oops::Variables getGeoVaLNames()
List of names of required GeoVaLs.
virtual oops::Variables getObsDiagNames()
List of names of required obs diagnostics.
const int missingValueInt
Missing value (int)
Profile check factory.
ProfileCheckFactory(const std::string &)
virtual std::unique_ptr< ProfileCheckBase > make(const ConventionalProfileProcessingParameters &)=0
static std::unique_ptr< ProfileCheckBase > create(const std::string &, const ConventionalProfileProcessingParameters &)
static std::map< std::string, ProfileCheckFactory * > & getMakers()
virtual ~ProfileCheckFactory()=default
ProfileCheckMaker(const std::string &name)
virtual std::unique_ptr< ProfileCheckBase > make(const ConventionalProfileProcessingParameters &options)
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
Definition: RunCRTM.h:27