UFO
ProfileCheckInterpolation.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<ProfileCheckInterpolation>
15 
17  (const ProfileConsistencyCheckParameters &options,
18  const ProfileIndices &profileIndices,
19  ProfileDataHandler &profileDataHandler,
20  ProfileCheckValidator &profileCheckValidator)
21  : ProfileCheckBase(options, profileIndices, profileDataHandler, profileCheckValidator),
22  ProfileStandardLevels(options)
23  {}
24 
26  {
27  oops::Log::debug() << " Interpolation check" << std::endl;
28 
29  const int numLevelsToCheck = profileIndices_.getNumLevelsToCheck();
30 
31  const std::vector <float> &pressures =
33  const std::vector <float> &tObs =
35  const std::vector <float> &tBkg =
37  std::vector <int> &tFlags =
39  std::vector <int> &NumAnyErrors =
41  std::vector <int> &NumInterpErrors =
43  std::vector <int> &NumInterpErrObs =
45  const std::vector <float> &tObsCorrection =
47 
48  if (!oops::allVectorsSameNonZeroSize(pressures, tObs, tBkg, tFlags,
49  tObsCorrection)) {
50  oops::Log::warning() << "At least one vector is the wrong size. "
51  << "Check will not be performed." << std::endl;
52  oops::Log::warning() << "Vector sizes: "
53  << oops::listOfVectorSizes(pressures, tObs, tBkg, tFlags,
54  tObsCorrection)
55  << std::endl;
56  return;
57  }
58 
59  std::vector <float> tObsFinal;
60  correctVector(tObs, tObsCorrection, tObsFinal);
61 
62  calcStdLevels(numLevelsToCheck, pressures, tObsFinal, tFlags);
63 
64  LevErrors_.assign(numLevelsToCheck, -1);
65  tInterp_.assign(numLevelsToCheck, missingValueFloat);
66 
67  int NumErrors = 0;
68 
69  for (int jlevstd = 0; jlevstd < NumStd_; ++jlevstd) {
70  int jlev = StdLev_[jlevstd]; // Standard level
71 
72  if (tFlags[jlev] & ufo::MetOfficeQCFlags::Profile::SurfaceLevelFlag) continue;
73  int SigB = SigBelow_[jlevstd];
74  int SigA = SigAbove_[jlevstd];
75  float PStd = pressures[jlev];
76  int IPStd = std::round(pressures[jlev] * 0.01); // Pressure rounded to nearest hPa
77 
78  /// BigGap - see 6.3.2.2.2 of the Guide on the Global Data-Processing System.
79  /// Reduced to 50 hPa for standard levels at 150 and 100 hPa
80  float BigGap = options_.ICheck_BigGapInit.value();
81  for (int i = 0; i < StandardLevels_.size(); ++i) {
82  if (StandardLevels_[i] <= IPStd) {
83  BigGap = BigGaps_[i] * 100.0; // hPa -> Pa
84  break;
85  }
86  }
87 
88  if (NumSig_ < std::max(3, NumStd_ / 2)) continue; // Too few sig levs for reliable check
89 
90  if (SigB == -1 || SigA == -1) continue;
91 
92  if (pressures[SigB] - PStd > BigGap ||
93  PStd - pressures[SigA] > BigGap ||
94  LogP_[SigB] == LogP_[SigA]) continue;
95 
96  float Ratio = (LogP_[jlev] - LogP_[SigB]) /
97  (LogP_[SigA] - LogP_[SigB]); // eqn 3.3a
98 
99  tInterp_[jlev] = tObsFinal[SigB] + (tObsFinal[SigA] - tObsFinal[SigB]) * Ratio; // eqn 3.3b
100 
101  // Temperature difference > TInterpTol*TolRelax degrees?
102  float TolRelax = 1.0;
103  if (PStd < options_.ICheck_TolRelaxPThresh.value())
104  TolRelax = options_.ICheck_TolRelax.value();
105  if (std::abs(tObsFinal[jlev] - tInterp_[jlev]) >
106  options_.ICheck_TInterpTol.value() * TolRelax) {
107  NumAnyErrors[0]++;
108  NumInterpErrors[0]++;
109  NumErrors++;
110 
111  // Simplest form of flagging - sig or std flags may be unset in other routines
115 
116  LevErrors_[jlev]++;
117  LevErrors_[SigB]++;
118  LevErrors_[SigA]++;
119 
120  oops::Log::debug() << " -> Failed interpolation check for levels " << jlev
121  << " (central), " << SigB << " (lower) and "
122  << SigA << " (upper)" << std::endl;
123  oops::Log::debug() << " -> Level " << jlev << ": "
124  << "P = " << pressures[jlev] * 0.01 << "hPa, tObs = "
125  << tObsFinal[jlev] - ufo::Constants::t0c << "C, "
126  << "tBkg = " << tBkg[jlev] - ufo::Constants::t0c << "C, "
127  << "tInterp = " << tInterp_[jlev] - ufo::Constants::t0c
128  << "C, tInterp - tObs = " << tInterp_[jlev] - tObsFinal[jlev]
129  << std::endl;
130  oops::Log::debug() << " -> Level " << SigB << ": "
131  << "P = " << pressures[SigB] * 0.01 << "hPa, tObs = "
132  << tObsFinal[SigB] - ufo::Constants::t0c << "C, "
133  << "tBkg = " << tBkg[SigB] - ufo::Constants::t0c << "C" << std::endl;
134  oops::Log::debug() << " -> Level " << SigA << ": "
135  << "P = " << pressures[SigA] * 0.01 << "hPa, tObs = "
136  << tObsFinal[SigA] - ufo::Constants::t0c << "C, "
137  << "tBkg = " << tBkg[SigA] - ufo::Constants::t0c << "C" << std::endl;
138  }
139  }
140  if (NumErrors > 0) NumInterpErrObs[0]++;
141  }
142 
144  {
152  std::vector <int> NumStd(profileIndices_.getNumLevelsToCheck(), std::move(NumStd_));
153  std::vector <int> NumSig(profileIndices_.getNumLevelsToCheck(), std::move(NumSig_));
156  }
157 } // namespace ufo
158 
ufo::VariableNames::counter_NumAnyErrors
static constexpr const char *const counter_NumAnyErrors
Definition: VariableNames.h:101
ufo::ProfileConsistencyCheckParameters::ICheck_TolRelax
oops::Parameter< float > ICheck_TolRelax
T tolerance relaxation factor.
Definition: ProfileConsistencyCheckParameters.h:142
ufo::ProfileStandardLevels::LogP_
std::vector< float > LogP_
Log(Pressure) - used for vertical interpolation.
Definition: ProfileStandardLevels.h:79
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::ProfileStandardLevels::StdLev_
std::vector< int > StdLev_
Index of standard levels.
Definition: ProfileStandardLevels.h:70
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::VariableNames::StdLev
static constexpr const char *const StdLev
Definition: VariableNames.h:132
ufo::ProfileIndices::getNumLevelsToCheck
int getNumLevelsToCheck() const
Return number of levels to which QC checks should be applied.
Definition: ProfileIndices.h:52
ufo::VariableNames::IndStd
static constexpr const char *const IndStd
Definition: VariableNames.h:135
ufo::Constants::t0c
static constexpr double t0c
Definition: Constants.h:24
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::ProfileStandardLevels
Calculate standard levels.
Definition: ProfileStandardLevels.h:31
ufo::ProfileCheckInterpolation::runCheck
void runCheck() override
Run check.
Definition: ProfileCheckInterpolation.cc:25
ufo::ProfileStandardLevels::NumSig_
int NumSig_
Number of significant levels.
Definition: ProfileStandardLevels.h:64
ufo::ProfileStandardLevels::IndStd_
std::vector< int > IndStd_
Indices of standard levels.
Definition: ProfileStandardLevels.h:82
ufo::ProfileConsistencyCheckParameters::ICheck_TInterpTol
oops::Parameter< float > ICheck_TInterpTol
Tolerance for interpolation check (K)
Definition: ProfileConsistencyCheckParameters.h:145
ufo::VariableNames::LogP
static constexpr const char *const LogP
Definition: VariableNames.h:140
ufo::ProfileStandardLevels::calcStdLevels
void calcStdLevels(const int numLevelsToCheck, const std::vector< float > &pressures, const std::vector< float > &tObs, const std::vector< int > &tFlags)
Calculate standard levels.
Definition: ProfileStandardLevels.cc:18
ufo::ProfileStandardLevels::StandardLevels_
std::vector< float > StandardLevels_
Standard levels (hPa)
Definition: ProfileStandardLevels.h:55
ufo::VariableNames::LevErrors
static constexpr const char *const LevErrors
Definition: VariableNames.h:136
ufo
Definition: RunCRTM.h:27
ufo::ProfileCheckBase
Profile QC checker base class.
Definition: ProfileCheckBase.h:40
ufo::VariableNames::SigBelow
static constexpr const char *const SigBelow
Definition: VariableNames.h:134
ufo::ProfileCheckBase::options_
const ProfileConsistencyCheckParameters & options_
Configurable parameters.
Definition: ProfileCheckBase.h:71
ufo::ProfileConsistencyCheckParameters::ICheck_TolRelaxPThresh
oops::Parameter< float > ICheck_TolRelaxPThresh
Pressure threshold for T tolerance relaxation.
Definition: ProfileConsistencyCheckParameters.h:139
ufo::ProfileStandardLevels::NumStd_
int NumStd_
Number of standard levels.
Definition: ProfileStandardLevels.h:67
ufo::ProfileCheckInterpolation::ProfileCheckInterpolation
ProfileCheckInterpolation(const ProfileConsistencyCheckParameters &options, const ProfileIndices &profileIndices, ProfileDataHandler &profileDataHandler, ProfileCheckValidator &profileCheckValidator)
Definition: ProfileCheckInterpolation.cc:17
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::ProfileCheckInterpolation::fillValidator
void fillValidator() override
Fill variables in validator.
Definition: ProfileCheckInterpolation.cc:143
ufo::VariableNames::hofx_air_temperature
static constexpr const char *const hofx_air_temperature
Definition: VariableNames.h:38
ufo::abs
util::Duration abs(const util::Duration &duration)
Definition: TrackCheckUtils.h:31
ufo::VariableNames::tInterp
static constexpr const char *const tInterp
Definition: VariableNames.h:137
ufo::ProfileConsistencyCheckParameters
Options controlling the operation of the ProfileConsistencyChecks filter.
Definition: ProfileConsistencyCheckParameters.h:33
ufo::VariableNames::counter_NumInterpErrObs
static constexpr const char *const counter_NumInterpErrObs
Definition: VariableNames.h:110
ufo::VariableNames::counter_NumInterpErrors
static constexpr const char *const counter_NumInterpErrors
Definition: VariableNames.h:109
ufo::ProfileStandardLevels::SigBelow_
std::vector< int > SigBelow_
Significant level below standard level.
Definition: ProfileStandardLevels.h:73
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::NumStd
static constexpr const char *const NumStd
Definition: VariableNames.h:141
ufo::VariableNames::obscorrection_air_temperature
static constexpr const char *const obscorrection_air_temperature
Definition: VariableNames.h:120
ufo::makerProfileCheckInterpolation_
static ProfileCheckMaker< ProfileCheckInterpolation > makerProfileCheckInterpolation_("Interpolation")
ufo::ProfileCheckInterpolation::tInterp_
std::vector< float > tInterp_
Interpolated value of T.
Definition: ProfileCheckInterpolation.h:46
ufo::ProfileConsistencyCheckParameters::ICheck_BigGapInit
oops::Parameter< float > ICheck_BigGapInit
Initial 'big gap' for interpolation check (hPa)
Definition: ProfileConsistencyCheckParameters.h:136
ufo::VariableNames::qcflags_air_temperature
static constexpr const char *const qcflags_air_temperature
Definition: VariableNames.h:92
ufo::ProfileStandardLevels::BigGaps_
std::vector< float > BigGaps_
Big gaps (hPa) used in interpolation check.
Definition: ProfileStandardLevels.h:58
ufo::MetOfficeQCFlags::InterpolationFlag
@ InterpolationFlag
Interpolation check flag.
Definition: MetOfficeQCFlags.h:87
VariableNames.h
ufo::ProfileCheckInterpolation::LevErrors_
std::vector< int > LevErrors_
Number of failed checks by level.
Definition: ProfileCheckInterpolation.h:43
ufo::ProfileStandardLevels::SigAbove_
std::vector< int > SigAbove_
Significant level above standard level.
Definition: ProfileStandardLevels.h:76
ufo::ProfileDataHandler::get
std::vector< T > & get(const std::string &fullname)
Definition: ProfileDataHandler.h:53
ProfileCheckInterpolation.h
ufo::VariableNames::obs_air_temperature
static constexpr const char *const obs_air_temperature
Definition: VariableNames.h:19
ufo::VariableNames::SigAbove
static constexpr const char *const SigAbove
Definition: VariableNames.h:133
ufo::ProfileDataHandler::set
void set(const std::string &fullname, std::vector< T > &&vec_in)
Definition: ProfileDataHandler.h:92
ufo::VariableNames::NumSig
static constexpr const char *const NumSig
Definition: VariableNames.h:142
ufo::MetOfficeQCFlags::SurfaceLevelFlag
@ SurfaceLevelFlag
Surface Level.
Definition: MetOfficeQCFlags.h:89