IODA
ObsIoGenerateList.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2019 UCAR
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 "ioda/io/ObsIoGenerateList.h"
9 
10 #include "ioda/Engines/Factory.h"
11 #include "ioda/io/ObsIoGenerateUtils.h"
12 #include "ioda/Misc/Dimensions.h"
13 
14 #include "oops/util/missingValues.h"
15 
16 namespace ioda {
17 
18 static ObsIoMaker<ObsIoGenerateList> maker("GenerateList");
19 
20 //----------------------------- public functions ------------------------------------
21 //-----------------------------------------------------------------------------------
23  const ObsSpaceParameters & obsSpaceParams) :
24  ObsIo() {
25  // Create an in-memory backend and attach it to an in-memory ObsGroup
26  Engines::BackendNames backendName;
28 
29  backendName = Engines::BackendNames::ObsStore;
30  Group backend = constructBackend(backendName, backendParams);
31 
33  const boost::optional<oops::Variables> & obsSimVarsVal =
34  obsSpaceParams.top_level_.simVars.value();
35 
36  oops::Log::trace() << "Constructing ObsIoGenerateList: List method" << std::endl;
37 
38  // Create the in-memory ObsGroup
39  Dimensions_t numLocs =
40  ioParams.list.lats.value().size();
41  newDims.push_back(
42  ioda::NewDimensionScale<int>("nlocs", numLocs, numLocs, numLocs));
44 
45  // Fill in the ObsGroup with the generated data
46  genDistList(ioParams.list, ioParams.obsErrors, obsSimVarsVal->variables());
47 
48  // record counts useful for an obs source
50 
51  // Collect variable and dimension infomation for downstream use
54 
55  // record variables by which observations should be grouped into records
56  obs_grouping_vars_ = ioParams.obsGrouping.value().obsGroupVars;
57 }
58 
60 
61 //----------------------------- public functions -------------------------------
62 
63 //----------------------------- private functions -----------------------------------
64 //-----------------------------------------------------------------------------------
66  const std::vector<float> & obsErrors,
67  const std::vector<std::string> & simVarNames) {
68  ASSERT(obsErrors.size() == simVarNames.size());
69 
70  // Grab the parameters
71  std::vector<float> latVals = params.lats;
72  std::vector<float> lonVals = params.lons;
73  std::vector<std::string> dtStrings = params.datetimes;
74 
75  // Transfer the specified values to the ObsGroup
76  storeGenData(latVals, lonVals, dtStrings, simVarNames, obsErrors, obs_group_);
77 }
78 
79 //-----------------------------------------------------------------------------------
80 void ObsIoGenerateList::print(std::ostream & os) const {
81  os << "ObsIoGenerateList: " << std::endl;
82 }
83 
84 } // namespace ioda
Describe the dimensions of a ioda::Attribute or ioda::Variable.
Definitions for setting up backends with file and memory I/O.
oops::RequiredParameter< std::vector< float > > lats
latitude values
Groups are a new implementation of ObsSpaces.
Definition: Group.h:159
Options controlling the ObsIoGenerateList class.
EmbeddedObsGenerateListParameters list
options shared by this class and the legacy implementation (LegacyObsGenerateParameters)
oops::Parameter< std::vector< float > > obsErrors
obs error estimates
static ObsGroup generate(Group &emptyGroup, const NewDimensionScales_t &fundamentalDims, std::shared_ptr< const detail::DataLayoutPolicy > layout=nullptr)
Create an empty ObsGroup and populate it with the fundamental dimensions.
Definition: ObsGroup.cpp:72
void print(std::ostream &os) const override
print routine for oops::Printable base class
void genDistList(const EmbeddedObsGenerateListParameters &params, const std::vector< float > &obsErrors, const std::vector< std::string > &simVarNames)
generate observation locations using the list method
ObsIoGenerateList(const Parameters_ &ioParams, const ObsSpaceParameters &obsSpaceParams)
Dimensions_t max_var_size_
maximum variable size (ie, first dimension size)
Definition: ObsIo.h:97
Dimensions_t nlocs_
number of locations from source (file or generator)
Definition: ObsIo.h:100
VarNameObjectList var_list_
list of regular variables from source (file or generator)
Definition: ObsIo.h:103
std::vector< std::string > obs_grouping_vars_
names of variables to be used to group observations into records
Definition: ObsIo.h:112
VarNameObjectList dim_var_list_
list of dimension scale variables from source (file or generator)
Definition: ObsIo.h:106
Dimensions_t numLocs() const
return number of locations from the source
Definition: ObsIo.h:45
VarDimMap dims_attached_to_vars_
map containing variables with their attached dimension scales
Definition: ObsIo.h:109
ObsGroup obs_group_
ObsGroup object representing io source/destination.
Definition: ObsIo.h:94
oops::Parameter< ObsGroupingParameters > obsGrouping
options controlling obs record grouping
ObsTopLevelParameters top_level_
sub groups of parameters
oops::RequiredParameter< oops::Variables > simVars
simulated variables
Has_Variables vars
Use this to access variables.
Definition: Group.h:123
virtual Variable open(const std::string &name) const
Open a Variable by name.
virtual Dimensions getDimensions() const
Definition: Variable.cpp:160
BackendNames
Backend names.
Definition: Factory.h:28
IODA_DL Group constructBackend(BackendNames name, BackendCreationParameters &params)
This is a simple factory style function that will instantiate a different backend based on a given na...
Definition: Factory.cpp:124
@ ObsStore
ObsStore in-memory.
list newDims
Definition: 05-ObsGroup.py:95
static DistributionMaker< AtlasDistribution > maker(DIST_NAME)
std::vector< std::shared_ptr< NewDimensionScale_Base > > NewDimensionScales_t
void storeGenData(const std::vector< float > &latVals, const std::vector< float > &lonVals, const std::vector< std::string > &dtStrings, const std::vector< std::string > &obsVarNames, const std::vector< float > &obsErrors, ObsGroup &obsGroup)
store generated data into an ObsGroup
void collectVarDimInfo(const ObsGroup &obsGroup, VarNameObjectList &varObjectList, VarNameObjectList &dimVarObjectList, VarDimMap &dimsAttachedToVars, Dimensions_t &maxVarSize0)
collect variable and dimension information from a ioda ObsGroup
Definition: IodaUtils.cc:125
std::vector< Dimensions_t > dimsCur
The dimensions of the data.
Definition: Dimensions.h:23
Used to specify backend creation-time properties.
Definition: Factory.h:59