8 #include "ufo/GeoVaLs.h"
15 #include "eckit/config/Configuration.h"
16 #include "eckit/exception/Exceptions.h"
18 #include "ioda/distribution/Accumulator.h"
19 #include "ioda/distribution/Distribution.h"
20 #include "ioda/ObsSpace.h"
22 #include "oops/base/Variables.h"
23 #include "oops/util/Logger.h"
26 #include "ufo/Locations.h"
36 const oops::Variables & vars)
37 : keyGVL_(-1), vars_(vars), dist_(std::move(dist))
39 oops::Log::trace() <<
"GeoVaLs default constructor starting" << std::endl;
41 oops::Log::trace() <<
"GeoVaLs default constructor end" << std::endl;
55 : keyGVL_(-1), vars_(vars), dist_(locs.distribution())
57 oops::Log::trace() <<
"GeoVaLs contructor starting" << std::endl;
59 oops::Log::trace() <<
"GeoVaLs contructor key = " <<
keyGVL_ << std::endl;
72 const std::vector<size_t> & nlevs)
73 : keyGVL_(-1), vars_(vars), dist_(locs.distribution())
75 oops::Log::trace() <<
"GeoVaLs contructor starting" << std::endl;
77 oops::Log::trace() <<
"GeoVaLs contructor key = " <<
keyGVL_ << std::endl;
87 const ioda::ObsSpace & obspace,
88 const oops::Variables & vars)
89 : keyGVL_(-1), vars_(vars), dist_(obspace.distribution())
91 oops::Log::trace() <<
"GeoVaLs constructor config starting" << std::endl;
95 oops::Log::trace() <<
"GeoVaLs contructor config key = " <<
keyGVL_ << std::endl;
104 : keyGVL_(-1), vars_(other.vars_), dist_(other.dist_)
106 oops::Log::trace() <<
"GeoVaLs copy one GeoVaLs constructor starting" << std::endl;
108 oops::Log::trace() <<
"GeoVaLs copy one GeoVaLs constructor key = " <<
keyGVL_ << std::endl;
114 : keyGVL_(-1), vars_(other.vars_), dist_(other.dist_)
116 oops::Log::trace() <<
"GeoVaLs copy constructor starting" << std::endl;
118 oops::Log::trace() <<
"GeoVaLs copy constructor key = " <<
keyGVL_ << std::endl;
123 oops::Log::trace() <<
"GeoVaLs destructor starting" << std::endl;
125 oops::Log::trace() <<
"GeoVaLs destructor done" << std::endl;
130 oops::Log::trace() <<
"GeoVaLs::allocate starting" << std::endl;
132 oops::Log::trace() <<
"GeoVaLs::allocate done" << std::endl;
137 oops::Log::trace() <<
"GeoVaLs::zero starting" << std::endl;
139 oops::Log::trace() <<
"GeoVaLs::zero done" << std::endl;
144 oops::Log::trace() <<
"GeoVaLs::reorderzdir starting" << std::endl;
146 vardir.size(), vardir.c_str());
147 oops::Log::trace() <<
"GeoVaLs::reorderzdir done" << std::endl;
152 oops::Log::trace() <<
"GeoVaLs::rms starting" << std::endl;
155 oops::Log::trace() <<
"GeoVaLs::rms done" << std::endl;
161 oops::Log::trace() <<
"GeoVaLs::normalizerms starting" << std::endl;
164 double zz = temp_gval.
rms();
165 oops::Log::trace() <<
"GeoVaLs::normalizerms done" << std::endl;
171 oops::Log::trace() <<
"GeoVaLs::random starting" << std::endl;
173 oops::Log::trace() <<
"GeoVaLs::random done" << std::endl;
178 oops::Log::trace() <<
"GeoVaLs::operator*= starting" << std::endl;
180 oops::Log::trace() <<
"GeoVaLs::operator*= done" << std::endl;
186 oops::Log::trace() <<
"GeoVaLs::operator*= starting" << std::endl;
189 oops::Log::trace() <<
"vals, nlocs = " << vals.size() <<
" " <<
nlocs << std::endl;
190 ASSERT(vals.size() ==
nlocs);
192 oops::Log::trace() <<
"GeoVaLs::operator*= done" << std::endl;
198 oops::Log::trace() <<
"GeoVaLs::operator= starting" << std::endl;
200 oops::Log::trace() <<
"GeoVaLs::operator= done" << std::endl;
206 oops::Log::trace() <<
"GeoVaLs::operator+= starting" << std::endl;
208 oops::Log::trace() <<
"GeoVaLs::operator+= done" << std::endl;
214 oops::Log::trace() <<
"GeoVaLs::operator-= starting" << std::endl;
216 oops::Log::trace() <<
"GeoVaLs::operator-= done" << std::endl;
222 oops::Log::trace() <<
"GeoVaLs::operator*= starting" << std::endl;
224 oops::Log::trace() <<
"GeoVaLs::operator*= done" << std::endl;
230 oops::Log::trace() <<
"GeoVaLs::dot_product_with starting" << std::endl;
234 auto accumulator =
dist_->createAccumulator<
double>();
235 std::vector<double> this_values(
nlocs), other_values(
nlocs);
238 for (
size_t jvar = 0; jvar <
vars_.size(); ++jvar) {
242 for (
size_t jlev = 0; jlev <
nlevs; ++jlev) {
246 for (
size_t jloc = 0; jloc <
nlocs; ++jloc) {
247 if ((this_values[jloc] !=
missing) && (other_values[jloc] !=
missing)) {
248 accumulator->addTerm(jloc, this_values[jloc]*other_values[jloc]);
253 const double dotprod = accumulator->computeResult();
254 oops::Log::trace() <<
"GeoVaLs::dot_product_with done" << std::endl;
260 oops::Log::trace() <<
"GeoVaLs::split GeoVaLs into 2" << std::endl;
262 oops::Log::trace() <<
"GeoVaLs::split GeoVaLs into 2" << std::endl;
268 oops::Log::trace() <<
"GeoVaLs::merge 2 GeoVaLs" << std::endl;
270 oops::Log::trace() <<
"GeoVaLs::merge 2 GeoVaLs" << std::endl;
277 double zmin, zmax, zrms;
279 os <<
"GeoVaLs: variables = " <<
vars_ << std::endl;
280 for (
size_t jv = 0; jv <
vars_.size(); ++jv) {
283 os <<
"GeoVaLs: nobs= " << nn <<
" " <<
vars_[jv] <<
" Min=" << zmin <<
", Max=" << zmax
284 <<
", RMS=" << zrms << std::endl;
303 << std::setprecision(4)
304 << mxval <<
" for observation = " << iobs
305 <<
" and variable = " << ivar << std::endl;
311 oops::Log::trace() <<
"GeoVaLs::nlevs starting" << std::endl;
314 oops::Log::trace() <<
"GeoVaLs::nlevs done" << std::endl;
319 void GeoVaLs::get(std::vector<float> & vals,
const std::string & var)
const {
320 oops::Log::trace() <<
"GeoVaLs::get 2D starting" << std::endl;
323 std::vector<double> doublevals(vals.size());
324 this->
get(doublevals, var);
325 vals.assign(doublevals.begin(), doublevals.end());
326 oops::Log::trace() <<
"GeoVaLs::get 2D done" << std::endl;
331 oops::Log::trace() <<
"GeoVaLs::getAtLevel(double) starting" << std::endl;
334 ASSERT(vals.size() ==
nlocs);
336 oops::Log::trace() <<
"GeoVaLs::getAtLevel(double) done" << std::endl;
341 oops::Log::trace() <<
"GeoVaLs::getAtLevel(float) starting" << std::endl;
344 ASSERT(vals.size() ==
nlocs);
346 oops::Log::trace() <<
"GeoVaLs::getAtLevel(float) done" << std::endl;
351 oops::Log::trace() <<
"GeoVaLs::getAtLevel(int) starting" << std::endl;
352 std::vector<double> doublevals(vals.size());
354 vals.assign(doublevals.begin(), doublevals.end());
355 oops::Log::trace() <<
"GeoVaLs::getAtLevel(int) done" << std::endl;
359 void GeoVaLs::get(std::vector<double> & vals,
const std::string & var)
const {
360 oops::Log::trace() <<
"GeoVaLs::get 2D starting" << std::endl;
363 ASSERT(vals.size() ==
nlocs);
365 oops::Log::trace() <<
"GeoVaLs::get 2D done" << std::endl;
369 void GeoVaLs::get(std::vector<int> & vals,
const std::string & var)
const {
370 oops::Log::trace() <<
"GeoVaLs::get 2D starting" << std::endl;
373 std::vector<double> doublevals(vals.size());
374 this->
get(doublevals, var);
375 vals.assign(doublevals.begin(), doublevals.end());
376 oops::Log::trace() <<
"GeoVaLs::get 2D done" << std::endl;
381 const std::string & var,
382 const int loc)
const {
383 oops::Log::trace() <<
"GeoVaLs::getAtLocation(double) starting" << std::endl;
385 ASSERT(vals.size() ==
nlevs);
386 ASSERT(loc >= 0 && loc < this->
nlocs());
388 oops::Log::trace() <<
"GeoVaLs::getAtLocation(double) done" << std::endl;
393 const std::string & var,
394 const int loc)
const {
395 oops::Log::trace() <<
"GeoVaLs::getAtLocation(float) starting" << std::endl;
396 std::vector <double> doublevals(vals.size());
398 vals.assign(doublevals.begin(), doublevals.end());
399 oops::Log::trace() <<
"GeoVaLs::getAtLocation(float) done" << std::endl;
404 const std::string & var,
405 const int loc)
const {
406 oops::Log::trace() <<
"GeoVaLs::getAtLocation(int) starting" << std::endl;
407 std::vector <double> doublevals(vals.size());
409 vals.assign(doublevals.begin(), doublevals.end());
410 oops::Log::trace() <<
"GeoVaLs::getAtLocation(int) done" << std::endl;
415 const std::string & var,
416 const int lev)
const {
417 oops::Log::trace() <<
"GeoVaLs::putAtLevel(double) starting" << std::endl;
420 ASSERT(vals.size() ==
nlocs);
422 oops::Log::trace() <<
"GeoVaLs::putAtLevel(double) done" << std::endl;
427 const std::string & var,
428 const int lev)
const {
429 oops::Log::trace() <<
"GeoVaLs::putAtLevel(float) starting" << std::endl;
432 ASSERT(vals.size() ==
nlocs);
433 std::vector<double> doublevals(vals.begin(), vals.end());
435 oops::Log::trace() <<
"GeoVaLs::putAtLevel(float) done" << std::endl;
440 const std::string & var,
441 const int lev)
const {
442 oops::Log::trace() <<
"GeoVaLs::putAtLevel(int) starting" << std::endl;
445 ASSERT(vals.size() ==
nlocs);
446 std::vector<double> doublevals(vals.begin(), vals.end());
448 oops::Log::trace() <<
"GeoVaLs::putAtLevel(int) done" << std::endl;
452 const std::string & var,
453 const int loc)
const {
454 oops::Log::trace() <<
"GeoVaLs::putAtLocation(double) starting" << std::endl;
456 ASSERT(vals.size() ==
nlevs);
457 ASSERT(loc >= 0 && loc < this->
nlocs());
459 oops::Log::trace() <<
"GeoVaLs::putAtLocation(double) done" << std::endl;
463 const std::string & var,
464 const int loc)
const {
465 oops::Log::trace() <<
"GeoVaLs::putAtLocation(float) starting" << std::endl;
467 ASSERT(vals.size() ==
nlevs);
468 ASSERT(loc >= 0 && loc < this->
nlocs());
469 std::vector<double> doublevals(vals.begin(), vals.end());
471 oops::Log::trace() <<
"GeoVaLs::putAtLocation(float) done" << std::endl;
475 const std::string & var,
476 const int loc)
const {
477 oops::Log::trace() <<
"GeoVaLs::putAtLocation(int) starting" << std::endl;
479 ASSERT(vals.size() ==
nlevs);
480 ASSERT(loc >= 0 && loc < this->
nlocs());
481 std::vector<double> doublevals(vals.begin(), vals.end());
483 oops::Log::trace() <<
"GeoVaLs::putAtLocation(int) done" << std::endl;
488 const ioda::ObsSpace & obspace) {
489 oops::Log::trace() <<
"GeoVaLs::read starting" << std::endl;
491 oops::Log::trace() <<
"GeoVaLs::read done" << std::endl;
496 oops::Log::trace() <<
"GeoVaLs::write starting" << std::endl;
498 oops::Log::trace() <<
"GeoVaLs::write done" << std::endl;
503 oops::Log::trace() <<
"GeoVaLs::nlocs starting" << std::endl;
506 oops::Log::trace() <<
"GeoVaLs::nlocs done" << std::endl;
GeoVaLs: geophysical values at locations.
GeoVaLs & operator+=(const GeoVaLs &)
Add another GeoVaLs.
size_t nlevs(const std::string &var) const
Return number of levels for a specified variable.
std::shared_ptr< const ioda::Distribution > dist_
void split(GeoVaLs &, GeoVaLs &) const
Split two GeoVaLs.
void zero()
Zero out the GeoVaLs.
void print(std::ostream &) const
Output GeoVaLs to a stream.
void reorderzdir(const std::string &, const std::string &)
Reorder GeoVaLs in vertical dimension based on vertical coordinate variable.
GeoVaLs & operator*=(const double)
Multiply by a constant scalar.
double dot_product_with(const GeoVaLs &) const
Scalar product of two GeoVaLs.
void write(const eckit::Configuration &) const
Write GeoVaLs to the file.
double rms() const
Calculate rms.
GeoVaLs(std::shared_ptr< const ioda::Distribution >, const oops::Variables &)
Deprecated default constructor - does not allocate fields.
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
void putAtLocation(const std::vector< double > &vals, const std::string &var, const int loc) const
Put GeoVaLs for double variable var at location loc.
size_t nlocs() const
Return the number of geovals.
GeoVaLs & operator-=(const GeoVaLs &)
Subtract another GeoVaLs.
void read(const eckit::Configuration &, const ioda::ObsSpace &)
Read GeoVaLs from the file.
void allocate(const int &nlev, const oops::Variables &vars)
Deprecated method. Allocates GeoVaLs for vars variables with nlev number of levels.
double normalizedrms(const GeoVaLs &) const
Calculate normalized rms.
void get(std::vector< double > &, const std::string &var) const
Get 2D GeoVaLs for variable var (fails for 3D GeoVaLs)
void merge(const GeoVaLs &, const GeoVaLs &)
Merge two GeoVaLs.
void putAtLevel(const std::vector< double > &vals, const std::string &var, const int lev) const
Put GeoVaLs for double variable var at level lev.
void random()
Randomize GeoVaLs.
void getAtLocation(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified location.
GeoVaLs & operator=(const GeoVaLs &)
Copy operator.
Locations class to handle simple lat-lon-time locations.
size_t size() const
size of locations
void ufo_geovals_rms_f90(const F90goms &, double &)
void ufo_geovals_copy_one_f90(F90goms &, const F90goms &, const int &)
void ufo_geovals_get_loc_f90(const F90goms &, const int &, const char *, const int &, const int &, double &)
void ufo_geovals_read_file_f90(const F90goms &, const eckit::Configuration &, const ioda::ObsSpace &, const oops::Variables &)
void ufo_geovals_split_f90(const F90goms &, const F90goms &, const F90goms &)
void ufo_geovals_profmult_f90(const F90goms &, const int &, const float &)
void ufo_geovals_delete_f90(F90goms &)
void ufo_geovals_partial_setup_f90(F90goms &key, const size_t &nlocs, const oops::Variables &vars)
void ufo_geovals_copy_f90(const F90goms &, F90goms &)
void ufo_geovals_nlocs_f90(const F90goms &, size_t &)
void ufo_geovals_put_loc_f90(const F90goms &, const int &, const char *, const int &, const int &, const double &)
void ufo_geovals_scalmult_f90(const F90goms &, const double &)
void ufo_geovals_nlevs_f90(const F90goms &, const int &, const char *, int &)
void ufo_geovals_maxloc_f90(const F90goms &, double &, int &, int &)
void ufo_geovals_zero_f90(const F90goms &)
void ufo_geovals_default_constr_f90(F90goms &)
Interface to Fortran UFO GeoVals routines.
void ufo_geovals_random_f90(const F90goms &)
void ufo_geovals_getdouble_f90(const F90goms &, const int &, const char *, const int &, const int &, double &)
void ufo_geovals_assign_f90(const F90goms &, const F90goms &)
void ufo_geovals_setup_f90(F90goms &key, const size_t &nlocs, const oops::Variables &vars, const size_t &nvars, const size_t &nlevs)
void ufo_geovals_normalize_f90(const F90goms &, const F90goms &)
void ufo_geovals_write_file_f90(const F90goms &, const eckit::Configuration &, const size_t &)
void ufo_geovals_merge_f90(const F90goms &, const F90goms &, const F90goms &)
void ufo_geovals_get_f90(const F90goms &, const int &, const char *, const int &, const int &, float &)
void ufo_geovals_diff_f90(const F90goms &, const F90goms &)
void ufo_geovals_schurmult_f90(const F90goms &, const F90goms &)
void ufo_geovals_putdouble_f90(const F90goms &, const int &, const char *, const int &, const int &, const double &)
void ufo_geovals_allocate_f90(const F90goms &, const size_t &nlevels, const oops::Variables &vars)
void ufo_geovals_reorderzdir_f90(const F90goms &, const int &, const char *, const int &, const char *)
void ufo_geovals_get2d_f90(const F90goms &, const int &, const char *, const int &, double &)
void ufo_geovals_minmaxavg_f90(const F90goms &, int &, int &, double &, double &, double &)
void ufo_geovals_add_f90(const F90goms &, const F90goms &)