8 #ifndef TEST_INTERFACE_OBSOPERATOR_H_
9 #define TEST_INTERFACE_OBSOPERATOR_H_
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
17 #include <boost/noncopyable.hpp>
19 #include "eckit/config/LocalConfiguration.h"
20 #include "eckit/testing/Test.h"
29 #include "oops/util/Expect.h"
41 typedef ObsTestsFixture<OBS> Test_;
44 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
45 eckit::LocalConfiguration obsopconf(Test_::config(jj),
"obs operator");
48 std::unique_ptr<ObsOperator_> hop(
new ObsOperator_(Test_::obspace()[jj], obsopconf));
56 EXPECT_THROWS_MSG(ObsOperator_(Test_::obspace()[jj], obsopconf),
57 expectedMessage.c_str());
72 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
73 const eckit::LocalConfiguration & conf = Test_::config(jj);
79 eckit::LocalConfiguration obsopconf(conf,
"obs operator");
80 ObsOperator_ hop(Test_::obspace()[jj], obsopconf);
83 eckit::LocalConfiguration biasconf = conf.getSubConfiguration(
"obs bias");
84 typename ObsAuxCtrl_::Parameters_ biasparams;
85 biasparams.validateAndDeserialize(biasconf);
86 const ObsAuxCtrl_ ybias(Test_::obspace()[jj], biasparams);
89 eckit::LocalConfiguration gconf(conf,
"geovals");
91 hopvars += ybias.requiredVars();
92 const GeoVaLs_ gval(gconf, Test_::obspace()[jj], hopvars);
95 ObsVector_ hofx(Test_::obspace()[jj]);
99 diagvars += ybias.requiredHdiagnostics();
100 ObsDiags_ diags(Test_::obspace()[jj], hop.locations(), diagvars);
106 const std::string expectedMessage =
108 EXPECT_THROWS_MSG(hop.simulateObs(gval, hofx, ybias, diags),
109 expectedMessage.c_str());
112 hop.simulateObs(gval, hofx, ybias, diags);
116 const double tol = conf.getDouble(
"tolerance");
117 if (conf.has(
"vector ref")) {
120 ObsVector_ obsref(Test_::obspace()[jj], conf.getString(
"vector ref"));
122 const double zz = obsref.rms();
123 oops::Log::test() <<
"Vector difference between reference and computed: " << obsref;
124 EXPECT(zz < 100*tol);
126 }
else if (conf.has(
"norm ref")) {
129 ObsVector_ obsref(Test_::obspace()[jj], conf.getString(
"norm ref"));
132 const double zz = obsref.rms();
133 oops::Log::test() <<
"Normalised vector difference between reference and computed: "
135 EXPECT(zz < 100*tol);
139 const double zz = hofx.rms();
140 const double xx = conf.getDouble(
"rms ref");
142 oops::Log::debug() <<
"zz: " << std::fixed << std::setprecision(8) << zz << std::endl;
143 oops::Log::debug() <<
"xx: " << std::fixed << std::setprecision(8) << xx << std::endl;
145 EXPECT(oops::is_close(xx, zz, tol));
152 template <
typename OBS>
159 std::string
testid()
const override {
return "test::ObsOperator<" +
OBS::name() +
">";}
162 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
164 ts.emplace_back(
CASE(
"interface/ObsOperator/testConstructor")
165 { testConstructor<OBS>(); });
166 ts.emplace_back(
CASE(
"interface/ObsOperator/testSimulateObs")
167 { testSimulateObs<OBS>(); });
void clear() const override
void register_tests() const override
ObsTestsFixture< OBS > Test_
std::string testid() const override
logical function has(this, var)
const char * expectConstructorToThrow
const char * expectSimulateObsToThrow
CASE("assimilation/FullGMRES/FullGMRES")
void testConstructor()
Tests creation and destruction of ObsErrorCovariances.