UFO
ModelHeightAdjustedAirTemperature.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 <vector>
10 
11 #include "ioda/ObsDataVector.h"
12 #include "oops/util/missingValues.h"
14 #include "ufo/filters/Variable.h"
15 #include "ufo/utils/Constants.h"
16 
17 namespace ufo {
18 
19 static ObsFunctionMaker<ModelHeightAdjustedAirTemperature>
20  makerModelHeightAdjustedAirTemperature_("ModelHeightAdjustedAirTemperature");
21 
22 // -----------------------------------------------------------------------------
23 
25  const eckit::LocalConfiguration & conf): invars_() {
26  // Required observation data
27  invars_ += Variable("air_temperature_at_2m@ObsValue");
28  // Required model surface altitude
29  invars_ += Variable("surface_altitude@GeoVaLs");
30 
31  // Required observation station height
32  parameters_.validateAndDeserialize(conf);
33  const Variable elevation = parameters_.elevation.value();
34  invars_ += elevation;
35 }
36 
37 // -----------------------------------------------------------------------------
38 
40  ioda::ObsDataVector<float> & out) const {
41  const size_t nlocs = in.nlocs();
42  std::vector<float> t2(nlocs);
43  std::vector<float> ModelHeight(nlocs);
44  std::vector<float> StationHeight(nlocs);
45 
46  in.get(Variable("air_temperature_at_2m@ObsValue"), t2);
47  in.get(Variable("surface_altitude@GeoVaLs"), ModelHeight);
48  in.get(parameters_.elevation.value(), StationHeight);
49 
50  const float missing = util::missingValue(missing);
51 
52  // compute temperature correction and adjusted temperature.
53  for (size_t jj = 0; jj < nlocs; ++jj) {
54  if (StationHeight[jj] == missing || ModelHeight[jj] == missing || t2[jj] == missing) {
55  out[0][jj] = missing;
56  } else {
57  out[0][jj] = t2[jj] + Constants::Lclr*(StationHeight[jj] - ModelHeight[jj]);
58  }
59  }
60 }
61 
62 // -----------------------------------------------------------------------------
63 
65  return invars_;
66 }
67 
68 // -----------------------------------------------------------------------------
69 
70 } // namespace ufo
ModelHeightAdjustedAirTemperature(const eckit::LocalConfiguration &=eckit::LocalConfiguration())
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
ModelHeightAdjustedAirTemperatureParameters parameters_
const ufo::Variables & requiredVariables() const
geovals required to compute the function
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< ModelHeightAdjustedAirTemperature > makerModelHeightAdjustedAirTemperature_("ModelHeightAdjustedAirTemperature")
static constexpr double Lclr
Definition: Constants.h:60