8 #ifndef TEST_IODA_OBSSPACE_H_
9 #define TEST_IODA_OBSSPACE_H_
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
20 #include "eckit/config/LocalConfiguration.h"
21 #include "eckit/testing/Test.h"
23 #include "oops/mpi/mpi.h"
24 #include "oops/runs/Test.h"
25 #include "oops/test/TestEnvironment.h"
27 #include "ioda/IodaTrait.h"
45 return theObsSpaceTestFixture;
49 util::DateTime bgn(::test::TestEnvironment::config().getString(
"window begin"));
50 util::DateTime end(::test::TestEnvironment::config().getString(
"window end"));
52 std::vector<eckit::LocalConfiguration> conf;
53 ::test::TestEnvironment::config().get(
"observations", conf);
55 for (std::size_t jj = 0; jj < conf.size(); ++jj) {
56 eckit::LocalConfiguration obsconf(conf[jj],
"obs space");
57 boost::shared_ptr<ioda::ObsSpace> tmp(
new ioda::ObsSpace(obsconf, oops::mpi::world(),
58 bgn, end, oops::mpi::myself()));
65 std::vector<boost::shared_ptr<ioda::ObsSpace> >
ospaces_;
73 std::vector<eckit::LocalConfiguration> conf;
74 ::test::TestEnvironment::config().get(
"observations", conf);
76 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
82 std::string DistMethod = conf[jj].getString(
"obs space.distribution",
"RoundRobin");
85 std::size_t Nlocs = Test_::obspace(jj).nlocs();
86 std::size_t Nrecs = Test_::obspace(jj).nrecs();
87 std::size_t Nvars = Test_::obspace(jj).nvars();
88 if (DistMethod !=
"InefficientDistribution") {
89 Test_::obspace(jj).comm().allReduceInPlace(Nlocs, eckit::mpi::sum());
90 Test_::obspace(jj).comm().allReduceInPlace(Nrecs, eckit::mpi::sum());
94 std::size_t ExpectedNlocs = conf[jj].getUnsigned(
"obs space.test data.nlocs");
95 std::size_t ExpectedNrecs = conf[jj].getUnsigned(
"obs space.test data.nrecs");
96 std::size_t ExpectedNvars = conf[jj].getUnsigned(
"obs space.test data.nvars");
99 std::string ObsGroupVar = Test_::obspace(jj).obs_group_var();
100 std::string ObsSortVar = Test_::obspace(jj).obs_sort_var();
101 std::string ObsSortOrder = Test_::obspace(jj).obs_sort_order();
104 std::string ExpectedObsGroupVar =
105 conf[jj].getString(
"obs space.test data.expected group variable");
106 std::string ExpectedObsSortVar =
107 conf[jj].getString(
"obs space.test data.expected sort variable");
108 std::string ExpectedObsSortOrder =
109 conf[jj].getString(
"obs space.test data.expected sort order");
111 oops::Log::debug() <<
"Nlocs, ExpectedNlocs: " << Nlocs <<
", "
112 << ExpectedNlocs << std::endl;
113 oops::Log::debug() <<
"Nrecs, ExpectedNrecs: " << Nrecs <<
", "
114 << ExpectedNrecs << std::endl;
115 oops::Log::debug() <<
"Nvars, ExpectedNvars: " << Nvars <<
", "
116 << ExpectedNvars << std::endl;
118 oops::Log::debug() <<
"ObsGroupVar, ExpectedObsGroupVar: " << ObsGroupVar <<
", "
119 << ExpectedObsGroupVar << std::endl;
120 oops::Log::debug() <<
"ObsSortVar, ExpectedObsSortVar: " << ObsSortVar <<
", "
121 << ExpectedObsSortVar << std::endl;
122 oops::Log::debug() <<
"ObsSortOrder, ExpectedObsSortOrder: " << ObsSortOrder <<
", "
123 << ExpectedObsSortOrder << std::endl;
125 EXPECT(Nlocs == ExpectedNlocs);
126 EXPECT(Nrecs == ExpectedNrecs);
127 EXPECT(Nvars == ExpectedNvars);
129 EXPECT(ObsGroupVar == ExpectedObsGroupVar);
130 EXPECT(ObsSortVar == ExpectedObsSortVar);
131 EXPECT(ObsSortOrder == ExpectedObsSortOrder);
140 std::vector<eckit::LocalConfiguration> conf;
141 ::test::TestEnvironment::config().get(
"observations", conf);
143 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
144 std::string DistMethod = conf[jj].getString(
"obs space.distribution",
"RoundRobin");
148 std::size_t Nlocs = Odb->
nlocs();
151 std::vector<eckit::LocalConfiguration> varconf =
152 conf[jj].getSubConfigurations(
"obs space.test data.variables");
153 double Tol = conf[jj].getDouble(
"obs space.test data.tolerance");
154 for (std::size_t i = 0; i < varconf.size(); ++i) {
156 std::string VarName = varconf[i].getString(
"name");
157 std::string GroupName = varconf[i].getString(
"group");
158 std::string VarType = varconf[i].getString(
"type");
161 if (VarType ==
"float") {
168 std::vector<double> TestVec(Nlocs);
169 Odb->
get_db(GroupName, VarName, TestVec);
172 double ExpectedVnorm = varconf[i].getDouble(
"norm");
174 for (std::size_t j = 0; j < Nlocs; ++j) {
175 Vnorm += pow(TestVec[j], 2.0);
177 if (DistMethod !=
"InefficientDistribution") {
178 Test_::obspace(jj).comm().allReduceInPlace(Vnorm, eckit::mpi::sum());
182 EXPECT(oops::is_close(Vnorm, ExpectedVnorm, Tol));
183 }
else if (VarType ==
"integer") {
189 std::vector<int> TestVec(Nlocs);
190 Odb->
get_db(GroupName, VarName, TestVec);
193 double ExpectedVnorm = varconf[i].getDouble(
"norm");
195 for (std::size_t j = 0; j < Nlocs; ++j) {
196 Vnorm += pow(
static_cast<double>(TestVec[j]), 2.0);
198 if (DistMethod !=
"InefficientDistribution") {
199 Test_::obspace(jj).comm().allReduceInPlace(Vnorm, eckit::mpi::sum());
203 EXPECT(oops::is_close(Vnorm, ExpectedVnorm, Tol));
204 }
else if (VarType ==
"string") {
210 std::string ExpectedFirstValue = varconf[i].getString(
"first value");
211 std::string ExpectedLastValue = varconf[i].getString(
"last value");
212 std::vector<std::string> TestVec(Nlocs);
213 Odb->
get_db(GroupName, VarName, TestVec);
215 EXPECT(TestVec[0] == ExpectedFirstValue);
216 EXPECT(TestVec[Nlocs-1] == ExpectedLastValue);
227 std::string VarName(
"DummyVar");
229 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
236 std::size_t Nlocs = Odb->
nlocs();
237 std::vector<double> TestVec(Nlocs);
238 std::vector<double> ExpectedVec(Nlocs);
240 for (std::size_t i = 0; i < Nlocs; ++i) {
241 ExpectedVec[i] =
static_cast<double>(i);
246 Odb->
put_db(
"MetaData", VarName, ExpectedVec);
247 Odb->
get_db(
"MetaData", VarName, TestVec);
249 bool VecMatch =
true;
250 for (std::size_t i = 0; i < Nlocs; ++i) {
251 VecMatch = VecMatch && (
static_cast<int>(ExpectedVec[i]) ==
static_cast<int>(TestVec[i]));
263 std::string VarName(
"DummyVar");
265 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
272 std::size_t Nlocs = Odb->
nlocs();
273 std::vector<double> TestVec(Nlocs);
274 std::vector<double> ExpectedVec(Nlocs);
276 for (std::size_t i = 0; i < Nlocs; ++i) {
277 ExpectedVec[i] =
static_cast<double>(i);
282 Odb->
put_db(
"TestGroup", VarName, ExpectedVec);
283 Odb->
get_db(
"TestGroup", VarName, TestVec);
285 bool VecMatch =
true;
286 for (std::size_t i = 0; i < Nlocs; ++i) {
287 VecMatch = VecMatch && (
static_cast<int>(ExpectedVec[i]) ==
static_cast<int>(TestVec[i]));
292 for (std::size_t i = 0; i < Nlocs; ++i) {
293 ExpectedVec[i] = ExpectedVec[i] * 2;
296 Odb->
put_db(
"TestGroup", VarName, ExpectedVec);
297 Odb->
get_db(
"TestGroup", VarName, TestVec);
300 for (std::size_t i = 0; i < Nlocs; ++i) {
301 VecMatch = VecMatch && (
static_cast<int>(ExpectedVec[i]) ==
static_cast<int>(TestVec[i]));
314 std::string
testid()
const override {
return "test::ObsSpace<ioda::IodaTrait>";}
317 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
319 ts.emplace_back(CASE(
"ioda/ObsSpace/testConstructor")
321 ts.emplace_back(CASE(
"ioda/ObsSpace/testGetDb")
323 ts.emplace_back(CASE(
"ioda/ObsSpace/testPutDb")
325 ts.emplace_back(CASE(
"ioda/ObsSpace/testWriteableGroup")
337 #endif // TEST_IODA_OBSSPACE_H_