UFO
ObsCategoricalTLAD.cc
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2021, Met Office
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 <map>
12 #include <ostream>
13 #include <utility>
14 
15 #include "ioda/ObsVector.h"
16 
17 #include "oops/util/Logger.h"
18 
20 #include "ufo/GeoVaLs.h"
21 
22 namespace ufo {
23 
24 // -----------------------------------------------------------------------------
26 // -----------------------------------------------------------------------------
27 
28 ObsCategoricalTLAD::ObsCategoricalTLAD(const ioda::ObsSpace & odb,
29  const Parameters_ & params)
30  : LinearObsOperatorBase(odb), odb_(odb)
31 {
32  oops::Log::trace() << "ObsCategoricalTLAD constructor starting" << std::endl;
33 
34  data_.configure(odb, params);
35 
36  oops::Log::trace() << "ObsCategoricalTLAD created." << std::endl;
37 }
38 
39 // -----------------------------------------------------------------------------
40 
42  oops::Log::trace() << "ObsCategoricalTLAD destructed" << std::endl;
43 }
44 
45 // -----------------------------------------------------------------------------
46 
48  ObsDiagnostics & ydiags) {
49  oops::Log::trace() << "ObsCategoricalTLAD: setTrajectory entered" << std::endl;
50 
51  // Set trajectory for each operator.
52  for (const auto& component : data_.components())
53  component.second->setTrajectory(geovals, ydiags);
54 
55  oops::Log::trace() << "ObsCategoricalTLAD: setTrajectory finished" << std::endl;
56 }
57 
58 // -----------------------------------------------------------------------------
59 
60 void ObsCategoricalTLAD::simulateObsTL(const GeoVaLs & geovals, ioda::ObsVector & ovec) const {
61  oops::Log::trace() << "ObsCategoricalTLAD: simulateObsTL entered" << std::endl;
62 
63  oops::Log::debug() << "Running TL operators" << std::endl;
64 
65  // Container of ObsVectors produced by each TL operator.
66  std::map <std::string, ioda::ObsVector> ovecs;
67  // Run each TL operator and store output in ovecs.
68  for (const auto& component : data_.components()) {
69  ioda::ObsVector ovecTemp(ovec);
70  component.second->simulateObsTL(geovals, ovecTemp);
71  ovecs.insert({component.first, ovecTemp});
72  }
73 
74  oops::Log::debug() << "Producing final TL" << std::endl;
75 
76  data_.fillHofX(ovecs, ovec);
77 
78  oops::Log::trace() << "ObsCategoricalTLAD: simulateObsTL finished" << std::endl;
79 }
80 
81 // -----------------------------------------------------------------------------
82 
83 void ObsCategoricalTLAD::simulateObsAD(GeoVaLs & geovals, const ioda::ObsVector & ovec) const {
84  oops::Log::trace() << "ObsCategoricalTLAD: simulateObsAD entered" << std::endl;
85 
86  oops::Log::debug() << "Running AD operators" << std::endl;
87 
88  // Container of GeoVaLs produced by each AD operator.
89  std::map <std::string, GeoVaLs> gvals;
90  // Run each AD operator and store output in gvals.
91  for (const auto& component : data_.components()) {
92  GeoVaLs gvalTemp(geovals);
93  component.second->simulateObsAD(gvalTemp, ovec);
94  gvals.insert({component.first, gvalTemp});
95  }
96 
97  oops::Log::debug() << "Producing final AD" << std::endl;
98 
99  // Insert values into geovals according to the categorical variable.
100  // Use the fallback operator when necessary.
101  const std::vector<std::string> &varnames = ovec.varnames().variables();
102  std::vector <double> vecgv;
103  for (size_t jloc = 0; jloc < ovec.nlocs(); ++jloc) {
104  const auto &operName = data_.locOperNames()[jloc];
105  const auto &gvaloper = gvals.at(operName);
106  // Loop over each variable at this location.
107  for (const auto& varname : varnames) {
108  vecgv.resize(gvaloper.nlevs(varname));
109  gvaloper.getAtLocation(vecgv, varname, jloc);
110  geovals.putAtLocation(vecgv, varname, jloc);
111  }
112  }
113 
114  oops::Log::trace() << "ObsCategoricalTLAD: simulateObsAD finished" << std::endl;
115 }
116 
117 // -----------------------------------------------------------------------------
118 
119 void ObsCategoricalTLAD::print(std::ostream & os) const {
120  data_.print(os);
121 }
122 
123 // -----------------------------------------------------------------------------
124 
125 } // namespace ufo
GeoVaLs: geophysical values at locations.
void putAtLocation(const std::vector< double > &vals, const std::string &var, const int loc) const
Put GeoVaLs for double variable var at location loc.
Definition: GeoVaLs.cc:451
Configuration options recognized by the Categorical operator.
ObsCategoricalTLAD(const ioda::ObsSpace &, const Parameters_ &)
void print(std::ostream &) const override
void simulateObsTL(const GeoVaLs &, ioda::ObsVector &) const override
void setTrajectory(const GeoVaLs &, ObsDiagnostics &) override
Obs Operator.
void simulateObsAD(GeoVaLs &, const ioda::ObsVector &) const override
ObsCategoricalData< LinearObsOperatorBase > data_
Data handler for the Categorical operator and TL/AD code.
Definition: RunCRTM.h:27
static LinearObsOperatorMaker< ObsCategoricalTLAD > makerCategoricalTL_("Categorical")