UFO
BayesianBackgroundQCFlags.h
Go to the documentation of this file.
1 /*
2  * (C) Crown Copyright 2021 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_FILTERS_BAYESIANBACKGROUNDQCFLAGS_H_
9 #define UFO_FILTERS_BAYESIANBACKGROUNDQCFLAGS_H_
10 
11 #include <map>
12 #include <memory>
13 #include <ostream>
14 #include <string>
15 #include <vector>
16 
17 #include "oops/util/ObjectCounter.h"
18 #include "oops/util/parameters/Parameter.h"
19 #include "oops/util/Printable.h"
20 #include "ufo/filters/FilterBase.h"
21 #include "ufo/filters/QCflags.h"
23 
24 namespace ioda {
25  template <typename DATATYPE> class ObsDataVector;
26  class ObsSpace;
27 }
28 
29 namespace ufo {
30 
31 /// Parameters controlling the operation of the BayesianBackgroundQCFlags filter.
34 
35  public:
36  /// This parameter is a collection of PGE variable name substitutions.
37  /// The PGE of the second variable in each pair is used to set the QC flags
38  /// of the first variable; this happens for (e.g.) wind u and v components.
39  /// todo(UKMO): might need to add the variables known as
40  /// u10, v10 and uSuperob, vSuperob in OPS.
41  oops::Parameter<std::map<std::string, std::string>> PGEsubstituteNames
42  {"PGE variable name substitutions", {{"northward_wind", "eastward_wind"}}, this};
43 
44  /// Parameters related to PGE calculations. The value of \p PGECrit
45  /// is obtained from here.
47 };
48 
49 /// BayesianBackgroundQCFlags: apply QC flags based on values of probability of
50 /// gross error (PGE). If the PGE is larger than the threshold \p PGEcrit then
51 /// the observation is rejected.
52 /// If the Bayesian background or buddy checks were applied,
53 /// use the PGE that was obtained from those checks.
54 /// Sometimes the PGE of one variable is used to set the QC flags of another;
55 /// this happens for (e.g.) wind u and v components.
56 ///
57 /// todo(UKMO): deal with Pstar/Pmsl and u10AmbWind/v10AmbWind (as they are known in OPS).
58 /// These are each treated slightly differently in the OPS code.
60  private util::ObjectCounter<BayesianBackgroundQCFlags> {
61  public:
63 
64  static const std::string classname() {return "ufo::BayesianBackgroundQCFlags";}
65 
66  BayesianBackgroundQCFlags(ioda::ObsSpace &, const Parameters_ &,
67  std::shared_ptr<ioda::ObsDataVector<int> >,
68  std::shared_ptr<ioda::ObsDataVector<float> >);
70 
71  private:
72  void print(std::ostream &) const override;
73  void applyFilter(const std::vector<bool> &, const Variables &,
74  std::vector<std::vector<bool>> &) const override;
75  int qcFlag() const override {return QCflags::bayesianQC;}
76 
77  /// Get the name of the variable whose PGE is tested in order to
78  /// set the QC flags for the variable \p varname.
79  /// By default, \p varname is returned by this routine; any substitutions
80  /// are listed in the \p PGEsubstituteNames parameter.
81  std::string getPGEsubstituteName(const std::string& varname) const;
82 
83  /// Set flags for the variable \p varname given the \p apply vector.
84  /// Set both integer bitmap flags and an overall filter flag (bayesianQC).
85  void setFlags(const std::string& varname,
86  const std::vector<bool>& apply,
87  std::vector<bool>& flagged) const;
88 
89  /// Parameters used in this filter.
91 };
92 
93 } // namespace ufo
94 
95 #endif // UFO_FILTERS_BAYESIANBACKGROUNDQCFLAGS_H_
Parameters_ parameters_
Parameters used in this filter.
std::string getPGEsubstituteName(const std::string &varname) const
BayesianBackgroundQCFlagsParameters Parameters_
void print(std::ostream &) const override
static const std::string classname()
void setFlags(const std::string &varname, const std::vector< bool > &apply, std::vector< bool > &flagged) const
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
BayesianBackgroundQCFlags(ioda::ObsSpace &, const Parameters_ &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
Parameters controlling the operation of the BayesianBackgroundQCFlags filter.
ProbabilityOfGrossErrorParameters PGEParameters
oops::Parameter< std::map< std::string, std::string > > PGEsubstituteNames
Base class for UFO QC filters.
Definition: FilterBase.h:45
Parameters shared by all filters having a default action (typically "reject").
Options controlling the operation of the calculations involving probability of gross error.
Forward declarations.
Definition: ObsAodExt.h:25
constexpr int bayesianQC
Definition: QCflags.h:36
Definition: RunCRTM.h:27