8 #include "ioda/io/ObsIoGenerateRandom.h"
11 #include "ioda/io/ObsIoGenerateUtils.h"
14 #include "oops/util/missingValues.h"
15 #include "oops/util/Random.h"
34 const boost::optional<oops::Variables> & obsSimVarsVal =
37 oops::Log::trace() <<
"Constructing ObsIoGenerateRandom: Random method" << std::endl;
48 ioParams.
obsErrors, obsSimVarsVal->variables());
68 const util::DateTime & winStart,
69 const util::DateTime & winEnd,
70 const eckit::mpi::Comm & comm,
71 const std::vector<float> & obsErrors,
72 const std::vector<std::string> & simVarNames) {
73 ASSERT(obsErrors.size() == simVarNames.size());
77 float latStart =
params.latStart;
78 float latEnd =
params.latEnd;
79 float lonStart =
params.lonStart;
80 float lonEnd =
params.lonEnd;
82 if (
params.ranSeed.value() != boost::none) {
83 ranSeed =
params.ranSeed.value().get();
85 ranSeed = std::time(0);
105 std::vector<float> ranVals(
numLocs, 0.0);
106 std::vector<float> ranVals2(
numLocs, 0.0);
107 if (comm.rank() == 0) {
108 util::UniformDistribution<float> ranUD(
numLocs, 0.0, 1.0, ranSeed);
109 util::UniformDistribution<float> ranUD2(
numLocs, 0.0, 1.0, ranSeed+1);
111 ranVals = ranUD.data();
112 ranVals2 = ranUD2.data();
114 comm.broadcast(ranVals, 0);
115 comm.broadcast(ranVals2, 0);
118 float latRange = latEnd - latStart;
119 float lonRange = lonEnd - lonStart;
120 util::Duration windowDuration(winEnd - winStart);
121 float timeRange =
static_cast<float>(windowDuration.toSeconds());
125 std::vector<float> latVals(
numLocs, 0.0);
126 std::vector<float> lonVals(
numLocs, 0.0);
127 std::vector<std::string> dtStrings(
numLocs,
"");
129 util::Duration durZero(0);
130 util::Duration durOneSec(1);
131 for (std::size_t ii = 0; ii <
numLocs; ii++) {
132 latVals[ii] = latStart + (ranVals[ii] * latRange);
133 lonVals[ii] = lonStart + (ranVals2[ii] * lonRange);
141 util::Duration offsetDt(
static_cast<int64_t
>(ranVals[ii] * timeRange));
142 if (offsetDt == durZero) {
143 offsetDt = durOneSec;
146 util::DateTime dtVal = winStart + offsetDt;
147 dtStrings[ii] = dtVal.toString();
156 os <<
"ObsIoGenerateRandom: " << std::endl;
Describe the dimensions of a ioda::Attribute or ioda::Variable.
Definitions for setting up backends with file and memory I/O.
oops::RequiredParameter< int > numObs
number of observations
Groups are a new implementation of ObsSpaces.
oops::Parameter< std::vector< float > > obsErrors
obs error estimates
Options controlling the ObsIoGenerateRandom class.
EmbeddedObsGenerateRandomParameters random
options shared by this class and the legacy implementation (LegacyObsGenerateParameters)
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.
ObsIoGenerateRandom(const Parameters_ &ioParams, const ObsSpaceParameters &obsSpaceParams)
void genDistRandom(const EmbeddedObsGenerateRandomParameters ¶ms, const util::DateTime &winStart, const util::DateTime &winEnd, const eckit::mpi::Comm &comm, const std::vector< float > &obsErrors, const std::vector< std::string > &simVarNames)
generate observation locations using the random method
void print(std::ostream &os) const override
print routine for oops::Printable base class
Dimensions_t max_var_size_
maximum variable size (ie, first dimension size)
Dimensions_t nlocs_
number of locations from source (file or generator)
VarNameObjectList var_list_
list of regular variables from source (file or generator)
std::vector< std::string > obs_grouping_vars_
names of variables to be used to group observations into records
VarNameObjectList dim_var_list_
list of dimension scale variables from source (file or generator)
Dimensions_t numLocs() const
return number of locations from the source
VarDimMap dims_attached_to_vars_
map containing variables with their attached dimension scales
ObsGroup obs_group_
ObsGroup object representing io source/destination.
oops::Parameter< ObsGroupingParameters > obsGrouping
options controlling obs record grouping
const util::DateTime & windowEnd() const
return the end of the DA timing window
ObsTopLevelParameters top_level_
sub groups of parameters
const util::DateTime & windowStart() const
return the start of the DA timing window
const eckit::mpi::Comm & comm() const
return the associated MPI group communicator
oops::RequiredParameter< oops::Variables > simVars
simulated variables
Has_Variables vars
Use this to access variables.
virtual Variable open(const std::string &name) const
Open a Variable by name.
virtual Dimensions getDimensions() const
BackendNames
Backend names.
IODA_DL Group constructBackend(BackendNames name, BackendCreationParameters ¶ms)
This is a simple factory style function that will instantiate a different backend based on a given na...
@ ObsStore
ObsStore in-memory.
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
std::vector< Dimensions_t > dimsCur
The dimensions of the data.
Used to specify backend creation-time properties.