UFO
ObsBoundsCheck.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018-2019 UCAR
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_OBSBOUNDSCHECK_H_
9 #define UFO_FILTERS_OBSBOUNDSCHECK_H_
10 
11 #include <memory>
12 #include <ostream>
13 #include <string>
14 #include <vector>
15 
16 #include "oops/util/ObjectCounter.h"
17 #include "oops/util/parameters/OptionalParameter.h"
18 #include "oops/util/parameters/RequiredParameter.h"
19 #include "ufo/filters/FilterBase.h"
20 #include "ufo/filters/QCflags.h"
21 #include "ufo/filters/Variable.h"
23 
24 namespace eckit {
25  class Configuration;
26 }
27 
28 namespace ioda {
29  template <typename DATATYPE> class ObsDataVector;
30  class ObsSpace;
31 }
32 
33 namespace ufo {
34 
35 /// Parameters controlling the operation of the ObsBoundsCheck filter.
37  OOPS_CONCRETE_PARAMETERS(ObsBoundsCheckParameters, FilterParametersBase)
38 
39  public:
40  /// Minimum allowed value of the tested variables.
41  oops::OptionalParameter<float> minvalue{"minvalue", this};
42 
43  /// Maximum allowed value of the tested variables.
44  oops::OptionalParameter<float> maxvalue{"maxvalue", this};
45 
46  /// Variables to be compared against the bounds specified in the `minvalue` and `maxvalue`
47  /// options.
48  ///
49  /// There are three valid possibilities:
50  ///
51  /// * If this option is not set, the filter will flag each filter variable at each location
52  /// where the measured value of that variable lies outside the specified bounds.
53  ///
54  /// * If this option is set to a single-element list containing only one single-channel variable
55  /// or the `flag all filter variables if any test variable is out of bounds` option is set to
56  /// `true`, the filter will flag each filter variable at each location where any test variable
57  /// lies outside the specified bounds. If
58  /// `test only filter variables with passed qc when flagging all filter variables` is set to
59  /// true and the number of filter vars is not equal to the number of test vars an error
60  /// will be thrown.
61  ///
62  /// * If this option is set to a list with as many elements as there are filter variables and
63  /// the `flag all filter variables if any test variable is out of bounds` option is set to
64  /// `false`, the filter will flag each filter variable at each location
65  /// where the corresponding test variable lies outside the specified bounds.
66  oops::OptionalParameter<std::vector<Variable>> testVariables{"test variables", this};
67 
68  /// Set this option to `true` to flag all filter variables at each location where any test
69  /// variable lies outside the specified bounds.
70  ///
71  /// This option is ignored if the `test variables` option is not set.
73  "flag all filter variables if any test variable is out of bounds", false, this};
74 
75  /// Set this option to `true` to only test the current filter variable if it is flagged
76  /// as pass qc when using "flag all filter variables if any test variables out of bounds".
77  ///
78  /// This option is not used if "flagAllFilterVarsIfAnyTestVarOutOfBounds" is false.
80  "test only filter variables with passed qc when flagging all filter variables", false, this};
81 
82  /// By default, the filter flags filter variables at locations where the corresponding test
83  /// variable is set to the missing value indicator. Set this option to `false` to stop it from
84  /// doing so (hence assuming "optimistically" that the test variable was in fact in bounds).
85  oops::Parameter<bool> treatMissingAsOutOfBounds{"treat missing as out of bounds", true, this};
86 };
87 
88 /// \brief Flag observations that lie outside specified bounds.
89 ///
90 /// This is a generic quality control filter based on observation data only.
91 ///
92 /// See ObsBoundsCheckParameters for the documentation of the parameters controlling this filter.
93 
94 class ObsBoundsCheck : public FilterBase,
95  private util::ObjectCounter<ObsBoundsCheck> {
96  public:
97  /// The type of parameters accepted by the constructor of this filter.
98  /// This typedef is used by the FilterFactory.
100 
101  static const std::string classname() {return "ufo::ObsBoundsCheck";}
102 
103  ObsBoundsCheck(ioda::ObsSpace &, const Parameters_ &,
104  std::shared_ptr<ioda::ObsDataVector<int> >,
105  std::shared_ptr<ioda::ObsDataVector<float> >);
106  ~ObsBoundsCheck();
107 
108  private:
109  void print(std::ostream &) const override;
110  void applyFilter(const std::vector<bool> &, const Variables &,
111  std::vector<std::vector<bool>> &) const override;
112  int qcFlag() const override {return QCflags::bounds;}
114 };
115 
116 } // namespace ufo
117 
118 #endif // UFO_FILTERS_OBSBOUNDSCHECK_H_
Base class for UFO QC filters.
Definition: FilterBase.h:45
Parameters shared by all filters having a default action (typically "reject").
Flag observations that lie outside specified bounds.
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
static const std::string classname()
ObsBoundsCheck(ioda::ObsSpace &, const Parameters_ &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
ObsBoundsCheckParameters Parameters_
void print(std::ostream &) const override
int qcFlag() const override
Parameters_ parameters_
Parameters controlling the operation of the ObsBoundsCheck filter.
oops::Parameter< bool > onlyTestGoodFilterVarsForFlagAllFilterVars
oops::OptionalParameter< std::vector< Variable > > testVariables
oops::Parameter< bool > treatMissingAsOutOfBounds
oops::Parameter< bool > flagAllFilterVarsIfAnyTestVarOutOfBounds
oops::OptionalParameter< float > minvalue
Minimum allowed value of the tested variables.
oops::OptionalParameter< float > maxvalue
Maximum allowed value of the tested variables.
Forward declarations.
Definition: ObsAodExt.h:21
Forward declarations.
Definition: ObsAodExt.h:25
constexpr int bounds
Definition: QCflags.h:22
Definition: RunCRTM.h:27