UFO
ProfileDataHolder.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021, 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 
8 #include <set>
9 #include <utility>
10 
12 
13 namespace ufo {
15  : profileDataHandler_(profileDataHandler)
16  {
18  }
19 
20  void ProfileDataHolder::fill(const std::vector <std::string> &variableNamesInt,
21  const std::vector <std::string> &variableNamesFloat,
22  const std::vector <std::string> &variableNamesString,
23  const std::vector <std::string> &variableNamesGeoVaLs,
24  const std::vector <std::string> &variableNamesObsDiags)
25  {
26  variableNamesInt_ = variableNamesInt;
27  variableNamesFloat_ = variableNamesFloat;
28  variableNamesString_ = variableNamesString;
29  variableNamesGeoVaLs_ = variableNamesGeoVaLs;
30  variableNamesObsDiags_ = variableNamesObsDiags;
31 
32  for (const auto& variable : variableNamesInt_)
33  profileData_.emplace(variable, profileDataHandler_.get<int>(variable));
34  for (const auto& variable : variableNamesFloat_)
35  profileData_.emplace(variable, profileDataHandler_.get<float>(variable));
36  for (const auto& variable : variableNamesString_)
37  profileData_.emplace(variable, profileDataHandler_.get<std::string>(variable));
38  for (const auto& variable : variableNamesGeoVaLs_)
39  profileGeoVaLs_.emplace(variable, profileDataHandler_.getGeoVaLVector(variable));
40  for (const auto& variable : variableNamesObsDiags_)
41  profileObsDiags_.emplace(variable, profileDataHandler_.getObsDiag(variable));
42  }
43 
44  std::vector <float>& ProfileDataHolder::getGeoVaLVector(const std::string &fullname)
45  {
46  auto it_profileGeoVaLs = profileGeoVaLs_.find(fullname);
47  if (it_profileGeoVaLs != profileGeoVaLs_.end()) {
48  return it_profileGeoVaLs->second;
49  } else {
50  throw eckit::BadValue("GeoVaL " + fullname + " not present in profile. "
51  "Please add it to the relevant argument in the call "
52  "to produceProfileVector()", Here());
53  }
54  }
55 
56  std::vector <float>& ProfileDataHolder::getObsDiagVector(const std::string &fullname)
57  {
58  auto it_profileObsDiags = profileObsDiags_.find(fullname);
59  if (it_profileObsDiags != profileObsDiags_.end()) {
60  return it_profileObsDiags->second;
61  } else {
62  throw eckit::BadValue("ObsDiag " + fullname + " not present in profile. "
63  "Please add it to the relevant argument in the call "
64  "to produceProfileVector()", Here());
65  }
66  }
67 
69  {
70  for (const auto& variable : variableNamesInt_)
71  profileDataHandler_.set<int>(variable, std::move(this->get<int>(variable)));
72  for (const auto& variable : variableNamesFloat_)
73  profileDataHandler_.set<float>(variable, std::move(this->get<float>(variable)));
74  for (const auto& variable : variableNamesString_)
75  profileDataHandler_.set<std::string>(variable, std::move(this->get<std::string>(variable)));
76  profileData_.clear();
77  }
78 
80  {
81  // If extended_obs_space is not present this will throw an exception.
82  const auto &extended_obs_space = this->get<int>(ufo::VariableNames::extended_obs_space);
83  if (section == ufo::ObsSpaceSection::Original &&
84  std::find(extended_obs_space.begin(),
85  extended_obs_space.end(), 1) != extended_obs_space.end())
86  throw eckit::BadValue("This profile is expected to be in the original ObsSpace "
87  "but has been labelled as being in the extended ObsSpace.", Here());
88  if (section == ufo::ObsSpaceSection::Extended &&
89  std::find(extended_obs_space.begin(),
90  extended_obs_space.end(), 0) != extended_obs_space.end())
91  throw eckit::BadValue("This profile is expected to be in the extended ObsSpace "
92  "but has been labelled as being in the original ObsSpace.", Here());
93  }
94 } // namespace ufo
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
std::vector< T > & get(const std::string &fullname)
void set(const std::string &fullname, std::vector< T > &&vec_in)
std::vector< float > & getGeoVaLVector(const std::string &variableName)
Get GeoVaLs for a particular profile.
int getNumProfileLevels() const
Return number of levels to which QC checks should be applied.
std::vector< float > & getObsDiag(const std::string &variableName)
Get ObsDiags for a particular profile.
std::vector< std::string > variableNamesInt_
Names of int variables.
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.
ProfileDataHolder(ProfileDataHandler &profileDataHandler)
std::vector< float > & getObsDiagVector(const std::string &fullname)
Retrieve an ObsDiag vector if it is present. If not, throw an exception.
void moveValuesToHandler()
Move all values to the associated ProfileDataHandler.
std::vector< std::string > variableNamesGeoVaLs_
Names of GeoVaLs.
ProfileDataHandler & profileDataHandler_
Profile data handler.
std::size_t numProfileLevels_
Number of profile levels.
void fill(const std::vector< std::string > &variableNamesInt, const std::vector< std::string > &variableNamesFloat, const std::vector< std::string > &variableNamesString, const std::vector< std::string > &variableNamesGeoVaLs, const std::vector< std::string > &variableNamesObsDiags)
Fill profile with data.
std::vector< std::string > variableNamesFloat_
Names of float variables.
std::vector< std::string > variableNamesString_
Names of string variables.
std::unordered_map< std::string, std::vector< float > > profileGeoVaLs_
Container of GeoVaLs in the current profile.
std::vector< float > & getGeoVaLVector(const std::string &fullname)
Retrieve a GeoVaL vector if it is present. If not, throw an exception.
std::vector< std::string > variableNamesObsDiags_
Names of ObsDiags.
void checkObsSpaceSection(ufo::ObsSpaceSection section)
Check this profile is in the expected ObsSpace section (original or extended).
std::unordered_map< std::string, std::vector< float > > profileObsDiags_
Container of ObsDiags in the current profile.
Definition: RunCRTM.h:27
static constexpr const char *const extended_obs_space
Definition: VariableNames.h:94