UFO
ProfileCheckUnstableLayer.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 
13  static ProfileCheckMaker<ProfileCheckUnstableLayer>
15 
17  (const ProfileConsistencyCheckParameters &options,
18  const ProfileIndices &profileIndices,
19  ProfileDataHandler &profileDataHandler,
20  ProfileCheckValidator &profileCheckValidator)
21  : ProfileCheckBase(options, profileIndices, profileDataHandler, profileCheckValidator)
22  {}
23 
25  {
26  oops::Log::debug() << " Unstable layer/superadiabat check" << std::endl;
27 
28  const int numLevelsToCheck = profileIndices_.getNumLevelsToCheck();
29 
30  const std::vector <float> &pressures =
32  const std::vector <float> &tObs =
34  const std::vector <float> &tBkg =
36  std::vector <int> &tFlags =
38  std::vector <int> &NumAnyErrors =
40  std::vector <int> &NumSuperadiabat =
42  const std::vector <float> &tObsCorrection =
44 
45  if (!oops::allVectorsSameNonZeroSize(pressures, tObs, tBkg, tFlags, tObsCorrection)) {
46  oops::Log::warning() << "At least one vector is the wrong size. "
47  << "Check will not be performed." << std::endl;
48  oops::Log::warning() << "Vector sizes: "
49  << oops::listOfVectorSizes(pressures, tObs, tBkg, tFlags, tObsCorrection)
50  << std::endl;
51  return;
52  }
53 
54  std::vector <float> tObsFinal;
55  correctVector(tObs, tObsCorrection, tObsFinal);
56 
57  PBottom_ = 0.0;
58 
59  int jlevprev = 0;
60  for (int jlev = 0; jlev < numLevelsToCheck; ++jlev) {
61  // Ignore this level if it has been flagged as rejected.
62  if (tFlags[jlev] & ufo::MetOfficeQCFlags::Elem::FinalRejectFlag) continue;
63  if (tObsFinal[jlev] != missingValueFloat &&
64  pressures[jlev] > options_.ULCheck_MinP.value()) {
65  if (PBottom_ == 0.0) {
66  PBottom_ = pressures[jlev];
67  } else {
68  // Temperature calculated adiabatically from prev level
69  const float Tadiabat = tObsFinal[jlevprev] *
70  std::pow(pressures[jlev] / pressures[jlevprev], ufo::Constants::rd_over_cp);
71  if (tObsFinal[jlev] - Tadiabat <= options_.ULCheck_SuperadiabatTol.value() &&
72  pressures[jlevprev] <= PBottom_ - options_.ULCheck_PBThresh.value()) {
73  NumAnyErrors[0]++;
74  NumSuperadiabat[0]++;
77 
78  oops::Log::debug() << " -> Failed unstable layer/superadiabat check for levels "
79  << jlevprev << " and " << jlev << std::endl;
80  oops::Log::debug() << " -> Tadiabat = " << Tadiabat - ufo::Constants::t0c << "C"
81  << std::endl;
82  oops::Log::debug() << " -> Level " << jlevprev << ": "
83  << "P = " << pressures[jlevprev] * 0.01 << "hPa, tObs = "
84  << tObsFinal[jlevprev] - ufo::Constants::t0c << "C, tBkg = "
85  << tBkg[jlevprev] - ufo::Constants::t0c << "C, "
86  << "tObs - Tadiabat = " << tObsFinal[jlev] - Tadiabat
87  << "C" << std::endl;
88  oops::Log::debug() << " -> Level " << jlev << ": "
89  << "P = " << pressures[jlev] * 0.01 << "hPa, tObs = "
90  << tObsFinal[jlev] - ufo::Constants::t0c << "C, tBkg = "
91  << tBkg[jlev] - ufo::Constants::t0c << "C" << std::endl;
92  }
93  }
94  jlevprev = jlev;
95  }
96  }
97  }
98 
100  {
101  std::vector <float> PBottom(profileIndices_.getNumLevelsToCheck(), PBottom_);
103  }
104 } // namespace ufo
ufo::VariableNames::counter_NumAnyErrors
static constexpr const char *const counter_NumAnyErrors
Definition: VariableNames.h:101
ufo::ProfileDataHandler
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
Definition: ProfileDataHandler.h:40
ufo::ProfileCheckBase::profileIndices_
const ProfileIndices & profileIndices_
Indices of profile's observations in the entire sample.
Definition: ProfileCheckBase.h:74
ufo::ProfileIndices
Determine indices of observations making up individual profiles. The indices are computed with respec...
Definition: ProfileIndices.h:39
ufo::ProfileCheckBase::profileDataHandler_
ProfileDataHandler & profileDataHandler_
Profile data handler.
Definition: ProfileCheckBase.h:77
ufo::ProfileIndices::getNumLevelsToCheck
int getNumLevelsToCheck() const
Return number of levels to which QC checks should be applied.
Definition: ProfileIndices.h:52
ufo::ProfileCheckUnstableLayer::ProfileCheckUnstableLayer
ProfileCheckUnstableLayer(const ProfileConsistencyCheckParameters &options, const ProfileIndices &profileIndices, ProfileDataHandler &profileDataHandler, ProfileCheckValidator &profileCheckValidator)
Definition: ProfileCheckUnstableLayer.cc:17
ufo::Constants::t0c
static constexpr double t0c
Definition: Constants.h:24
ProfileCheckUnstableLayer.h
ufo::ProfileCheckValidator
Profile QC check validator.
Definition: ProfileCheckValidator.h:27
ufo_radiancerttov_utils_mod::debug
logical, public debug
Definition: ufo_radiancerttov_utils_mod.F90:100
ufo::VariableNames::PBottom
static constexpr const char *const PBottom
Definition: VariableNames.h:131
ufo::ProfileCheckUnstableLayer::fillValidator
void fillValidator() override
Fill variables in validator.
Definition: ProfileCheckUnstableLayer.cc:99
ufo::ProfileConsistencyCheckParameters::ULCheck_MinP
oops::Parameter< float > ULCheck_MinP
Min P for unstable layer/superadiabat check (Pa)
Definition: ProfileConsistencyCheckParameters.h:122
ufo
Definition: RunCRTM.h:27
ufo::ProfileCheckBase
Profile QC checker base class.
Definition: ProfileCheckBase.h:40
ufo::MetOfficeQCFlags::SuperadiabatFlag
@ SuperadiabatFlag
Superadiabatic check flag.
Definition: MetOfficeQCFlags.h:88
ufo::ProfileCheckBase::options_
const ProfileConsistencyCheckParameters & options_
Configurable parameters.
Definition: ProfileCheckBase.h:71
ufo::VariableNames::obs_air_pressure
static constexpr const char *const obs_air_pressure
Definition: VariableNames.h:18
ufo::ProfileCheckBase::missingValueFloat
const float missingValueFloat
Missing value (float)
Definition: ProfileCheckBase.h:83
ufo::ProfileCheckUnstableLayer::PBottom_
float PBottom_
PBottom.
Definition: ProfileCheckUnstableLayer.h:41
ufo::VariableNames::hofx_air_temperature
static constexpr const char *const hofx_air_temperature
Definition: VariableNames.h:38
ufo::ProfileConsistencyCheckParameters
Options controlling the operation of the ProfileConsistencyChecks filter.
Definition: ProfileConsistencyCheckParameters.h:33
ufo::ProfileCheckUnstableLayer::runCheck
void runCheck() override
Run check.
Definition: ProfileCheckUnstableLayer.cc:24
ufo::Constants::rd_over_cp
static constexpr double rd_over_cp
Definition: Constants.h:35
ufo::ProfileCheckBase::correctVector
void correctVector(const std::vector< T > &v1, const std::vector< T > &v2, std::vector< T > &vout)
Apply correction to vector of values.
Definition: ProfileCheckBase.h:60
ufo::VariableNames::counter_NumSuperadiabat
static constexpr const char *const counter_NumSuperadiabat
Definition: VariableNames.h:103
ufo::ProfileConsistencyCheckParameters::ULCheck_SuperadiabatTol
oops::Parameter< float > ULCheck_SuperadiabatTol
Tolerance for unstable layer/superadiabat check (K)
Definition: ProfileConsistencyCheckParameters.h:128
ufo::VariableNames::obscorrection_air_temperature
static constexpr const char *const obscorrection_air_temperature
Definition: VariableNames.h:120
ufo::makerProfileCheckUnstableLayer_
static ProfileCheckMaker< ProfileCheckUnstableLayer > makerProfileCheckUnstableLayer_("UnstableLayer")
ufo::VariableNames::qcflags_air_temperature
static constexpr const char *const qcflags_air_temperature
Definition: VariableNames.h:92
ufo::MetOfficeQCFlags::FinalRejectFlag
@ FinalRejectFlag
Final QC flag.
Definition: MetOfficeQCFlags.h:54
ufo::ProfileConsistencyCheckParameters::ULCheck_PBThresh
oops::Parameter< float > ULCheck_PBThresh
Bottom pressure threshold for unstable layer/superadiabat check (Pa)
Definition: ProfileConsistencyCheckParameters.h:125
VariableNames.h
ufo::ProfileDataHandler::get
std::vector< T > & get(const std::string &fullname)
Definition: ProfileDataHandler.h:53
ufo::VariableNames::obs_air_temperature
static constexpr const char *const obs_air_temperature
Definition: VariableNames.h:19
ufo::ProfileDataHandler::set
void set(const std::string &fullname, std::vector< T > &&vec_in)
Definition: ProfileDataHandler.h:92