UFO
ProfileCheckSamePDiffT.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 
10 
11 namespace ufo {
12 
14 
17  : ProfileCheckBase(options)
18  {}
19 
21  {
22  oops::Log::debug() << " Test for same pressure and different temperature" << std::endl;
23  int jlevprev = -1;
24  int NumErrors = 0;
25 
26  const int numProfileLevels = profileDataHandler.getNumProfileLevels();
27 
28  const std::vector <float> &pressures =
29  profileDataHandler.get<float>(ufo::VariableNames::obs_air_pressure);
30  const std::vector <float> &tObs =
31  profileDataHandler.get<float>(ufo::VariableNames::obs_air_temperature);
32  const std::vector <float> &tBkg =
33  profileDataHandler.get<float>(ufo::VariableNames::hofx_air_temperature);
34  std::vector <int> &tFlags =
35  profileDataHandler.get<int>(ufo::VariableNames::qcflags_air_temperature);
36  std::vector <int> &NumAnyErrors =
37  profileDataHandler.get<int>(ufo::VariableNames::counter_NumAnyErrors);
38  std::vector <int> &NumSamePErrObs =
39  profileDataHandler.get<int>(ufo::VariableNames::counter_NumSamePErrObs);
40  const std::vector <float> &tObsCorrection =
41  profileDataHandler.get<float>(ufo::VariableNames::obscorrection_air_temperature);
42 
43  if (!oops::allVectorsSameNonZeroSize(pressures, tObs, tBkg, tFlags, tObsCorrection)) {
44  oops::Log::warning() << "At least one vector is the wrong size. "
45  << "Check will not be performed." << std::endl;
46  oops::Log::warning() << "Vector sizes: "
47  << oops::listOfVectorSizes(pressures, tObs, tBkg, tFlags, tObsCorrection)
48  << std::endl;
49  return;
50  }
51 
52  std::vector <float> tObsFinal;
53  correctVector(tObs, tObsCorrection, tObsFinal);
54 
55  for (int jlev = 0; jlev < numProfileLevels; ++jlev) {
56  if (tObs[jlev] == missingValueFloat) continue;
57 
58  if (jlevprev == -1) {
59  jlevprev = jlev;
60  continue;
61  }
62 
63  if (pressures[jlev] == pressures[jlevprev]) {
64  int jlevuse = jlevprev;
65  if (std::abs(tObsFinal[jlev] - tObsFinal[jlevprev]) > options_.SPDTCheck_TThresh.value()) {
66  NumErrors++;
67  NumAnyErrors[0]++;
68 
69  // Choose which level to flag
70  if (std::abs(tObsFinal[jlev] - tBkg[jlev]) <=
71  std::abs(tObsFinal[jlevprev] - tBkg[jlevprev])) {
74  jlevuse = jlev;
75  } else {
78  }
79 
80  oops::Log::debug() << " -> Failed same P/different T check for levels "
81  << jlevprev << " and " << jlev << std::endl;
82  oops::Log::debug() << " -> Level " << jlevprev << ": "
83  << "P = " << pressures[jlevprev] * 0.01 << "hPa, tObs = "
84  << tObsFinal[jlevprev] - ufo::Constants::t0c << "C, "
85  << "tBkg = " << tBkg[jlevprev] - ufo::Constants::t0c
86  << "C" << std::endl;
87  oops::Log::debug() << " -> Level " << jlev << ": "
88  << "P = " << pressures[jlev] * 0.01 << "hPa, tObs = "
89  << tObsFinal[jlev] - ufo::Constants::t0c << "C, "
90  << "tBkg = " << tBkg[jlev] - ufo::Constants::t0c
91  << "C" << std::endl;
92  oops::Log::debug() << " -> tObs difference: " << tObsFinal[jlev] - tObsFinal[jlevprev]
93  << std::endl;
94  oops::Log::debug() << " -> Use level " << jlevuse << std::endl;
95  }
96  jlevprev = jlevuse;
97  } else { // Distinct pressures
98  jlevprev = jlev;
99  }
100  }
101  if (NumErrors > 0) NumSamePErrObs[0]++;
102  }
103 } // namespace ufo
104 
Options controlling the operation of the ConventionalProfileProcessing filter.
oops::Parameter< float > SPDTCheck_TThresh
Threshold used for same P/different T check (K)
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.
ProfileCheckSamePDiffT(const ConventionalProfileProcessingParameters &options)
void runCheck(ProfileDataHandler &profileDataHandler) override
Run check.
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.
@ InterpolationFlag
Interpolation check flag.
@ FinalRejectFlag
Final QC flag.
Definition: RunCRTM.h:27
static ProfileCheckMaker< ProfileCheckSamePDiffT > makerProfileCheckSamePDiffT_("SamePDiffT")
util::Duration abs(const util::Duration &duration)
static constexpr double t0c
Definition: Constants.h:24
static constexpr const char *const hofx_air_temperature
Definition: VariableNames.h:38
static constexpr const char *const counter_NumSamePErrObs
static constexpr const char *const obs_air_temperature
Definition: VariableNames.h:19
static constexpr const char *const counter_NumAnyErrors
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_air_temperature