UFO
GaussianThinningParameters.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 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_GAUSSIANTHINNINGPARAMETERS_H_
9 #define UFO_FILTERS_GAUSSIANTHINNINGPARAMETERS_H_
10 
11 #include <string>
12 #include <utility>
13 
14 #include "eckit/exception/Exceptions.h"
15 #include "oops/util/parameters/OptionalParameter.h"
16 #include "oops/util/parameters/Parameter.h"
17 #include "oops/util/parameters/Parameters.h"
19 #include "ufo/utils/Constants.h"
21 
22 namespace eckit {
23  class Configuration;
24 }
25 
26 namespace ufo {
27 
28 enum class DistanceNorm {
30 };
31 
34  static constexpr char enumTypeName[] = "DistanceNorm";
35  static constexpr util::NamedEnumerator<DistanceNorm> namedValues[] = {
36  { DistanceNorm::GEODESIC, "geodesic" },
37  { DistanceNorm::MAXIMUM, "maximum" }
38  };
39 };
40 
41 } // namespace ufo
42 
43 namespace oops {
44 
45 template <>
46 struct ParameterTraits<ufo::DistanceNorm> :
47  public EnumParameterTraits<ufo::DistanceNormParameterTraitsHelper>
48 {};
49 
50 } // namespace oops
51 
52 namespace ufo {
53 
54 /// \brief Options controlling the operation of the Gaussian_Thinning filter.
56  OOPS_CONCRETE_PARAMETERS(GaussianThinningParameters, FilterParametersBase)
57 
58  public:
59  /// Reimplemented to detect incompatible options.
60  void deserialize(util::CompositePath &path, const eckit::Configuration &config) override;
61 
62  // Horizontal grid
63 
64  /// Cell size (in km) along the meridians. Thinning in the horizontal direction is disabled if
65  /// this parameter is negative.
66  // FIXME(wsmigaj): for consistency with vertical thinning, I think it would be better to
67  // interpret absence of the horizontal_mesh setting as "don't do horizontal thinning"
68  // rather than using an arbitrary default grid size. Leaving things as they are for backward
69  // compatibility, for now.
70  oops::Parameter<float> horizontalMesh{"horizontal_mesh", defaultHorizontalMesh(), this};
71  /// True to use a reduced grid, with fewer cells at high latitudes.
72  /// False to use a regular grid, with the same number of cells at all latitudes.
73  oops::Parameter<bool> useReducedHorizontalGrid{"use_reduced_horizontal_grid", true, this};
74  /// True to set the number of zonal bands so that the band width is as close as possible to
75  /// \c horizontal_mesh, and the number of bins in each zonal band so that the bin width in the
76  /// zonal direction is as close as possible to that in the meridional direction.
77  /// False to set the number of zonal bands so that the band width is as small as possible, but
78  /// no smaller than \c horizontal_mesh, and the bin width in the zonal direction is as small as
79  /// possible, but no smaller than in the meridional direction.
80  ///
81  /// Defaults to \c false unless the \c ops_compatibility_mode option is enabled, in which case
82  /// it's set to \c true.
83  oops::OptionalParameter<bool> roundHorizontalBinCountToNearest{
84  "round_horizontal_bin_count_to_nearest", this};
85 
86  // Vertical grid
87 
88  /// Cell size in the vertical direction. Thinning in the vertical direction is disabled
89  /// if this parameter is not specified or negative.
90  oops::Parameter<float> verticalMesh{"vertical_mesh", -1.0f, this};
91  /// Lower bound of the vertical coordinate interval split into cells of size \c vertical_mesh.
92  oops::Parameter<float> verticalMin{"vertical_min", 100.0f, this};
93  /// Upper bound of the vertical coordinate interval split into cells of size \c vertical_mesh.
94  /// This parameter is rounded upwards to the nearest multiple of \c vertical_mesh starting from
95  /// \c vertical_min.
96  oops::Parameter<float> verticalMax{"vertical_max", 110000.0f, this};
97  /// Observation vertical coordinate.
98  oops::Parameter<std::string> verticalCoord{"vertical_coordinate", "air_pressure", this};
99 
100  // Temporal grid
101 
102  /// Cell size in the temporal direction. Temporal thinning is disabled if this this parameter is
103  /// not specified or set to 0.
104  oops::OptionalParameter<util::Duration> timeMesh{"time_mesh", this};
105  /// Lower bound of the time interval split into cells of size \c time_mesh. Temporal thinning is
106  /// disabled if this parameter is not specified.
107  oops::OptionalParameter<util::DateTime> timeMin{"time_min", this};
108  /// Upper bound of the time interval split into cells of size \c time_mesh.
109  /// This parameter is rounded upwards to the nearest multiple of \c time_mesh starting from
110  /// \c time_min. Temporal thinning is disabled if this parameter is not specified.
111  oops::OptionalParameter<util::DateTime> timeMax{"time_max", this};
112 
113  // Observation categories
114 
115  /// A string-valued or integer-valued variable. Observations with different values of that
116  /// variable are thinned separately.
117  ///
118  /// Note: The filter will automatically detect if the chosen variable was also used to group
119  /// observations into records when the ObsSpace was constructed, and if so, avoid exchanging
120  /// data with other MPI processes, since in these circumstances each process can thin its
121  /// observations independently from others.
122  ///
123  /// The variable used to group observations into records can be set with the
124  /// `obs space.obsdatain.obsgrouping.group variable` YAML option.
125  oops::OptionalParameter<Variable> categoryVariable{"category_variable", this};
126 
127  // Selection of observations to retain
128 
129  /// Variable storing observation priorities. Among all observations in a cell, only those with
130  /// the highest priority are considered as candidates for retaining. If not specified, all
131  /// observations are assumed to have equal priority.
132  oops::OptionalParameter<Variable> priorityVariable{"priority_variable", this};
133 
134  /// Determines which of the highest-priority observations lying in a cell is retained.
135  ///
136  /// Allowed values:
137  ///
138  /// - \c geodesic: retain the observation closest to the cell centre in the horizontal direction
139  /// (the vertical coordinate and time are ignored)
140  /// - \c maximum: retain the observation lying furthest from the cell's bounding box in the
141  /// system of coordinates in which the cell is a unit cube (all dimensions along which thinning
142  /// is enabled are taken into account).
143  ///
144  /// Defaults to \c geodesic unless the \c ops_compatibility_mode option is enabled, in which case
145  /// it's set to \c maximum.
146  oops::OptionalParameter<DistanceNorm> distanceNorm{"distance_norm", this};
147 
148  /// Set this option to \c true to make the filter produce identical results as the Ops_Thinning
149  /// subroutine from the Met Office OPS system when both are run serially (on a single process).
150  ///
151  /// The filter behavior is modified in several ways:
152  ///
153  /// - The \c round_horizontal_bin_count_to_nearest option is set to \c true.
154  ///
155  /// - The \c distance_norm option is set to \c maximum.
156  ///
157  /// - Bin indices are calculated by rounding values away from rather towards zero. This can alter
158  /// the bin indices assigned to observations lying at bin boundaries.
159  ///
160  /// - The bin lattice is assumed to cover the whole real axis (for times and pressures) or the
161  /// [-360, 720] degrees interval (for longitudes) rather than just the intervals [\c time_min,
162  /// \c time_max], [\c pressure_min, \c pressure_max] and [0, 360] degrees, respectively. This
163  /// may cause observations lying at the boundaries of the latter intervals to be put in bins of
164  /// their own, which is normally undesirable.
165  ///
166  /// - A different (non-stable) sorting algorithm is used to order observations before inspection.
167  /// This can alter the set of retained observations if some bins contain multiple equally good
168  /// observations (with the same priority and distance to the cell center measured with the
169  /// selected norm). If this happens for a significant fraction of bins, it may be a sign the
170  /// criteria used to rank observations (the priority and the distance norm) are not specific
171  /// enough.
172  oops::Parameter<bool> opsCompatibilityMode{"ops_compatibility_mode", false, this};
173 
174  /// Option to choose how to treat observations where there are multiple filter variables. If true,
175  /// treats an observation location as valid if any filter variables have not been rejected.
176  /// If false, observations are treated as valid only if all filter variables have passed QC.
177  /// This is an optional parameter, if omitted the default value is true.
178  oops::Parameter<bool>
179  thinIfAnyFilterVariablesAreValid{"thin_if_any_filter_variables_are_valid", true, this};
180 
181  private:
182  static float defaultHorizontalMesh() {
183  return static_cast<float>(2 * M_PI * Constants::mean_earth_rad / 360.0);
184  }
185 };
186 
187 } // namespace ufo
188 
189 #endif // UFO_FILTERS_GAUSSIANTHINNINGPARAMETERS_H_
Parameters shared by all filters having a default action (typically "reject").
Options controlling the operation of the Gaussian_Thinning filter.
oops::OptionalParameter< DistanceNorm > distanceNorm
oops::Parameter< std::string > verticalCoord
Observation vertical coordinate.
oops::OptionalParameter< Variable > priorityVariable
oops::OptionalParameter< util::DateTime > timeMin
oops::Parameter< bool > useReducedHorizontalGrid
void deserialize(util::CompositePath &path, const eckit::Configuration &config) override
Reimplemented to detect incompatible options.
oops::Parameter< bool > thinIfAnyFilterVariablesAreValid
oops::Parameter< float > verticalMin
Lower bound of the vertical coordinate interval split into cells of size vertical_mesh.
oops::OptionalParameter< Variable > categoryVariable
oops::OptionalParameter< util::Duration > timeMesh
oops::OptionalParameter< bool > roundHorizontalBinCountToNearest
oops::OptionalParameter< util::DateTime > timeMax
Forward declarations.
Definition: ObsAodExt.h:21
Definition: RunCRTM.h:27
static constexpr double mean_earth_rad
Definition: Constants.h:40
static constexpr util::NamedEnumerator< DistanceNorm > namedValues[]