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::ObsSpace obsspace(obsSpaceConf, oops::mpi::world(), bgn, end, oops::mpi::myself());
38 
39  if (conf.has("category")) {
40  const std::vector<int> categories = conf.getIntVector("category");
41  obsspace.put_db("MetaData", "category", categories);
42  }
43 
44  if (conf.has("priority")) {
45  const std::vector<int> priorities = conf.getIntVector("priority");
46  obsspace.put_db("MetaData", "priority", priorities);
47  }
48 
49  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
50  obsspace, obsspace.obsvariables(), "ObsError"));
51  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
52  obsspace, obsspace.obsvariables()));
53 
54  const eckit::LocalConfiguration filterConf(conf, "TemporalThinning");
55  ufo::TemporalThinning filter(obsspace, filterConf, qcflags, obserr);
56  filter.preProcess();
57 
58  const std::vector<size_t> expectedThinnedObsIndices =
59  conf.getUnsignedVector("expected_thinned_obs_indices");
60  std::vector<size_t> thinnedObsIndices;
61  for (size_t i = 0; i < qcflags->nlocs(); ++i)
62  if ((*qcflags)[0][i] == ufo::QCflags::thinned)
63  thinnedObsIndices.push_back(i);
64  EXPECT_EQUAL(thinnedObsIndices, expectedThinnedObsIndices);
65 }
66 
67 class TemporalThinning : public oops::Test {
68  private:
69  std::string testid() const override {return "ufo::test::TemporalThinning";}
70 
71  void register_tests() const override {
72  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
73 
74  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
75  for (const std::string & testCaseName : conf.keys())
76  {
77  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
78  ts.emplace_back(CASE("ufo/TemporalThinning/" + testCaseName, testCaseConf)
79  {
80  testTemporalThinning(testCaseConf);
81  });
82  }
83  }
84 
85  void clear() const override {}
86 };
87 
88 } // namespace test
89 } // namespace ufo
90 
91 #endif // TEST_UFO_TEMPORALTHINNING_H_
TemporalThinning.h
ufo::test::CASE
CASE("ufo/MetOfficeBuddyPairFinder/" "Duplicates, constraints on buddy counts, legacy pair collector")
Definition: test/ufo/MetOfficeBuddyPairFinder.h:171
ufo::test::TemporalThinning::testid
std::string testid() const override
Definition: test/ufo/TemporalThinning.h:69
ufo::FilterBase::preProcess
void preProcess()
Definition: FilterBase.cc:66
ufo::test::TemporalThinning
Definition: test/ufo/TemporalThinning.h:67
ufo::test::TemporalThinning::register_tests
void register_tests() const override
Definition: test/ufo/TemporalThinning.h:71
ufo
Definition: RunCRTM.h:27
Variables.h
ufo::test::testTemporalThinning
void testTemporalThinning(const eckit::LocalConfiguration &conf)
Definition: test/ufo/TemporalThinning.h:32
ufo::test::TemporalThinning::clear
void clear() const override
Definition: test/ufo/TemporalThinning.h:85
ufo::QCflags::thinned
constexpr int thinned
Definition: QCflags.h:21
ioda::ObsDataVector
Definition: BackgroundCheck.h:26
ufo::TemporalThinning
Thin observations so that the retained ones are sufficiently separated in time.
Definition: src/ufo/filters/TemporalThinning.h:45
conf
Definition: conf.py:1