UFO
test/ufo/TrackCheck.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_TRACKCHECK_H_
9 #define TEST_UFO_TRACKCHECK_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/TrackCheck.h"
27 #include "ufo/filters/Variables.h"
28 
29 namespace ufo {
30 namespace test {
31 
32 void testTrackCheck(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("air_pressures")) {
40  const std::vector<float> airPressures = conf.getFloatVector("air_pressures");
41  obsspace.put_db("MetaData", "air_pressure", airPressures);
42  const std::vector<float> airPressureObserrors(airPressures.size(), 1.0f);
43  obsspace.put_db("ObsError", "air_pressure", airPressureObserrors);
44  }
45 
46  if (conf.has("station_ids")) {
47  const std::vector<int> stationIds = conf.getIntVector("station_ids");
48  obsspace.put_db("MetaData", "station_id", stationIds);
49  }
50 
51  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
52  obsspace, obsspace.obsvariables(), "ObsError"));
53  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
54  obsspace, obsspace.obsvariables()));
55 
56  const eckit::LocalConfiguration filterConf(conf, "Track Check");
57  ufo::TrackCheck filter(obsspace, filterConf, qcflags, obserr);
58  filter.preProcess();
59 
60  const std::vector<size_t> expectedRejectedObsIndices =
61  conf.getUnsignedVector("expected_rejected_obs_indices");
62  std::vector<size_t> rejectedObsIndices;
63  for (size_t i = 0; i < qcflags->nlocs(); ++i)
64  if ((*qcflags)[0][i] == ufo::QCflags::track)
65  rejectedObsIndices.push_back(i);
66  EXPECT_EQUAL(rejectedObsIndices, expectedRejectedObsIndices);
67 }
68 
69 class TrackCheck : public oops::Test {
70  private:
71  std::string testid() const override {return "ufo::test::TrackCheck";}
72 
73  void register_tests() const override {
74  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
75 
76  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
77  for (const std::string & testCaseName : conf.keys())
78  {
79  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
80  ts.emplace_back(CASE("ufo/TrackCheck/" + testCaseName, testCaseConf)
81  {
82  testTrackCheck(testCaseConf);
83  });
84  }
85  }
86 
87  void clear() const override {}
88 };
89 
90 } // namespace test
91 } // namespace ufo
92 
93 #endif // TEST_UFO_TRACKCHECK_H_
ufo::TrackCheck
Checks tracks of mobile weather stations, rejecting observations inconsistent with the rest of the tr...
Definition: src/ufo/filters/TrackCheck.h:54
ufo::test::CASE
CASE("ufo/MetOfficeBuddyPairFinder/" "Duplicates, constraints on buddy counts, legacy pair collector")
Definition: test/ufo/MetOfficeBuddyPairFinder.h:171
TrackCheck.h
ufo::FilterBase::preProcess
void preProcess()
Definition: FilterBase.cc:66
ufo::test::testTrackCheck
void testTrackCheck(const eckit::LocalConfiguration &conf)
Definition: test/ufo/TrackCheck.h:32
ufo::test::TrackCheck::clear
void clear() const override
Definition: test/ufo/TrackCheck.h:87
ufo
Definition: RunCRTM.h:27
Variables.h
ufo::QCflags::track
constexpr int track
Definition: QCflags.h:26
ufo::test::TrackCheck
Definition: test/ufo/TrackCheck.h:69
ioda::ObsDataVector
Definition: BackgroundCheck.h:26
ufo::test::TrackCheck::testid
std::string testid() const override
Definition: test/ufo/TrackCheck.h:71
ufo::test::TrackCheck::register_tests
void register_tests() const override
Definition: test/ufo/TrackCheck.h:73
conf
Definition: conf.py:1