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 #include <vector>
12 
13 #include "ioda/ObsDataVector.h"
14 #include "ioda/ObsSpace.h"
15 #include "oops/util/Logger.h"
16 
17 namespace ufo {
18 
19 PreQC::PreQC(ioda::ObsSpace & obsdb, const Parameters_ & parameters,
20  std::shared_ptr<ioda::ObsDataVector<int> > flags,
21  std::shared_ptr<ioda::ObsDataVector<float> > obserr)
22  : FilterBase(obsdb, parameters, flags, obserr), parameters_(parameters)
23 {
24  oops::Log::debug() << "PreQC: config = " << parameters_ << std::endl;
25 }
26 
27 // -----------------------------------------------------------------------------
28 
29 void PreQC::applyFilter(const std::vector<bool> & apply,
30  const Variables & filtervars,
31  std::vector<std::vector<bool>> & flagged) const {
32  oops::Log::trace() << "PreQC applyFilter starting " << std::endl;
33 
34  const int missing = util::missingValue(missing);
35 
36  // Read QC flags from pre-processing
38  filtervars.toOopsVariables(),
40  oops::Log::debug() << "PreQC::PreQC preqc: " << preqc;
41 
42  // Get min and max values and reject outside range
43  const int qcmin = parameters_.minvalue;
44  const int qcmax = parameters_.maxvalue;
45 
46  for (size_t jv = 0; jv < filtervars.nvars(); ++jv) {
47  const ioda::ObsDataRow<int> &currentPreQC = preqc[jv];
48  std::vector<bool> &currentFlagged = flagged[jv];
49  for (size_t jobs = 0; jobs < obsdb_.nlocs(); ++jobs) {
50  if (apply[jobs] &&
51  (currentPreQC[jobs] == missing ||
52  currentPreQC[jobs] > qcmax ||
53  currentPreQC[jobs] < qcmin)) {
54  currentFlagged[jobs] = true;
55  }
56  }
57  }
58 
59  oops::Log::trace() << "PreQC applyFilter done" << std::endl;
60 }
61 
62 // -----------------------------------------------------------------------------
63 
64 void PreQC::print(std::ostream & os) const {
65  os << "PreQC: config = " << parameters_ << std::endl;
66 }
67 
68 // -----------------------------------------------------------------------------
69 
70 } // namespace ufo
Base class for UFO QC filters.
Definition: FilterBase.h:45
ioda::ObsSpace & obsdb_
PreQC(ioda::ObsSpace &, const Parameters_ &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
Definition: PreQC.cc:19
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
Definition: PreQC.cc:29
void print(std::ostream &) const override
Definition: PreQC.cc:64
Parameters_ parameters_
Definition: PreQC.h:57
oops::Parameter< int > minvalue
Minimum PreQC flag denoting "pass". By default, zero.
Definition: PreQC.h:34
oops::Parameter< int > maxvalue
Maximum PreQC flag denoting "pass". By default, zero.
Definition: PreQC.h:36
oops::Parameter< std::string > inputQC
The ObsSpace group holding PreQC flags. By default, 'PreQC'.
Definition: PreQC.h:32
size_t nvars() const
Return the number of constituent "primitive" (single-channel) variables.
Definition: Variables.cc:104
oops::Variables toOopsVariables() const
Definition: Variables.cc:156
constexpr int missing
Definition: QCflags.h:20
Definition: RunCRTM.h:27