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 
30 namespace ufo {
31  class ProfileConsistencyCheckParameters;
32  class ProfileCheckValidator;
33  class ProfileDataHandler;
34  class ProfileIndices;
35 }
36 
37 namespace ufo {
38 
39  /// \brief Profile QC checker base class
41  public:
43  const ProfileIndices &profileIndices,
44  ProfileDataHandler &profileDataHandler,
45  ProfileCheckValidator &profileCheckValidator);
46  virtual ~ProfileCheckBase() {}
47 
48  /// Run check
49  virtual void runCheck() = 0;
50 
51  /// Fill variables in validator
52  virtual void fillValidator() = 0;
53 
54  /// Get result of check (default fail)
55  virtual bool getResult() {return false;}
56 
57  protected: // functions
58  /// Apply correction to vector of values
59  template <typename T>
60  void correctVector(const std::vector <T> &v1,
61  const std::vector <T> &v2,
62  std::vector <T> &vout)
63  {
64  ASSERT(v1.size() == v2.size());
65  vout.assign(v1.size(), 0);
66  std::transform(v1.begin(), v1.end(), v2.begin(), vout.begin(), std::plus<T>());
67  }
68 
69  protected: // variables
70  /// Configurable parameters
72 
73  /// Indices of profile's observations in the entire sample
75 
76  /// Profile data handler
78 
79  /// Profile check validator
81 
82  /// Missing value (float)
83  const float missingValueFloat = util::missingValue(1.0f);
84  };
85 
86  /// Profile check factory
88  {
89  public:
90  static std::unique_ptr<ProfileCheckBase> create(const std::string&,
92  const ProfileIndices&,
95  virtual ~ProfileCheckFactory() = default;
96  protected:
97  explicit ProfileCheckFactory(const std::string &);
98  private:
99  virtual std::unique_ptr<ProfileCheckBase> make(const ProfileConsistencyCheckParameters&,
100  const ProfileIndices&,
102  ProfileCheckValidator&) = 0;
103 
104  static std::map <std::string, ProfileCheckFactory*> & getMakers()
105  {
106  static std::map <std::string, ProfileCheckFactory*> makers_;
107  return makers_;
108  }
109  };
110 
111  template<class T>
113  {
114  virtual std::unique_ptr<ProfileCheckBase>
116  const ProfileIndices &profileIndices,
117  ProfileDataHandler &profileDataHandler,
118  ProfileCheckValidator &profileCheckValidator)
119  {
120  return std::unique_ptr<ProfileCheckBase>(new T(options,
121  profileIndices,
122  profileDataHandler,
123  profileCheckValidator));
124  }
125  public:
126  explicit ProfileCheckMaker(const std::string & name)
127  : ProfileCheckFactory(name) {}
128  };
129 } // namespace ufo
130 
131 #endif // UFO_PROFILE_PROFILECHECKBASE_H_
ufo::ProfileCheckFactory::~ProfileCheckFactory
virtual ~ProfileCheckFactory()=default
ufo::ProfileDataHandler
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
Definition: ProfileDataHandler.h:40
MetOfficeQCFlags.h
ufo::ProfileCheckFactory
Profile check factory.
Definition: ProfileCheckBase.h:88
ufo::ProfileCheckFactory::ProfileCheckFactory
ProfileCheckFactory(const std::string &)
Definition: ProfileCheckBase.cc:26
ufo::ProfileCheckMaker::ProfileCheckMaker
ProfileCheckMaker(const std::string &name)
Definition: ProfileCheckBase.h:126
ufo::ProfileCheckBase::profileIndices_
const ProfileIndices & profileIndices_
Indices of profile's observations in the entire sample.
Definition: ProfileCheckBase.h:74
ufo::ProfileCheckBase::profileCheckValidator_
ProfileCheckValidator & profileCheckValidator_
Profile check validator.
Definition: ProfileCheckBase.h:80
ufo::ProfileIndices
Determine indices of observations making up individual profiles. The indices are computed with respec...
Definition: ProfileIndices.h:39
ufo::ProfileCheckBase::profileDataHandler_
ProfileDataHandler & profileDataHandler_
Profile data handler.
Definition: ProfileCheckBase.h:77
ufo::ProfileCheckBase::ProfileCheckBase
ProfileCheckBase(const ProfileConsistencyCheckParameters &options, const ProfileIndices &profileIndices, ProfileDataHandler &profileDataHandler, ProfileCheckValidator &profileCheckValidator)
Definition: ProfileCheckBase.cc:16
ufo::ProfileCheckMaker::make
virtual std::unique_ptr< ProfileCheckBase > make(const ProfileConsistencyCheckParameters &options, const ProfileIndices &profileIndices, ProfileDataHandler &profileDataHandler, ProfileCheckValidator &profileCheckValidator)
Definition: ProfileCheckBase.h:115
ufo::ProfileCheckBase::~ProfileCheckBase
virtual ~ProfileCheckBase()
Definition: ProfileCheckBase.h:46
ufo::ProfileCheckValidator
Profile QC check validator.
Definition: ProfileCheckValidator.h:27
ufo::ProfileCheckFactory::getMakers
static std::map< std::string, ProfileCheckFactory * > & getMakers()
Definition: ProfileCheckBase.h:104
ufo::ProfileCheckBase::getResult
virtual bool getResult()
Get result of check (default fail)
Definition: ProfileCheckBase.h:55
ufo::ProfileCheckBase::fillValidator
virtual void fillValidator()=0
Fill variables in validator.
ufo::ProfileCheckMaker
Definition: ProfileCheckBase.h:113
ufo
Definition: RunCRTM.h:27
ufo::ProfileCheckBase
Profile QC checker base class.
Definition: ProfileCheckBase.h:40
ufo::ProfileCheckFactory::make
virtual std::unique_ptr< ProfileCheckBase > make(const ProfileConsistencyCheckParameters &, const ProfileIndices &, ProfileDataHandler &, ProfileCheckValidator &)=0
ufo::ProfileCheckBase::options_
const ProfileConsistencyCheckParameters & options_
Configurable parameters.
Definition: ProfileCheckBase.h:71
ufo::ProfileCheckBase::missingValueFloat
const float missingValueFloat
Missing value (float)
Definition: ProfileCheckBase.h:83
ufo::ProfileCheckBase::runCheck
virtual void runCheck()=0
Run check.
ufo::ProfileConsistencyCheckParameters
Options controlling the operation of the ProfileConsistencyChecks filter.
Definition: ProfileConsistencyCheckParameters.h:33
ufo::ProfileCheckBase::correctVector
void correctVector(const std::vector< T > &v1, const std::vector< T > &v2, std::vector< T > &vout)
Apply correction to vector of values.
Definition: ProfileCheckBase.h:60
ufo::ProfileCheckFactory::create
static std::unique_ptr< ProfileCheckBase > create(const std::string &, const ProfileConsistencyCheckParameters &, const ProfileIndices &, ProfileDataHandler &, ProfileCheckValidator &)
Definition: ProfileCheckBase.cc:34