UFO
test/ufo/HistoryCheck.h
Go to the documentation of this file.
1 /*
2  * (C) 2021 Crown Copyright Met Office. All rights reserved.
3  * This software is licensed under the terms of the Apache Licence Version 2.0
4  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5  */
6 #ifndef TEST_UFO_HISTORYCHECK_H_
7 #define TEST_UFO_HISTORYCHECK_H_
8 
9 #include <iomanip>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
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 "oops/util/Expect.h"
23 #include "test/TestEnvironment.h"
25 #include "ufo/filters/Variables.h"
26 
27 namespace ufo {
28 namespace test {
29 void testHistoryCheck(const eckit::LocalConfiguration &conf) {
30  util::DateTime bgn(conf.getString("window begin"));
31  util::DateTime end(conf.getString("window end"));
32 
33  const eckit::LocalConfiguration obsSpaceConf(conf, "obs space");
34  ioda::ObsTopLevelParameters obsParams;
35  obsParams.validateAndDeserialize(obsSpaceConf);
36  ioda::ObsSpace obsspace(obsParams, oops::mpi::world(), bgn, end, oops::mpi::myself());
37 
38  eckit::LocalConfiguration filterConf(conf, "History Check");
39  ufo::HistoryCheckParameters filterParameters;
40  filterParameters.validateAndDeserialize(filterConf);
41 
42  if (conf.has("air_temperatures")) {
43  const std::vector<float> airTemperatures = conf.getFloatVector("air_temperatures");
44  obsspace.put_db("ObsValue", "air_temperature", airTemperatures);
45  }
46 
47  if (conf.has("station_ids")) {
48  const std::vector<int> stationIds = conf.getIntVector("station_ids");
49  obsspace.put_db("MetaData", "station_id", stationIds);
50  }
51 
52  if (conf.has("station_ids_string")) {
53  const std::vector<std::string> stationIds = conf.getStringVector("station_ids_string");
54  obsspace.put_db("MetaData", "station_id", stationIds);
55  }
56 
57  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
58  obsspace, obsspace.obsvariables(), "ObsError"));
59  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
60  obsspace, obsspace.obsvariables()));
61 
62  ufo::HistoryCheck filter(obsspace, filterParameters, qcflags, obserr, conf);
63  filter.preProcess();
64 
65  const std::vector<size_t> expectedRejectedObsIndices =
66  conf.getUnsignedVector("expected rejected obs indices");
67  std::vector<size_t> rejectedObsIndices;
68  for (size_t i = 0; i < qcflags->nlocs(); ++i)
69  if ((*qcflags)[0][i] == ufo::QCflags::history)
70  rejectedObsIndices.push_back(i);
71  EXPECT_EQUAL(rejectedObsIndices, expectedRejectedObsIndices);
72 }
73 
74 class HistoryCheck : public oops::Test {
75  private:
76  std::string testid() const override {return "ufo::test::HistoryCheck";}
77 
78  void register_tests() const override {
79  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
80 
81  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
82  for (const std::string &testCaseName : conf.keys())
83  {
84  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
85  ts.emplace_back(CASE("ufo/HistoryCheck/" + testCaseName, testCaseConf)
86  {
87  testHistoryCheck(testCaseConf);
88  });
89  }
90  }
91 
92  void clear() const override {}
93 };
94 
95 } // namespace test
96 } // namespace ufo
97 
98 #endif // TEST_UFO_HISTORYCHECK_H_
Options controlling the operation of history check filter.
void preProcess() override
void register_tests() const override
std::string testid() const override
void clear() const override
constexpr int history
Definition: QCflags.h:38
void testHistoryCheck(const eckit::LocalConfiguration &conf)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27