UFO
ProfileCheckBackgroundGeopotentialHeight.cc
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2020, 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 namespace ufo {
11 
12  static ProfileCheckMaker<ProfileCheckBackgroundGeopotentialHeight>
13  makerProfileCheckBackgroundGeopotentialHeight_("BackgroundGeopotentialHeight");
14 
17  : ProfileCheckBase(options)
18  {}
19 
21  {
22  oops::Log::debug() << " Background check for geopotential height" << std::endl;
23 
24  const size_t numProfileLevels = profileDataHandler.getNumProfileLevels();
25  const bool ModelLevels = options_.modellevels.value();
26  const std::vector <float> &Zstation =
27  profileDataHandler.get<float>(ufo::VariableNames::Zstation);
28  const std::vector <float> &pressures =
29  profileDataHandler.get<float>(ufo::VariableNames::obs_air_pressure);
30  const std::vector <float> &zObs =
31  profileDataHandler.get<float>(ufo::VariableNames::obs_geopotential_height);
32  const std::vector <float> &zObsErr =
33  profileDataHandler.get<float>(ufo::VariableNames::obserr_geopotential_height);
34  const std::vector <float> &zBkg =
35  profileDataHandler.get<float>(ufo::VariableNames::hofx_geopotential_height);
36  std::vector <float> &zBkgErr =
38  std::vector <float> &zPGE =
39  profileDataHandler.get<float>(ufo::VariableNames::pge_geopotential_height);
40  std::vector <float> &zPGEBd =
41  profileDataHandler.get<float>(ufo::VariableNames::pgebd_geopotential_height);
42  std::vector <int> &zFlags =
44  const std::vector <int> &tFlags =
45  profileDataHandler.get<int>(ufo::VariableNames::qcflags_air_temperature);
46  const std::vector <float> &zObsCorrection =
48  const std::vector <int> &timeFlags =
49  profileDataHandler.get<int>(ufo::VariableNames::qcflags_time);
50 
51  if (!oops::allVectorsSameNonZeroSize(Zstation, pressures,
52  zObs, zObsErr, zBkg,
53  zPGE, zFlags, zObsCorrection,
54  tFlags, timeFlags)) {
55  oops::Log::warning() << "At least one vector is the wrong size. "
56  << "Check will not be performed." << std::endl;
57  oops::Log::warning() << "Vector sizes: "
58  << oops::listOfVectorSizes(Zstation, pressures,
59  zObs, zObsErr, zBkg,
60  zPGE, zFlags, zObsCorrection,
61  tFlags, timeFlags)
62  << std::endl;
63  return;
64  }
65 
66  std::vector <float> zObsFinal;
67  correctVector(zObs, zObsCorrection, zObsFinal);
68 
69  // Probability density of 'bad' observations.
70  std::vector <float> PdBad(numProfileLevels, 0);
71  // The z background error may not have been set before this point.
72  if (zBkgErr.empty())
73  zBkgErr.assign(numProfileLevels, missingValueFloat);
74  // Background error estimates are taken from ECMWF Research Manual 1
75  // (ECMWF Data Assimilation Scientific Documentation, 3/92, 3rd edition), table 2.1.
76  // They are then multiplied by 1.2.
77  for (int jlev = 0; jlev < numProfileLevels; ++jlev) {
78  if (zObsFinal[jlev] != missingValueFloat) {
79  // Permanently reject any levels at/below surface
81  zObsFinal[jlev] <= Zstation[jlev]) {
83  }
84  const float Plevel = pressures[jlev] / 100.0; // hPa
85  const std::vector<float> zBkgErrs = options_.BkCheck_zBkgErrs.value();
86  const std::vector<float> zBadPGEs = options_.BkCheck_zBadPGEs.value();
87  size_t idx = 0;
88  for (const auto& PlevelThreshold : options_.BkCheck_PlevelThresholds.value()) {
89  if (Plevel > PlevelThreshold) {
90  zBkgErr[jlev] = 1.2 * zBkgErrs[idx];
91  PdBad[jlev] = zBadPGEs[idx];
92  break;
93  }
94  idx++;
95  }
96  }
97  }
98 
99  // Modify observation PGE if certain flags have been set.
100  for (int jlev = 0; jlev < numProfileLevels; ++jlev) {
102  zPGE[jlev] = 0.5 + 0.5 * zPGE[jlev];
104  zPGE[jlev] = 0.5 + 0.5 * zPGE[jlev];
105  if (timeFlags[jlev])
107  }
108 
109  // Calculate probability of gross error.
111  zObsFinal,
112  zObsErr,
113  zBkg,
114  zBkgErr,
115  PdBad,
116  ModelLevels,
117  zFlags,
118  zPGE,
119  zPGEBd);
120  }
121 } // namespace ufo
Options controlling the operation of the ConventionalProfileProcessing filter.
ProbabilityOfGrossErrorParameters PGEParameters
Parameters related to PGE calculations.
oops::Parameter< bool > modellevels
Have the observation and model values been averaged onto model levels?
void runCheck(ProfileDataHandler &profileDataHandler) override
Run check.
ProfileCheckBackgroundGeopotentialHeight(const ConventionalProfileProcessingParameters &options)
Profile QC checker base class.
const float missingValueFloat
Missing value (float)
const ConventionalProfileProcessingParameters & options_
Configurable parameters.
void correctVector(const std::vector< T > &v1, const std::vector< T > &v2, std::vector< T > &vout)
Apply correction to vector of values.
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
std::vector< T > & get(const std::string &fullname)
int getNumProfileLevels() const
Return number of levels to which QC checks should be applied.
std::vector< float > & getObsDiag(const std::string &variableName)
Get ObsDiags for a particular profile.
@ InterpolationFlag
Interpolation check flag.
@ HydrostaticFlag
Hydrostatic check flag.
@ SurfaceLevelFlag
Surface Level.
@ PermRejectFlag
Blacklisted data.
Definition: RunCRTM.h:27
static ProfileCheckMaker< ProfileCheckBackgroundGeopotentialHeight > makerProfileCheckBackgroundGeopotentialHeight_("BackgroundGeopotentialHeight")
void BayesianPGEUpdate(const ProbabilityOfGrossErrorParameters &options, const std::vector< float > &obsVal, const std::vector< float > &obsErr, const std::vector< float > &bkgVal, const std::vector< float > &bkgErr, const std::vector< float > &PdBad, const bool ModelLevels, std::vector< int > &flags, std::vector< float > &PGE, std::vector< float > &PGEBd, float ErrVarMax, const std::vector< float > *obsVal2, const std::vector< float > *bkgVal2)
Bayesian update of probability of gross error (PGE)
static constexpr const char *const bkgerr_geopotential_height
Definition: VariableNames.h:55
static constexpr const char *const pge_geopotential_height
Definition: VariableNames.h:67
static constexpr const char *const Zstation
Definition: VariableNames.h:91
static constexpr const char *const pgebd_geopotential_height
Definition: VariableNames.h:80
static constexpr const char *const obs_geopotential_height
Definition: VariableNames.h:23
static constexpr const char *const obserr_geopotential_height
Definition: VariableNames.h:32
static constexpr const char *const qcflags_time
static constexpr const char *const hofx_geopotential_height
Definition: VariableNames.h:39
static constexpr const char *const obs_air_pressure
Definition: VariableNames.h:18
static constexpr const char *const qcflags_air_temperature
Definition: VariableNames.h:99
static constexpr const char *const obscorrection_geopotential_height
static constexpr const char *const qcflags_geopotential_height