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::ObsTopLevelParameters obsParams;
38  obsParams.validateAndDeserialize(obsSpaceConf);
39  ioda::ObsSpace obsspace(obsParams, oops::mpi::world(), bgn, end, oops::mpi::myself());
40 
41  if (conf.has("air_pressures")) {
42  const std::vector<float> airPressures = conf.getFloatVector("air_pressures");
43  obsspace.put_db("MetaData", "air_pressure", airPressures);
44  const std::vector<float> airPressureObserrors(airPressures.size(), 1.0f);
45  obsspace.put_db("ObsError", "air_pressure", airPressureObserrors);
46  }
47 
48  if (conf.has("station_ids")) {
49  const std::vector<int> stationIds = conf.getIntVector("station_ids");
50  obsspace.put_db("MetaData", "station_id", stationIds);
51  }
52 
53  std::shared_ptr<ioda::ObsDataVector<float>> obserr(new ioda::ObsDataVector<float>(
54  obsspace, obsspace.obsvariables(), "ObsError"));
55  std::shared_ptr<ioda::ObsDataVector<int>> qcflags(new ioda::ObsDataVector<int>(
56  obsspace, obsspace.obsvariables()));
57 
58  eckit::LocalConfiguration filterConf(conf, "Track Check");
59  ufo::TrackCheckParameters filterParameters;
60  filterParameters.validateAndDeserialize(filterConf);
61  ufo::TrackCheck filter(obsspace, filterParameters, qcflags, obserr);
62  filter.preProcess();
63 
64  const std::vector<size_t> expectedRejectedObsIndices =
65  conf.getUnsignedVector("expected_rejected_obs_indices");
66  std::vector<size_t> rejectedObsIndices;
67  for (size_t i = 0; i < qcflags->nlocs(); ++i)
68  if ((*qcflags)[0][i] == ufo::QCflags::track)
69  rejectedObsIndices.push_back(i);
70  EXPECT_EQUAL(rejectedObsIndices, expectedRejectedObsIndices);
71 }
72 
73 class TrackCheck : public oops::Test {
74  private:
75  std::string testid() const override {return "ufo::test::TrackCheck";}
76 
77  void register_tests() const override {
78  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
79 
80  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
81  for (const std::string & testCaseName : conf.keys())
82  {
83  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(), testCaseName);
84  ts.emplace_back(CASE("ufo/TrackCheck/" + testCaseName, testCaseConf)
85  {
86  testTrackCheck(testCaseConf);
87  });
88  }
89  }
90 
91  void clear() const override {}
92 };
93 
94 } // namespace test
95 } // namespace ufo
96 
97 #endif // TEST_UFO_TRACKCHECK_H_
void preProcess() override
Checks tracks of mobile weather stations, rejecting observations inconsistent with the rest of the tr...
Options controlling the operation of the track check filter.
void clear() const override
void register_tests() const override
std::string testid() const override
constexpr int track
Definition: QCflags.h:31
void testTrackCheck(const eckit::LocalConfiguration &conf)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27