UFO
MetOfficeBuddyCollector.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 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 
9 
10 #include <algorithm>
11 #include <cmath>
12 
13 #include "oops/util/sqr.h"
15 #include "ufo/utils/Constants.h"
16 
17 namespace ufo {
18 
20  const std::vector<float> &latitudes,
21  const std::vector<float> &longitudes,
22  const std::vector<int> &stationIds)
23  : options_(options), latitudes_(latitudes), longitudes_(longitudes), stationIds_(stationIds)
24 {
25  // eqn 3.1
28 }
29 
31  double &deltaLatInRad,
32  double &deltaLonInRad,
33  double &distanceInKm) const {
34  deltaLatInRad = (latitudes_[obsIdB] - latitudes_[obsIdA_]) * Constants::deg2rad;
35 
36  deltaLonInRad = (longitudes_[obsIdB] - longitudes_[obsIdA_]) * Constants::deg2rad;
37  if (deltaLonInRad > M_PI)
38  deltaLonInRad -= 2 * M_PI;
39  else if (deltaLonInRad < -M_PI)
40  deltaLonInRad += 2 * M_PI;
41 
42  distanceInKm = Constants::mean_earth_rad *
43  std::sqrt(util::sqr(deltaLatInRad) +
44  4.0 * util::sqr(std::sin(0.5 * deltaLonInRad)) *
46  std::cos(latitudes_[obsIdB] * Constants::deg2rad)); // eqn 3.3
47 }
48 
50  double deltaLatInRad,
51  double deltaLonInRad,
52  double distanceInKm) const {
53  double rotA, rotB;
54  if (distanceInKm < 10.0) {
55  rotA = 0.0; // the transformation is undefined
56  rotB = 0.0; // for distanceInKm = 0.0, use u,v components
57  } else {
58  // eqn 3.5
59  double alpha = 0.5 * std::sin(latitudes_[obsIdA_] * Constants::deg2rad) * deltaLonInRad;
60  // eqn 3.6
61  double sinBeta = Constants::mean_earth_rad * deltaLatInRad * std::cos(alpha) / distanceInKm;
62  sinBeta = std::min(1.0, std::max(-1.0, sinBeta));
63  double beta = std::asin(sinBeta);
64  rotA = alpha + beta; // eqn 3.7
65  rotB = beta - alpha; // eqn 3.8
66  }
67 
68  return MetOfficeBuddyPair(obsIdA_, obsIdB, distanceInKm, rotA, rotB);
69 }
70 
71 } // namespace ufo
Options controlling the operation of the MetOfficeBuddyCheck filter.
oops::Parameter< float > searchRadius
Maximum distance between two observations that may be classified as buddies, in km.
const std::vector< float > & latitudes_
MetOfficeBuddyPair createBuddyPair(int obsIdB, double deltaLatInRad, double deltaLonInRad, double distanceInKm) const
void calcDeltaLatLonAndDistanceTo(int obsIdB, double &deltaLatInRad, double &deltaLonInRad, double &distanceInKm) const
const std::vector< float > & longitudes_
MetOfficeBuddyCollector(const MetOfficeBuddyCheckParameters &options, const std::vector< float > &latitudes, const std::vector< float > &longitudes, const std::vector< int > &stationIds)
Constructor.
real(kind_real), parameter, public alpha
Definition: RunCRTM.h:27
static constexpr double deg2rad
Definition: Constants.h:21
static constexpr double rad2deg
Definition: Constants.h:22
static constexpr double mean_earth_rad
Definition: Constants.h:40
Properties of a pair of observations checked against each other during buddy check.