UFO
MetOfficeRadianceErrorMatrices.h
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 
8 #ifndef TEST_UFO_METOFFICERADIANCEERRORMATRICES_H_
9 #define TEST_UFO_METOFFICERADIANCEERRORMATRICES_H_
10 
11 #include <Eigen/Dense>
12 #include <algorithm>
13 #include <set>
14 #include <string>
15 #include <vector>
16 
17 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
18 
19 #include "eckit/config/LocalConfiguration.h"
20 #include "eckit/testing/Test.h"
21 #include "oops/runs/Test.h"
22 #include "oops/util/Expect.h"
23 #include "oops/util/IntSetParser.h"
24 #include "oops/util/Logger.h"
25 #include "test/TestEnvironment.h"
28 
29 namespace ufo {
30 namespace test {
31 
32 void testMetOfficeRadianceErrorMatrices(const eckit::LocalConfiguration &conf) {
33  // Get test values from configuration
34  std::string chlist = conf.getString("channels");
35  const float latitude = conf.getFloat("latitude");
36  const size_t nelements = conf.getUnsigned("nelements");
37  const float BHT_value = conf.getFloat("BHT_value");
38  const float HBHT_value = conf.getFloat("HBHT_value");
39  const float HBHT_R_value = conf.getFloat("HBHT_R_value");
40  const float tol = conf.getFloat("tol");
41 
42  // Setup local variables
43  std::vector<int> channels;
44  std::set<int> chans = oops::parseIntSet(chlist);
45  std::copy(chans.begin(), chans.end(), std::back_inserter(channels));
46  const size_t nchans = channels.size();
47 
48  // -----------------
49  // Bmatrix testing
50  // -----------------
51 
52  // Construct object
53  MetOfficeBMatrixStatic bmatrix(conf);
54 
55  // Get an eigen matrix for a specific latitude
56  Eigen::MatrixXf Hmatrix = Eigen::MatrixXf::Constant(nchans, nelements, 2.0);
57  Eigen::MatrixXf BHT;
58  bmatrix.multiply(latitude, Hmatrix.transpose(), BHT);
59 
60  // Test print function
61  oops::Log::info() << "bmatrix = " << bmatrix << std::endl;
62 
63  // -----------------
64  // Rmatrix testing
65  // -----------------
66 
67  // Construct object
68  MetOfficeRMatrixRadiance rmatrix(conf);
69 
70  // Create a matrix to add to
71  Eigen::MatrixXf HBHT;
72  Eigen::MatrixXf HBHT_R;
73  HBHT = Hmatrix * BHT;
74  // HBH' + R
75  rmatrix.add(channels, HBHT, HBHT_R);
76 
77  // Test print function
78  oops::Log::info() << "rmatrix = " << rmatrix << std::endl;
79 
80  // -----------------------------
81  // Check values during testing
82  // ----------------------------
83 
84  // Test to check the multiplication appears to be correct
85  ASSERT(std::abs(BHT(0, 0) - BHT_value) < tol);
86  ASSERT(std::abs(HBHT(0, 0) - HBHT_value) < tol);
87  ASSERT(std::abs(HBHT_R(0, 0) - HBHT_R_value) < tol);
88 }
89 
90 class MetOfficeRadianceErrorMatrices : public oops::Test {
91  private:
92  std::string testid() const override {return "ufo::test::MetOfficeRadianceErrorMatrices";}
93 
94  void register_tests() const override {
95  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
96 
97  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
98  for (const std::string & testCaseName : conf.keys())
99  {
100  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
101  ts.emplace_back(CASE("ufo/MetOfficeRadianceErrorMatrices/" + testCaseName, testCaseConf)
102  {
104  });
105  }
106  }
107 
108  void clear() const override {}
109 };
110 
111 } // namespace test
112 } // namespace ufo
113 
114 #endif // TEST_UFO_METOFFICERADIANCEERRORMATRICES_H_
void multiply(const float, const Eigen::MatrixXf &, Eigen::MatrixXf &) const
Multiply input matrix by bmatrix array based on latitude.
void add(const std::vector< int > &, const Eigen::MatrixXf &, Eigen::MatrixXf &) const
Add r matrix variance onto input array.
void testMetOfficeRadianceErrorMatrices(const eckit::LocalConfiguration &conf)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27
util::Duration abs(const util::Duration &duration)