8 #include "ioda/core/obsspace_f.h"
15 #include "eckit/exception/Exceptions.h"
17 #include "oops/util/DateTime.h"
25 const util::DateTime * begin,
26 const util::DateTime * end) {
27 return new ObsSpace(*conf, oops::mpi::world(), *begin, *end, oops::mpi::myself());
32 ASSERT(obss !=
nullptr);
38 std::string obsname = obss.
obsname();
39 lcname = obsname.size();
41 strncpy(cname, obsname.c_str(), lcname);
72 std::size_t & len_dim_name,
char * dim_name) {
74 len_dim_name = dimName.size();
75 ASSERT(len_dim_name < 100);
76 strncpy(dim_name, dimName.c_str(), len_dim_name);
84 return static_cast<int>(obss.
get_dim_id(std::string(dim_name)));
89 lcname = obss.
comm().name().size();
91 strncpy(cname, obss.
comm().name().c_str(), lcname);
95 const std::size_t & length, std::size_t * recnum) {
96 ASSERT(length >= obss.
nlocs());
97 for (std::size_t i = 0; i < length; i++) {
98 recnum[i] = obss.
recnum()[i];
103 const std::size_t & length, std::size_t * index) {
104 ASSERT(length >= obss.
nlocs());
105 for (std::size_t i = 0; i < length; i++) {
108 index[i] = obss.
index()[i] + 1;
113 return obss.
has(std::string(group), std::string(vname));
117 const std::size_t & length, int32_t* vec,
118 const std::size_t & len_cs,
int* chan_select) {
119 ASSERT(len_cs <= obss.
nchans());
120 std::vector<int> chanSelect(len_cs);
121 chanSelect.assign(chan_select, chan_select + len_cs);
122 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
124 ASSERT(length >= obss.
nlocs());
125 std::vector<int32_t> vdata(length);
126 obss.
get_db(std::string(group), std::string(vname), vdata, chanSelect);
127 std::copy(vdata.begin(), vdata.end(), vec);
131 const std::size_t & length, int64_t* vec,
132 const std::size_t & len_cs,
int* chan_select) {
133 ASSERT(len_cs <= obss.
nchans());
134 std::vector<int> chanSelect(len_cs);
135 chanSelect.assign(chan_select, chan_select + len_cs);
136 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
138 ASSERT(length >= obss.
nlocs());
143 const std::size_t & length,
float* vec,
144 const std::size_t & len_cs,
int* chan_select) {
145 ASSERT(len_cs <= obss.
nchans());
146 std::vector<int> chanSelect(len_cs);
147 chanSelect.assign(chan_select, chan_select + len_cs);
148 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
150 ASSERT(length >= obss.
nlocs());
155 const std::size_t & length,
double* vec,
156 const std::size_t & len_cs,
int* chan_select) {
157 ASSERT(len_cs <= obss.
nchans());
158 std::vector<int> chanSelect(len_cs);
159 chanSelect.assign(chan_select, chan_select + len_cs);
160 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
162 ASSERT(length >= obss.
nlocs());
163 std::vector<double> vdata(length);
164 obss.
get_db(std::string(group), std::string(vname), vdata, chanSelect);
165 std::copy(vdata.begin(), vdata.end(), vec);
169 const std::size_t & length, int32_t* date, int32_t* time,
170 const std::size_t & len_cs,
int* chan_select) {
171 ASSERT(len_cs <= obss.
nchans());
172 std::vector<int> chanSelect(len_cs);
173 chanSelect.assign(chan_select, chan_select + len_cs);
174 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
176 ASSERT(length >= obss.
nlocs());
180 util::DateTime temp_dt(
"0000-01-01T00:00:00Z");
181 std::vector<util::DateTime> dt_vect(length, temp_dt);
182 obss.
get_db(std::string(group), std::string(vname), dt_vect, chanSelect);
192 for (std::size_t i = 0; i < length; i++) {
193 dt_vect[i].toYYYYMMDDhhmmss(year, month, day, hour, minute, second);
194 date[i] = (year * 10000) + (month * 100) + day;
195 time[i] = (hour * 10000) + (minute * 100) + second;
200 const std::size_t & length, int32_t* vec,
201 const std::size_t & ndims,
int* dim_ids) {
205 std::vector<std::string> dimList;
206 int numElements = (ndims > 0) ? 1 : 0;
207 for (std::size_t i = 0; i < ndims; ++i) {
213 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
215 ASSERT(length >= numElements);
216 std::vector<int32_t> vdata;
217 vdata.assign(vec, vec + length);
219 obss.
put_db(std::string(group), std::string(vname), vdata, dimList);
223 const std::size_t & length, int64_t* vec,
224 const std::size_t & ndims,
int* dim_ids) {
228 std::vector<std::string> dimList;
229 int numElements = (ndims > 0) ? 1 : 0;
230 for (std::size_t i = 0; i < ndims; ++i) {
236 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
238 ASSERT(length >= numElements);
243 const std::size_t & length,
float* vec,
244 const std::size_t & ndims,
int* dim_ids) {
248 std::vector<std::string> dimList;
249 int numElements = (ndims > 0) ? 1 : 0;
250 for (std::size_t i = 0; i < ndims; ++i) {
256 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
258 ASSERT(length >= numElements);
263 const std::size_t & length,
double* vec,
264 const std::size_t & ndims,
int* dim_ids) {
268 std::vector<std::string> dimList;
269 int numElements = (ndims > 0) ? 1 : 0;
270 for (std::size_t i = 0; i < ndims; ++i) {
276 if (std::string(group) ==
"VarMetaData") ASSERT(length >= obss.
nvars());
278 ASSERT(length >= numElements);
279 std::vector<double> vdata;
280 vdata.assign(vec, vec + length);
282 obss.
put_db(std::string(group), std::string(vname), vdata, dimList);
Observation data class for IODA.
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
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< int > &vdata, const std::vector< std::string > &dimList={ "nlocs" })
transfer data from vdata to the obs container
size_t nchans() const
return the number of channels in the container. If this is not a radiance obs type,...
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
const std::vector< std::size_t > & index() const
return reference to the index vector
const eckit::mpi::Comm & comm() const
ObsDimensionId get_dim_id(const std::string &dimName) const
return the standard dimension id for the given dimension name
size_t nlocs() const
return the number of locations in the obs space. Note that nlocs may be smaller than global unique nl...
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
std::size_t nvars() const
return the number of variables in the obs space container. "Variables" refers to the quantities that ...
std::size_t globalNumLocs() const
return the total number of locations in the corresponding obs spaces across all MPI tasks
const oops::Variables & obsvariables() const
return oops variables object (simulated variables)
const std::string & obsname() const
return the name of the obs type being stored
std::size_t obsspace_get_nvars_f(const ObsSpace &obss)
void obsspace_get_comm_f(const ObsSpace &obss, int &lcname, char *cname)
const ObsSpace * obsspace_construct_f(const eckit::Configuration *conf, const util::DateTime *begin, const util::DateTime *end)
void obsspace_get_int32_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_put_real32_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, float *vec, const std::size_t &ndims, int *dim_ids)
void obsspace_put_int32_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *vec, const std::size_t &ndims, int *dim_ids)
void obsspace_get_real32_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, float *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_destruct_f(ObsSpace *obss)
std::size_t obsspace_get_nlocs_f(const ObsSpace &obss)
const oops::Variables * obsspace_obsvariables_f(const ObsSpace &obss)
IODA_DL void copy(const ObjectSelection &from, ObjectSelection &to, const ScaleMapping &scale_map)
Generic data copying function.
void obsspace_get_recnum_f(const ObsSpace &obss, const std::size_t &length, std::size_t *recnum)
int obsspace_get_dim_id_f(const ObsSpace &obss, const char *dim_name)
void obsspace_obsname_f(const ObsSpace &obss, size_t &lcname, char *cname)
void obsspace_get_real64_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, double *vec, const std::size_t &len_cs, int *chan_select)
void obsspace_get_datetime_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int32_t *date, int32_t *time, const std::size_t &len_cs, int *chan_select)
void obsspace_get_index_f(const ObsSpace &obss, const std::size_t &length, std::size_t *index)
void obsspace_put_real64_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, double *vec, const std::size_t &ndims, int *dim_ids)
bool obsspace_has_f(const ObsSpace &obss, const char *group, const char *vname)
void obsspace_get_int64_f(const ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int64_t *vec, const std::size_t &len_cs, int *chan_select)
std::size_t obsspace_get_nchans_f(const ObsSpace &obss)
int obsspace_get_nchans_dim_id_f()
int obsspace_get_nlocs_dim_id_f()
void obsspace_put_int64_f(ObsSpace &obss, const char *group, const char *vname, const std::size_t &length, int64_t *vec, const std::size_t &ndims, int *dim_ids)
std::size_t obsspace_get_dim_size_f(const ObsSpace &obss, const int &dim_id)
std::size_t obsspace_get_gnlocs_f(const ObsSpace &obss)
void obsspace_get_dim_name_f(const ObsSpace &obss, const int &dim_id, std::size_t &len_dim_name, char *dim_name)
std::size_t obsspace_get_nrecs_f(const ObsSpace &obss)