18 #include <type_traits>
19 #include <unordered_map>
23 #include "eckit/exception/Exceptions.h"
24 #include "eckit/mpi/Comm.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/Logger.h"
30 #include "ioda/core/IodaUtils.h"
31 #include "ioda/distribution/Distribution.h"
35 #include "ioda/ObsSpaceParameters.h"
119 typedef std::map<std::size_t, std::vector<std::size_t>>
RecIdxMap;
137 const util::DateTime & bgn,
const util::DateTime & end,
138 const eckit::mpi::Comm & timeComm);
208 const std::vector<std::string> & obs_group_vars()
const;
211 std::string obs_sort_var()
const;
214 std::string obs_sort_order()
const;
242 const std::vector<std::size_t> &
index()
const {
return indx_;}
246 bool has(
const std::string & group,
const std::string &
name,
247 bool skipDerived =
false)
const;
257 bool skipDerived =
false)
const;
273 void get_db(
const std::string & group,
const std::string &
name,
274 std::vector<int> & vdata,
275 const std::vector<int> & chanSelect = { },
276 bool skipDerived =
false)
const;
277 void get_db(
const std::string & group,
const std::string &
name,
278 std::vector<float> & vdata,
279 const std::vector<int> & chanSelect = { },
280 bool skipDerived =
false)
const;
281 void get_db(
const std::string & group,
const std::string &
name,
282 std::vector<double> & vdata,
283 const std::vector<int> & chanSelect = { },
284 bool skipDerived =
false)
const;
285 void get_db(
const std::string & group,
const std::string &
name,
286 std::vector<std::string> & vdata,
287 const std::vector<int> & chanSelect = { },
288 bool skipDerived =
false)
const;
289 void get_db(
const std::string & group,
const std::string &
name,
290 std::vector<util::DateTime> & vdata,
291 const std::vector<int> & chanSelect = { },
292 bool skipDerived =
false)
const;
304 void put_db(
const std::string & group,
const std::string &
name,
305 const std::vector<int> & vdata,
306 const std::vector<std::string> & dimList = {
"nlocs" });
307 void put_db(
const std::string & group,
const std::string &
name,
308 const std::vector<float> & vdata,
309 const std::vector<std::string> & dimList = {
"nlocs" });
310 void put_db(
const std::string & group,
const std::string &
name,
311 const std::vector<double> & vdata,
312 const std::vector<std::string> & dimList = {
"nlocs" });
313 void put_db(
const std::string & group,
const std::string &
name,
314 const std::vector<std::string> & vdata,
315 const std::vector<std::string> & dimList = {
"nlocs" });
316 void put_db(
const std::string & group,
const std::string &
name,
317 const std::vector<util::DateTime> & vdata,
318 const std::vector<std::string> & dimList = {
"nlocs" });
321 const RecIdxIter recidx_begin()
const;
324 const RecIdxIter recidx_end()
const;
328 bool recidx_has(
const std::size_t recNum)
const;
335 std::size_t recidx_recnum(
const RecIdxIter & irec)
const;
339 const std::vector<std::size_t> & recidx_vector(
const RecIdxIter & irec)
const;
343 const std::vector<std::size_t> & recidx_vector(
const std::size_t recNum)
const;
346 std::vector<std::size_t> recidx_all_recnums()
const;
403 std::shared_ptr<const Distribution>
dist_;
432 void print(std::ostream & os)
const;
469 void resizeNlocs(
const Dimensions_t nlocsSize,
const bool append);
475 template<
typename VarType>
477 const std::string & varName, std::vector<VarType> & varValues);
485 template<
typename VarType>
486 void storeVar(
const std::string & varName, std::vector<VarType> & varValues,
487 const Dimensions_t frameStart,
const Dimensions_t frameCount);
490 template<
typename DataType>
492 DataType fillVal = util::missingValue(fillVal);
510 template<
typename VarType>
512 const std::vector<int> & chanSelect,
513 std::vector<VarType> & varValues,
bool skipDerived =
false)
const;
526 template<
typename VarType>
528 const std::vector<VarType> & varValues,
529 const std::vector<std::string> & dimList);
536 std::size_t nchansDimIndex,
550 template<
typename VarType>
552 const std::vector<std::string> & varDimList) {
555 var = obs_group_.
vars.
open(varName);
558 std::vector<Variable> varDims;
559 for (
auto & dimName : varDimList) {
560 varDims.push_back(obs_group_.
vars.
open(dimName));
565 VarType fillVal = this->getFillValue<VarType>();
568 params.compressWithGZIP();
569 params.setFillValue<VarType>(fillVal);
577 void fillChanNumToIndexMap();
597 void splitChanSuffix(
const std::string & group,
const std::string &
name,
598 const std::vector<int> & chanSelect, std::string & nameToUse,
599 std::vector<int> & chanSelectToUse,
600 bool skipDerived =
false)
const;
605 template <
typename DataType>
Describe the dimensions of a ioda::Attribute or ioda::Variable.
Definitions for setting up backends with file and memory I/O.
Fill value getters and setters.
Interfaces for ioda::ObsGroup and related classes.
This class exists inside of ioda::Group and provides the interface to manipulating Variables.
void set_dim_size(const ObsDimensionId dimId, std::size_t dimSize)
set the dimension size for the given dimension id
std::string get_dim_name(const ObsDimensionId dimId) const
return the dimension name for the given dimension id
ObsDimensionId get_dim_id(const std::string &dimName) const
return the standard id value for the given dimension name
std::map< ObsDimensionId, std::size_t > dim_id_size_
map going from dim id to dim size
std::size_t get_dim_size(const ObsDimensionId dimId) const
return the dimension size for the given dimension id
std::map< std::string, ObsDimensionId > dim_name_id_
map going from dim name to id
std::map< ObsDimensionId, std::string > dim_id_name_
map going from dim id to dim name
Implementation of ObsFrameRead class.
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
void extendObsSpace(const ObsExtendParameters ¶ms)
Extend the ObsSpace according to the method requested in the configuration file.
void storeVar(const std::string &varName, std::vector< VarType > &varValues, const Dimensions_t frameStart, const Dimensions_t frameCount)
store a variable in the obs_group_ object
void createVariables(const Has_Variables &srcVarContainer, Has_Variables &destVarContainer, const VarDimMap &dimsAttachedToVars)
create set of variables from source variables and lists
std::size_t get_dim_size(const ObsDimensionId dimId) const
return the standard dimension size for the given dimension id
void saveToFile()
Dump the database into the output file.
const std::vector< std::size_t > & recnum() const
return reference to the record number vector
void put_db(const std::string &group, const std::string &name, const std::vector< util::DateTime > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
void put_db(const std::string &group, const std::string &name, const std::vector< int > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
transfer data from vdata to the obs container
std::shared_ptr< const Distribution > dist_
MPI distribution object.
void get_db(const std::string &group, const std::string &name, std::vector< int > &vdata, const std::vector< int > &chanSelect={ }, bool skipDerived=false) const
transfer data from the obs container to vdata
std::size_t gnlocs_outside_timewindow_
number of nlocs from the obs source that are outside the time window
void buildRecIdxUnsorted()
Create the recidx data structure with unsorted record groups.
ObsDimInfo dim_info_
dimension information for variables in this obs space
void get_db(const std::string &group, const std::string &name, std::vector< float > &vdata, const std::vector< int > &chanSelect={ }, bool skipDerived=false) const
void get_db(const std::string &group, const std::string &name, std::vector< std::string > &vdata, const std::vector< int > &chanSelect={ }, bool skipDerived=false) const
size_t nchans() const
return the number of channels in the container. If this is not a radiance obs type,...
VarDimMap dims_attached_to_vars_
map showing association of dim names with each variable name
std::string get_dim_name(const ObsDimensionId dimId) const
return the standard dimension name for the given dimension id
std::size_t nrecs() const
return the number of records in the obs space container
void createObsGroupFromObsFrame(ObsFrameRead &obsFrame)
Initialize the database from a source (ObsFrame ojbect)
std::string obsname_
name of obs space
ObsTopLevelParameters Parameters_
std::size_t nrecs_
number of records
DataType getFillValue()
get fill value for use in the obs_group_ object
void print(std::ostream &os) const
print function for oops::Printable class
void get_db(const std::string &group, const std::string &name, std::vector< double > &vdata, const std::vector< int > &chanSelect={ }, bool skipDerived=false) const
void put_db(const std::string &group, const std::string &name, const std::vector< float > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
const std::vector< std::size_t > & index() const
return reference to the index vector
void put_db(const std::string &group, const std::string &name, const std::vector< std::string > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
ObsSpace(const ObsSpace &)
oops::Variables obsvars_
Observation "variables" to be simulated.
std::map< int, int > chan_num_to_index_
map to go from channel number (not necessarily consecutive) to channel index (consecutive,...
void saveVar(const std::string &group, std::string name, const std::vector< VarType > &varValues, const std::vector< std::string > &dimList)
save a variable to the obs_group_ object
const eckit::mpi::Comm & comm() const
void initFromObsSource(ObsFrameRead &obsFrame)
initialize the in-memory obs_group_ (ObsGroup) object from the ObsIo source
void loadVar(const std::string &group, const std::string &name, const std::vector< int > &chanSelect, std::vector< VarType > &varValues, bool skipDerived=false) const
load a variable from the obs_group_ object
RecIdxMap::const_iterator RecIdxIter
void createMissingObsErrors()
For each simulated variable that doesn't have an accompanying array in the ObsError or DerivedObsErro...
RecIdxMap recidx_
profile ordering
std::shared_ptr< const Distribution > distribution() const
return MPI distribution object
ObsDimensionId get_dim_id(const std::string &dimName) const
return the standard dimension id for the given dimension name
ObsSpaceParameters obs_params_
obs io parameters
std::string distname() const
return the name of the MPI distribution
void buildSortedObsGroups()
Create the recidx data structure holding sorted record groups.
size_t nlocs() const
return the number of locations in the obs space. Note that nlocs may be smaller than global unique nl...
const util::DateTime winbgn_
Beginning of DA timing window.
void get_db(const std::string &group, const std::string &name, std::vector< util::DateTime > &vdata, const std::vector< int > &chanSelect={ }, bool skipDerived=false) const
ObsGroup obs_group_
observation data store
std::vector< std::size_t > indx_
indexes of locations to extract from the input obs file
const util::DateTime winend_
End of DA timing window.
const util::DateTime & windowStart() const
std::size_t nvars() const
return the number of variables in the obs space container. "Variables" refers to the quantities that ...
void extendVariable(Variable &extendVar, const size_t startFill)
Extend the given variable.
bool obsAreSorted() const
true if the groups in the recidx data member are sorted
const ObsSpaceParameters & params() const
Variable openCreateVar(const std::string &varName, const std::vector< std::string > &varDimList)
open an obs_group_ variable, create the varialbe if necessary
void resizeNlocs(const Dimensions_t nlocsSize, const bool append)
resize along nlocs dimension
const oops::Variables & derived_obsvariables() const
return the collection of derived simulated variables (variables computed after loading the input file...
bool readObsSource(ObsFrameRead &obsFrame, const std::string &varName, std::vector< VarType > &varValues)
read in values for variable from obs source
std::size_t createChannelSelections(const Variable &variable, std::size_t nchansDimIndex, const std::vector< int > &channels, Selection &memSelect, Selection &obsGroupSelect) const
Create selections of slices of the variable variable along dimension nchansDimIndex corresponding to ...
bool recidx_is_sorted_
indicator whether the data in recidx_ is sorted
std::size_t globalNumLocsOutsideTimeWindow() const
return number of locations from obs source that were outside the time window
const eckit::mpi::Comm & commMPI_
MPI communicator.
std::size_t globalNumLocs() const
return the total number of locations in the corresponding obs spaces across all MPI tasks
std::size_t gnlocs_
total number of locations
std::map< std::vector< std::string >, Selection > known_be_selections_
cache for backend selection
void put_db(const std::string &group, const std::string &name, const std::vector< double > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
const oops::Variables & obsvariables() const
return the collection of all simulated variables
std::map< std::size_t, std::vector< std::size_t > > RecIdxMap
const oops::Variables & initial_obsvariables() const
return the collection of simulated variables loaded from the input file
const std::string & obsname() const
return the name of the obs type being stored
const util::DateTime & windowEnd() const
std::map< std::vector< std::string >, Selection > known_fe_selections_
cache for frontend selection
std::vector< std::size_t > recnums_
record numbers associated with the location indexes
ObsTopLevelParameters top_level_
sub groups of parameters
oops::RequiredParameter< oops::Variables > simVars
simulated variables
oops::Parameter< oops::Variables > derivedSimVars
oops::Parameter< std::string > distName
name of MPI distribution
A Selection represents the bounds of the data, in ioda or in userspace, that you are reading or writi...
Represents the "type" (i.e. integer, string, float) of a piece of data.
Has_Variables vars
Use this to access variables.
Variable createWithScales(const std::string &name, const std::vector< Variable > &dimension_scales, const VariableCreationParameters ¶ms=VariableCreationParameters::defaulted< DataType >())
Convenience function to create a Variable from certain dimension scales.
virtual Variable open(const std::string &name) const
Open a Variable by name.
virtual bool exists(const std::string &name) const
Does a Variable with the specified name exist?
Base class for observation spaces.
std::map< std::string, std::vector< std::string > > VarDimMap
typedef for holding dim names attached to variables
character(maxvarlen) function variable(this, jj)
logical function has(this, var)
Template handlers for implicit variable conversion.
Type to_type
The type that data should be converted to upon write.
Used to specify Variable creation-time properties.