UFO
ProfileCheckRH.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 
16  (const ProfileConsistencyCheckParameters &options,
17  const ProfileIndices &profileIndices,
18  ProfileDataHandler &profileDataHandler,
19  ProfileCheckValidator &profileCheckValidator)
20  : ProfileCheckBase(options, profileIndices, profileDataHandler, profileCheckValidator)
21  {}
22 
24  {
25  oops::Log::debug() << " Relative humidity check" << std::endl;
26 
27  const int numLevelsToCheck = profileIndices_.getNumLevelsToCheck();
28  const std::vector <float> &pressures =
30  const std::vector <float> &tObs =
32  const std::vector <float> &tBkg =
34  const std::vector <float> &RHObs =
36  const std::vector <float> &RHBkg =
38  const std::vector <float> &tdObs =
40  const std::vector <int> &tFlags =
42  std::vector <int> &RHFlags =
44  const std::vector <float> &tObsCorrection =
46 
47  std::vector <int> &TotCProfs =
49  std::vector <int> &TotHProfs =
51  std::vector <int> &TotCFlags =
53  std::vector <int> &TotHFlags =
55  std::vector <int> &TotLFlags =
57 
58  if (!oops::allVectorsSameNonZeroSize(pressures, tObs, tBkg, RHObs, RHBkg,
59  tdObs, tFlags, RHFlags, tObsCorrection)) {
60  oops::Log::warning() << "At least one vector is the wrong size. "
61  << "Check will not be performed." << std::endl;
62  oops::Log::warning() << "Vector sizes: "
63  << oops::listOfVectorSizes(pressures, tObs, tBkg, RHObs, RHBkg,
64  tdObs, tFlags, RHFlags, tObsCorrection)
65  << std::endl;
66  return;
67  }
68 
69  std::vector <float> tObsFinal;
70  correctVector(tObs, tObsCorrection, tObsFinal);
71 
72  // Set up arrays and counters
73 
74  int NumLev = 0;
75  float PTrop = 0.0; // Tropopause pressure level
76  int NLowP = 0; // Number of RH reports above 100 hPa
77  float RHDLowP = 0.0; // Mean RH O-B above 100 hPa
78  Press_.assign(numLevelsToCheck, 0.0);
79  Temp_.assign(numLevelsToCheck, 0.0);
80  rh_.assign(numLevelsToCheck, 0.0);
81  td_.assign(numLevelsToCheck, 0.0);
82  tbk_.assign(numLevelsToCheck, 0.0);
83  rhbk_.assign(numLevelsToCheck, 0.0);
84  FlagH_.assign(numLevelsToCheck, 0);
85  Indx_.assign(numLevelsToCheck, -1);
86 
87  float Tmin = options_.RHCheck_TminInit.value();
88  for (int jlev = 0; jlev < numLevelsToCheck; ++jlev) {
90  PTrop = pressures[jlev] * 0.01;
91  }
92  if (pressures[jlev] > 0.0 &&
93  RHObs[jlev] != missingValueFloat) {
94  Tmin = std::min(Tmin, tObsFinal[jlev]);
95  Indx_[NumLev] = jlev;
96  Press_[NumLev] = pressures[jlev] * 0.01;
97  Temp_[NumLev] = tObsFinal[jlev];
98  rh_[NumLev] = RHObs[jlev];
99  td_[NumLev] = tdObs[jlev];
100  tbk_[NumLev] = tBkg[jlev];
101  rhbk_[NumLev] = RHBkg[jlev];
102  if (Press_[NumLev] <= options_.RHCheck_PressInitThresh.value()) {
103  NLowP++;
104  RHDLowP = RHDLowP + rh_[NumLev] - rhbk_[NumLev];
105  }
106  NumLev++;
107  }
108  }
109  if (NumLev <= 1) return;
110 
111  // Look for errors at the top of cloud layers
112 
113  const float RHThresh = options_.RHCheck_RHThresh.value();
114  const float PressDiffAdjThresh = options_.RHCheck_PressDiffAdjThresh.value();
115  for (int jlev = 1; jlev < NumLev; ++jlev) {
116  if (Press_[jlev] < options_.RHCheck_PressThresh.value()) break;
117  if ((Press_[0] - Press_[jlev]) < options_.RHCheck_PressDiff0Thresh.value()) continue;
118  if (FlagH_[jlev] == 1) continue;
119  if ((td_[jlev] - td_[jlev - 1] > options_.RHCheck_tdDiffThresh.value() &&
120  rh_[jlev - 1] >= RHThresh) ||
121  (td_[jlev] > td_[jlev - 1] &&
122  std::min(rh_[jlev - 1], rh_[jlev]) >= RHThresh)) {
123  float MinRHabove = rh_[jlev]; // Min RH in levels close in pressure to test level
124  for (int klev = jlev + 1; klev < NumLev; ++klev) {
125  if (Press_[jlev] - Press_[klev] > PressDiffAdjThresh) break;
126  MinRHabove = std::min(MinRHabove, rh_[klev]);
127  }
128  if (MinRHabove < options_.RHCheck_MinRHThresh.value()) {
129  FlagH_[jlev] = 2;
130  TotCProfs[0]++;
131  oops::Log::debug() << " -> Error at top of cloud layer for level " << jlev << std::endl;
132  for (int klev = jlev + 1; klev < NumLev; ++klev) {
133  if (Press_[jlev] - Press_[klev] > PressDiffAdjThresh) break;
134  if (td_[klev] <= td_[jlev - 1]) break;
135  FlagH_[klev] = 2;
136  }
137  }
138  }
139  }
140 
141  if (NLowP > 0) RHDLowP = RHDLowP / static_cast <float> (NLowP);
142 
143  // Simple check for sonde ascent too moist at high levels
144  // Start at top and work down
145 
146  const float SondeRHHiTol = options_.RHCheck_SondeRHHiTol.value();
147 
148  int NumLFlags = 0;
149  int NumHFlags = 0;
150  int NumCFlags = 0;
151  if ((PTrop != 0.0 && Press_[NumLev - 1] <= PTrop) ||
152  Tmin < options_.RHCheck_TminThresh.value()) {
153  for (int ilev = NumLev - 1; ilev >= 0; ilev--) {
154  if (rh_[ilev] > rhbk_[ilev] + SondeRHHiTol ||
155  (Press_[ilev] <= options_.RHCheck_PressInitThresh.value() && RHDLowP > SondeRHHiTol)) {
156  if (FlagH_[ilev] == 0) {
157  oops::Log::debug() << " -> Sonde ascent too moist for level " << ilev << std::endl;
158  FlagH_[ilev] = 1;
159  if (Temp_[ilev] >= options_.RHCheck_TempThresh.value()) NumLFlags = NumLFlags + 1;
160  }
161  } else {
162  break;
163  }
164  }
165  }
166 
167  // Set level flags
168  for (int i = 0; i < NumLev; ++i) {
169  if (FlagH_[i] == 1) ++NumHFlags;
170  if (FlagH_[i] == 2) ++NumCFlags;
171  }
172 
173  if (NumHFlags > 0) TotHProfs[0]++;
174 
175  for (int n = 0; n < NumCFlags; ++n)
176  TotCFlags[0]++;
177  for (int n = 0; n < NumHFlags; ++n)
178  TotHFlags[0]++;
179  for (int n = 0; n < NumLFlags; ++n)
180  TotLFlags[0]++;
181 
182  if (NumCFlags + NumHFlags > 0) {
183  for (int jlev = 0; jlev < NumLev; ++jlev) {
184  if (FlagH_[jlev] > 0) {
185  int ilev = Indx_[jlev];
188  }
189  }
190  }
191  }
192 
194  {
203  }
204 } // namespace ufo
ufo::MetOfficeQCFlags::TropopauseFlag
@ TropopauseFlag
Tropopause Level.
Definition: MetOfficeQCFlags.h:94
ufo::ProfileCheckRH::rhbk_
std::vector< float > rhbk_
Model relative humidity for selected levels (%)
Definition: ProfileCheckRH.h:60
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::VariableNames::obs_dew_point_temperature
static constexpr const char *const obs_dew_point_temperature
Definition: VariableNames.h:24
ufo::ProfileCheckBase::profileDataHandler_
ProfileDataHandler & profileDataHandler_
Profile data handler.
Definition: ProfileCheckBase.h:77
ufo::VariableNames::hofx_relative_humidity
static constexpr const char *const hofx_relative_humidity
Definition: VariableNames.h:40
ufo::ProfileCheckRH::runCheck
void runCheck() override
Run check.
Definition: ProfileCheckRH.cc:23
ufo::ProfileIndices::getNumLevelsToCheck
int getNumLevelsToCheck() const
Return number of levels to which QC checks should be applied.
Definition: ProfileIndices.h:52
ufo::ProfileCheckRH::tbk_
std::vector< float > tbk_
Model temperature for selected levels (K)
Definition: ProfileCheckRH.h:57
ufo::ProfileConsistencyCheckParameters::RHCheck_SondeRHHiTol
oops::Parameter< float > RHCheck_SondeRHHiTol
Tolerance for high level check of relative humidity (%)
Definition: ProfileConsistencyCheckParameters.h:223
ufo::ProfileConsistencyCheckParameters::RHCheck_PressDiffAdjThresh
oops::Parameter< float > RHCheck_PressDiffAdjThresh
Threshold for pressure difference between adjacent levels (Pa)
Definition: ProfileConsistencyCheckParameters.h:241
ufo::ProfileConsistencyCheckParameters::RHCheck_TminInit
oops::Parameter< float > RHCheck_TminInit
Initial value of minimum temperature (K)
Definition: ProfileConsistencyCheckParameters.h:220
ufo::VariableNames::tbk
static constexpr const char *const tbk
Definition: VariableNames.h:147
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::Temp
static constexpr const char *const Temp
Definition: VariableNames.h:144
ufo::VariableNames::qcflags_relative_humidity
static constexpr const char *const qcflags_relative_humidity
Definition: VariableNames.h:93
ufo::ProfileCheckRH::FlagH_
std::vector< int > FlagH_
Flags for RH checks.
Definition: ProfileCheckRH.h:63
ufo::ProfileCheckMaker
Definition: ProfileCheckBase.h:113
ufo::VariableNames::counter_TotCFlags
static constexpr const char *const counter_TotCFlags
Definition: VariableNames.h:114
ufo::makerProfileCheckRH_
static ProfileCheckMaker< ProfileCheckRH > makerProfileCheckRH_("RH")
ufo
Definition: RunCRTM.h:27
ufo::ProfileCheckRH::Press_
std::vector< float > Press_
Observed pressure for selected levels (hPa)
Definition: ProfileCheckRH.h:45
ufo::ProfileCheckBase
Profile QC checker base class.
Definition: ProfileCheckBase.h:40
ufo::ProfileConsistencyCheckParameters::RHCheck_MinRHThresh
oops::Parameter< float > RHCheck_MinRHThresh
Threshold for minimum relative humidity (%)
Definition: ProfileConsistencyCheckParameters.h:244
ProfileCheckRH.h
ufo::ProfileCheckBase::options_
const ProfileConsistencyCheckParameters & options_
Configurable parameters.
Definition: ProfileCheckBase.h:71
ufo::VariableNames::counter_TotLFlags
static constexpr const char *const counter_TotLFlags
Definition: VariableNames.h:116
ufo::ProfileConsistencyCheckParameters::RHCheck_RHThresh
oops::Parameter< float > RHCheck_RHThresh
Threshold for relative humidity (%)
Definition: ProfileConsistencyCheckParameters.h:238
ufo::ProfileCheckRH::fillValidator
void fillValidator() override
Fill variables in validator.
Definition: ProfileCheckRH.cc:193
ufo::VariableNames::td
static constexpr const char *const td
Definition: VariableNames.h:146
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::VariableNames::Press
static constexpr const char *const Press
Definition: VariableNames.h:143
ufo::ProfileConsistencyCheckParameters::RHCheck_PressDiff0Thresh
oops::Parameter< float > RHCheck_PressDiff0Thresh
Threshold for pressure difference relative to level 0 (Pa)
Definition: ProfileConsistencyCheckParameters.h:232
ufo::VariableNames::hofx_air_temperature
static constexpr const char *const hofx_air_temperature
Definition: VariableNames.h:38
ufo::ProfileConsistencyCheckParameters::RHCheck_tdDiffThresh
oops::Parameter< float > RHCheck_tdDiffThresh
Threshold for dew point temperature difference (K)
Definition: ProfileConsistencyCheckParameters.h:235
ufo::ProfileConsistencyCheckParameters
Options controlling the operation of the ProfileConsistencyChecks filter.
Definition: ProfileConsistencyCheckParameters.h:33
ufo::VariableNames::counter_TotHProfs
static constexpr const char *const counter_TotHProfs
Definition: VariableNames.h:113
ufo::VariableNames::counter_TotCProfs
static constexpr const char *const counter_TotCProfs
Definition: VariableNames.h:112
ufo::VariableNames::rhbk
static constexpr const char *const rhbk
Definition: VariableNames.h:148
ufo::ProfileCheckRH::rh_
std::vector< float > rh_
Observed relative humidity for selected levels (%)
Definition: ProfileCheckRH.h:51
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::obscorrection_air_temperature
static constexpr const char *const obscorrection_air_temperature
Definition: VariableNames.h:120
ufo::ProfileConsistencyCheckParameters::RHCheck_TempThresh
oops::Parameter< float > RHCheck_TempThresh
Lower threshold for temperature in moisture check.
Definition: ProfileConsistencyCheckParameters.h:250
ufo::ProfileCheckRH::Temp_
std::vector< float > Temp_
Observed temperature for selected levels (K)
Definition: ProfileCheckRH.h:48
ufo::VariableNames::obs_relative_humidity
static constexpr const char *const obs_relative_humidity
Definition: VariableNames.h:20
ufo::ProfileConsistencyCheckParameters::RHCheck_PressThresh
oops::Parameter< float > RHCheck_PressThresh
Threshold for pressure (Pa)
Definition: ProfileConsistencyCheckParameters.h:229
ufo::VariableNames::qcflags_air_temperature
static constexpr const char *const qcflags_air_temperature
Definition: VariableNames.h:92
ufo::ProfileConsistencyCheckParameters::RHCheck_PressInitThresh
oops::Parameter< float > RHCheck_PressInitThresh
Threshold for pressure when setting up arrays (Pa)
Definition: ProfileConsistencyCheckParameters.h:226
ufo::ProfileCheckRH::td_
std::vector< float > td_
Observed dew point temperature for selected levels (K)
Definition: ProfileCheckRH.h:54
ufo::MetOfficeQCFlags::FinalRejectFlag
@ FinalRejectFlag
Final QC flag.
Definition: MetOfficeQCFlags.h:54
ufo::VariableNames::counter_TotHFlags
static constexpr const char *const counter_TotHFlags
Definition: VariableNames.h:115
ufo::ProfileCheckRH::Indx_
std::vector< int > Indx_
Indices of selected levels.
Definition: ProfileCheckRH.h:66
ufo::VariableNames::Indx
static constexpr const char *const Indx
Definition: VariableNames.h:150
ufo::MetOfficeQCFlags::InterpolationFlag
@ InterpolationFlag
Interpolation check flag.
Definition: MetOfficeQCFlags.h:87
VariableNames.h
ufo::VariableNames::FlagH
static constexpr const char *const FlagH
Definition: VariableNames.h:149
ufo::ProfileConsistencyCheckParameters::RHCheck_TminThresh
oops::Parameter< float > RHCheck_TminThresh
Upper threshold for Tmin in moisture check.
Definition: ProfileConsistencyCheckParameters.h:247
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
ufo::ProfileCheckRH::ProfileCheckRH
ProfileCheckRH(const ProfileConsistencyCheckParameters &options, const ProfileIndices &profileIndices, ProfileDataHandler &profileDataHandler, ProfileCheckValidator &profileCheckValidator)
Definition: ProfileCheckRH.cc:16
ufo::VariableNames::rh
static constexpr const char *const rh
Definition: VariableNames.h:145