12 #include <Eigen/Dense>
14 #include "eckit/config/LocalConfiguration.h"
15 #include "eckit/config/YAMLConfiguration.h"
16 #include "eckit/exception/Exceptions.h"
17 #include "eckit/filesystem/PathName.h"
22 #include "oops/util/missingValues.h"
28 const std::string & coeffile,
const std::string & errfile,
29 const std::string & sensor,
30 const std::vector<std::string> & predictors,
31 const size_t nchannels) {
33 std::vector<int>
channels(nchannels), channels_in_errorfile(nchannels);
34 long numPreds = predictors.size();
38 Eigen::ArrayXXf biascoeffs(numPreds,
numChans);
39 Eigen::ArrayXXf biascoefferrs(numPreds,
numChans);
43 ASSERT(
channels == channels_in_errorfile);
47 ioda::NewDimensionScale<int>(
"npredictors", numPreds),
48 ioda::NewDimensionScale<int>(
"nchannels",
numChans)
56 "predictors", {ogrp.
vars[
"npredictors"]});
57 predsVar.
write(predictors);
63 float_params.
chunk =
true;
70 {ogrp.
vars[
"npredictors"], ogrp.
vars[
"nchannels"]}, float_params);
75 {ogrp.
vars[
"npredictors"], ogrp.
vars[
"nchannels"]}, float_params);
80 {ogrp.
vars[
"nchannels"]}, float_params);
85 int main(
int argc,
char** argv) {
88 eckit::PathName configfile = argv[1];
89 eckit::YAMLConfiguration config(configfile);
90 const std::string coeffile = config.getString(
"input coeff file");
91 const std::string errfile = config.getString(
"input err file");
93 std::vector<std::string> sensors;
94 std::vector<int> nchannels;
99 std::cout <<
"Found " << sensors.size() <<
" sensors:" << std::endl;
100 for (
size_t jj = 0; jj < sensors.size(); ++jj) {
101 std::cout <<
"-- " << sensors[jj] <<
", " << nchannels[jj] <<
" channels." << std::endl;
104 std::vector<eckit::LocalConfiguration> configs = config.getSubConfigurations(
"output");
105 for (
size_t jj = 0; jj < configs.size(); ++jj) {
106 const std::string sensor = configs[jj].getString(
"sensor");
107 const std::string output_filename = configs[jj].getString(
"output file");
108 const std::vector<std::string> predictors = configs[jj].getStringVector(
"predictors");
110 const std::string
error =
"Number of predictors specified in yaml must be " +
111 std::to_string(
gsi_npredictors) +
" (same as number of predictors in GSI satinfo)";
112 throw eckit::BadValue(
error, Here());
114 auto it = find(sensors.begin(), sensors.end(), sensor);
115 if (it != sensors.end()) {
116 int index = it - sensors.begin();
119 makeObsBiasObject(group, coeffile, errfile, sensor, predictors, nchannels[index]);
121 const std::string
error =
"No " + sensor +
" sensor in the input file";
122 throw eckit::BadValue(
error, Here());
void readObsBiasCoefficients(const std::string &filename, const std::string &sensor, std::vector< int > &channels, Eigen::ArrayXXf &coeffs)
void findSensorsChannels(const std::string &filename, std::vector< std::string > &sensors, std::vector< int > &nchannels)
void readObsBiasCoeffErrors(const std::string &filename, const std::string &sensor, std::vector< int > &channels, Eigen::ArrayXXf &errs, Eigen::ArrayXf &nobs)
constexpr size_t gsi_npredictors
Number of predictors in GSI satbias file.
Interfaces for ioda::ObsGroup and related classes.
int main(int argc, char **argv)
ioda::ObsGroup makeObsBiasObject(ioda::Group &empty_base_object, const std::string &coeffile, const std::string &errfile, const std::string &sensor, const std::vector< std::string > &predictors, const size_t nchannels)
Groups are a new implementation of ObsSpaces.
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.
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.
Variable_Implementation writeWithEigenRegular(const EigenClass &d, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
Write an Eigen object (a Matrix, an Array, a Block, a Map).
virtual Variable write(gsl::span< char > data, const Type &in_memory_dataType, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
The fundamental write function. Backends overload this function to implement all write operations.
IODA_DL Group createFile(const std::string &filename, BackendCreateModes mode, HDF5_Version_Range compat=defaultVersionRange())
Create a ioda::Group backed by an HDF5 file.
@ Truncate_If_Exists
If the file already exists, overwrite it.
std::vector< std::shared_ptr< NewDimensionScale_Base > > NewDimensionScales_t
Used to specify Variable creation-time properties.
void compressWithGZIP(int level=6)
VariableCreationParameters & setFillValue(DataType fill)
bool chunk
Do we chunk this variable? Required for extendible / compressible Variables.