18 #include <type_traits>
19 #include <unordered_map>
23 #include "eckit/exception/Exceptions.h"
24 #include "eckit/mpi/Comm.h"
26 #include "oops/base/ObsSpaceBase.h"
27 #include "oops/base/Variables.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;
135 ObsSpace(
const eckit::Configuration & config,
const eckit::mpi::Comm &
comm,
136 const util::DateTime & bgn,
const util::DateTime & end,
137 const eckit::mpi::Comm & timeComm);
189 std::size_t
nvars()
const;
241 const std::vector<std::size_t> &
index()
const {
return indx_;}
244 bool has(
const std::string & group,
const std::string &
name)
const;
261 void get_db(
const std::string & group,
const std::string &
name,
262 std::vector<int> & vdata,
263 const std::vector<int> & chanSelect = { })
const;
264 void get_db(
const std::string & group,
const std::string &
name,
265 std::vector<float> & vdata,
266 const std::vector<int> & chanSelect = { })
const;
267 void get_db(
const std::string & group,
const std::string &
name,
268 std::vector<double> & vdata,
269 const std::vector<int> & chanSelect = { })
const;
270 void get_db(
const std::string & group,
const std::string &
name,
271 std::vector<std::string> & vdata,
272 const std::vector<int> & chanSelect = { })
const;
273 void get_db(
const std::string & group,
const std::string &
name,
274 std::vector<util::DateTime> & vdata,
275 const std::vector<int> & chanSelect = { })
const;
287 void put_db(
const std::string & group,
const std::string &
name,
288 const std::vector<int> & vdata,
289 const std::vector<std::string> & dimList = {
"nlocs" });
290 void put_db(
const std::string & group,
const std::string &
name,
291 const std::vector<float> & vdata,
292 const std::vector<std::string> & dimList = {
"nlocs" });
293 void put_db(
const std::string & group,
const std::string &
name,
294 const std::vector<double> & vdata,
295 const std::vector<std::string> & dimList = {
"nlocs" });
296 void put_db(
const std::string & group,
const std::string &
name,
297 const std::vector<std::string> & vdata,
298 const std::vector<std::string> & dimList = {
"nlocs" });
299 void put_db(
const std::string & group,
const std::string &
name,
300 const std::vector<util::DateTime> & vdata,
301 const std::vector<std::string> & dimList = {
"nlocs" });
311 bool recidx_has(
const std::size_t recNum)
const;
326 const std::vector<std::size_t> &
recidx_vector(
const std::size_t recNum)
const;
380 std::shared_ptr<const Distribution>
dist_;
409 void print(std::ostream & os)
const;
441 void resizeNlocs(
const Dimensions_t nlocsSize,
const bool append);
447 template<
typename VarType>
449 const std::string & varName, std::vector<VarType> & varValues);
457 template<
typename VarType>
458 void storeVar(
const std::string & varName, std::vector<VarType> & varValues,
459 const Dimensions_t frameStart,
const Dimensions_t frameCount);
462 template<
typename DataType>
464 DataType fillVal = util::missingValue(fillVal);
478 template<
typename VarType>
479 void loadVar(
const std::string & group,
const std::string &
name,
480 const std::vector<int> & chanSelect,
481 std::vector<VarType> & varValues)
const;
494 template<
typename VarType>
495 void saveVar(
const std::string & group, std::string
name,
496 const std::vector<VarType> & varValues,
497 const std::vector<std::string> & dimList);
504 std::size_t nchansDimIndex,
518 template<
typename VarType>
520 const std::vector<std::string> & varDimList) {
526 std::vector<Variable> varDims;
527 for (
auto & dimName : varDimList) {
533 VarType fillVal = this->getFillValue<VarType>();
536 params.compressWithGZIP();
537 params.setFillValue<VarType>(fillVal);
562 const std::vector<int> & chanSelect, std::string & nameToUse,
563 std::vector<int> & chanSelectToUse)
const;
568 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...
Observation data class for IODA.
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
bool has(const std::string &group, const std::string &name) const
return true if group/variable exists
void saveToFile()
Dump the database into the output file.
const std::vector< std::size_t > & recnum() const
return reference to the record number vector
ObsDtype dtype(const std::string &group, const std::string &name) const
return data type for group/variable
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.
std::size_t gnlocs_outside_timewindow_
number of nlocs from the obs source that are outside the time window
std::vector< std::size_t > recidx_all_recnums() const
return all record numbers from the recidx_ data member
const RecIdxIter recidx_begin() const
Return the begin iterator associated with the recidx_ data member.
void buildRecIdxUnsorted()
Create the recidx data structure with unsorted record groups.
ObsDimInfo dim_info_
dimension information for variables in this obs space
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::size_t recidx_recnum(const RecIdxIter &irec) const
return record number pointed to by the given iterator
std::string get_dim_name(const ObsDimensionId dimId) const
return the standard dimension name for the given dimension id
void splitChanSuffix(const std::string &group, const std::string &name, const std::vector< int > &chanSelect, std::string &nameToUse, std::vector< int > &chanSelectToUse) const
split off the channel number suffix from a given variable name
void print(std::ostream &os) const
print function for oops::Printable class
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
const eckit::LocalConfiguration config_
Configuration file.
std::size_t nrecs_
number of records
DataType getFillValue()
get fill value for use in the obs_group_ object
const std::vector< std::string > & obs_group_vars() const
return YAML configuration parameter: obsdatain.obsgrouping.group variables
const RecIdxIter recidx_end() const
Return the end iterator associated with the recidx_ data member.
const std::vector< std::size_t > & index() const
return reference to the index vector
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
ObsSpace & operator=(const ObsSpace &)=delete
disable the "=" operator
void initFromObsSource(ObsFrameRead &obsFrame)
initialize the in-memory obs_group_ (ObsGroup) object from the ObsIo source
const std::vector< std::size_t > & recidx_vector(const RecIdxIter &irec) const
return record number vector pointed to by the given iterator
RecIdxMap::const_iterator RecIdxIter
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.
void loadVar(const std::string &group, const std::string &name, const std::vector< int > &chanSelect, std::vector< VarType > &varValues) const
load a variable from the obs_group_ object
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.
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.
void get_db(const std::string &group, const std::string &name, std::vector< int > &vdata, const std::vector< int > &chanSelect={ }) const
transfer data from the obs container to vdata
const util::DateTime & windowStart() const
void fillChanNumToIndexMap()
fill in the channel number to channel index map
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
std::string obs_sort_order() const
return YAML configuration parameter: obsdatain.obsgrouping.sort order
void save()
save the obs space data into a file (if obsdataout specified)
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
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
const oops::Variables & obsvariables() const
return oops variables object (simulated variables)
std::map< std::size_t, std::vector< std::size_t > > RecIdxMap
ObsSpace(const eckit::Configuration &config, const eckit::mpi::Comm &comm, const util::DateTime &bgn, const util::DateTime &end, const eckit::mpi::Comm &timeComm)
Config based constructor for an ObsSpace object.
const std::string & obsname() const
return the name of the obs type being stored
const util::DateTime & windowEnd() const
std::string obs_sort_var() const
return YAML configuration parameter: obsdatain.obsgrouping.sort variable
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
bool recidx_has(const std::size_t recNum) const
true if given record number exists in the recidx_ data member
ObsTopLevelParameters top_level_
sub groups of parameters
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?
std::map< std::string, std::vector< std::string > > VarDimMap
typedef for holding dim names attached to variables
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.