FV3 Bundle
l95/test/lorenz95/ObsBiasCovariance.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <iostream>
12 
13 #include <boost/scoped_ptr.hpp>
14 #include <boost/test/unit_test.hpp>
15 
16 #include "./TestConfig.h"
17 #include "eckit/config/LocalConfiguration.h"
20 #include "lorenz95/Resolution.h"
21 #include "test/TestFixture.h"
22 
23 namespace test {
24 
25 // -----------------------------------------------------------------------------
26 class ObsBiasTestFixture : TestFixture {
27  public:
29  biasconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "ObsBias"));
30  nobias_.reset(new eckit::LocalConfiguration());
31  covconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "Covariance"));
32  }
34  boost::scoped_ptr<const eckit::LocalConfiguration> biasconf_;
35  boost::scoped_ptr<const eckit::LocalConfiguration> nobias_;
36  boost::scoped_ptr<const eckit::LocalConfiguration> covconf_;
37 };
38 // -----------------------------------------------------------------------------
39 
40 // -----------------------------------------------------------------------------
41 BOOST_FIXTURE_TEST_SUITE(test_obsBiasCovariance, ObsBiasTestFixture)
42 // -----------------------------------------------------------------------------
43  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_constructor_conf) {
44  lorenz95::ObsBiasCovariance obcovar(*covconf_);
45  BOOST_CHECK_EQUAL(obcovar.active(), true);
46  }
47 // -----------------------------------------------------------------------------
48  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_constructor_no_conf) {
49  lorenz95::ObsBiasCovariance obcovar(*nobias_);
50  BOOST_CHECK_EQUAL(obcovar.active(), false);
51  }
52 // -----------------------------------------------------------------------------
53  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_destructor) {
54  // not yet implemented
55  }
56 // -----------------------------------------------------------------------------
57  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_linearize) {
58  // not yet implemented
59  }
60 // -----------------------------------------------------------------------------
61  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_multiply_active) {
62  lorenz95::ObsBiasCovariance obcovar(*covconf_);
63 
64  lorenz95::ObsBiasCorrection db1(*covconf_);
65  db1.value() = 2.0;
66  lorenz95::ObsBiasCorrection db2(db1, *covconf_);
67 
68  obcovar.multiply(db1, db2);
69 
70  const double stdev = covconf_->getDouble("standard_deviation");
71  BOOST_CHECK_EQUAL(db2.value(), db1.value() * stdev * stdev);
72  }
73 // -----------------------------------------------------------------------------
74  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_multiply_inactive) {
75  lorenz95::ObsBiasCovariance obcovar(*nobias_);
76 
77  lorenz95::ObsBiasCorrection db1(*nobias_);
78  db1.value() = 2.0;
79  lorenz95::ObsBiasCorrection db2(db1, *covconf_);
80 
81  obcovar.multiply(db1, db2);
82 
83  // because the OBC has empty config, the bias is set to 0.0
84  BOOST_CHECK_EQUAL(db2.value(), 0.0);
85  }
86 // -----------------------------------------------------------------------------
87  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_invMult_active) {
88  lorenz95::ObsBiasCovariance obcovar(*covconf_);
89 
90  lorenz95::ObsBiasCorrection db1(*covconf_);
91  db1.value() = 2.0;
92  lorenz95::ObsBiasCorrection db2(db1, *covconf_);
93 
94  obcovar.inverseMultiply(db1, db2);
95 
96  const double stdev = covconf_->getDouble("standard_deviation");
97  BOOST_CHECK_EQUAL(db2.value(), db1.value() * 1.0 / (stdev * stdev));
98  }
99 // -----------------------------------------------------------------------------
100  BOOST_AUTO_TEST_CASE(test_obsBiasCovariance_invMult_inactive) {
101  lorenz95::ObsBiasCovariance obcovar(*nobias_);
102 
103  lorenz95::ObsBiasCorrection db1(*nobias_);
104  db1.value() = 2.0;
105  lorenz95::ObsBiasCorrection db2(db1, *covconf_);
106 
107  obcovar.inverseMultiply(db1, db2);
108 
109  // because the OBC has empty config, the bias is set to 0.0
110  BOOST_CHECK_EQUAL(db2.value(), 0.0);
111  }
112 // -----------------------------------------------------------------------------
113 
114 BOOST_AUTO_TEST_SUITE_END()
115 } // namespace test
boost::scoped_ptr< const eckit::LocalConfiguration > covconf_
void inverseMultiply(const ObsBiasCorrection &, ObsBiasCorrection &) const
boost::scoped_ptr< const eckit::LocalConfiguration > nobias_
void multiply(const ObsBiasCorrection &, ObsBiasCorrection &) const
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
boost::scoped_ptr< const eckit::LocalConfiguration > biasconf_
static const eckit::Configuration & config()
Definition: TestConfig.h:30