19 #include "boost/none_t.hpp"
20 #include "boost/optional.hpp"
21 #include "eckit/config/Configuration.h"
22 #include "eckit/config/LocalConfiguration.h"
23 #include "eckit/config/YAMLConfiguration.h"
24 #include "eckit/exception/Exceptions.h"
25 #include "eckit/filesystem/LocalPathName.h"
26 #include "eckit/filesystem/PathName.h"
27 #include "oops/util/parameters/Parameters.h"
31 #include <unordered_map>
46 const std::string &method) {
47 if (method !=
"concat") {
48 throw eckit::MethodNotYetImplemented(
"Concatenation is the only supported merge method.");
54 eckit::PathName yamlPath = nameMapFile;
55 eckit::YAMLConfiguration conf(yamlPath);
56 eckit::LocalConfiguration
ioda(conf,
"ioda");
67 if (variable.unit.value())
68 Mapping[variable.source] = {variable.name, {
true, *(variable.unit.value())}};
70 Mapping[variable.source] = {variable.name, {
false,
""}};
79 if (variable.outputVariableDataType.value() !=
"string") {
80 throw eckit::MethodNotYetImplemented(
"YAML mapping file: the output variable "
81 "data type for a derived variable is not "
85 if (std::find(variable.inputNames.value().begin(), variable.inputNames.value().end(),
86 variable.outputName.value()) != variable.inputNames.value().end()) {
87 throw eckit::ReadError(std::string(
"YAML mapping file has a complementary variable name") +
88 std::string(
"matching a derived variable name."));
90 std::type_index outputTypeIndex =
typeid(std::string);
94 std::shared_ptr<ComplementaryVariableOutputMetadata> sharedOutputMetaData(
96 variable.
outputName, outputTypeIndex, mergeMethod, 0});
97 size_t inputIndex = 0;
98 for (
const std::string &input : variable.inputNames.value()) {
102 sharedOutputMetaData->inputVariableCount = inputIndex;
109 g.atts.add<std::string>(
"_ioda_layout", std::string(
"ObsGroup_ODB"));
127 std::string mappedStr;
130 mappedStr = (it->second).iodaName;
154 throw eckit::ReadError(input +
" was not found to be a complementary variable.");
161 throw eckit::ReadError(input + std::string(
" was not found to be a complementary variable."));
166 const std::string &input)
const
169 throw eckit::ReadError(input +
" was not found to be a complementary variable.");
174 const std::string &input)
const
177 throw eckit::ReadError(input +
" was not found to be a complementary variable.");
182 const std::string &input)
const
185 throw eckit::ReadError(input +
" was not found to be a complementary variable.");
190 const std::string & input)
const {
192 throw eckit::ReadError(input +
" was not found to to be an ODB source variable.");
194 return (
Mapping.at(input)).inputUnit;
Interfaces for ioda::Group and related classes.
Contains definitions for how data are arranged in ioda internally.
Contains definitions for how ODB data are arranged in ioda internally.
Defines all of the information which should be stored in the YAML mapping file.
DataLayoutPolicy::MergeMethod getMergeMethod(const std::string &) const override
std::string doMap(const std::string &) const override
Map a user-specified Variable path to the correct location.
std::unordered_map< std::string, variableStorageInformation > Mapping
Mapping with ODB equivalents as keys and IODA naming/unit pairs as values.
DataLayoutPolicy_ObsGroup_ODB(const std::string &)
DataLayoutPolicy::MergeMethod parseMergeMethod(const std::string &)
size_t getInputsNeeded(const std::string &) const override
virtual ~DataLayoutPolicy_ObsGroup_ODB()
std::string getOutputNameFromComponent(const std::string &) const override
const int32_t ObsGroup_ODB_Layout_Version
Record versioning information for this layout in the ioda object. Provides forward compatability.
void initializeStructure(Group_Base &) const override
bool isComplementary(const std::string &) const override
Check if the named variable will be a part of a derived variable.
void parseComponentVariables()
std::string name() const override
A descriptive name for the policy.
std::pair< bool, std::string > getUnit(const std::string &) const override
std::unordered_map< std::string, complementaryVariableMetaData > complementaryVariableDataMap
void parseMappingFile(const std::string &)
bool isMapped(const std::string &) const override
Check if the named variable is in the Variables section of the ODB mapping file.
size_t getComplementaryPosition(const std::string &) const override
std::shared_ptr< ODBLayoutParameters > mappingParams_
std::type_index getOutputVariableDataType(const std::string &) const override
@ Concat
Concatenate complementary variables entry-by-entry.
Hidden base class to prevent constructor confusion.
Common preprocessor definitions used throughout IODA.
IODA_DL std::string convertV1PathToV2Path(const std::string &path)
Split path into substrings separated by @ characters, then concatenate them in reverse order,...