UFO
PreQC.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018-2019 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 
8 #include "ufo/filters/PreQC.h"
9 
10 #include <string>
11 
12 #include "eckit/config/Configuration.h"
13 
14 #include "ioda/ObsDataVector.h"
15 #include "ioda/ObsSpace.h"
16 #include "oops/base/Variables.h"
17 #include "oops/interface/ObsFilter.h"
18 #include "oops/util/Logger.h"
19 #include "oops/util/missingValues.h"
20 #include "ufo/filters/QCflags.h"
21 
22 namespace ufo {
23 
24 // Presets for QC filters could be performed in a function outside of any class.
25 // We keep them as a filter for now. The main reason for this is to be able to use
26 // the factory for models not in UFO/IODA.
27 
28 // -----------------------------------------------------------------------------
29 
30 PreQC::PreQC(ioda::ObsSpace & obsdb, const eckit::Configuration & config,
31  std::shared_ptr<ioda::ObsDataVector<int> > qcflags,
32  std::shared_ptr<ioda::ObsDataVector<float> > obserr)
33  : nogeovals_()
34 {
35  oops::Log::trace() << "PreQC::PreQC starting " << config << std::endl;
36  const int missing = util::missingValue(missing);
37 
38 // Basic arguments checks
39  ASSERT(qcflags);
40  ASSERT(obserr);
41 
42  const oops::Variables observed = obsdb.obsvariables();
43 
44  ASSERT(qcflags->nvars() == observed.size());
45  ASSERT(qcflags->nlocs() == obsdb.nlocs());
46  ASSERT(obserr->nvars() == observed.size());
47  ASSERT(obserr->nlocs() == obsdb.nlocs());
48 
49 // Read QC flags from pre-processing
50  const std::string qcin = config.getString("inputQC", "PreQC");
51  ioda::ObsDataVector<int> preqc(obsdb, observed, qcin);
52  oops::Log::debug() << "PreQC::PreQC preqc: " << preqc;
53 
54 // Get min and max values and reject outside range
55  const int qcmin = config.getInt("minvalue", 0);
56  const int qcmax = config.getInt("maxvalue", 0);
57 
58  for (size_t jv = 0; jv < observed.size(); ++jv) {
59  for (size_t jobs = 0; jobs < obsdb.nlocs(); ++jobs) {
60  if (preqc[jv][jobs] == missing ||
61  preqc[jv][jobs] > qcmax ||
62  preqc[jv][jobs] < qcmin) {
63  (*qcflags)[jv][jobs] = QCflags::preQC;
64  }
65  }
66  }
67 
68  oops::Log::trace() << "PreQC::PreQC done" << std::endl;
69 }
70 
71 // -----------------------------------------------------------------------------
72 
73 void PreQC::print(std::ostream & os) const {
74  os << "PreQC";
75 }
76 
77 // -----------------------------------------------------------------------------
78 
79 } // namespace ufo
ufo_radiancerttov_utils_mod::debug
logical, public debug
Definition: ufo_radiancerttov_utils_mod.F90:100
ufo::PreQC::print
void print(std::ostream &) const
Definition: PreQC.cc:73
ufo
Definition: RunCRTM.h:27
PreQC.h
ufo::QCflags::preQC
constexpr int preQC
Definition: QCflags.h:16
ufo::QCflags::missing
constexpr int missing
Definition: QCflags.h:15
ufo::PreQC::PreQC
PreQC(ioda::ObsSpace &, const eckit::Configuration &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
Definition: PreQC.cc:30
QCflags.h
ioda::ObsDataVector< int >