UFO
SymmCldImpactIR.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 <set>
13 #include <string>
14 #include <vector>
15 
16 #include "ioda/ObsDataVector.h"
17 #include "oops/util/IntSetParser.h"
18 #include "oops/util/missingValues.h"
19 #include "ufo/filters/Variable.h"
20 #include "ufo/utils/Constants.h"
21 
22 namespace ufo {
23 
25 
26 // -----------------------------------------------------------------------------
27 
28 SymmCldImpactIR::SymmCldImpactIR(const eckit::LocalConfiguration config)
29  : invars_(), channels_() {
30  // Initialize options
31  options_.deserialize(config);
32 
33  // Get channels from options
34  std::string chlist = options_.chlist;
35  std::set<int> channelset = oops::parseIntSet(chlist);
36  std::copy(channelset.begin(), channelset.end(), std::back_inserter(channels_));
37 
38  // Include required variables from ObsDiag
39  invars_ += Variable("brightness_temperature_assuming_clear_sky@ObsDiag", channels_);
40 }
41 
42 // -----------------------------------------------------------------------------
43 
45 
46 // -----------------------------------------------------------------------------
47 
49  ioda::ObsDataVector<float> & SCI) const {
50  const float missing = util::missingValue(missing);
51 
52  // Get dimensions
53  size_t nlocs = in.nlocs();
54 
55  // Allocate vectors common across channels
56  std::vector<float> clr(nlocs);
57  std::vector<float> bak(nlocs);
58  std::vector<float> obs(nlocs);
59  std::vector<float> bias(nlocs);
60 
61  float Cmod, Cobs;
62 
63  for (size_t ich = 0; ich < SCI.nvars(); ++ich) {
64  // Get channel-specific clr, bak, obs, and bias
65  in.get(Variable("brightness_temperature_assuming_clear_sky@ObsDiag", channels_)[ich], clr);
66  in.get(Variable("brightness_temperature@HofX", channels_)[ich], bak);
67  in.get(Variable("brightness_temperature@ObsValue", channels_)[ich], obs);
68  if (in.has(Variable("brightness_temperature@ObsBiasData", channels_)[ich])) {
69  in.get(Variable("brightness_temperature@ObsBiasData", channels_)[ich], bias);
70  } else {
71  std::fill(bias.begin(), bias.end(), 0.0f);
72  }
73  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
74  if (clr[iloc] != missing && bak[iloc] != missing &&
75  obs[iloc] != missing && bias[iloc] != missing) {
76  // Temporarily account for ZERO clear-sky BT output from CRTM
77  // TODO(JJG): change CRTM clear-sky behavior
78  if (clr[iloc] > -1.0f && clr[iloc] < 1.0f) clr[iloc] = bak[iloc];
79 
80  // HofX contains bias correction; subtracting it here
81  Cmod = std::abs(clr[iloc] - bak[iloc] + bias[iloc]);
82  Cobs = std::abs(clr[iloc] - obs[iloc] + bias[iloc]);
83  SCI[ich][iloc] = 0.5f * (Cmod + Cobs);
84  } else {
85  SCI[ich][iloc] = missing;
86  }
87  }
88  }
89 }
90 
91 // -----------------------------------------------------------------------------
92 
94  return invars_;
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 } // 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.
bool has(const Variable &varname) const
Returns true if variable varname is known to ObsFilterData, false otherwise.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
SymmCldImpactIR(const eckit::LocalConfiguration)
SymmCldImpactIRParameters options_
const ufo::Variables & requiredVariables() const
geovals required to compute the function
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
std::vector< int > channels_
ufo::Variables invars_
oops::RequiredParameter< std::string > chlist
channels for which SCI will be calculated
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< SymmCldImpactIR > makerSCIIR_("SymmCldImpactIR")
util::Duration abs(const util::Duration &duration)