8 #ifndef TEST_IO_OBSFRAMEREAD_H_
9 #define TEST_IO_OBSFRAMEREAD_H_
20 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
22 #include "eckit/config/LocalConfiguration.h"
23 #include "eckit/testing/Test.h"
25 #include "oops/mpi/mpi.h"
26 #include "oops/runs/Test.h"
27 #include "oops/test/TestEnvironment.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/FloatCompare.h"
30 #include "oops/util/Logger.h"
32 #include "ioda/core/IodaUtils.h"
33 #include "ioda/distribution/DistributionFactory.h"
34 #include "ioda/io/ObsFrameRead.h"
36 #include "ioda/ObsSpaceParameters.h"
49 float floatTol = obsConfig.getFloat(
"tolerance", 1.0e-5);
50 std::vector<eckit::LocalConfiguration> readVarConfigs =
51 obsConfig.getSubConfigurations(
"read variables");
55 for (obsFrame.frameInit(); obsFrame.frameAvailable(); obsFrame.frameNext()) {
56 Dimensions_t frameStart = obsFrame.frameStart();
57 oops::Log::debug() <<
"testRead: Frame number: " << iframe << std::endl
58 <<
" frameStart: " << frameStart << std::endl;
61 for (std::size_t j = 0; j < readVarConfigs.size(); ++j) {
62 std::string varName = readVarConfigs[j].getString(
"name");
63 std::string expectedVarType = readVarConfigs[j].getString(
"type");
66 oops::Log::debug() <<
" Variable: " << varName
67 <<
", frameCount: " << obsFrame.frameCount(varName) << std::endl;
69 if (expectedVarType ==
"int") {
70 EXPECT(var.
isA<
int>());
71 std::vector<int> expectedVarValue0 =
72 readVarConfigs[j].getIntVector(
"value0");
73 std::vector<int> varValues;
74 if (obsFrame.readFrameVar(varName, varValues)) {
75 EXPECT_EQUAL(varValues[0], expectedVarValue0[iframe]);
77 }
else if (expectedVarType ==
"float") {
78 EXPECT(var.
isA<
float>());
79 std::vector<float> expectedVarValue0 =
80 readVarConfigs[j].getFloatVector(
"value0");
81 std::vector<float> varValues;
82 if (obsFrame.readFrameVar(varName, varValues)) {
83 EXPECT(oops::is_close_relative(varValues[0],
84 expectedVarValue0[iframe], floatTol));
86 }
else if (expectedVarType ==
"string") {
87 EXPECT(var.
isA<std::string>());
88 std::vector<std::string> expectedVarValue0 =
89 readVarConfigs[j].getStringVector(
"value0");
90 std::vector<std::string> varValues;
91 if (obsFrame.readFrameVar(varName, varValues)) {
92 EXPECT_EQUAL(varValues[0], expectedVarValue0[iframe]);
106 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
107 std::vector<eckit::LocalConfiguration> confOspaces = conf.getSubConfigurations(
"observations");
108 util::DateTime bgn(::test::TestEnvironment::config().getString(
"window begin"));
109 util::DateTime end(::test::TestEnvironment::config().getString(
"window end"));
111 for (std::size_t i = 0; i < confOspaces.size(); ++i) {
112 eckit::LocalConfiguration obsConfig;
113 eckit::LocalConfiguration testConfig;
114 confOspaces[i].get(
"obs space", obsConfig);
115 confOspaces[i].get(
"test data", testConfig);
116 oops::Log::trace() <<
"ObsFrame testRead obs space config: " << i <<
": "
117 << obsConfig << std::endl;
118 oops::Log::trace() <<
"ObsFrame testRead test data config: " << i
119 <<
": " << testConfig << std::endl;
122 topParams.validateAndDeserialize(obsConfig);
124 oops::mpi::world(), oops::mpi::myself());
130 ioda::Dimensions_t expectedNumLocs = testConfig.getInt(
"nlocs", 0);
131 ioda::Dimensions_t
numLocs = obsFrame.ioNumLocs();
132 EXPECT_EQUAL(
numLocs, expectedNumLocs);
134 ioda::Dimensions_t expectedNumVars = testConfig.getInt(
"nvars", 0);
135 ioda::Dimensions_t numVars = obsFrame.ioNumVars();
136 EXPECT_EQUAL(numVars, expectedNumVars);
138 ioda::Dimensions_t expectedNumDimVars = testConfig.getInt(
"ndvars", 0);
139 ioda::Dimensions_t numDimVars = obsFrame.ioNumDimVars();
140 EXPECT_EQUAL(numDimVars, expectedNumDimVars);
142 ioda::Dimensions_t expectedMaxVarSize = testConfig.getInt(
"max var size", 0);
143 ioda::Dimensions_t maxVarSize = obsFrame.ioMaxVarSize();
144 EXPECT_EQUAL(maxVarSize, expectedMaxVarSize);
158 std::string
testid()
const override {
return "test::ObsFrameRead";}
161 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
163 ts.emplace_back(
CASE(
"ioda/ObsFrameRead/testRead")
Interfaces for ioda::ObsGroup and related classes.
Interfaces for ioda::Variable and related classes.
bool isA() const
Convenience function to check a Variable's storage type.
std::string testid() const override
void register_tests() const override
void clear() const override
CASE("Derived variable, unit conversion, and exception checking methods")
void testFrameRead(ObsFrameRead &obsFrame, eckit::LocalConfiguration &obsConfig, ioda::ObsSpaceParameters &obsParams)