8 #ifndef UFO_CATEGORICALOPER_OBSCATEGORICALDATA_H_
9 #define UFO_CATEGORICALOPER_OBSCATEGORICALDATA_H_
19 #include "ioda/ObsVector.h"
21 #include "oops/base/Variables.h"
23 #include "oops/util/Logger.h"
41 class LinearObsOperatorBase;
42 class LinearObsOperatorFactory;
43 class LinearObsOperatorParametersWrapper;
45 class ObsOperatorBase;
46 class ObsOperatorFactory;
47 class ObsOperatorParametersWrapper;
49 template <
typename OPBASE>
65 template <
typename OPBASE>
76 oops::Log::debug() <<
"categorical variable: " << categoricalVariableName << std::endl;
78 if (odb.has(
"MetaData", categoricalVariableName)) {
79 const ioda::ObsDtype dtype = odb.dtype(
"MetaData", categoricalVariableName);
80 if (dtype == ioda::ObsDtype::String) {
82 }
else if (dtype == ioda::ObsDtype::Integer) {
83 std::vector <int> categoricalVariableInt(odb.nlocs());
84 odb.get_db(
"MetaData", categoricalVariableName, categoricalVariableInt);
85 std::transform(categoricalVariableInt.cbegin(), categoricalVariableInt.cend(),
88 throw eckit::UserError(
"The categorical variable must be a vector of "
89 "either strings or integers", Here());
92 throw eckit::UserError(
"The categorical variable " + categoricalVariableName +
93 " does not exist", Here());
105 for (
size_t jloc = 0; jloc < odb.nlocs(); ++jloc) {
108 it_operName->second :
114 for (
const eckit::LocalConfiguration &operatorConfig :
119 ParametersWrapper_ operatorParams;
120 operatorParams.validateAndDeserialize(operatorConfig);
121 std::unique_ptr<OPBASE> op(Factory_::create(odb, operatorParams.operatorParameters));
123 components_.emplace(std::make_pair(operatorConfig.getString(
"name"), std::move(op)));
129 " has not been configured", Here());
134 throw eckit::UserError(
"The operator " + operName.second +
135 " has not been configured", Here());
148 void fillHofX(
const std::map <std::string, ioda::ObsVector> & ovecs,
149 ioda::ObsVector & ovec)
const {
152 for (
size_t jloc = 0; jloc < ovec.nlocs(); ++jloc) {
155 for (
size_t jvar = 0; jvar < ovec.nvars(); ++jvar) {
156 const size_t idx = jloc * ovec.nvars() + jvar;
157 ovec[idx] = ovecloc[idx];
162 void print(std::ostream & os)
const {
163 os <<
"ObsCategorical operator:" << std::endl;
Linear obs operator factory.
Contains a polymorphic parameter holding an instance of a subclass of ObsOperatorParametersBase.
Data handler for the Categorical observation operator and TL/AD code.
const oops::Variables & requiredVars() const
Return required variables for the operator.
std::map< std::string, std::string > categorisedOperatorNames_
Names of the categorised observation operators.
void print(std::ostream &os) const
const std::map< std::string, std::unique_ptr< OPBASE > > & components() const
Return component operators.
std::vector< std::string > locOperNames_
Operator name at each location.
std::map< std::string, std::unique_ptr< OPBASE > > components_
Observation operators which are run by the Categorical operator.
std::string fallbackOperatorName_
Name of the fallback observation operator.
std::vector< std::string > categoricalVariable_
Value of the categorical variable in the ObsSpace.
const std::vector< std::string > & locOperNames() const
Return list of operator names to use at each location.
void fillHofX(const std::map< std::string, ioda::ObsVector > &ovecs, ioda::ObsVector &ovec) const
Fill final H(x) vector from a list of components.
void configure(const ioda::ObsSpace &odb, const ObsCategoricalParameters ¶meters)
Get all information related to the configuration of the Categorical operator and TL/AD code.
oops::Variables requiredVars_
Required variables.
Configuration options recognized by the Categorical operator.
oops::RequiredParameter< std::vector< eckit::LocalConfiguration > > operatorConfigurations
oops::RequiredParameter< std::string > fallbackOperatorName
oops::RequiredParameter< std::map< std::string, std::string > > categorisedOperatorNames
oops::RequiredParameter< std::string > categoricalVariable
Categorical variable used to divide H(x) into sections.
Contains a polymorphic parameter holding an instance of a subclass of ObsOperatorParametersBase.
LinearObsOperatorParametersWrapper ParametersWrapper_
LinearObsOperatorFactory Factory_
ObsOperatorFactory Factory_
ObsOperatorParametersWrapper ParametersWrapper_