UFO
VariableAssignment.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 Met Office UK
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_VARIABLEASSIGNMENT_H_
9 #define UFO_FILTERS_VARIABLEASSIGNMENT_H_
10 
11 #include <memory>
12 #include <ostream>
13 #include <string>
14 #include <vector>
15 
16 #include "eckit/config/LocalConfiguration.h"
17 #include "ioda/core/ParameterTraitsObsDtype.h"
18 #include "oops/generic/ObsFilterParametersBase.h"
19 #include "oops/util/ObjectCounter.h"
20 #include "oops/util/parameters/OptionalParameter.h"
21 #include "oops/util/parameters/Parameter.h"
22 #include "oops/util/parameters/Parameters.h"
23 #include "oops/util/parameters/RequiredParameter.h"
27 
28 namespace ufo {
29 
30 /// Parameters controlling assignment of new values to a variable.
31 class AssignmentParameters : public oops::Parameters {
32  OOPS_CONCRETE_PARAMETERS(AssignmentParameters, Parameters)
33 
34  public:
35  /// Name of the variable to which new values should be assigned.
36  oops::RequiredParameter<std::string> name{"name", this};
37 
38  /// Set of channels to which new values should be assigned.
39  oops::Parameter<std::string> channels{"channels", "", this};
40 
41  /// Value to be assigned to the specified variable (at all locations selected be the `where`
42  /// statement, if present).
43  ///
44  /// Exactly one of the `value` and `function` options must be given.
45  oops::OptionalParameter<std::string> value_{"value", this};
46 
47  /// Variable that should be copied into the destination variable specified using the `name` option
48  /// (at all locations selected be the `where` statement, if present).
49  ///
50  /// Exactly one of the `value`, `source variable` and `function` options must be given.
51  oops::OptionalParameter<ufo::Variable> sourceVariable{"source variable", this};
52 
53  /// An ObsFunction that should be evaluated and assigned to the specified
54  /// variable (at all locations selected be the `where` statement, if present).
55  ///
56  /// Exactly one of the `value`, `source variable` and `function` options must be given.
57  oops::OptionalParameter<ufo::Variable> function{"function", this};
58 
59  /// Type (int, float, string or datetime) of the variable to which new values should be assigned.
60  ///
61  /// This option must be provided if the variable doesn't exist yet. If this option is provided
62  /// and the variable already exists, its type must match the value of this option,
63  /// otherwise an exception will be thrown.
64  oops::OptionalParameter<ioda::ObsDtype> type{"type", this};
65 
66  /// This function is overridden to check that mutually exclusive options aren't specified
67  /// together, throwing an exception otherwise.
68  void deserialize(util::CompositePath &path, const eckit::Configuration &config) override;
69 };
70 
71 /// Parameters controlling the VariableAssignment filter.
72 class VariableAssignmentParameters : public oops::ObsFilterParametersBase {
73  OOPS_CONCRETE_PARAMETERS(VariableAssignmentParameters, ObsFilterParametersBase)
74 
75  public:
76  /// One or more sets of options controlling the values assigned to a particular variable.
77  oops::Parameter<std::vector<AssignmentParameters>> assignments{"assignments", {}, this};
78 
79  /// Conditions used to select locations where variable assignment should be performed.
80  /// If not specified, variable assignment will be performed at all locations.
81  oops::Parameter<std::vector<WhereParameters>> where{"where", {}, this};
82 
83  /// If set to true, variable assignment will be done after the obs operator has been invoked
84  /// (even if the filter doesn't require any variables from the GeoVaLs or HofX groups).
85  oops::Parameter<bool> deferToPost{"defer to post", false, this};
86 };
87 
88 /// \brief Assigns specified values to elements of specified variables selected by the where
89 /// statement.
90 ///
91 /// The values can be constants or vectors generated by ObsFunctions. If the variables don't exist
92 /// yet, they will be created; in this case elements not selected by the where clause will be
93 /// initialized with the missing value markers.
94 ///
95 /// If the modified variable belongs to the `DerivedObsValue` group and is a simulated variable, QC
96 /// flags previously set to `missing` are reset to `pass` at locations where a valid obs value has
97 /// been assigned. Conversely, QC flags previously set to `pass` are reset to `missing` at
98 /// locations where the obs value has been set to missing.
99 ///
100 /// Example 1: Create new variables `air_temperature@GrossErrorProbability` and
101 /// `relative_humidity@GrossErrorProbability` and set them to 0.1 at all locations.
102 ///
103 /// filter: Variable Assignment
104 /// assignments:
105 /// - name: air_temperature@GrossErrorProbability
106 /// type: float # type must be specified if the variable doesn't already exist
107 /// value: 0.1
108 /// - name: relative_humidity@GrossErrorProbability
109 /// type: float
110 /// value: 0.1
111 ///
112 /// Example 2: Set `air_temperature@GrossErrorProbability` to 0.05 at all locations in the tropics.
113 ///
114 /// filter: Variable Assignment
115 /// where:
116 /// - variable:
117 /// name: latitude@MetaData
118 /// minvalue: -30
119 /// maxvalue: 30
120 /// assignments:
121 /// - name: air_temperature@GrossErrorProbability
122 /// value: 0.05
123 ///
124 /// Example 3: Set `relative_humidity@GrossErrorProbability` to values computed by an ObsFunction
125 /// (0.1 in the southern extratropics and 0.05 in the northern extratropics, with a linear
126 /// transition in between).
127 ///
128 /// filter: Variable Assignment
129 /// assignments:
130 /// - name: relative_humidity@GrossErrorProbability
131 /// function:
132 /// name: ObsErrorModelRamp@ObsFunction
133 /// options:
134 /// xvar:
135 /// name: latitude@MetaData
136 /// x0: [-30]
137 /// x1: [30]
138 /// err0: [0.1]
139 /// err1: [0.05]
140 ///
142  private util::ObjectCounter<VariableAssignment> {
143  public:
144  /// The type of parameters accepted by the constructor of this filter.
145  /// This typedef is used by the FilterFactory.
147 
148  static const std::string classname() {return "ufo::VariableAssignment";}
149 
150  VariableAssignment(ioda::ObsSpace & obsdb, const Parameters_ & parameters,
151  std::shared_ptr<ioda::ObsDataVector<int> > flags,
152  std::shared_ptr<ioda::ObsDataVector<float> > obserr);
153 
154  private:
155  void print(std::ostream &) const override;
156  void doFilter() const override;
157 
159 };
160 
161 } // namespace ufo
162 
163 #endif // UFO_FILTERS_VARIABLEASSIGNMENT_H_
Parameters controlling assignment of new values to a variable.
oops::OptionalParameter< std::string > value_
void deserialize(util::CompositePath &path, const eckit::Configuration &config) override
oops::OptionalParameter< ufo::Variable > sourceVariable
oops::RequiredParameter< std::string > name
Name of the variable to which new values should be assigned.
oops::Parameter< std::string > channels
Set of channels to which new values should be assigned.
oops::OptionalParameter< ioda::ObsDtype > type
Base class for UFO observation processors (including QC filters).
Assigns specified values to elements of specified variables selected by the where statement.
static const std::string classname()
void doFilter() const override
VariableAssignment(ioda::ObsSpace &obsdb, const Parameters_ &parameters, std::shared_ptr< ioda::ObsDataVector< int > > flags, std::shared_ptr< ioda::ObsDataVector< float > > obserr)
void print(std::ostream &) const override
VariableAssignmentParameters Parameters_
Parameters controlling the VariableAssignment filter.
oops::Parameter< std::vector< WhereParameters > > where
oops::Parameter< bool > deferToPost
oops::Parameter< std::vector< AssignmentParameters > > assignments
One or more sets of options controlling the values assigned to a particular variable.
Definition: RunCRTM.h:27