UFO
TotalColumnVaporGuess.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 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 <cmath>
11 #include <iostream>
12 #include <string>
13 #include <vector>
14 
15 #include "ioda/ObsDataVector.h"
16 #include "ufo/filters/Variable.h"
17 #include "ufo/utils/Constants.h"
18 
19 namespace ufo {
20 
22 
23 TotalColumnVaporGuess::TotalColumnVaporGuess(const eckit::LocalConfiguration & conf)
24  : invars_() {
25  // Include list of required data from GeoVaLs
26  invars_ += Variable("humidity_mixing_ratio@GeoVaLs");
27  invars_ += Variable("air_pressure_levels@GeoVaLs");
28 }
29 
30 // -----------------------------------------------------------------------------
31 
33 
34 // -----------------------------------------------------------------------------
35 
37  ioda::ObsDataVector<float> & out) const {
38  // Get dimension
39  const size_t nlocs = in.nlocs();
40  const size_t nlevs = in.nlevs(Variable("air_pressure_levels@GeoVaLs"));
41  const float GK = 1.0/Constants::grav;
42 
43  // column q (kg/m^2) = sum( pressure_thickness * (q_mixrati/(1 + q_mixrati)) / grav)
44  std::vector<float> q_mixrati(nlocs);
45  std::vector<float> tcwv(nlocs, 0.0);
46  std::vector<float> pre_lev0(nlocs), pre_levl(nlocs);
47 
48  in.get(Variable("air_pressure_levels@GeoVaLs"), 0, pre_lev0);
49  for (size_t ilev = 1; ilev < nlevs; ++ilev) {
50  in.get(Variable("air_pressure_levels@GeoVaLs"), ilev, pre_levl);
51  in.get(Variable("humidity_mixing_ratio@GeoVaLs"), ilev - 1, q_mixrati);
52  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
53  // Change the unit of q_mixing g/kg => kg/kg.
54  q_mixrati[iloc] *= 0.001;
55  tcwv[iloc] = tcwv[iloc] + q_mixrati[iloc]/(q_mixrati[iloc]+1)
56  * fabs(pre_levl[iloc] - pre_lev0[iloc]);
57  }
58  pre_lev0 = pre_levl;
59  }
60  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
61  tcwv[iloc] *= GK;
62  }
63  out[0] = tcwv;
64 }
65 
66 // -----------------------------------------------------------------------------
67 
69  return invars_;
70 }
71 
72 // -----------------------------------------------------------------------------
73 
74 } // namespace ufo
ObsFilterData provides access to all data related to an ObsFilter.
size_t nlocs() const
Returns the number of locations in the associated ObsSpace.
size_t nlevs(const Variable &) const
Returns the number of levels in the specified variable.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
TotalColumnVaporGuess(const eckit::LocalConfiguration &=eckit::LocalConfiguration())
const ufo::Variables & requiredVariables() const
geovals required to compute the function
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static ObsFunctionMaker< TotalColumnVaporGuess > makerTotalColumnVaporGuess_("TotalColumnVaporGuess")
static constexpr double grav
Definition: Constants.h:23