UFO
ModelHeightAdjustedRelativeHumidity.cc
Go to the documentation of this file.
1 /* -----------------------------------------------------------------------------
2  * (C) British Crown Copyright 2021 Met Office
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  */
8 
9 #include <algorithm>
10 #include <vector>
11 
12 #include "ioda/ObsDataVector.h"
13 #include "oops/util/missingValues.h"
15 #include "ufo/filters/Variable.h"
16 #include "ufo/utils/Constants.h"
17 
18 namespace ufo {
19 
20 static ObsFunctionMaker<ModelHeightAdjustedRelativeHumidity>
21  makerModelHeightAdjustedRelativeHumidity_("ModelHeightAdjustedRelativeHumidity");
22 
23 // -----------------------------------------------------------------------------
24 
26  const eckit::LocalConfiguration & conf): invars_() {
27  // Retrieve observation data // Required observation data
28  invars_ += Variable("relative_humidity_at_2m@ObsValue");
29  // Required model surface altitude
30  invars_ += Variable("surface_altitude@GeoVaLs");
31 
32  // Required observation station height and temperature
33  parameters_.validateAndDeserialize(conf);
34  const Variable elevation = parameters_.elevation.value();
35  const Variable temperature = parameters_.temperature.value();
36  invars_ += elevation;
37  invars_ += temperature;
38 }
39 
40 // -----------------------------------------------------------------------------
41 
43  ioda::ObsDataVector<float> & out) const {
44  const size_t nlocs = in.nlocs();
45  std::vector<float> rh(nlocs);
46  std::vector<float> T(nlocs);
47  std::vector<float> ModelHeight(nlocs);
48  std::vector<float> StationHeight(nlocs);
49 
50  in.get(Variable("relative_humidity_at_2m@ObsValue"), rh);
51  in.get(parameters_.temperature.value(), T);
52  in.get(Variable("surface_altitude@GeoVaLs"), ModelHeight);
53  in.get(parameters_.elevation.value(), StationHeight);
54 
55  const float missing = util::missingValue(missing);
56 
57  // Maximum values of RH_ice for temperatures 0 to -40 deg C
58  const std::vector<float> rhmax{100.00, 100.98, 101.97, 102.96, 103.97, 104.99,
59  106.01, 107.05, 108.10, 109.16, 110.23, 111.31,
60  112.40, 113.51, 114.62, 115.75, 116.88, 118.03,
61  119.19, 120.36, 121.54, 122.74, 123.94, 125.15,
62  126.38, 127.62, 128.87, 130.12, 131.39, 132.67,
63  133.96, 135.26, 136.58, 137.90, 139.23, 140.57,
64  141.92, 143.27, 144.64, 146.02, 147.40};
65 
66  // compute relative humidity correction and adjusted relative humidity.
67  for (size_t jj = 0; jj < nlocs; ++jj) {
68  if (StationHeight[jj] == missing || ModelHeight[jj] == missing || rh[jj] == missing) {
69  out[0][jj] = missing;
70  } else {
71  int Tbin = std::ceil(Constants::t0c - T[jj]);
72  Tbin = std::max(0, std::min(40, Tbin));
73  float CorrectedRH = std::max(rh[jj] - 0.01*(StationHeight[jj] - ModelHeight[jj]), 0.0);
74  CorrectedRH = std::min(CorrectedRH, rhmax[Tbin]);
75  out[0][jj] = CorrectedRH;
76  }
77  }
78 }
79 
80 // -----------------------------------------------------------------------------
81 
83  return invars_;
84 }
85 
86 // -----------------------------------------------------------------------------
87 
88 } // namespace ufo
ModelHeightAdjustedRelativeHumidityParameters parameters_
const ufo::Variables & requiredVariables() const
geovals required to compute the function
ModelHeightAdjustedRelativeHumidity(const eckit::LocalConfiguration &=eckit::LocalConfiguration())
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
oops::RequiredParameter< Variable > temperature
Temperature to be used.
oops::RequiredParameter< Variable > elevation
Input observation station height to be used.
ObsFilterData provides access to all data related to an ObsFilter.
size_t nlocs() const
Returns the number of locations in the associated ObsSpace.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
constexpr int missing
Definition: QCflags.h:20
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static ObsFunctionMaker< ModelHeightAdjustedRelativeHumidity > makerModelHeightAdjustedRelativeHumidity_("ModelHeightAdjustedRelativeHumidity")
static constexpr double t0c
Definition: Constants.h:24