UFO
ObsErrorAssign.h
Go to the documentation of this file.
1 /*
2  * (C) 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_OBSERRORASSIGN_H_
9 #define TEST_UFO_OBSERRORASSIGN_H_
10 
11 #include <iomanip>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
17 
18 #include "eckit/config/LocalConfiguration.h"
19 #include "eckit/testing/Test.h"
20 #include "ioda/ObsSpace.h"
21 #include "ioda/ObsVector.h"
22 #include "oops/mpi/mpi.h"
23 #include "oops/runs/Test.h"
24 #include "oops/util/Expect.h"
25 #include "test/TestEnvironment.h"
26 #include "ufo/filters/BlackList.h"
27 #include "ufo/filters/Variables.h"
28 
29 namespace ufo {
30 namespace test {
31 
32 void testObsErrorAssign(const eckit::LocalConfiguration &conf) {
33  util::DateTime bgn(conf.getString("window begin"));
34  util::DateTime end(conf.getString("window end"));
35 
36  const eckit::LocalConfiguration obsSpaceConf(conf, "obs space");
37  ioda::ObsTopLevelParameters obsParams;
38  obsParams.validateAndDeserialize(obsSpaceConf);
39  ioda::ObsSpace obsspace(obsParams, oops::mpi::world(), bgn, end, oops::mpi::myself());
40 
41  std::vector<std::string> varnames {"air_pressure", "station_id", "observation_type",
42  "latitude_band", "channel_number", "processing_center",
43  "satellite_id"};
44  for (std::string varname : varnames) {
45  if (conf.has(varname)) {
46  const std::vector<int> dat = conf.getIntVector(varname);
47  obsspace.put_db("MetaData", varname, dat);
48  }
49  }
50  if (conf.has("StringVar")) {
51  const std::vector<std::string> dat = conf.getStringVector("StringVar");
52  obsspace.put_db("MetaData", "StringVar", dat);
53  }
54 
55  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
56  obsspace, obsspace.obsvariables(), "ObsError"));
57  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
58  obsspace, obsspace.obsvariables()));
59 
60  const eckit::LocalConfiguration filterConf(conf, "ObsError assign");
62  bfparam.deserialize(filterConf);
63 
64  ufo::BlackList filter(obsspace, bfparam, qcflags, obserr);
65  if (conf.has("expectExceptionWithMessage")) {
66  const std::string msg = conf.getString("expectExceptionWithMessage");
67  EXPECT_THROWS_MSG(filter.preProcess(), msg.c_str());
68  return;
69  } else {
70  filter.preProcess();
71  }
72 
73  std::vector<float> expectedObsError;
74  if (conf.has("expected_obserror")) {
75  expectedObsError = conf.getFloatVector("expected_obserror");
76  } else {
77  expectedObsError = conf.getFloatVector("expected_obserror_variance");
78  for (size_t ind=0; ind < expectedObsError.size(); ind++) {
79  expectedObsError[ind] = std::sqrt(expectedObsError[ind]);
80  }
81  }
82  int ind = 0;
83  for (size_t varn = 0; varn < obserr->nvars(); ++varn) {
84  for (size_t locn = 0; locn < obserr->nlocs(); ++locn) {
85  EXPECT(oops::is_close_absolute((*obserr)[varn][locn], expectedObsError[ind], 1e-4f, 0,
86  oops::TestVerbosity::LOG_SUCCESS_AND_FAILURE));
87  ind++;
88  }
89  }
90 }
91 
92 class ObsErrorAssign : public oops::Test {
93  private:
94  std::string testid() const override {return "ufo::test::ObsErrorAssign";}
95 
96  void register_tests() const override {
97  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
98 
99  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
100  for (const std::string & testCaseName : conf.keys())
101  {
102  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
103  ts.emplace_back(CASE("ufo/ObsErrorAssign/" + testCaseName, testCaseConf)
104  {
105  testObsErrorAssign(testCaseConf);
106  });
107  }
108  }
109 
110  void clear() const override {}
111 };
112 
113 } // namespace test
114 } // namespace ufo
115 
116 #endif // TEST_UFO_OBSERRORASSIGN_H_
Generic black listing of observations.
Definition: BlackList.h:44
void preProcess() override
void clear() const override
void register_tests() const override
std::string testid() const override
void testObsErrorAssign(const eckit::LocalConfiguration &conf)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27