14 #include "ioda/ObsSpace.h"
16 #include "oops/base/Variables.h"
17 #include "oops/util/abor1_cpp.h"
18 #include "oops/util/Logger.h"
20 #include "ufo/GeoVaLs.h"
21 #include "ufo/ObsDiagnostics.h"
31 order_(parameters.order.value().value_or(1))
33 if (parameters.
order.value() != boost::none) {
39 geovars_ += oops::Variables({
"air_temperature",
41 "average_surface_temperature_within_field_of_view"});
42 if (vars.size() > 0) {
43 hdiags_ += oops::Variables({
"transmittances_of_atmosphere_layer"}, vars.channels());
45 oops::Log::error() <<
"Channels size is ZERO !" << std::endl;
46 ABORT(
"Channels size is ZERO !");
51 const std::string & tlapse_file = parameters.
tlapse;
52 std::ifstream infile(tlapse_file);
57 if (infile.is_open()) {
58 while (!infile.eof()) {
66 oops::Log::error() <<
"Unable to open file : "
67 << tlapse_file << std::endl;
68 ABORT(
"Unable to open tlapse file ");
77 ioda::ObsVector & out)
const {
78 const std::size_t nvars = out.nvars();
79 const std::size_t
nlocs = out.nlocs();
82 std::vector <float> pred(
nlocs, 0.0);
85 std::vector<float> tsavg5(
nlocs, 0.0);
86 geovals.
get(tsavg5,
"average_surface_temperature_within_field_of_view");
89 std::vector<std::vector<std::vector<float>>> ptau5;
90 std::vector<std::vector<float>> tmpvar;
93 for (std::size_t jvar = 0; jvar < nvars; ++jvar) {
94 hdiags =
"transmittances_of_atmosphere_layer_" + std::to_string(
vars_.channels()[jvar]);
96 for (std::size_t js = 0; js < ydiags.
nlevs(hdiags); ++js) {
97 ydiags.
get(pred, hdiags, js);
98 tmpvar.push_back(pred);
100 ptau5.push_back(tmpvar);
104 std::vector<std::vector<float>> tvp;
105 std::size_t nlevs = geovals.
nlevs(
"air_temperature");
106 for (std::size_t js = 0; js < nlevs; ++js) {
107 geovals.
getAtLevel(pred,
"air_temperature", js);
110 nlevs = geovals.
nlevs(
"air_pressure");
114 std::vector<float> tlap;
115 for (std::size_t jvar = 0; jvar < nvars; ++jvar) {
118 tlap.push_back(it->second);
120 oops::Log::error() <<
"Could not locate tlapemean for channel: " <<
121 vars_.channels()[jvar] << std::endl;
122 ABORT(
"Could not locate tlapemean value");
126 for (std::size_t jloc = 0; jloc <
nlocs; ++jloc) {
127 for (std::size_t jvar = 0; jvar < nvars; ++jvar) {
128 tlapchn = (ptau5[jvar][nlevs-2][jloc]-ptau5[jvar][nlevs-1][jloc])*
129 (tsavg5[jloc]-tvp[nlevs-2][jloc]);
130 for (std::size_t k = 1; k < nlevs-1; ++k) {
131 tlapchn = tlapchn+(ptau5[jvar][nlevs-k-2][jloc]-ptau5[jvar][nlevs-k-1][jloc])*
132 (tvp[nlevs-k][jloc]-tvp[nlevs-k-2][jloc]);
134 out[jloc*nvars+jvar] = pow((tlapchn - tlap[jvar]),
order_);
GeoVaLs: geophysical values at locations.
size_t nlevs(const std::string &var) const
Return number of levels for a specified variable.
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
void get(std::vector< double > &, const std::string &var) const
Get 2D GeoVaLs for variable var (fails for 3D GeoVaLs)
std::map< int, float > tlapmean_
LapseRate(const Parameters_ &, const oops::Variables &)
void compute(const ioda::ObsSpace &, const GeoVaLs &, const ObsDiagnostics &, ioda::ObsVector &) const override
compute the predictor
Configuration parameters of the LapseRate predictor.
oops::OptionalParameter< int > order
oops::RequiredParameter< std::string > tlapse
Path to an input file.
void get(std::vector< float > &, const std::string &) const
size_t nlevs(const std::string &) const
std::string & name()
predictor name
oops::Variables vars_
variables that will be bias-corrected using this predictor
oops::Variables geovars_
required GeoVaLs
oops::Variables hdiags_
required ObsDiagnostics
integer function nlocs(this)
Return the number of observational locations in this Locations object.
static PredictorMaker< LapseRate > makerFuncLapseRate_("lapse_rate")