UFO
SatWindsLNVDCheck.cc
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 
9 
10 #include <math.h>
11 #include <vector>
12 
13 #include "ioda/ObsDataVector.h"
14 #include "oops/util/missingValues.h"
15 #include "ufo/filters/Variable.h"
16 
17 namespace ufo {
18 
20 
21 // -----------------------------------------------------------------------------
22 
23 SatWindsLNVDCheck::SatWindsLNVDCheck(const eckit::LocalConfiguration & conf)
24  : invars_() {
25  oops::Log::debug() << "SatWindsLNVDCheck: config = " << conf << std::endl;
26  // Initialize options
27  options_.deserialize(conf);
28 
29  // We need to retrieve the observed wind components.
30  invars_ += Variable("eastward_wind@ObsValue");
31  invars_ += Variable("northward_wind@ObsValue");
32 
33  // Typical use would be HofX group, but during testing, we include option for GsiHofX
34  std::string test_hofx = options_.test_hofx.value();
35  invars_ += Variable("eastward_wind@" + test_hofx);
36  invars_ += Variable("northward_wind@" + test_hofx);
37 
38  // TODO(gthompsn): Need to include a check that whatever HofX group name used actually exists.
39 }
40 
41 // -----------------------------------------------------------------------------
42 
43 SatWindsLNVDCheck::~SatWindsLNVDCheck() {}
44 
45 // -----------------------------------------------------------------------------
46 
47 void SatWindsLNVDCheck::compute(const ObsFilterData & in,
48  ioda::ObsDataVector<float> & out) const {
49  const size_t nlocs = in.nlocs();
50  const float missing = util::missingValue(missing);
51 
52  // Ensure that only one output variable is expected.
53  ASSERT(out.nvars() == 1);
54 
55  // Retrieve SatWinds observations of wind components
56  std::vector<float> u, v;
57  in.get(Variable("eastward_wind@ObsValue"), u);
58  in.get(Variable("northward_wind@ObsValue"), v);
59  // Retrieve Model HofX wind components
60  std::string test_hofx = options_.test_hofx.value();
61  std::vector<float> um, vm;
62  in.get(Variable("eastward_wind@" + test_hofx), um);
63  in.get(Variable("northward_wind@" + test_hofx), vm);
64 
65  for (size_t jj = 0; jj < nlocs; ++jj) {
66  if (u[jj] != missing && v[jj] != missing) {
67  if ((u[jj]*u[jj] + v[jj]*v[jj]) > 1.01f) {
68  out[0][jj] = sqrt((u[jj]-um[jj])*(u[jj]-um[jj]) + (v[jj]-vm[jj])*(v[jj]-vm[jj]))
69  / log(sqrt(u[jj]*u[jj] + v[jj]*v[jj]));
70  } else {
71  out[0][jj] = sqrt((u[jj]-um[jj])*(u[jj]-um[jj]) + (v[jj]-vm[jj])*(v[jj]-vm[jj]));
72  }
73  } else {
74  out[0][jj] = missing;
75  }
76  }
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 const ufo::Variables & SatWindsLNVDCheck::requiredVariables() const {
82  return invars_;
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 } // namespace ufo
constexpr int missing
Definition: QCflags.h:20
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static ObsFunctionMaker< SatWindsLNVDCheck > makerObsFuncSatWindsLNVDCheck_("SatWindsLNVDCheck")