8 #include "oops/util/abor1_cpp.h"
10 #include "oops/util/Logger.h"
12 #include "ioda/io/ObsFrameWrite.h"
24 oops::Log::debug() <<
"ObsFrameWrite: maximum frame size: " <<
max_frame_size_ << std::endl;
32 const VarDimMap & varDimMap,
const Dimensions_t maxVarSize) {
50 for (
auto & varNameObject : varList) {
51 std::string varName = varNameObject.first;
68 if (destVar.
isA<
int>()) {
69 std::vector<int> varValues;
70 sourceVar.
read<
int>(varValues, memBufferSelect, obsFrameSelect);
71 destVar.
write<
int>(varValues, memBufferSelect, obsIoSelect);
72 }
else if (destVar.
isA<
float>()) {
73 std::vector<float> varValues;
74 sourceVar.
read<
float>(varValues, memBufferSelect, obsFrameSelect);
75 destVar.
write<
float>(varValues, memBufferSelect, obsIoSelect);
76 }
else if (destVar.
isA<std::string>()) {
77 std::vector<std::string> varValues;
78 sourceVar.
read<std::string>(varValues, memBufferSelect, obsFrameSelect);
79 destVar.
write<std::string>(varValues, memBufferSelect, obsIoSelect);
104 if (count < 0) { count = 0; }
113 const std::vector<int> & varData) {
114 writeFrameVarHelper<int>(varName, varData);
117 const std::vector<float> & varData) {
118 writeFrameVarHelper<float>(varName, varData);
121 const std::vector<std::string> & varData) {
122 writeFrameVarHelper<std::string>(varName, varData);
132 for (
auto & dimVarNameObject : dimVarList) {
133 std::string dimVarName = dimVarNameObject.first;
135 Variable destDimVar = destVarContainer.
open(dimVarName);
147 if (srcDimVar.
isA<
int>()) {
148 std::vector<int> dimCoords;
149 srcDimVar.
read<
int>(dimCoords, memSelect, srcSelect);
150 destDimVar.
write<
int>(dimCoords, memSelect, destSelect);
151 }
else if (srcDimVar.
isA<
float>()) {
152 std::vector<float> dimCoords;
153 srcDimVar.
read<
float>(dimCoords, memSelect, srcSelect);
154 destDimVar.
write<
float>(dimCoords, memSelect, destSelect);
166 for (
auto & ivar : dimsAttachedToVars) {
167 std::string varName = ivar.first;
168 std::vector<std::string> varDimNames = ivar.second;
172 params.compressWithGZIP();
175 std::vector<Variable> varDims;
176 for (
auto & dimVarName : varDimNames) {
177 varDims.push_back(destVarContainer.
open(dimVarName));
181 if (srcVar.
isA<
int>()) {
184 params.setFillValue<
int>(ioda::detail::getFillValue<int>(varFillValue));
187 }
else if (srcVar.
isA<
float>()) {
190 params.setFillValue<
float>(ioda::detail::getFillValue<float>(varFillValue));
193 }
else if (srcVar.
isA<std::string>()) {
196 params.setFillValue<std::string>(
197 ioda::detail::getFillValue<std::string>(varFillValue));
201 oops::Log::warning() <<
"WARNING: ObsWriteFrame::createObsIoVariables: "
202 <<
"Skipping variable due to an unexpected data type for variable: "
203 << varName << std::endl;
219 std::vector<Dimensions_t> varDims =
obs_io_->vars().open(varName).getDimensions().dimsCur;
230 Dimensions_t numElements = std::accumulate(
231 varDims.begin(), varDims.end(), 1, std::multiplies<Dimensions_t>());
232 std::vector<Dimensions_t> feStarts(1, 0);
233 std::vector<Dimensions_t> feCounts(1, numElements);
237 std::vector<Dimensions_t> beStarts(varDims.size(), 0);
239 std::vector<Dimensions_t> beCounts = varDims;
245 os <<
"ObsFrameWrite: " << std::endl;
This class exists inside of ioda::Group and provides the interface to manipulating Variables.
std::shared_ptr< ObsIo > obs_io_
ObsIo object.
Selection createMemSelection(const std::vector< Dimensions_t > &varShape, const Dimensions_t frameCount)
create selection object for accessing a memory buffer
virtual void frameNext()
move to the next frame for a read frame object
virtual void frameInit()
initialize frame for a read frame object
void createFrameFromObsGroup(const VarNameObjectList &varList, const VarNameObjectList &dimVarList, const VarDimMap &varDimMap)
create a frame object based on dimensions and variables from a source ObsGroup
Dimensions_t max_frame_size_
maximum frame size
Dimensions_t max_var_size_
maximum variable size
Selection createEntireFrameSelection(const std::vector< Dimensions_t > &varShape, const Dimensions_t frameCount)
create selection object for accessing the entire frame variable
Dimensions_t frame_start_
current frame starting index
Selection createObsIoSelection(const std::vector< Dimensions_t > &varShape, const Dimensions_t frameStart, const Dimensions_t frameCount)
create selection object for accessing an ObsIo variable
ObsGroup obs_frame_
ObsGroup object (temporary storage for a single frame)
ObsFrameWrite(const ObsSpaceParameters ¶ms)
void writeFrameVar(const std::string &varName, const std::vector< int > &varData)
write a frame variable
void print(std::ostream &os) const override
print routine for oops::Printable base class
Dimensions_t frameCount(const std::string &varName) override
return current frame count for variable
void createObsIoVariables(const Has_Variables &srcVarContainer, Has_Variables &destVarContainer, const VarDimMap &dimsAttachedToVars)
create set of variables from source variables and lists in the ObsIo backend
void copyObsIoDimCoords(const Has_Variables &srcVarContainer, Has_Variables &destVarContainer, const VarNameObjectList &dimVarList)
copy dimension coordinate values from the frame to the ObsIo backend
void createFrameSelection(const std::string &varName, Selection &feSelect, Selection &beSelect)
set up frontend and backend selection objects for the given variable
bool frameAvailable() override
true if a frame is available (not past end of frames)
Dimensions_t frameStart() override
return current frame starting index
static std::shared_ptr< ObsIo > create(ObsIoModes mode, const ObsSpaceParameters ¶meters)
Create and return a new instance of an ObsIo subclass.
A Selection represents the bounds of the data, in ioda or in userspace, that you are reading or writi...
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 FillValueData_t getFillValue() const
Retrieve the fill value.
bool isA() const
Convenience function to check a Variable's storage type.
virtual bool hasFillValue() const
Check if a variable has a fill value set.
virtual Dimensions getDimensions() const
virtual Variable read(gsl::span< char > data, const Type &in_memory_dataType, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all) const
Read the Variable - as char array. Ordering is row-major.
virtual Variable write(gsl::span< char > data, const Type &in_memory_dataType, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
The fundamental write function. Backends overload this function to implement all write operations.
Selection & extent(const VecDimensions_t &sz)
Provide the dimensions of the object that you are selecting from.
Selection & select(const SingleSelection &s)
Append a new selection.
std::vector< std::pair< std::string, Variable > > VarNameObjectList
typedef for holding list of variable names with associated variable object
std::map< std::string, std::vector< std::string > > VarDimMap
typedef for holding dim names attached to variables
std::vector< Dimensions_t > dimsCur
The dimensions of the data.
Used to specify Variable creation-time properties.