7 #include "eckit/exception/Exceptions.h"
16 typedef std::vector<std::pair<std::string, boost::variant<std::vector<int>,
18 std::vector<std::string>>
28 obData.emplace_back(var.
fullName(), std::move(dat));
36 std::vector<util::DateTime> dat;
37 std::vector<std::string> datConv;
39 datConv.resize(dat.size());
42 std::transform(dat.begin(), dat.end(), datConv.begin(),
43 [](util::DateTime dt){return dt.toString();});
44 obData.emplace_back(var.
fullName(), std::move(datConv));
51 constexpr util::NamedEnumerator<InterpMethod>
67 std::vector<eckit::LocalConfiguration> interpSubConfs;
68 const std::vector<InterpolationParameters> &interpolationParameters =
71 for (
auto intParam = interpolationParameters.begin();
72 intParam != interpolationParameters.end(); ++intParam) {
76 }
else if (nlin > 0) {
77 throw eckit::UserError(
"Bilinear interpolation can only be supplied as the final two "
78 "arguments.", Here());
80 (intParam + 1 != interpolationParameters.end())) {
81 throw eckit::UserError(
"Linear interpolation can only be supplied as the very last "
84 interpSubConfs.push_back(intParam->toConfiguration());
87 if (nlin > 0 && nlin != 2) {
88 throw eckit::UserError(
"Bilinear interpolation requires two variables.", Here());
93 channels_ = {std::make_move_iterator(std::begin(channels)),
94 std::make_move_iterator(std::end(channels))};
102 template <
typename ExtractedValue>
106 const size_t &
iloc) :
109 template <
typename T>
114 template <
typename T,
typename R>
115 void operator()(
const std::vector<T> &obDat1,
const std::vector<R> &obDat2) {
125 template <
typename T>
131 if (options_.chlist.value() != boost::none)
135 for (
size_t ind=0; ind < allvars_.size(); ind++) {
137 " from the obsSpace" << std::endl;
139 const std::string varName = allvars_[ind].fullName();
140 const InterpMethod &interpolationMethod = interpMethod_.at(varName);
141 interpolator.scheduleSort(varName, interpolationMethod);
142 switch (in.
dtype(allvars_[ind])) {
143 case ioda::ObsDtype::Integer:
144 updateObData<int>(in, allvars_[ind], obData);
146 case ioda::ObsDtype::String:
147 updateObData<std::string>(in, allvars_[ind], obData);
149 case ioda::ObsDtype::Float:
150 updateObData<float>(in, allvars_[ind], obData);
152 case ioda::ObsDtype::DateTime:
156 throw eckit::UserError(
"Data type not yet handled.", Here());
162 for (
size_t jvar = 0; jvar < out.nvars(); ++jvar) {
163 for (
size_t iloc = 0; iloc < in.
nlocs(); ++iloc) {
164 if (options_.chlist.value() != boost::none)
165 interpolator.extract(channels_[jvar]);
168 ExtractVisitor<T> visitor(interpolator, iloc);
169 for (
size_t ind=0; ind < obData.size(); ind++) {
172 boost::apply_visitor(visitor, obData[ind].second, obData[ind+1].second);
175 boost::apply_visitor(visitor, obData[ind].second);
178 out[jvar][iloc] = interpolator.getResult();
184 template <
typename T>
const ufo::Variables & requiredVariables() const
geovals required to compute the function
std::unordered_map< std::string, InterpMethod > interpMethod_
void compute(const ObsFilterData &, ioda::ObsDataVector< T > &) const
compute the result of the function
std::vector< int > channels_
DrawValueFromFile(const eckit::LocalConfiguration &)
DrawValueFromFileParameters options_
oops::RequiredParameter< std::vector< InterpolationParameters > > interpolation
oops::RequiredParameter< std::string > fpath
Path to the file containing the data to interpolate.
oops::OptionalParameter< std::set< int > > chlist
ObsFilterData provides access to all data related to an ObsFilter.
size_t nlocs() const
Returns the number of locations in the associated ObsSpace.
ioda::ObsDtype dtype(const Variable &) const
Determines dtype of the provided variable.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
std::string fullName() const
void updateObData(const ObsFilterData &in, const Variable &var, ObData &obData)
This is a convenience function for updating our container for useful observation data.
std::vector< std::pair< std::string, boost::variant< std::vector< int >, std::vector< float >, std::vector< std::string > > > > ObData
void updateObDataDateTime(const ObsFilterData &in, const Variable &var, ObData &obData)
Add datetime observation information data to our container.
static ObsFunctionMaker< Conditional< std::string > > stringMaker("Conditional")
static ObsFunctionMaker< Conditional< float > > floatMaker("Conditional")
InterpMethod
Method used by the DataExtractor to map the value of an ObsSpace variable to a range of slices of the...
@ LINEAR
Perform a piecewise linear interpolation along the dimension indexed by the ObsSpace variable.
@ BILINEAR
Perform a bilinear interpolation along two dimensions indexed by the ObsSpace variables.
@ EXACT
Select slices where the indexing coordinate matches exactly the value of the corresponding ObsSpace v...
static ObsFunctionMaker< Conditional< int > > intMaker("Conditional")
static constexpr util::NamedEnumerator< InterpMethod > namedValues[]
static constexpr char enumTypeName[]