8 #ifndef TEST_IODA_OBSSPACEINDEXRECNUM_H_
9 #define TEST_IODA_OBSSPACEINDEXRECNUM_H_
16 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
18 #include <boost/noncopyable.hpp>
19 #include <boost/shared_ptr.hpp>
21 #include "eckit/config/LocalConfiguration.h"
22 #include "eckit/testing/Test.h"
24 #include "oops/mpi/mpi.h"
25 #include "oops/runs/Test.h"
26 #include "oops/test/TestEnvironment.h"
28 #include "ioda/distribution/Accumulator.h"
29 #include "ioda/IodaTrait.h"
37 class ObsSpaceTestFixture :
private boost::noncopyable {
45 for (
auto &space : spaces) {
54 return theObsSpaceTestFixture;
58 util::DateTime bgn(::test::TestEnvironment::config().getString(
"window begin"));
59 util::DateTime end(::test::TestEnvironment::config().getString(
"window end"));
61 std::vector<eckit::LocalConfiguration> conf;
62 ::test::TestEnvironment::config().get(
"observations", conf);
64 for (std::size_t jj = 0; jj < conf.size(); ++jj) {
65 eckit::LocalConfiguration obsconf(conf[jj],
"obs space");
66 std::string distname = obsconf.getString(
"distribution",
"RoundRobin");
67 boost::shared_ptr<ioda::ObsSpace> tmp(
new ioda::ObsSpace(obsconf, oops::mpi::world(),
68 bgn, end, oops::mpi::myself()));
75 std::vector<boost::shared_ptr<ioda::ObsSpace> >
ospaces_;
81 typedef ObsSpaceTestFixture Test_;
83 std::vector<eckit::LocalConfiguration> conf;
84 ::test::TestEnvironment::config().get(
"observations", conf);
86 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
88 eckit::LocalConfiguration testConfig;
89 conf[jj].get(
"test data", testConfig);
90 oops::Log::debug() <<
"Test data configuration: " << testConfig << std::endl;
92 const ObsSpace &odb = Test_::obspace(jj);
97 std::size_t Nvars = odb.
nvars();
101 std::size_t ExpectedGlobalNlocs = testConfig.getUnsigned(
"nlocs");
102 std::size_t ExpectedNvars = testConfig.getUnsigned(
"nvars");
103 bool ExpectedObsAreSorted = testConfig.getBool(
"obs are sorted");
105 oops::Log::debug() <<
"GlobalNlocs, ExpectedGlobalNlocs: " << GlobalNlocs <<
", "
106 << ExpectedGlobalNlocs << std::endl;
107 oops::Log::debug() <<
"Nvars, ExpectedNvars: " << Nvars <<
", "
108 << ExpectedNvars << std::endl;
109 oops::Log::debug() <<
"ObsAreSorted, ExpectedObsAreSorted: " << ObsAreSorted <<
", "
110 << ExpectedObsAreSorted << std::endl;
112 EXPECT(GlobalNlocs == ExpectedGlobalNlocs);
114 EXPECT(Nvars == ExpectedNvars);
115 EXPECT(ObsAreSorted == ExpectedObsAreSorted);
119 std::size_t Nrecs = 0;
120 std::set<std::size_t> recIndices;
121 auto accumulator = odb.
distribution()->createAccumulator<std::size_t>();
122 for (std::size_t loc = 0; loc <
Nlocs; ++loc) {
123 if (
bool isNewRecord = recIndices.insert(odb.
recnum()[loc]).second) {
124 accumulator->addTerm(loc, 1);
128 const size_t ExpectedNrecs = odb.
nrecs();
129 EXPECT_EQUAL(Nrecs, ExpectedNrecs);
132 std::size_t GlobalNrecs = accumulator->computeResult();
133 std::size_t ExpectedGlobalNrecs = testConfig.getUnsigned(
"nrecs");
134 EXPECT_EQUAL(GlobalNrecs, ExpectedGlobalNrecs);
144 std::vector<eckit::LocalConfiguration> conf;
145 ::test::TestEnvironment::config().get(
"observations", conf);
147 for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
149 eckit::LocalConfiguration testConfig;
150 conf[jj].get(
"test data", testConfig);
151 oops::Log::debug() <<
"Test data configuration: " << testConfig << std::endl;
154 std::vector<std::size_t> Index = Test_::obspace(jj).index();
155 std::vector<std::size_t> Recnum = Test_::obspace(jj).recnum();
159 int MyMpiSize = Test_::obspace(jj).comm().
size();
160 int MyMpiRank = Test_::obspace(jj).comm().rank();
162 std::string MyPath =
"mpi size" + std::to_string(MyMpiSize) +
163 ".rank" + std::to_string(MyMpiRank);
164 std::vector<std::size_t> ExpectedIndex = testConfig.getUnsignedVector(MyPath +
".index");
165 std::vector<std::size_t> ExpectedRecnum = testConfig.getUnsignedVector(MyPath +
".recnum");
166 eckit::LocalConfiguration recidxTestConfig;
167 testConfig.get(MyPath +
".recidx", recidxTestConfig);
169 oops::Log::debug() <<
"Index, ExpectedIndex: " << Index <<
", "
170 << ExpectedIndex << std::endl;
171 oops::Log::debug() <<
"Recnum, ExpectedRecnum: " << Recnum <<
", "
172 << ExpectedRecnum << std::endl;
174 EXPECT(Index == ExpectedIndex);
175 EXPECT(Recnum == ExpectedRecnum);
178 oops::Log::debug() <<
"recidxTestConfig: " << recidxTestConfig << std::endl;
179 std::vector<std::size_t> RecIdxRecNums = Test_::obspace(jj).recidx_all_recnums();
180 for (std::size_t i = 0; i < RecIdxRecNums.size(); ++i) {
181 std::size_t RecNum = RecIdxRecNums[i];
182 std::string TestConfigKey =
"rec" + std::to_string(RecNum);
183 std::vector<std::size_t> ExpectedRecIdxVector =
184 recidxTestConfig.getUnsignedVector(TestConfigKey);
185 std::vector<std::size_t> RecIdxVector = Test_::obspace(jj).recidx_vector(RecNum);
187 oops::Log::debug() <<
"RecIdxVector, ExpectedRecIdxVector: "
188 << RecIdxVector <<
", " << ExpectedRecIdxVector << std::endl;
189 EXPECT(RecIdxVector == ExpectedRecIdxVector);
199 typedef ObsSpaceTestFixture Test_;
211 std::string
testid()
const override {
return "test::ObsSpaceIndexRecnum<ioda::IodaTrait>";}
214 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
216 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testConstructor")
218 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testIndexRecnum")
220 ts.emplace_back(
CASE(
"ioda/ObsSpaceIndexRecnum/testCleanup")
Observation data class for IODA.
const std::vector< std::size_t > & recnum() const
return reference to the record number vector
std::size_t nrecs() const
return the number of records in the obs space container
std::shared_ptr< const Distribution > distribution() const
return MPI distribution object
size_t nlocs() const
return the number of locations in the obs space. Note that nlocs may be smaller than global unique nl...
std::size_t nvars() const
return the number of variables in the obs space container. "Variables" refers to the quantities that ...
bool obsAreSorted() const
true if the groups in the recidx data member are sorted
std::size_t globalNumLocs() const
return the total number of locations in the corresponding obs spaces across all MPI tasks
std::string testid() const override
void clear() const override
virtual ~ObsSpaceIndexRecnum()
void register_tests() const override
std::vector< boost::shared_ptr< ioda::ObsSpace > > ospaces_
static ioda::ObsSpace & obspace(const std::size_t ii)
static ObsSpaceTestFixture & getInstance()
static std::size_t size()
CASE("Derived variable and unit conversion methods")