UFO
CLWMatchIndexMW.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 <cmath>
11 
12 #include <algorithm>
13 #include <iomanip>
14 #include <iostream>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 #include "ioda/ObsDataVector.h"
20 #include "oops/util/IntSetParser.h"
22 #include "ufo/filters/Variable.h"
23 #include "ufo/utils/Constants.h"
24 
25 namespace ufo {
26 
28 
29 // -----------------------------------------------------------------------------
30 
31 CLWMatchIndexMW::CLWMatchIndexMW(const eckit::LocalConfiguration & conf)
32  : invars_() {
33  // Initialize options
34  options_.deserialize(conf);
35 
36  // Get channels from options
37  std::set<int> channelset = oops::parseIntSet(options_.channelList);
38  std::copy(channelset.begin(), channelset.end(), std::back_inserter(channels_));
39  ASSERT(channels_.size() > 0);
40 
41  // Include list of required data from GeoVaLs
42  invars_ += Variable("water_area_fraction@GeoVaLs");
43 
44  const Variable &clwobs = options_.clwobsFunction.value();
45  invars_ += clwobs;
46 
47  const Variable &clwbkg = options_.clwbkgFunction.value();
48  invars_ += clwbkg;
49 }
50 
51 // -----------------------------------------------------------------------------
52 
54 
55 // -----------------------------------------------------------------------------
56 
58  ioda::ObsDataVector<float> & out) const {
59  // Get dimension
60  const size_t nlocs = in.nlocs();
61  const size_t nchans = channels_.size();
62 
63  // Get area fraction of each surface type
64  std::vector<float> water_frac(nlocs);
65  in.get(Variable("water_area_fraction@GeoVaLs"), water_frac);
66 
67  // Get CLW retrieval based on observation from ObsFunction
68  const Variable &clwobsvar = options_.clwobsFunction.value();
69  ioda::ObsDataVector<float> clwobs(in.obsspace(), clwobsvar.toOopsVariables());
70  in.get(clwobsvar, clwobs);
71 
72  // Get CLW retrieval based on simulated observation from ObsFunction
73  const Variable &clwbkgvar = options_.clwbkgFunction.value();
74  ioda::ObsDataVector<float> clwbkg(in.obsspace(), clwbkgvar.toOopsVariables());
75  in.get(clwbkgvar, clwbkg);
76 
77  // Get parameters for observation errors from options
78  const std::vector<float> &clw_clr = options_.clwretClearSky.value();
79  for (size_t ichan = 0; ichan < nchans; ++ichan) {
80  for (size_t iloc = 0; iloc < nlocs; ++iloc) {
81  out[ichan][iloc] = 1.0;
82  if (water_frac[iloc] > 0.99) {
83  float condition1 = (clwobs[0][iloc] - clw_clr[ichan]) * (clwbkg[0][iloc] - clw_clr[ichan]);
84  float condition2 = std::abs(clwobs[0][iloc] - clwbkg[0][iloc]);
85  if ( condition1 < 0 && condition2 >= 0.005) out[ichan][iloc] = 0.0;
86  }
87  }
88  }
89 }
90 
91 // -----------------------------------------------------------------------------
92 
94  return invars_;
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 } // namespace ufo
void compute(const ObsFilterData &, ioda::ObsDataVector< float > &) const
compute the result of the function
const ufo::Variables & requiredVariables() const
geovals required to compute the function
std::vector< int > channels_
ufo::Variables invars_
CLWMatchIndexMWParameters options_
CLWMatchIndexMW(const eckit::LocalConfiguration &=eckit::LocalConfiguration())
oops::RequiredParameter< Variable > clwobsFunction
Function to retrieve the cloud liquid water from observation.
oops::RequiredParameter< std::vector< float > > clwretClearSky
oops::RequiredParameter< Variable > clwbkgFunction
Function to retrieve the cloud liquid water from the simulated observation.
oops::RequiredParameter< std::string > channelList
List of channels available for assimilation.
ObsFilterData provides access to all data related to an ObsFilter.
size_t nlocs() const
Returns the number of locations in the associated ObsSpace.
ioda::ObsSpace & obsspace() const
Returns reference to ObsSpace associated with ObsFilterData.
void get(const Variable &varname, std::vector< float > &values) const
Fills a std::vector with values of the specified variable.
oops::Variables toOopsVariables() const
Definition: Variable.cc:139
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static ObsFunctionMaker< CLWMatchIndexMW > makerCLWMatchIndexMW_("CLWMatchIndexMW")
util::Duration abs(const util::Duration &duration)