UFO
ObsLocGC99.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020-2021 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef UFO_OBSLOCALIZATION_OBSLOCGC99_H_
9 #define UFO_OBSLOCALIZATION_OBSLOCGC99_H_
10 
11 #include <ostream>
12 #include <vector>
13 
14 #include "eckit/config/Configuration.h"
15 
16 #include "ioda/ObsSpace.h"
17 #include "ioda/ObsVector.h"
18 
19 #include "oops/generic/gc99.h"
20 
23 
24 namespace ufo {
25 
26 /// Horizontal Gaspari-Cohn observation space localization
27 template<class MODEL>
28 class ObsLocGC99: public ufo::ObsLocalization<MODEL> {
29  typedef typename MODEL::GeometryIterator GeometryIterator_;
30 
31  public:
32  ObsLocGC99(const eckit::Configuration &, const ioda::ObsSpace &);
33 
34  /// compute localization and save localization values in \p locfactor
35  /// (missing values indicate that observation is outside of localization)
37  ioda::ObsVector & locfactor) const override;
38 
39  private:
40  void print(std::ostream &) const override;
41 };
42 // -----------------------------------------------------------------------------
43 
44 template<typename MODEL>
45 ObsLocGC99<MODEL>::ObsLocGC99(const eckit::Configuration & config,
46  const ioda::ObsSpace & obsspace):
47  ObsLocalization<MODEL>::ObsLocalization(config, obsspace) {
49  oops::Log::debug() << "Gaspari-Cohn horizontal localization with " << options.lengthscale
50  << " lengthscale" << std::endl;
51 }
52 
53 // -----------------------------------------------------------------------------
54 
55 template<typename MODEL>
57  ioda::ObsVector & locvector) const {
58  oops::Log::trace() << "ObsLocGC99::computeLocalization" << std::endl;
59 
60  // do distance search and compute box-car locvector
62 
63  // return refs to internals of ObsLocalization
64  const std::vector<int> & localobs = ObsLocalization<MODEL>::localobs();
65  const std::vector<double> & horizontalObsdist = ObsLocalization<MODEL>::horizontalObsdist();
67 
68  const size_t nvars = locvector.nvars();
69  for (size_t jlocal = 0; jlocal < localobs.size(); ++jlocal) {
70  double locFactor = oops::gc99(horizontalObsdist[jlocal] / options.lengthscale);
71  // obsdist is calculated at each location; need to update R for each variable
72  for (size_t jvar = 0; jvar < nvars; ++jvar) {
73  locvector[jvar + localobs[jlocal] * nvars] *= locFactor;
74  }
75  }
76 }
77 
78 // -----------------------------------------------------------------------------
79 
80 template<typename MODEL>
81 void ObsLocGC99<MODEL>::print(std::ostream & os) const {
83  os << "Gaspari-Cohn horizontal localization with " << options.lengthscale
84  << " lengthscale" << std::endl;
85 }
86 
87 } // namespace ufo
88 
89 #endif // UFO_OBSLOCALIZATION_OBSLOCGC99_H_
Horizontal Gaspari-Cohn observation space localization.
Definition: ObsLocGC99.h:28
ObsLocGC99(const eckit::Configuration &, const ioda::ObsSpace &)
Definition: ObsLocGC99.h:45
void print(std::ostream &) const override
Definition: ObsLocGC99.h:81
void computeLocalization(const GeometryIterator_ &, ioda::ObsVector &locfactor) const override
Definition: ObsLocGC99.h:56
MODEL::GeometryIterator GeometryIterator_
Definition: ObsLocGC99.h:29
Options controlling local observations subsetting.
oops::RequiredParameter< double > lengthscale
Localization lengthscale (find all obs within the distance from reference point)
Horizontal Box car observation space localization.
const std::vector< int > & localobs() const
MODEL::GeometryIterator GeometryIterator_
void computeLocalization(const GeometryIterator_ &, ioda::ObsVector &locvector) const override
const ObsLocParameters & localizationOptions() const
const std::vector< double > & horizontalObsdist() const
Definition: RunCRTM.h:27