11 #ifndef OOPS_BASE_DEPARTURES_H_
12 #define OOPS_BASE_DEPARTURES_H_
14 #include <Eigen/Dense>
26 #include "oops/util/dot_product.h"
27 #include "oops/util/Logger.h"
31 template<
typename OBS>
class Observations;
43 template <
typename OBS>
48 template <
typename DATA>
using ObsDataVec_ = std::vector<std::shared_ptr<ObsData_<DATA>>>;
76 void mask(ObsDataVec_<int>);
86 void save(
const std::string &)
const;
89 void print(std::ostream &)
const;
92 std::vector<ObsVector_>
dep_;
97 template<
typename OBS>
99 const std::string & name): dep_()
102 for (
size_t jj = 0; jj < obsdb.
size(); ++jj) {
103 dep_.emplace_back(obsdb[jj], name);
105 Log::trace() <<
"Departures created" << std::endl;
108 template<
typename OBS>
110 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
116 template<
typename OBS>
118 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
124 template<
typename OBS>
126 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
132 template<
typename OBS>
134 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
140 template<
typename OBS>
142 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
148 template<
typename OBS>
150 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
155 template<
typename OBS>
157 for (
auto & dep : dep_) {
162 template<
typename OBS>
164 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
169 template<
typename OBS>
171 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
176 template<
typename OBS>
178 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
179 dep_[jj].axpy(zz, rhs[jj]);
183 template<
typename OBS>
186 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
187 zz += dot_product(dep_[jj], other[jj]);
192 template<
typename OBS>
195 if (nobs() > 0) zz = sqrt(dot_product_with(*
this) / this->nobs());
199 template<
typename OBS>
202 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
203 nobs += dep_[jj].nobs();
208 template<
typename OBS>
210 for (
size_t ii = 0; ii < dep_.size(); ++ii) {
211 dep_[ii].mask(*qcflags[ii]);
215 template<
typename OBS>
217 for (
size_t ii = 0; ii < dep_.size(); ++ii) {
218 dep_[ii].mask(mask[ii]);
222 template <
typename OBS>
224 std::vector<size_t> len(dep_.size());
225 for (
size_t idep = 0; idep < dep_.size(); ++idep) {
226 len[idep] = dep_[idep].packEigenSize(mask[idep]);
228 size_t all_len = std::accumulate(len.begin(), len.end(), 0);
230 Eigen::VectorXd vec(all_len);
232 for (
size_t idep = 0; idep < dep_.size(); ++idep) {
233 vec.segment(ii, len[idep]) = dep_[idep].packEigen(mask[idep]);
239 template <
typename OBS>
242 for (
size_t idep = 0; idep < dep_.size(); ++idep) {
243 len += dep_[idep].packEigenSize(mask[idep]);
248 template <
typename OBS>
250 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
255 template <
typename OBS>
257 for (
size_t jj = 0; jj < dep_.size(); ++jj) {
258 os << dep_[jj] << std::endl;
Difference between two observation vectors.
Departures & operator*=(const double &)
std::vector< std::shared_ptr< ObsData_< DATA > >> ObsDataVec_
void save(const std::string &) const
Save departures values.
double dot_product_with(const Departures &) const
void mask(ObsDataVec_< int >)
Mask out departures where the passed in qc flags are > 0.
size_t nobs() const
Return number of departures (excluding departures that are masked out)
Departures & operator/=(const Departures &)
ObsVector< OBS > ObsVector_
size_t size() const
Access.
ObsSpaces< OBS > ObsSpaces_
void axpy(const double &, const Departures &)
Departures(const ObsSpaces_ &, const std::string &name="")
create Departures for all obs (read from ObsSpace if name is specified)
ObsVector_ & operator[](const size_t ii)
void print(std::ostream &) const
std::vector< ObsVector_ > dep_
Data.
Eigen::VectorXd packEigen(const Departures &) const
Pack departures in an Eigen vector (excluding departures that are masked out)
Departures & operator-=(const Departures &)
const ObsVector_ & operator[](const size_t ii) const
Departures & operator+=(const Departures &)
size_t packEigenSize(const Departures &) const
Size of departures packed into an Eigen vector.
Abstract base class for quantities.
ObsDataVector is a vector templated on data type, in the observation space.
std::size_t size() const
Access.
ObsVector class used in oops; subclass of interface class interface::ObsVector.
The namespace for the main oops code.