Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to IODA example utility; write out a file #572

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions utils/ioda_example/gdas_meanioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <string>
#include <vector>
#include "eckit/config/LocalConfiguration.h"
#include "ioda/Engines/EngineUtils.h"
#include "ioda/Group.h"
#include "ioda/ObsDataIoParameters.h"
#include "ioda/ObsGroup.h"
#include "ioda/ObsSpace.h"
#include "ioda/ObsVector.h"
#include "oops/base/PostProcessor.h"
Expand Down Expand Up @@ -80,6 +83,47 @@ namespace gdasapp {
oops::Log::info() << "mean value for " << group << "/" << variable
<< "=" << mean << std::endl;

// let's try writing the mean out to a IODA file now!
////////////////////////////////////////////////////
// get the configuration for the obsdataout
eckit::LocalConfiguration outconf(fullConfig, "obsdataout");
ioda::ObsDataOutParameters outparams;
outparams.validateAndDeserialize(outconf);

// set up the backend
auto backendParams = ioda::Engines::BackendCreationParameters();
backendParams.fileName = outconf.getString("engine.obsfile");
backendParams.createMode = ioda::Engines::BackendCreateModes::Truncate_If_Exists;
backendParams.action = ioda::Engines::BackendFileActions::Create;
backendParams.flush = true;
backendParams.allocBytes = 1024*1024*50; // no idea what this number should be

// construct the output group(s)
ioda::Group grpFromFile
= ioda::Engines::constructBackend(ioda::Engines::BackendNames::Hdf5File, backendParams);
const int numLocs = 1;
ioda::NewDimensionScales_t newDims;
newDims.push_back(ioda::NewDimensionScale<int>("Location",
numLocs, ioda::Unlimited, numLocs));
ioda::ObsGroup og = ioda::ObsGroup::generate(grpFromFile, newDims);

// create the output variables
ioda::Variable LocationVar = og.vars["Location"];
std::string varname = "mean/" + group + "/" + variable;
ioda::VariableCreationParameters float_params;
float_params.chunk = true; // allow chunking
float_params.compressWithGZIP(); // compress using gzip
float_params.setFillValue<float>(-999); // set the fill value to -999
ioda::Variable outVar = og.vars.createWithScales<float>(varname, {LocationVar}, float_params);

// write to file
std::vector<float> meanVec(numLocs);
meanVec[0] = mean;
outVar.write(meanVec);

// print a message
oops::Log::info() << "mean written to" << backendParams.fileName << std::endl;

// a better program should return a real exit code depending on result,
// but this is just an example!
return 0;
Expand Down
1 change: 1 addition & 0 deletions utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ list( APPEND utils_test_input
)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testinput)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testrun)
CREATE_SYMLINK( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${utils_test_input} )

# copy the cpp linter script
Expand Down
4 changes: 4 additions & 0 deletions utils/test/testinput/gdas_meanioda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ group: ObsValue
variable: brightnessTemperature
# channel is optional, depends on what variable you are reading
channel: 6
obsdataout:
engine:
type: H5File
obsfile: testrun/gmi_gpm_mean.nc
Loading