UFO
test/ufo/LinearObsBiasOperator.h
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2021 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 TEST_UFO_LINEAROBSBIASOPERATOR_H_
9 #define TEST_UFO_LINEAROBSBIASOPERATOR_H_
10 
11 #include <iomanip>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include "eckit/config/LocalConfiguration.h"
17 #include "eckit/testing/Test.h"
18 #include "ioda/ObsSpace.h"
19 #include "ioda/ObsVector.h"
20 #include "oops/mpi/mpi.h"
21 #include "oops/runs/Test.h"
22 #include "test/interface/ObsTestsFixture.h"
23 #include "test/TestEnvironment.h"
24 #include "ufo/filters/Variables.h"
25 #include "ufo/GeoVaLs.h"
26 #include "ufo/LinearObsBiasOperator.h"
27 #include "ufo/ObsBias.h"
28 #include "ufo/ObsBiasIncrement.h"
29 #include "ufo/ObsDiagnostics.h"
30 #include "ufo/ObsTraits.h"
31 
32 namespace ufo {
33 namespace test {
34 
35 // -----------------------------------------------------------------------------
36 
37 // Tests whether application of the linear obs bias operator to an obs bias increment obtained
38 // by subtracting two obs biases from each other produces the expected results.
39 CASE("ufo/LinearObsBiasOperator/testLinearObsBiasOperator") {
40  typedef ::test::ObsTestsFixture<ObsTraits> Test_;
41 
42  std::vector<eckit::LocalConfiguration> typeconfs;
43  ::test::TestEnvironment::config().get("observations", typeconfs);
44 
45  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
46  ioda::ObsSpace &odb = Test_::obspace()[jj].obsspace();
47  const eckit::Configuration &conf = typeconfs[jj];
48 
49  // initialize obs bias objects
50  eckit::LocalConfiguration biasConf = conf.getSubConfiguration("obs bias");
51  eckit::LocalConfiguration targetBiasConf = conf.getSubConfiguration("target obs bias");
52  ObsBiasParameters biasParams;
53  ObsBiasParameters targetBiasParams;
54  biasParams.validateAndDeserialize(biasConf);
55  targetBiasParams.validateAndDeserialize(targetBiasConf);
56  const ObsBias bias(odb, biasParams);
57  const ObsBias targetBias(odb, targetBiasParams);
58 
59  // read geovals from the file
60  const eckit::LocalConfiguration gconf(conf, "geovals");
61  oops::Variables requiredVars = odb.obsvariables();
62  requiredVars += bias.requiredVars();
63  requiredVars += targetBias.requiredVars();
64  const GeoVaLs geovals(gconf, odb, requiredVars);
65 
66  // set up obs diagnostics
67  oops::Variables requiredHdiagnostics;
68  requiredHdiagnostics += bias.requiredHdiagnostics();
69  std::vector<float> lons(odb.nlocs());
70  std::vector<float> lats(odb.nlocs());
71  std::vector<util::DateTime> times(odb.nlocs());
72  odb.get_db("MetaData", "latitude", lats);
73  odb.get_db("MetaData", "longitude", lons);
74  odb.get_db("MetaData", "datetime", times);
75  ObsDiagnostics ydiags(odb, Locations(lons, lats, times, odb.distribution()),
76  requiredHdiagnostics);
77 
78  // set TL trajectory to the geovals and the bias coeff. from the files
79  LinearObsBiasOperator biasOperator(odb);
80  biasOperator.setTrajectory(geovals, bias, ydiags);
81 
82  // set the bias increment to the difference between two obs biases initialised earlier
83  ObsBiasIncrement biasInc(odb, biasParams);
84  biasInc.diff(targetBias, bias);
85 
86  // apply the linear obs bias operator
87  ioda::ObsVector dy(odb);
88  biasOperator.computeObsBiasTL(geovals, biasInc, dy);
89 
90  // verify results
91  const double dy_rms = dy.rms();
92  const double expected_dy_rms = conf.getDouble("rms ref");
93  const double tol = conf.getDouble("relative tolerance");
94  EXPECT(oops::is_close_relative(dy_rms, expected_dy_rms, tol));
95  }
96 }
97 
98 // -----------------------------------------------------------------------------
99 
100 class LinearObsBiasOperator : public oops::Test {
101  private:
102  std::string testid() const override {return "ufo::test::LinearObsBiasOperator";}
103 
104  void register_tests() const override { }
105 
106  void clear() const override {}
107 };
108 
109 // -----------------------------------------------------------------------------
110 
111 } // namespace test
112 } // namespace ufo
113 
114 #endif // TEST_UFO_LINEAROBSBIASOPERATOR_H_
Contains increments to bias correction coefficients.
void diff(const ObsBias &, const ObsBias &)
Parameters influencing the bias correction process.
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27