8 #ifndef TEST_IO_OBSFRAMEWRITE_H_
9 #define TEST_IO_OBSFRAMEWRITE_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"
34 #include "ioda/io/ObsFrameWrite.h"
37 #include "ioda/ObsSpaceParameters.h"
49 const std::vector<eckit::LocalConfiguration> & varConfigs) {
57 backendParams.
flush =
false;
64 for (std::size_t i = 0; i < dimConfigs.size(); ++i) {
65 std::string dimName = dimConfigs[i].getString(
"name");
66 Dimensions_t dimSize = dimConfigs[i].getInt(
"size");
67 bool isUnlimited = dimConfigs[i].getBool(
"unlimited",
false);
71 ioda::NewDimensionScale<int>(
75 ioda::NewDimensionScale<int>(
76 dimName, dimSize, dimSize, dimSize));
82 for (std::size_t j = 0; j < varConfigs.size(); ++j) {
83 std::string varName = varConfigs[j].getString(
"name");
84 std::string varType = varConfigs[j].getString(
"type");
85 std::vector<std::string> varDimNames =
86 varConfigs[j].getStringVector(
"dims");
88 std::vector<ioda::Variable> varDims;
89 for (std::size_t idim = 0; idim < varDimNames.size(); ++idim) {
90 varDims.push_back(obsGroup.
vars.
open(varDimNames[idim]));
96 if (varType ==
"int") {
97 params.setFillValue<
int>(-999);
99 .write<int>(varConfigs[j].getIntVector(
"values"));
100 }
else if (varType ==
"float") {
101 params.setFillValue<
float>(-999);
103 .write<float>(varConfigs[j].getFloatVector(
"values"));
104 }
else if (varType ==
"string") {
105 params.setFillValue<std::string>(
"fill");
107 .write<std::string>(varConfigs[j].getStringVector(
"values"));
117 const VarDimMap & varDimMap,
const Dimensions_t maxVarSize) {
118 std::vector<eckit::LocalConfiguration> writeVarConfigs =
119 testConfig.getSubConfigurations(
"write variables");
122 for (obsFrame.frameInit(varList, dimVarList, varDimMap, maxVarSize);
123 obsFrame.frameAvailable(); obsFrame.frameNext(varList)) {
124 Dimensions_t frameStart = obsFrame.frameStart();
125 oops::Log::debug() <<
"testWrite: Frame number: " << iframe << std::endl
126 <<
" frameStart: " << frameStart << std::endl;
129 for (std::size_t j = 0; j < writeVarConfigs.size(); ++j) {
130 std::string varName = writeVarConfigs[j].getString(
"name");
131 std::string varType = writeVarConfigs[j].getString(
"type");
132 std::vector<std::string> varDimNames =
133 writeVarConfigs[j].getStringVector(
"dims");
137 Dimensions_t frameCount = obsFrame.frameCount(varName);
138 if (frameCount > 0) {
139 oops::Log::debug() <<
" Variable: " << varName
140 <<
", frameCount: " << frameCount << std::endl;
142 if (varType ==
"int") {
143 std::vector<int> values =
144 writeVarConfigs[j].getIntVector(
"values");
145 std::vector<int> varValues(values.begin() + frameStart,
146 values.begin() + frameStart + frameCount);
147 obsFrame.writeFrameVar(varName, varValues);
148 }
else if (varType ==
"float") {
149 std::vector<float> values =
150 writeVarConfigs[j].getFloatVector(
"values");
151 std::vector<float> varValues(values.begin() + frameStart,
152 values.begin() + frameStart + frameCount);
153 obsFrame.writeFrameVar(varName, varValues);
154 }
else if (varType ==
"string") {
155 std::vector<std::string> values =
156 writeVarConfigs[j].getStringVector(
"values");
157 std::vector<std::string> varValues(values.begin() + frameStart,
158 values.begin() + frameStart + frameCount);
159 obsFrame.writeFrameVar(varName, varValues);
173 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
174 std::vector<eckit::LocalConfiguration> confOspaces = conf.getSubConfigurations(
"observations");
175 util::DateTime bgn(::test::TestEnvironment::config().getString(
"window begin"));
176 util::DateTime end(::test::TestEnvironment::config().getString(
"window end"));
178 for (std::size_t i = 0; i < confOspaces.size(); ++i) {
179 eckit::LocalConfiguration obsConfig;
180 eckit::LocalConfiguration testConfig;
181 confOspaces[i].get(
"obs space", obsConfig);
182 confOspaces[i].get(
"test data", testConfig);
183 oops::Log::trace() <<
"ObsFrame testWrite obs space config: " << i <<
": "
184 << obsConfig << std::endl;
185 oops::Log::trace() <<
"ObsFrame testWrite test data config: " << i <<
": "
186 << testConfig << std::endl;
189 topParams.validateAndDeserialize(obsConfig);
191 oops::mpi::world(), oops::mpi::myself());
195 std::vector<eckit::LocalConfiguration> writeDimConfigs =
196 testConfig.getSubConfigurations(
"write dimensions");
197 std::vector<eckit::LocalConfiguration> writeVarConfigs =
198 testConfig.getSubConfigurations(
"write variables");
207 Dimensions_t maxVarSize;
209 dimsAttachedToVars, maxVarSize);
212 for (
auto & dimNameObject : dimVarList) {
213 std::string dimName = dimNameObject.first;
214 Dimensions_t dimSize = dimNameObject.second.getDimensions().dimsCur[0];
215 Dimensions_t dimMaxSize = dimSize;
216 if (dimName ==
"nlocs") {
219 obsParams.
setDimScale(dimName, dimSize, dimMaxSize, dimSize);
229 frameWrite(obsFrame, testConfig, testObsGroup.
vars, varList, dimVarList,
230 dimsAttachedToVars, maxVarSize);
231 obsFrame.ioUpdateVarDimInfo();
235 std::vector<std::string> expectedDimList;
236 for (
size_t i = 0; i < writeDimConfigs.size(); ++i) {
237 expectedDimList.push_back(writeDimConfigs[i].getString(
"name"));
239 std::sort(expectedDimList.begin(), expectedDimList.end());
240 std::vector<std::string> dimList;
241 for (
auto & dimVarNameObject : obsFrame.ioDimVarList()) {
242 dimList.push_back(dimVarNameObject.first);
244 std::sort(dimList.begin(), dimList.end());
245 for (
size_t i = 0; i < expectedDimList.size(); ++i) {
246 EXPECT_EQUAL(dimList[i], expectedDimList[i]);
250 std::vector<std::string> expectedVariableList;
251 for (
size_t i = 0; i < writeVarConfigs.size(); ++i) {
252 expectedVariableList.push_back(writeVarConfigs[i].getString(
"name"));
254 std::sort(expectedVariableList.begin(), expectedVariableList.end());
255 std::vector<std::string> variableList;
256 for (
auto & varNameObject : obsFrame.ioVarList()) {
257 variableList.push_back(varNameObject.first);
259 std::sort(variableList.begin(), variableList.end());
260 EXPECT_EQUAL(variableList, expectedVariableList);
272 std::string
testid()
const override {
return "test::ObsFrameWrite";}
275 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
277 ts.emplace_back(
CASE(
"ioda/ObsFrameWrite/testWrite")
Contains definitions for how data are arranged in ioda internally.
Interfaces for ioda::ObsGroup and related classes.
Interfaces for ioda::Variable and related classes.
Groups are a new implementation of ObsSpaces.
This class exists inside of ioda::Group and provides the interface to manipulating Variables.
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
static ObsGroup generate(Group &emptyGroup, const NewDimensionScales_t &fundamentalDims, std::shared_ptr< const detail::DataLayoutPolicy > layout=nullptr)
Create an empty ObsGroup and populate it with the fundamental dimensions.
void setMaxVarSize(const Dimensions_t maxVarSize)
set the maximum variable size
ObsTopLevelParameters top_level_
sub groups of parameters
void setDimScale(const std::string &dimName, const Dimensions_t curSize, const Dimensions_t maxSize, const Dimensions_t chunkSize)
set a new dimension scale
oops::OptionalParameter< ObsFileOutParameters > obsOutFile
output specification by writing to a file
Has_Variables vars
Use this to access variables.
Variable createWithScales(const std::string &name, const std::vector< Variable > &dimension_scales, const VariableCreationParameters ¶ms=VariableCreationParameters::defaulted< DataType >())
Convenience function to create a Variable from certain dimension scales.
virtual Variable open(const std::string &name) const
Open a Variable by name.
void register_tests() const override
void clear() const override
std::string testid() const override
IODA_DL std::string genUniqueName()
Convenience function to generate a random file name.
BackendNames
Backend names.
IODA_DL Group constructBackend(BackendNames name, BackendCreationParameters ¶ms)
This is a simple factory style function that will instantiate a different backend based on a given na...
@ Create
Create a new file.
@ ObsStore
ObsStore in-memory.
@ Truncate_If_Exists
If the file already exists, overwrite it.
CASE("Derived variable, unit conversion, and exception checking methods")
void frameWrite(ObsFrameWrite &obsFrame, eckit::LocalConfiguration &testConfig, const Has_Variables &sourceVars, const VarNameObjectList &varList, const VarNameObjectList &dimVarList, const VarDimMap &varDimMap, const Dimensions_t maxVarSize)
ObsGroup buildTestObsGroup(const std::vector< eckit::LocalConfiguration > &dimConfigs, const std::vector< eckit::LocalConfiguration > &varConfigs)
constexpr int Unlimited
Specifies that a dimension is resizable to infinity.
std::vector< std::pair< std::string, Variable > > VarNameObjectList
typedef for holding list of variable names with associated variable object
std::vector< std::shared_ptr< NewDimensionScale_Base > > NewDimensionScales_t
std::map< std::string, std::vector< std::string > > VarDimMap
typedef for holding dim names attached to variables
void collectVarDimInfo(const ObsGroup &obsGroup, VarNameObjectList &varObjectList, VarNameObjectList &dimVarObjectList, VarDimMap &dimsAttachedToVars, Dimensions_t &maxVarSize0)
collect variable and dimension information from a ioda ObsGroup
Used to specify backend creation-time properties.
BackendFileActions action
BackendCreateModes createMode
Used to specify Variable creation-time properties.