UFO
ProfileStandardLevels.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 {
12  : optionsSL_(options)
13  {
15  BigGaps_ = optionsSL_.BigGaps.value();
16  }
17 
18  void ProfileStandardLevels::calcStdLevels(const int numLevelsToCheck,
19  const std::vector <float> &pressures,
20  const std::vector <float> &tObs,
21  const std::vector <int> &tFlags)
22  {
23  oops::Log::debug() << " Finding standard levels" << std::endl;
24 
25  // Reset calculated values
26  NumSig_ = 0;
27  NumStd_ = 0;
28  StdLev_.assign(numLevelsToCheck, -1);
29  SigBelow_.assign(numLevelsToCheck, -1);
30  SigAbove_.assign(numLevelsToCheck, -1);
31  LogP_.assign(numLevelsToCheck, 0.0);
32  IndStd_.assign(numLevelsToCheck, -1);
33 
34  /// Missing value (float)
35  const float missingValueFloat = util::missingValue(1.0f);
36 
37  int SigPrev = -1; // Previous significant level
38  int jlevStdA = 0; // Standard level below previous significant level
39  for (int jlev = 0; jlev < numLevelsToCheck; ++jlev) {
40  // Ignore this level if it has been flagged as rejected.
41  if (tFlags[jlev] & ufo::MetOfficeQCFlags::Elem::FinalRejectFlag) continue;
42  if (tObs[jlev] != missingValueFloat &&
43  pressures[jlev] > optionsSL_.FS_MinP.value()) {
44  LogP_[jlev] = (pressures[jlev] > 0 ? std::log(pressures[jlev]) : 0.0);
46  // Surface
47  NumStd_++;
48  StdLev_[NumStd_ - 1] = jlev;
49  } else if (tFlags[jlev] & ufo::MetOfficeQCFlags::Profile::StandardLevelFlag) {
50  // Standard level
51  NumStd_++;
52  StdLev_[NumStd_ - 1] = jlev;
53  SigBelow_[NumStd_ - 1] = SigPrev;
54  } else {
55  NumSig_++;
56  for (int jlevStd = jlevStdA; jlevStd < NumStd_; ++jlevStd) {
57  SigAbove_[jlevStd] = jlev;
58  }
59  jlevStdA = NumStd_;
60  SigPrev = jlev;
61  }
62  }
63  }
64 
65  // Calculate IndStd_ (standard level indices)
66  for (int jlevstd = 0; jlevstd < NumStd_; ++jlevstd) {
67  int jlev = StdLev_[jlevstd]; // Standard level
68  if (tFlags[jlev] & ufo::MetOfficeQCFlags::Profile::SurfaceLevelFlag) continue;
69  int IPStd = std::round(pressures[jlev] * 0.01); // Pressure rounded to nearest hPa
70  for (size_t i = 0; i < StandardLevels_.size(); ++i) {
71  if (IPStd == StandardLevels_[i])
72  IndStd_[jlevstd] = static_cast<int> (i); // Index at which standard level appears
73  if (StandardLevels_[i] <= IPStd) break;
74  }
75  }
76  }
77 
79  {
80  // Find indices in StandardLevels that are closest to 925 and 100 hPa
81  // Required for hydrostatic check
82 
83  // StandardLevels_ must contain decreasing pressures
84  for (size_t jstdlev = 0; jstdlev < StandardLevels_.size() - 1; ++jstdlev) {
85  if (StandardLevels_[jstdlev] < StandardLevels_[jstdlev + 1]) {
86  throw eckit::BadValue("Standard levels in wrong order", Here());
87  }
88  }
89 
90  // Find indices using reverse iterators
91  auto it925 = std::lower_bound(StandardLevels_.rbegin(), StandardLevels_.rend(), 925.0);
92  Ind925_ = std::distance(StandardLevels_.begin(), it925.base()) - 1;
93  auto it100 = std::lower_bound(StandardLevels_.rbegin(), StandardLevels_.rend(), 100.0);
94  Ind100_ = std::distance(StandardLevels_.begin(), it100.base()) - 1;
95  }
96 
97  void ProfileStandardLevels::calcStdLevelsUV(const int numLevelsToCheck,
98  const std::vector <float> &pressures,
99  const std::vector <float> &uObs,
100  const std::vector <float> &vObs,
101  const std::vector <int> &uFlags)
102  {
103  oops::Log::debug() << " Finding standard levels for U and V data" << std::endl;
104 
105  // Reset calculated values
106  NumSig_ = 0;
107  NumStd_ = 0;
108  StdLev_.assign(numLevelsToCheck, -1);
109  SigBelow_.assign(numLevelsToCheck, -1);
110  SigAbove_.assign(numLevelsToCheck, -1);
111  LogP_.assign(numLevelsToCheck, 0.0);
112 
113  /// Missing value (float)
114  const float missingValueFloat = util::missingValue(1.0f);
115 
116  int SigPrev = -1; // Previous significant level
117  int jlevStdA = 0; // Standard level below previous significant level
118 
119  for (int jlev = 0; jlev < numLevelsToCheck; ++jlev) {
120  if (uObs[jlev] != missingValueFloat && vObs[jlev] != missingValueFloat) {
121  LogP_[jlev] = std::log(pressures[jlev]);
122  if (uFlags[jlev] & ufo::MetOfficeQCFlags::Profile::StandardLevelFlag) { // Standard level
123  NumStd_++;
124  StdLev_[NumStd_ - 1] = jlev;
125  SigBelow_[NumStd_ - 1] = SigPrev;
126  } else {
127  NumSig_++;
128  for (int jlevstd = jlevStdA; jlevstd < NumStd_; ++jlevstd) {
129  SigAbove_[jlevstd] = jlev;
130  }
131  jlevStdA = NumStd_;
132  SigPrev = jlev;
133  }
134  }
135  }
136  }
137 } // namespace ufo
ProfileStandardLevels.h
ufo::ProfileStandardLevels::LogP_
std::vector< float > LogP_
Log(Pressure) - used for vertical interpolation.
Definition: ProfileStandardLevels.h:79
ufo::ProfileStandardLevels::StdLev_
std::vector< int > StdLev_
Index of standard levels.
Definition: ProfileStandardLevels.h:70
ufo::ProfileConsistencyCheckParameters::BigGaps
oops::Parameter< std::vector< float > > BigGaps
Big gaps (hPa) used in interpolation check.
Definition: ProfileConsistencyCheckParameters.h:148
ufo::ProfileStandardLevels::calcStdLevelsUV
void calcStdLevelsUV(const int numLevelsToCheck, const std::vector< float > &pressures, const std::vector< float > &uObs, const std::vector< float > &vObs, const std::vector< int > &uFlags)
Calculate standard levels for U and V data.
Definition: ProfileStandardLevels.cc:97
ufo_radiancerttov_utils_mod::debug
logical, public debug
Definition: ufo_radiancerttov_utils_mod.F90:100
ufo::ProfileStandardLevels::Ind925_
int Ind925_
Standard level index closest to 925 hPa.
Definition: ProfileStandardLevels.h:85
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::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
Definition: RunCRTM.h:27
ufo::ProfileStandardLevels::NumStd_
int NumStd_
Number of standard levels.
Definition: ProfileStandardLevels.h:67
ufo::ProfileConsistencyCheckParameters::FS_MinP
oops::Parameter< float > FS_MinP
Min P for finding standard levels (Pa)
Definition: ProfileConsistencyCheckParameters.h:62
ufo::ProfileConsistencyCheckParameters
Options controlling the operation of the ProfileConsistencyChecks filter.
Definition: ProfileConsistencyCheckParameters.h:33
ufo::ProfileStandardLevels::Ind100_
int Ind100_
Standard level index closest to 100 hPa.
Definition: ProfileStandardLevels.h:88
ufo::ProfileStandardLevels::SigBelow_
std::vector< int > SigBelow_
Significant level below standard level.
Definition: ProfileStandardLevels.h:73
ufo::ProfileConsistencyCheckParameters::StandardLevels
oops::Parameter< std::vector< float > > StandardLevels
Standard Levels (hPa)
Definition: ProfileConsistencyCheckParameters.h:65
ufo::MetOfficeQCFlags::FinalRejectFlag
@ FinalRejectFlag
Final QC flag.
Definition: MetOfficeQCFlags.h:54
ufo::ProfileStandardLevels::BigGaps_
std::vector< float > BigGaps_
Big gaps (hPa) used in interpolation check.
Definition: ProfileStandardLevels.h:58
ufo::ProfileStandardLevels::findHCheckStdLevs
void findHCheckStdLevs()
Compute indices of particular standard levels for the hydrostatic check.
Definition: ProfileStandardLevels.cc:78
ufo::ProfileStandardLevels::ProfileStandardLevels
ProfileStandardLevels(const ProfileConsistencyCheckParameters &options)
Definition: ProfileStandardLevels.cc:11
ufo::ProfileStandardLevels::SigAbove_
std::vector< int > SigAbove_
Significant level above standard level.
Definition: ProfileStandardLevels.h:76
ufo::TrackCheckUtils::distance
float distance(const Point &a, const Point &b)
Returns the distance between the two cartesian-mapped Point arguments
Definition: TrackCheckUtils.cc:51
ufo::MetOfficeQCFlags::StandardLevelFlag
@ StandardLevelFlag
Standard Level.
Definition: MetOfficeQCFlags.h:90
ufo::ProfileStandardLevels::optionsSL_
const ProfileConsistencyCheckParameters & optionsSL_
Configurable parameters.
Definition: ProfileStandardLevels.h:61
ufo::MetOfficeQCFlags::SurfaceLevelFlag
@ SurfaceLevelFlag
Surface Level.
Definition: MetOfficeQCFlags.h:89