UFO
MaxNormDistanceCalculator.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_UTILS_MAXNORMDISTANCECALCULATOR_H_
9 #define UFO_UTILS_MAXNORMDISTANCECALCULATOR_H_
10 
11 #include <algorithm>
12 #include <cmath>
13 
15 
16 namespace ufo {
17 
18 /// A DistanceCalculator implementing the distance function that maps each pair of points
19 /// (x1, x2, x3, ...) and (y1, y2, y3, ...) to max_i(|x_i - y_i|/w_i), where w_i (i >= 1)
20 /// are scaling factors.
22 {
23  public:
24  float spatialDistanceComponent(float obsLatitude, float obsLongitude,
25  float latitudeBinCenter, float longitudeBinCenter,
26  float inverseLatitudeBinWidth,
27  float inverseLongitudeBinWidth) const override {
28  float latitudeComponent =
29  std::abs(obsLatitude - latitudeBinCenter) * inverseLatitudeBinWidth;
30  float longitudeComponent =
31  std::abs(obsLongitude - longitudeBinCenter) * inverseLongitudeBinWidth;
32  return combineDistanceComponents(latitudeComponent, longitudeComponent);
33  }
34 
35  float nonspatialDistanceComponent(float obs, float binCenter,
36  float inverseBinWidth) const override {
37  return std::abs(obs - binCenter) * inverseBinWidth;
38  }
39 
40  float combineDistanceComponents(float componentA, float componentB) const override {
41  return std::max(componentA, componentB);
42  }
43 
44  float finalise(float combinedComponents) const override {
45  return combinedComponents;
46  }
47 };
48 
49 } // namespace ufo
50 
51 #endif // UFO_UTILS_MAXNORMDISTANCECALCULATOR_H_
Calculates distances between observations and centres of bins used during thinning.
float combineDistanceComponents(float componentA, float componentB) const override
float spatialDistanceComponent(float obsLatitude, float obsLongitude, float latitudeBinCenter, float longitudeBinCenter, float inverseLatitudeBinWidth, float inverseLongitudeBinWidth) const override
float finalise(float combinedComponents) const override
float nonspatialDistanceComponent(float obs, float binCenter, float inverseBinWidth) const override
Definition: RunCRTM.h:27
util::Duration abs(const util::Duration &duration)