UFO
test/ufo/TemporalThinning.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 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_TEMPORALTHINNING_H_
9 #define TEST_UFO_TEMPORALTHINNING_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"
27 #include "ufo/filters/Variables.h"
28 
29 namespace ufo {
30 namespace test {
31 
32 void testTemporalThinning(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  if (conf.has("category")) {
42  const std::vector<int> categories = conf.getIntVector("category");
43  obsspace.put_db("MetaData", "category", categories);
44  }
45 
46  if (conf.has("string_category")) {
47  const std::vector<std::string> categories = conf.getStringVector("string_category");
48  obsspace.put_db("MetaData", "string_category", categories);
49  }
50 
51  if (conf.has("priority")) {
52  const std::vector<int> priorities = conf.getIntVector("priority");
53  obsspace.put_db("MetaData", "priority", priorities);
54  }
55 
56  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
57  obsspace, obsspace.obsvariables(), "ObsError"));
58  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
59  obsspace, obsspace.obsvariables()));
60 
61  eckit::LocalConfiguration filterConf(conf, "TemporalThinning");
62  ufo::TemporalThinningParameters filterParameters;
63  filterParameters.validateAndDeserialize(filterConf);
64  ufo::TemporalThinning filter(obsspace, filterParameters, qcflags, obserr);
65  filter.preProcess();
66 
67  const std::vector<size_t> expectedThinnedObsIndices =
68  conf.getUnsignedVector("expected_thinned_obs_indices");
69  std::vector<size_t> thinnedObsIndices;
70  for (size_t i = 0; i < qcflags->nlocs(); ++i)
71  if ((*qcflags)[0][i] == ufo::QCflags::thinned)
72  thinnedObsIndices.push_back(i);
73  EXPECT_EQUAL(thinnedObsIndices, expectedThinnedObsIndices);
74 }
75 
76 class TemporalThinning : public oops::Test {
77  private:
78  std::string testid() const override {return "ufo::test::TemporalThinning";}
79 
80  void register_tests() const override {
81  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
82 
83  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
84  for (const std::string & testCaseName : conf.keys())
85  {
86  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
87  ts.emplace_back(CASE("ufo/TemporalThinning/" + testCaseName, testCaseConf)
88  {
89  testTemporalThinning(testCaseConf);
90  });
91  }
92  }
93 
94  void clear() const override {}
95 };
96 
97 } // namespace test
98 } // namespace ufo
99 
100 #endif // TEST_UFO_TEMPORALTHINNING_H_
void preProcess() override
Thin observations so that the retained ones are sufficiently separated in time.
Options controlling the operation of the TemporalThinning filter.
std::string testid() const override
constexpr int thinned
Definition: QCflags.h:26
void testTemporalThinning(const eckit::LocalConfiguration &conf)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27