15 #include "ioda/ObsDataVector.h"
16 #include "ioda/ObsSpace.h"
18 #include "oops/util/Logger.h"
25 (ioda::ObsSpace & obsdb,
29 :
FilterBase(obsdb, parameters, flags, obserr), parameters_(parameters)
31 oops::Log::trace() <<
"BayesianBackgroundQCFlags constructor" << std::endl;
35 oops::Log::trace() <<
"BayesianBackgroundQCFlags destructor" << std::endl;
40 const auto it = PGEsubstituteNames.find(varname);
41 if (it != PGEsubstituteNames.end())
48 const std::vector<bool>& apply,
49 std::vector<bool>& flagged)
const {
50 const float missingValueFloat = util::missingValue(missingValueFloat);
51 const int missingValueInt = util::missingValue(missingValueInt);
54 const float PGEMult = 1000.0;
56 const float PGEMDI = 1.111;
60 const float packedPGECrit = PGEMult * PGECrit;
68 std::vector <int> QCflags(
nlocs, missingValueInt);
69 if (
obsdb_.has(
"QCFlags", varname))
70 obsdb_.get_db(
"QCFlags", varname, QCflags);
72 throw eckit::BadValue(varname +
"@QCFlags not present", Here());
78 if (
obsdb_.has(
"GrossErrorProbabilityBuddyCheck", varPGE)) {
80 std::vector <float> buddyCheckPGEs(
nlocs, missingValueFloat);
81 obsdb_.get_db(
"GrossErrorProbabilityBuddyCheck", varPGE, buddyCheckPGEs);
82 for (
size_t iloc = 0; iloc <
nlocs; ++iloc) {
83 if (!apply[iloc])
continue;
84 if (buddyCheckPGEs[iloc] == PGEMDI) {
87 }
else if (buddyCheckPGEs[iloc] >= PGECrit) {
93 }
else if (
obsdb_.has(
"GrossErrorProbability", varPGE)) {
96 std::vector <float> PGEs(
nlocs, missingValueFloat);
97 obsdb_.get_db(
"GrossErrorProbability", varPGE, PGEs);
99 for (
size_t iloc = 0; iloc <
nlocs; ++iloc) {
100 if (apply[iloc] && PGEs[iloc] >= packedPGECrit) {
102 flagged[iloc] =
true;
106 std::stringstream errormessage;
107 errormessage <<
"At least one of "
108 << varname +
"@GrossErrorProbability or "
109 << varname +
"@GrossErrorProbabilityBuddyCheck must be present"
111 throw eckit::BadValue(errormessage.str(), Here());
115 obsdb_.put_db(
"QCFlags", varname, QCflags);
120 std::vector<std::vector<bool>> & flagged)
const {
121 print(oops::Log::trace());
123 for (
size_t ivar = 0; ivar < filtervars.
nvars(); ++ivar) {
125 setFlags(varname, apply, flagged[ivar]);
130 os <<
"BayesianBackgroundQCFlags: config = " <<
parameters_ << std::endl;
Parameters_ parameters_
Parameters used in this filter.
~BayesianBackgroundQCFlags()
std::string getPGEsubstituteName(const std::string &varname) const
void print(std::ostream &) const override
void setFlags(const std::string &varname, const std::vector< bool > &apply, std::vector< bool > &flagged) const
void applyFilter(const std::vector< bool > &, const Variables &, std::vector< std::vector< bool >> &) const override
BayesianBackgroundQCFlags(ioda::ObsSpace &, const Parameters_ &, std::shared_ptr< ioda::ObsDataVector< int > >, std::shared_ptr< ioda::ObsDataVector< float > >)
Parameters controlling the operation of the BayesianBackgroundQCFlags filter.
ProbabilityOfGrossErrorParameters PGEParameters
oops::Parameter< std::map< std::string, std::string > > PGEsubstituteNames
Base class for UFO QC filters.
oops::Parameter< float > PGE_PGECrit
PGE rejection limit.
const std::string & variable() const
size_t nvars() const
Return the number of constituent "primitive" (single-channel) variables.
Variable variable(const size_t) const
Return a given constituent "primitive" (single-channel) variable.
@ FinalRejectFlag
Final QC flag.
@ BuddyRejectFlag
PGE>0.5 after buddy check.
integer function nlocs(this)
Return the number of observational locations in this Locations object.