FV3 Bundle
oops/src/test/interface/ObsCheck.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 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_INTERFACE_OBSCHECK_H_
9 #define TEST_INTERFACE_OBSCHECK_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #define BOOST_TEST_NO_MAIN
15 #define BOOST_TEST_ALTERNATIVE_INIT_API
16 #define BOOST_TEST_DYN_LINK
17 #include <boost/test/unit_test.hpp>
18 
19 #include <boost/noncopyable.hpp>
20 #include <boost/scoped_ptr.hpp>
21 
22 #include "eckit/config/LocalConfiguration.h"
23 #include "oops/interface/GeoVaLs.h"
28 #include "oops/runs/Test.h"
30 #include "test/TestEnvironment.h"
31 
32 namespace test {
33 
34 // -----------------------------------------------------------------------------
35 
36 template <typename MODEL> void testConstructor() {
37  typedef ObsTestsFixture<MODEL> Test_;
38  typedef oops::ObsCheck<MODEL> ObsCheck_;
39 
40  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
41  boost::scoped_ptr<ObsCheck_> oc(new ObsCheck_(Test_::obspace()[jj]));
42  BOOST_CHECK(oc.get());
43 
44  oc.reset();
45  BOOST_CHECK(!oc.get());
46  }
47 }
48 
49 // -----------------------------------------------------------------------------
50 
51 template <typename MODEL> void testObsCheck() {
52  typedef ObsTestsFixture<MODEL> Test_;
53  typedef oops::GeoVaLs<MODEL> GeoVaLs_;
54  typedef oops::ObsAuxControl<MODEL> ObsAuxCtrl_;
55  typedef oops::ObsCheck<MODEL> ObsCheck_;
56  typedef oops::ObsOperator<MODEL> ObsOperator_;
57  typedef oops::ObsVector<MODEL> ObsVector_;
58 
59  const eckit::LocalConfiguration obsconf(TestEnvironment::config(), "Observations");
60  std::vector<eckit::LocalConfiguration> conf;
61  obsconf.get("ObsTypes", conf);
62 
63  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
64  ObsOperator_ hop(Test_::obspace()[jj]);
65  eckit::LocalConfiguration gconf(conf[jj], "GeoVaLs");
66  const GeoVaLs_ gval(gconf, hop.variables());
67 
68  eckit::LocalConfiguration biasConf;
69  conf[jj].get("ObsBias", biasConf);
70  const ObsAuxCtrl_ ybias(biasConf);
71 
72  ObsVector_ ovec(Test_::obspace()[jj]);
73 
74  const eckit::LocalConfiguration oconf(conf[jj], "GeoVaLs");
75  ObsCheck_ ocheck(oconf);
76  ocheck.priorFilter(Test_::obspace()[jj]);
77 
78  hop.simulateObs(gval, ovec, ybias);
79 
80  ocheck.postFilter(gval, ovec, Test_::obspace()[jj]);
81 
82  const double tol = 1.0e-8;
83  const double zz = ovec.rms();
84  const double xx = conf[jj].getDouble("rmsequiv");
85 
86  oops::Log::trace() << "ObsCheck check filter zz = " << zz << " and xx " <<std::endl;
87 // BOOST_CHECK_CLOSE(xx, zz, tol);
88  }
89 }
90 
91 // -----------------------------------------------------------------------------
92 
93 template <typename MODEL> class ObsCheck : public oops::Test {
94  public:
95  ObsCheck() {}
96  virtual ~ObsCheck() {}
97  private:
98  std::string testid() const {return "test::ObsCheck<" + MODEL::name() + ">";}
99 
100  void register_tests() const {
101  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/ObsCheck");
102 
103  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
104  ts->add(BOOST_TEST_CASE(&testObsCheck<MODEL>));
105 
106  boost::unit_test::framework::master_test_suite().add(ts);
107  }
108 };
109 
110 // =============================================================================
111 
112 } // namespace test
113 
114 #endif // TEST_INTERFACE_OBSCHECK_H_
Definition: conf.py:1
static const eckit::Configuration & config()
character(len=32) name
void testConstructor()