UFO
ROobserror.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
9 
10 #include "eckit/config/Configuration.h"
11 
12 #include "ioda/ObsDataVector.h"
13 #include "ioda/ObsSpace.h"
14 #include "ioda/ObsVector.h"
15 #include "oops/util/Logger.h"
16 #include "ufo/GeoVaLs.h"
17 
18 namespace ufo {
19 
20 // -----------------------------------------------------------------------------
21 
22 ROobserror::ROobserror(ioda::ObsSpace & obsdb,
23  const eckit::Configuration & config,
24  std::shared_ptr<ioda::ObsDataVector<int> > qc,
25  std::shared_ptr<ioda::ObsDataVector<float> > oberr)
26  : FilterBase(obsdb, config, qc, oberr)
27 {
28  oops::Log::trace() << "ROobserror contructor starting" << std::endl;
29  const oops::Variables filvar = filtervars_[0].toOopsVariables();;
30  oops::Log::trace() << "ROobserror contructor = "<< filvar << std::endl;
31  ufo_roobserror_create_f90(key_, obsdb, config, filvar);
32  oops::Log::trace() << "ROobserror contructor key = " << key_ << std::endl;
33 
34  // Declare the geovals that are needed by the fortran
35  allvars_ += Variable("air_temperature@GeoVaLs");
36  allvars_ += Variable("geopotential_height@GeoVaLs");
37 
38  // Get the number of horizontal geovals (used by ROPP-2D)
39  // Default to 1
40  n_horiz = config_.getInt("n_horiz", 1);
41  oops::Log::debug() << "constructor: n_horiz = " << n_horiz << std::endl;
42 }
43 
44 // -----------------------------------------------------------------------------
45 
47  oops::Log::trace() << "ROobserror destructor key = " << key_ << std::endl;
49 }
50 
51 // -----------------------------------------------------------------------------
52 
53 void ROobserror::applyFilter(const std::vector<bool> & apply,
54  const Variables & filtervars,
55  std::vector<std::vector<bool>> & flagged) const {
56  oops::Log::trace() << "ROobserror using priorFilter" << std::endl;
57  // Check that we have valid data to apply the filter to
58  if (obsdb_.nlocs() > 0 && data_.getGeoVaLs()->nlocs() > 0) {
59  // Get the geovals
60  Eigen::ArrayXXf air_temperature = get_geovals("air_temperature@GeoVaLs");
61  Eigen::ArrayXXf geopot_height = get_geovals("geopotential_height@GeoVaLs");
62  oops::Log::debug() << "Shape geopotential height " << geopot_height.rows() <<
63  " " << geopot_height.cols() << std::endl;
64 
65  // Call the fortran routines to do the processing
66  flags_->save("FortranQC"); // should pass values to fortran properly
67  obserr_->save("FortranERR"); // should pass values to fortran properly
69  air_temperature.rows(), air_temperature.cols(), air_temperature.data(),
70  geopot_height.rows(), geopot_height.cols(), geopot_height.data());
71  flags_->read("FortranQC"); // should get values from fortran properly
72  obserr_->read("FortranERR"); // should get values from fortran properly
73  }
74 }
75 
76 
77 Eigen::ArrayXXf ROobserror::get_geovals(const std::string& var_name) const {
78  // Get the geovals
79  oops::Log::debug() << "Running get_geovals for " << var_name << std::endl;
80  // Note that ROPP has more geovals than observation locations, and this converts to
81  // the correct number (there are n_horiz geovals for every observation)
82  size_t nlocs = obsdb_.nlocs() * static_cast<size_t>(n_horiz);
83  ASSERT(nlocs == data_.getGeoVaLs()->nlocs());
84  size_t nlevs = data_.nlevs(Variable(var_name));
85  oops::Log::debug() << "nlocs = " << nlocs << " nlevs = " << nlevs << std::endl;
86  Eigen::ArrayXXf all_geovals(nlocs, nlevs);
87  std::vector<float> single_geoval(nlocs);
88  for (int ilev=0; ilev < static_cast<int>(nlevs); ilev++) {
89  oops::Log::debug() << "Getting data for level " << ilev+1 << std::endl;
90  data_.getGeoVaLs()->getAtLevel(single_geoval, Variable(var_name).variable(), ilev);
91  all_geovals.col(ilev) = Eigen::VectorXf::Map(single_geoval.data(), single_geoval.size());
92  }
93  return all_geovals;
94 }
95 
96 
97 // -----------------------------------------------------------------------------
98 
99 void ROobserror::print(std::ostream & os) const {
100  os << "ROobserror::print not yet implemented " << key_;
101 }
102 
103 // -----------------------------------------------------------------------------
104 
105 } // namespace ufo
Base class for UFO QC filters.
Definition: FilterBase.h:45
const eckit::LocalConfiguration config_
Definition: FilterBase.h:59
ufo::Variables filtervars_
Definition: FilterBase.h:60
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
Definition: GeoVaLs.cc:330
size_t nlocs() const
Return the number of geovals.
Definition: GeoVaLs.cc:502
const GeoVaLs * getGeoVaLs() const
Returns reference to GeoVaLs required by 1DVar.
size_t nlevs(const Variable &) const
Returns the number of levels in the specified variable.
ufo::Variables allvars_
std::shared_ptr< ioda::ObsDataVector< float > > obserr_
ioda::ObsSpace & obsdb_
std::shared_ptr< ioda::ObsDataVector< int > > flags_
void print(std::ostream &) const override
Definition: ROobserror.cc:99
ROobserror(ioda::ObsSpace &, const eckit::Configuration &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
Definition: ROobserror.cc:22
F90roerr key_
Definition: ROobserror.h:53
Eigen::ArrayXXf get_geovals(const std::string &) const
Definition: ROobserror.cc:77
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
Definition: ROobserror.cc:53
oops::Variables toOopsVariables() const
Definition: Variables.cc:156
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
void ufo_roobserror_delete_f90(F90roerr &)
void ufo_roobserror_create_f90(F90roerr &, const ioda::ObsSpace &, const eckit::Configuration &, const oops::Variables &)
Interface to Fortran RO observation error routines.
void ufo_roobserror_prior_f90(const F90roerr &, const int &, const int &, const float *, const int &, const int &, const float *)