IODA
LocalObsSpaceParameters.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 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 CORE_LOCALOBSSPACEPARAMETERS_H_
9 #define CORE_LOCALOBSSPACEPARAMETERS_H_
10 
11 #include <string>
12 #include <utility>
13 
14 #include "eckit/exception/Exceptions.h"
15 #include "eckit/geometry/KPoint.h"
16 #include "eckit/geometry/Point2.h"
17 #include "eckit/geometry/UnitSphere.h"
18 
19 #include "oops/util/parameters/OptionalParameter.h"
20 #include "oops/util/parameters/Parameter.h"
21 #include "oops/util/parameters/Parameters.h"
22 #include "oops/util/parameters/RequiredParameter.h"
23 
24 namespace eckit {
25  class Configuration;
26 }
27 
28 namespace ioda {
29 
30 enum class DistanceType {
32 };
33 
34 enum class SearchMethod {
36 };
37 
40  static constexpr char enumTypeName[] = "DistanceType";
41  static constexpr util::NamedEnumerator<DistanceType> namedValues[] = {
42  { DistanceType::GEODESIC, "geodesic" },
43  { DistanceType::CARTESIAN, "cartesian" }
44  };
45 };
46 
49  static constexpr char enumTypeName[] = "SearchMethod";
50  static constexpr util::NamedEnumerator<SearchMethod> namedValues[] = {
51  { SearchMethod::BRUTEFORCE, "brute_force" },
52  { SearchMethod::KDTREE, "kd_tree" }
53  };
54 };
55 
56 } // namespace ioda
57 
58 namespace oops {
59 
60 /// Extraction of DistanceType parameters from config
61 template <>
62 struct ParameterTraits<ioda::DistanceType> :
63  public EnumParameterTraits<ioda::DistanceTypeParameterTraitsHelper>
64 {};
65 
66 
67 /// Extraction of SearchMethod parameters from config
68 template <>
69 struct ParameterTraits<ioda::SearchMethod> :
70  public EnumParameterTraits<ioda::SearchMethodParameterTraitsHelper>
71 {};
72 
73 } // namespace oops
74 
75 namespace ioda {
76 
77 /// \brief Options controlling local observations subsetting
78 class LocalObsSpaceParameters : public oops::Parameters {
79  OOPS_CONCRETE_PARAMETERS(LocalObsSpaceParameters, Parameters)
80 
81  public:
82  /// Localization lengthscale (find all obs within the distance from reference point)
83  oops::RequiredParameter<double> lengthscale{"lengthscale", this};
84 
85  /// Method for searching for nearest points: brute force or KD-tree
86  oops::Parameter<SearchMethod> searchMethod{"search method", SearchMethod::BRUTEFORCE, this};
87 
88  /// Maximum number of obs
89  oops::OptionalParameter<int> maxnobs{"max nobs", this};
90 
91  /// Distance calculation type: geodesic (on sphere) or cartesian (euclidian)
92  /// Default: geodesic
93  oops::Parameter<DistanceType> distanceType{"distance type", DistanceType::GEODESIC, this};
94 
95  /// returns distance between points \p p1 and \p p2, depending on the
96  /// distance calculation type distanceType
97  double distance(const eckit::geometry::Point2 & p1, const eckit::geometry::Point2 & p2) {
99  return eckit::geometry::Sphere::distance(radius_earth, p1, p2);
100  } else {
102  return p1.distance(p2);
103  }
104  }
105 
106  // Earth radius in m
107  static constexpr double radius_earth = 6.371e6;
108 };
109 
110 } // namespace ioda
111 
112 #endif // CORE_LOCALOBSSPACEPARAMETERS_H_
oops
Definition: LocalObsSpaceParameters.h:58
ioda::DistanceTypeParameterTraitsHelper::EnumType
DistanceType EnumType
Definition: LocalObsSpaceParameters.h:39
ioda::LocalObsSpaceParameters::maxnobs
oops::OptionalParameter< int > maxnobs
Maximum number of obs.
Definition: LocalObsSpaceParameters.h:89
ioda::SearchMethodParameterTraitsHelper
Definition: LocalObsSpaceParameters.h:47
ioda::SearchMethod
SearchMethod
Definition: LocalObsSpaceParameters.h:34
ioda::LocalObsSpaceParameters::distance
double distance(const eckit::geometry::Point2 &p1, const eckit::geometry::Point2 &p2)
Definition: LocalObsSpaceParameters.h:97
ioda::DistanceTypeParameterTraitsHelper
Definition: LocalObsSpaceParameters.h:38
ioda::DistanceType
DistanceType
Definition: LocalObsSpaceParameters.h:30
ioda::DistanceType::CARTESIAN
@ CARTESIAN
ioda
Definition: IodaUtils.cc:13
eckit
Definition: LocalObsSpaceParameters.h:24
ioda::SearchMethod::BRUTEFORCE
@ BRUTEFORCE
ioda::SearchMethodParameterTraitsHelper::EnumType
SearchMethod EnumType
Definition: LocalObsSpaceParameters.h:48
ioda::LocalObsSpaceParameters::lengthscale
oops::RequiredParameter< double > lengthscale
Localization lengthscale (find all obs within the distance from reference point)
Definition: LocalObsSpaceParameters.h:83
ioda::LocalObsSpaceParameters
Options controlling local observations subsetting.
Definition: LocalObsSpaceParameters.h:78
ioda::DistanceTypeParameterTraitsHelper::enumTypeName
static constexpr char enumTypeName[]
Definition: LocalObsSpaceParameters.h:40
ioda::SearchMethodParameterTraitsHelper::namedValues
static constexpr util::NamedEnumerator< SearchMethod > namedValues[]
Definition: LocalObsSpaceParameters.h:50
ioda::SearchMethod::KDTREE
@ KDTREE
ioda::SearchMethodParameterTraitsHelper::enumTypeName
static constexpr char enumTypeName[]
Definition: LocalObsSpaceParameters.h:49
ioda::DistanceType::GEODESIC
@ GEODESIC
ioda::LocalObsSpaceParameters::radius_earth
static constexpr double radius_earth
Definition: LocalObsSpaceParameters.h:107
ioda::LocalObsSpaceParameters::distanceType
oops::Parameter< DistanceType > distanceType
Definition: LocalObsSpaceParameters.h:93
ioda::LocalObsSpaceParameters::searchMethod
oops::Parameter< SearchMethod > searchMethod
Method for searching for nearest points: brute force or KD-tree.
Definition: LocalObsSpaceParameters.h:86
ioda::DistanceTypeParameterTraitsHelper::namedValues
static constexpr util::NamedEnumerator< DistanceType > namedValues[]
Definition: LocalObsSpaceParameters.h:41