UFO
ProfileFewObsCheck.cc
Go to the documentation of this file.
1 /*
2  * (C) British Crown Copyright 2021 Met Office
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 <iomanip>
11 #include <iostream>
12 #include <vector>
13 
14 #include "ioda/ObsDataVector.h"
15 #include "ioda/ObsSpace.h"
16 
17 #include "oops/util/Logger.h"
18 #include "ufo/filters/QCflags.h"
19 
20 namespace ufo {
21 
22 // -----------------------------------------------------------------------------
23 /// ProfileFewObsCheck: Check the number of observations in a profile
24 ///
25 /// This will use the record number in obsdb_ to identify which observations belong to a
26 /// given profile (all members of a profile must share the same record number).
27 /// For each profile the number of valid observations is found, and the profile
28 /// is rejected if this is below the given threshold.
29 
31  ioda::ObsSpace & obsdb,
32  const Parameters_ & parameters,
33  std::shared_ptr<ioda::ObsDataVector<int> > flags,
34  std::shared_ptr<ioda::ObsDataVector<float> > obserr)
35  : FilterBase(obsdb, parameters, flags, obserr), parameters_(parameters)
36 {
37  oops::Log::trace() << "ProfileFewObsCheck constructor" << std::endl;
38 }
39 
40 // -----------------------------------------------------------------------------
41 
43  oops::Log::trace() << "ProfileFewObsCheck destructed" << std::endl;
44 }
45 
46 // -----------------------------------------------------------------------------
47 /// Apply the profile check for the number of observations.
48 
49 void ProfileFewObsCheck::applyFilter(const std::vector<bool> & apply,
50  const Variables & filtervars,
51  std::vector<std::vector<bool>> & flagged) const {
52  oops::Log::trace() << "ProfileFewObsCheck preProcess filter" << std::endl;
53  const oops::Variables observed = obsdb_.obsvariables();
54 
55  // Get the record numbers from the observation data. These will be used to identify
56  // which observations belong to which profile.
57  const std::vector<size_t> & record_numbers = obsdb_.recidx_all_recnums();
58  oops::Log::debug() << "Unique record numbers" << std::endl;
59  for (size_t iProfile : record_numbers)
60  oops::Log::debug() << iProfile << ' ';
61  oops::Log::debug() << std::endl;
62 
63  // For each variable, check the number of observations in the profile
64  for (size_t iFilterVar = 0; iFilterVar < filtervars.nvars(); ++iFilterVar) {
65  const size_t iVar = observed.find(filtervars.variable(iFilterVar).variable());
66 
67  // Loop over the unique profiles
68  for (size_t iProfile : record_numbers) {
69  const std::vector<size_t> & obs_numbers = obsdb_.recidx_vector(iProfile);
70 
71  // Count the number of valid observations in this profile
72  int numValid = 0;
73  for (size_t jobs : obs_numbers)
74  if (apply[jobs] && (*flags_)[iVar][jobs] == QCflags::pass)
75  numValid++;
76 
77  // Reject profiles which don't contain sufficient observations
78  if (numValid < parameters_.threshold.value())
79  for (size_t jobs : obs_numbers)
80  if (apply[jobs] && (*flags_)[iVar][jobs] == QCflags::pass)
81  flagged[iFilterVar][jobs] = true;
82  }
83  }
84 }
85 
86 // -----------------------------------------------------------------------------
87 
88 void ProfileFewObsCheck::print(std::ostream & os) const {
89  os << "ProfileFewObsCheck: config = " << parameters_ << std::endl;
90 }
91 
92 // -----------------------------------------------------------------------------
93 
94 } // namespace ufo
Base class for UFO QC filters.
Definition: FilterBase.h:45
ioda::ObsSpace & obsdb_
std::shared_ptr< ioda::ObsDataVector< int > > flags_
ProfileFewObsCheck(ioda::ObsSpace &, const Parameters_ &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
void print(std::ostream &) const override
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
Apply the profile check for the number of observations.
Parameters controlling the operation of the ProfileFewObsCheck filter.
oops::RequiredParameter< int > threshold
const std::string & variable() const
Definition: Variable.cc:99
size_t nvars() const
Return the number of constituent "primitive" (single-channel) variables.
Definition: Variables.cc:104
Variable variable(const size_t) const
Return a given constituent "primitive" (single-channel) variable.
Definition: Variables.cc:114
constexpr int pass
Definition: QCflags.h:14
Definition: RunCRTM.h:27