UFO
SCATRetMW.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 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 <algorithm>
11 #include <cmath>
12 #include <iomanip>
13 #include <iostream>
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 #include "ioda/ObsDataVector.h"
19 #include "oops/util/IntSetParser.h"
20 #include "oops/util/missingValues.h"
21 #include "ufo/filters/Variable.h"
22 #include "ufo/utils/Constants.h"
23 
24 namespace ufo {
25 
27 
28 SCATRetMW::SCATRetMW(const eckit::LocalConfiguration & conf)
29  : invars_() {
30  // Initialize options
31  options_.deserialize(conf);
32 
33  // Check required parameters
34  // Get variable group types for scattering index retrieval from option
35  ASSERT(options_.varGroup.value().size() == 1 || options_.varGroup.value().size() == 2);
36 
37  // Get channels for CLW retrieval from options
38  const std::vector<int> channels_ = {options_.ch238.value(), options_.ch314.value(),
39  options_.ch890.value()};
40  ASSERT(options_.ch238 != 0 && options_.ch314 != 0 && options_.ch890 != 0 &&
41  channels_.size() == 3);
42 
43  // Include list of required data from ObsSpace
44  for (size_t igrp = 0; igrp < options_.varGroup.value().size(); ++igrp) {
45  invars_ += Variable("brightness_temperature@" + options_.varGroup.value()[igrp], channels_);
46  }
47  invars_ += Variable("brightness_temperature@" + options_.testBias.value(), channels_);
48 
49  // Include list of required data from GeoVaLs
50  invars_ += Variable("water_area_fraction@GeoVaLs");
51 }
52 
53 // -----------------------------------------------------------------------------
54 
56 
57 // -----------------------------------------------------------------------------
58 
60  ioda::ObsDataVector<float> & out) const {
61  // Get dimension
62  const size_t nlocs = in.nlocs();
63  const size_t ngrps = options_.varGroup.value().size();
64 
65  // Get required parameters
66  const std::vector<std::string> &vargrp = options_.varGroup.value();
67  const std::vector<int> channels_ = {options_.ch238.value(), options_.ch314.value(),
68  options_.ch890.value()};
69 
70  // Get area fraction of each surface type from GeoVaLs
71  std::vector<float> water_frac(nlocs);
72  in.get(Variable("water_area_fraction@GeoVaLs"), water_frac);
73 
74  // Get observation, bias correction and HofX from ObsSpace
75  std::vector<float> bt238(nlocs), bt314(nlocs), bt890(nlocs);
76  for (size_t igrp = 0; igrp < ngrps; ++igrp) {
77  // Get data based on group type
78  in.get(Variable("brightness_temperature@"+vargrp[igrp], channels_)[0], bt238);
79  in.get(Variable("brightness_temperature@"+vargrp[igrp], channels_)[1], bt314);
80  in.get(Variable("brightness_temperature@"+vargrp[igrp], channels_)[2], bt890);
81  // Get bias based on group type
82  if (options_.addBias.value() == vargrp[igrp]) {
83  std::vector<float> bias238(nlocs), bias314(nlocs), bias890(nlocs);
84  in.get(Variable("brightness_temperature@"+options_.testBias.value(), channels_)[0], bias238);
85  in.get(Variable("brightness_temperature@"+options_.testBias.value(), channels_)[1], bias314);
86  in.get(Variable("brightness_temperature@"+options_.testBias.value(), channels_)[2], bias890);
87  // Add bias correction to the assigned group (only need to do it for ObsValue, since HofX
88  // includes bias correction
89  if (options_.addBias.value() == "ObsValue") {
90  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
91  bt238[iloc] = bt238[iloc] - bias238[iloc];
92  bt314[iloc] = bt314[iloc] - bias314[iloc];
93  bt890[iloc] = bt890[iloc] - bias890[iloc];
94  }
95  }
96  }
97  const float missing = util::missingValue(missing);
98  // Retrieve scattering index
99  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
100  if (water_frac[iloc] >= 0.99 &&
101  bt238[iloc] != missing && bt314[iloc] != missing && bt890[iloc] != missing) {
102  out[igrp][iloc] = -113.2 + (2.41 - 0.0049 * bt238[iloc]) * bt238[iloc]
103  + 0.454 * bt314[iloc] - bt890[iloc];
104  out[igrp][iloc] = std::max(0.f, out[igrp][iloc]);
105  }
106  }
107  }
108 }
109 
110 // -----------------------------------------------------------------------------
111 
113  return invars_;
114 }
115 
116 // -----------------------------------------------------------------------------
117 
118 } // 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.
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
Definition: SCATRetMW.cc:59
ufo::Variables invars_
Definition: SCATRetMW.h:94
SCATRetMWParameters options_
Definition: SCATRetMW.h:95
const ufo::Variables & requiredVariables() const
geovals required to compute the function
Definition: SCATRetMW.cc:112
SCATRetMW(const eckit::LocalConfiguration &=eckit::LocalConfiguration())
Definition: SCATRetMW.cc:28
oops::Parameter< std::string > addBias
Definition: SCATRetMW.h:65
oops::RequiredParameter< std::vector< std::string > > varGroup
Definition: SCATRetMW.h:58
oops::RequiredParameter< int > ch238
Definition: SCATRetMW.h:38
oops::RequiredParameter< int > ch890
Definition: SCATRetMW.h:50
oops::RequiredParameter< int > ch314
Definition: SCATRetMW.h:44
oops::Parameter< std::string > testBias
Definition: SCATRetMW.h:70
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< SCATRetMW > makerSCATRetMW_("SCATRetMW")