UFO
test/ufo/processWhere.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
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_PROCESSWHERE_H_
9 #define TEST_UFO_PROCESSWHERE_H_
10 
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 "oops/mpi/mpi.h"
20 #include "oops/runs/Test.h"
21 #include "oops/util/Logger.h"
22 #include "test/TestEnvironment.h"
25 #include "ufo/filters/Variables.h"
26 
27 #include "oops/util/parameters/Parameter.h"
28 #include "oops/util/parameters/Parameters.h"
29 #include "oops/util/parameters/RequiredParameter.h"
30 
31 namespace ufo {
32 namespace test {
33 
34 class TestParameters : public oops::Parameters {
36  public:
37  oops::Parameter<std::vector<WhereParameters>> where{"where", {}, this};
38  oops::RequiredParameter<int> sizeWhereTrue{"size where true", this};
39 };
40 
41 // -----------------------------------------------------------------------------
42 
43 void testProcessWhere(const eckit::LocalConfiguration &conf,
44  bool is_in_usererror = false) {
45  util::DateTime bgn(conf.getString("window begin"));
46  util::DateTime end(conf.getString("window end"));
47 
48  eckit::LocalConfiguration obsconf(conf, "obs space");
49  ioda::ObsTopLevelParameters obsparams;
50  obsparams.validateAndDeserialize(obsconf);
51  ioda::ObsSpace ospace(obsparams, oops::mpi::world(), bgn, end, oops::mpi::myself());
52  ObsFilterData data(ospace);
53 
54  const int nlocs = conf.getInt("nlocs");
55  EXPECT(data.nlocs() == nlocs);
56 
57  std::vector<eckit::LocalConfiguration> confs;
58  conf.get("ProcessWhere", confs);
59  for (size_t jconf = 0; jconf < confs.size(); ++jconf) {
60  eckit::LocalConfiguration config = confs[jconf];
61  TestParameters params;
62  params.validateAndDeserialize(config);
63  if (is_in_usererror) {
64  EXPECT_THROWS(processWhere(params.where, data));
65  } else {
66  std::vector<bool> result = processWhere(params.where, data);
67  const int size_ref = params.sizeWhereTrue;
68  const int size = std::count(result.begin(), result.end(), true);
69  oops::Log::info() << "reference: " << size_ref << ", compare with " << size << std::endl;
70  EXPECT(size == size_ref);
71  }
72  }
73 }
74 
75 // -----------------------------------------------------------------------------
76 
77 class ProcessWhere : public oops::Test {
78  public:
80  virtual ~ProcessWhere() {}
81  private:
82  std::string testid() const override {return "ufo::test::ProcessWhere";}
83 
84  void register_tests() const override {
85  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
86 
87  ts.emplace_back(CASE("ufo/ProcessWhere/testProcessWhere_successful") {
88  testProcessWhere(eckit::LocalConfiguration(::test::TestEnvironment::config(),
89  "successful"));
90  });
91 
92  ts.emplace_back(CASE("ufo/ProcessWhere/testProcessWhere_isin_usererror") {
93  testProcessWhere(eckit::LocalConfiguration(::test::TestEnvironment::config(),
94  "user_error_type_handling_is_in"),
95  true);
96  });
97  }
98 
99  void clear() const override {}
100 };
101 
102 // -----------------------------------------------------------------------------
103 
104 } // namespace test
105 } // namespace ufo
106 
107 #endif // TEST_UFO_PROCESSWHERE_H_
void clear() const override
std::string testid() const override
void register_tests() const override
oops::Parameter< std::vector< WhereParameters > > where
oops::RequiredParameter< int > sizeWhereTrue
OOPS_CONCRETE_PARAMETERS(TestParameters, Parameters)
void testProcessWhere(const eckit::LocalConfiguration &conf, bool is_in_usererror=false)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
std::vector< bool > processWhere(const std::vector< WhereParameters > &params, const ObsFilterData &filterdata)