UFO
ProfileDataHandler.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 {
13  const DataHandlerParameters &options,
14  EntireSampleDataHandler &entireSampleDataHandler,
15  const ProfileIndices &profileIndices)
16  : obsdb_(obsdb),
17  options_(options),
18  entireSampleDataHandler_(entireSampleDataHandler),
19  profileIndices_(profileIndices)
20  {}
21 
23  {
24  profileData_.clear();
25  }
26 
27  void ProfileDataHandler::getProfileIndicesInEntireSample(const std::string& groupname)
28  {
30  const size_t entriesPerProfile = options_.getEntriesPerProfile(groupname);
31  // If the number of entries per profile was not specified, use the indices
32  // that were obtained by sorting and grouping the record numbers.
33  if (entriesPerProfile == 0) {
35  } else {
36  // Otherwise increment the indices sequentially, starting at the
37  // relevant position.
38  profileIndicesInEntireSample_.resize(entriesPerProfile);
39  std::iota(profileIndicesInEntireSample_.begin(),
41  profileIndices_.getProfileNumCurrent() * entriesPerProfile);
42  }
43  }
45  {
46  for (const auto &it_profile : profileData_) {
47  std::string fullname = it_profile.first;
48  std::string varname;
49  std::string groupname;
50  ufo::splitVarGroup(fullname, varname, groupname);
51 
52  if (groupname == "QCFlags" || fullname == ufo::VariableNames::counter_NumAnyErrors) {
54  const std::vector <int>& profileData = get<int>(fullname);
55  std::vector <int>& entireSampleData = entireSampleDataHandler_.get<int>(fullname);
56  size_t idx = 0;
57  for (const auto& profileIndex : profileIndicesInEntireSample_) {
58  updateValueIfPresent(profileData, idx, entireSampleData, profileIndex);
59  idx++;
60  }
61  } else if (groupname == "Corrections") {
63  const std::vector <float>& profileData = get<float>(fullname);
64  std::vector <float>& entireSampleData = entireSampleDataHandler_.get<float>(fullname);
65  size_t idx = 0;
66  for (const auto& profileIndex : profileIndicesInEntireSample_) {
67  updateValueIfPresent(profileData, idx, entireSampleData, profileIndex);
68  idx++;
69  }
70  }
71  }
72  }
73 
75  {
76  std::vector <int> &ReportFlags = get<int>(ufo::VariableNames::qcflags_observation_report);
77  const std::vector <int> &NumAnyErrors = get<int>(ufo::VariableNames::counter_NumAnyErrors);
78  if (!NumAnyErrors.empty() && NumAnyErrors[0] > options_.nErrorsFail.value()) {
79  oops::Log::debug() << " " << NumAnyErrors[0]
80  << " errors detected, whole profile rejected" << std::endl;
81  for (size_t jlev = 0; jlev < ReportFlags.size(); ++jlev) {
83  }
84  }
85  }
86 
87  void ProfileDataHandler::setFlagged(const size_t nvars,
88  std::vector<std::vector<bool>> &flagged)
89  {
90  oops::Log::debug() << "Flagging observations" << std::endl;
91 
92  for (const auto& it_profile : profileData_) {
93  std::string fullname = it_profile.first;
94  std::string varname;
95  std::string groupname;
96  ufo::splitVarGroup(fullname, varname, groupname);
97 
98  if (groupname == "QCFlags") {
99  oops::Log::debug() << " " << fullname << std::endl;
100 
101  const std::vector <int> &Flags = get<int>(fullname);
103 
104  size_t idx = 0;
105  for (const auto& profileIndex : profileIndicesInEntireSample_) {
106  // Please note this concise code relies on both FlagsElem::FinalRejectFlag
107  // and FlagsWholeObReport::FinalRejectReport being equal to the same value
108  // (as is the case in OPS).
109  // If one or both values change, and clash with another flag in the enum,
110  // this will have to be rewritten.
111  if (!Flags.empty() &&
114  oops::Log::debug() << " " << profileIndex << std::endl;
115  // Flag all variables
116  for (size_t jv = 0; jv < nvars; ++jv)
117  flagged[jv][profileIndex] = true;
118  }
119  idx++;
120  }
121  }
122  }
123  }
124 } // namespace ufo
125 
126 
ufo::VariableNames::counter_NumAnyErrors
static constexpr const char *const counter_NumAnyErrors
Definition: VariableNames.h:101
ufo::ProfileDataHandler::updateValueIfPresent
void updateValueIfPresent(const std::vector< T > &vecIn, const size_t &idxIn, std::vector< T > &vecOut, const size_t &idxOut)
Transfer values from one vector to another (as long as neither is empty).
Definition: ProfileDataHandler.h:110
ufo::ProfileDataHandler::profileIndicesInEntireSample_
std::vector< size_t > profileIndicesInEntireSample_
Indices in the entire data sample that correspond to the current profile.
Definition: ProfileDataHandler.h:156
ufo::ProfileIndices
Determine indices of observations making up individual profiles. The indices are computed with respec...
Definition: ProfileIndices.h:39
ufo::splitVarGroup
void splitVarGroup(const std::string &vargrp, std::string &var, std::string &grp)
Definition: StringUtils.cc:19
ufo::DataHandlerParameters::nErrorsFail
oops::Parameter< int > nErrorsFail
Number of errors, accumulated over checks, that cause the observation to have failed.
Definition: DataHandlerParameters.h:62
ufo_radiancerttov_utils_mod::debug
logical, public debug
Definition: ufo_radiancerttov_utils_mod.F90:100
ufo::ProfileDataHandler::entireSampleDataHandler_
EntireSampleDataHandler & entireSampleDataHandler_
Class that handles the entire data sample.
Definition: ProfileDataHandler.h:150
ufo::VariableNames::qcflags_observation_report
static constexpr const char *const qcflags_observation_report
Definition: VariableNames.h:91
ufo
Definition: RunCRTM.h:27
ufo::ProfileIndices::getProfileIndices
const std::vector< size_t > & getProfileIndices() const
Return indices for the current profile.
Definition: ProfileIndices.h:49
ufo::ProfileDataHandler::options_
const DataHandlerParameters & options_
Configurable parameters.
Definition: ProfileDataHandler.h:147
ufo::ProfileIndices::getProfileNumCurrent
size_t getProfileNumCurrent() const
Get number of current profile.
Definition: ProfileIndices.h:55
ufo::ProfileDataHandler::setFinalReportFlags
void setFinalReportFlags()
Set final report flags based on the NumAnyErrors counter.
Definition: ProfileDataHandler.cc:74
ProfileDataHandler.h
ufo::ProfileDataHandler::profileIndices_
const ProfileIndices & profileIndices_
Class that handles profile indices.
Definition: ProfileDataHandler.h:153
ufo::DataHandlerParameters
Options controlling the operation of the EntireSampleDataHandler and ProfileDataHandler classes.
Definition: DataHandlerParameters.h:25
ufo::ProfileDataHandler::updateEntireSampleData
void updateEntireSampleData()
Definition: ProfileDataHandler.cc:44
ufo::EntireSampleDataHandler
Retrieve and store data for entire sample. This class uses lazy loading; vectors of variables are ret...
Definition: EntireSampleDataHandler.h:42
ufo::ProfileDataHandler::getProfileIndicesInEntireSample
void getProfileIndicesInEntireSample(const std::string &groupname)
Get indices in entire sample corresponding to current profile.
Definition: ProfileDataHandler.cc:27
ufo::MetOfficeQCFlags::FinalRejectReport
@ FinalRejectReport
One of flags 1-6 set.
Definition: MetOfficeQCFlags.h:26
ufo::DataHandlerParameters::getEntriesPerProfile
size_t getEntriesPerProfile(const std::string &groupname) const
Determine number of entries per profile for a variable group.
Definition: DataHandlerParameters.h:40
ufo::MetOfficeQCFlags::FinalRejectFlag
@ FinalRejectFlag
Final QC flag.
Definition: MetOfficeQCFlags.h:54
VariableNames.h
ufo::ProfileDataHandler::profileData_
std::unordered_map< std::string, boost::variant< std::vector< int >, std::vector< float >, std::vector< std::string > > > profileData_
Container of each variable in the current profile.
Definition: ProfileDataHandler.h:141
ufo::EntireSampleDataHandler::get
std::vector< T > & get(const std::string &fullname)
Definition: EntireSampleDataHandler.h:56
ufo::ProfileDataHandler::ProfileDataHandler
ProfileDataHandler(ioda::ObsSpace &obsdb, const DataHandlerParameters &options, EntireSampleDataHandler &entireSampleDataHandler, const ProfileIndices &profileIndices)
Definition: ProfileDataHandler.cc:12
ufo::ProfileDataHandler::setFlagged
void setFlagged(const size_t nvars, std::vector< std::vector< bool >> &flagged)
Definition: ProfileDataHandler.cc:87
ufo::ProfileDataHandler::reset
void reset()
Definition: ProfileDataHandler.cc:22