UFO
ObsErrorFactorQuotient.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 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 "eckit/exception/Exceptions.h"
11 
12 #include "ioda/ObsDataVector.h"
13 
14 #include "oops/util/Logger.h"
15 #include "oops/util/missingValues.h"
16 
17 namespace ufo {
18 
19 static ObsFunctionMaker<ObsErrorFactorQuotient> makerSteps_("ObsErrorFactorQuotient");
20 
21 // -----------------------------------------------------------------------------
22 
23 ObsErrorFactorQuotient::ObsErrorFactorQuotient(const eckit::LocalConfiguration config)
24  : invars_() {
25  // Initialize options
26  options_.deserialize(config);
27 
28  // Initialize the two desired variables, numerator and denominator
29  const Variable &numerator = options_.numerator.value();
30  const Variable &denominator = options_.denominator.value();
31  ASSERT(numerator.size() == 1);
32  ASSERT(denominator.size() == 1);
33 
34  invars_ += numerator;
35  invars_ += denominator;
36 
37  oops::Log::debug() << "ObsErrorFactorQuotient: config (constructor) = "
38  << config << std::endl;
39 }
40 
41 // -----------------------------------------------------------------------------
42 
44 
45 // -----------------------------------------------------------------------------
46 
48  ioda::ObsDataVector<float> & out) const {
49  const float missing = util::missingValue(missing);
50 
51  // Get the numeratory and denominator names
52  const Variable &numerator = options_.numerator.value();
53  const Variable &denominator = options_.denominator.value();
54  oops::Log::debug() << " ObsErrorFactorQuotient, numerator name: " << numerator.variable()
55  << " and group: " << numerator.group() << std::endl
56  << " denominator name: " << denominator.variable()
57  << " and group: " << denominator.group() << std::endl;
58 
59  // Populate the arrays.
60  ioda::ObsDataVector<float> numer(data.obsspace(), numerator.toOopsVariables());
61  data.get(numerator, numer);
62  ioda::ObsDataVector<float> denom(data.obsspace(), denominator.toOopsVariables());
63  data.get(denominator, denom);
64 
65  // The 1st index of data should have size 1 and 2nd index should be size nlocs.
66  int iv = 0;
67  if (numer[iv].size() != out[iv].size() || numer[iv].size() != denom[iv].size()) {
68  std::ostringstream errString;
69  errString << "Something is wrong, numer size not equal out or denom size."
70  << " Sizes: " << numer[iv].size() << " and " << out[iv].size() << std::endl;
71  oops::Log::error() << errString.str();
72  throw eckit::BadValue(errString.str());
73  }
74 
75  for (size_t jobs = 0; jobs < numer[iv].size(); ++jobs) {
76  out[iv][jobs] = missing;
77  if (numer[iv][jobs] == missing || denom[iv][jobs] == missing || denom[iv][jobs] == 0) {
78  continue;
79  }
80  out[iv][jobs] = numer[iv][jobs]/denom[iv][jobs];
81  }
82 
83  if (options_.save) {
84  out.save("DerivedValue");
85  }
86 }
87 
88 // -----------------------------------------------------------------------------
89 
91  return invars_;
92 }
93 
94 // -----------------------------------------------------------------------------
95 
96 } // namespace ufo
const ufo::Variables & requiredVariables() const
geovals required to compute the function
ObsErrorFactorQuotient(const eckit::LocalConfiguration)
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
ObsErrorFactorQuotientParameters options_
oops::RequiredParameter< Variable > denominator
oops::RequiredParameter< Variable > numerator
the name of the numerator and denominator variables (with group names).
ObsFilterData provides access to all data related to an ObsFilter.
ioda::ObsSpace & obsspace() const
Returns reference to ObsSpace associated with ObsFilterData.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
const std::string & variable() const
Definition: Variable.cc:99
const std::string & group() const
Definition: Variable.cc:116
oops::Variables toOopsVariables() const
Definition: Variable.cc:139
size_t size() const
Definition: Variable.cc:78
constexpr int missing
Definition: QCflags.h:20
Definition: RunCRTM.h:27
static ObsFunctionMaker< ObsErrorFactorConventional > makerSteps_("ObsErrorFactorConventional")