UFO
SatelliteSelector.cc
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2021, MetOffice
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 #include <memory>
9 #include <string>
10 #include <utility>
11 
13 #include "ufo/utils/Constants.h"
14 
15 #include "ioda/ObsSpace.h"
16 
17 namespace ufo {
18 
20 
21 // -----------------------------------------------------------------------------
22 
23 SatelliteSelector::SatelliteSelector(const Parameters_ & parameters, const oops::Variables & vars)
24  : PredictorBase(parameters, vars), predictor_(), satid_(parameters.satelliteId),
25  metadata_name_(parameters.metadataName) {
26  // Setup the predictor that will be run
27  std::string predname = parameters.predictor.value().getString("name");
28  std::unique_ptr<PredictorParametersBase> params(PredictorFactory::createParameters(predname));
29  params->validateAndDeserialize(parameters.predictor.value());
30  std::unique_ptr<PredictorBase> pred(PredictorFactory::create(*params, vars));
31  predictor_ = std::move(pred);
32 
33  // Setup the name and variables for external access
34  name() = predictor_->name() + "_satid_" + std::to_string(satid_);
35  geovars_ = predictor_->requiredGeovars();
36  hdiags_ = predictor_->requiredHdiagnostics();
37 }
38 
39 // -----------------------------------------------------------------------------
40 
41 void SatelliteSelector::compute(const ioda::ObsSpace & odb,
42  const GeoVaLs & gv,
43  const ObsDiagnostics & obsdiags,
44  ioda::ObsVector & out) const {
45  const size_t nlocs = out.nlocs();
46  const size_t nvars = out.nvars();
47 
48  predictor_->compute(odb, gv, obsdiags, out);
49 
50  std::vector<int> satid(nlocs);
51  odb.get_db("MetaData", metadata_name_, satid);
52 
53  for (std::size_t jloc = 0; jloc < nlocs; ++jloc) {
54  if (satid[jloc] != satid_) {
55  for (std::size_t jvar = 0; jvar < nvars; ++jvar) {
56  out[jloc*nvars+jvar] = Constants::zero;
57  } // jvar
58  }
59  } // jloc
60 }
61 
62 // -----------------------------------------------------------------------------
63 
64 } // namespace ufo
GeoVaLs: geophysical values at locations.
std::string & name()
predictor name
Definition: PredictorBase.h:80
oops::Variables geovars_
required GeoVaLs
Definition: PredictorBase.h:85
oops::Variables hdiags_
required ObsDiagnostics
Definition: PredictorBase.h:86
static std::unique_ptr< PredictorBase > create(const PredictorParametersBase &parameters, const oops::Variables &vars)
Create and return a new predictor.
static std::unique_ptr< PredictorParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of PredictorParametersBase storing parameters of predic...
std::unique_ptr< PredictorBase > predictor_
The local predictor specified from yaml.
void compute(const ioda::ObsSpace &, const GeoVaLs &, const ObsDiagnostics &, ioda::ObsVector &) const override
compute the predictor
const std::string metadata_name_
SatelliteSelector(const Parameters_ &, const oops::Variables &)
Configuration parameters of the SatelliteSelector wrapper for a predictor.
oops::RequiredParameter< eckit::LocalConfiguration > predictor
The configuration for a specific predictor.
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static PredictorMaker< SatelliteSelector > makerFuncSatelliteSelector_("satellite_selector")
static constexpr double zero
Definition: Constants.h:41