UFO
ObsChlEuzIntegr.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020-2020 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 
9 
10 #include <ostream>
11 #include <string>
12 #include <vector>
13 
14 #include "ioda/ObsVector.h"
15 
16 #include "oops/base/Variables.h"
17 
18 #include "ufo/GeoVaLs.h"
19 #include "ufo/ObsDiagnostics.h"
20 #include "ufo/utils/Constants.h"
21 
22 namespace ufo {
23 
24 // -----------------------------------------------------------------------------
25 static ObsOperatorMaker<ObsChlEuzIntegr> makerChlEuzIntegr_("Chlorophyll Ocean Color");
26 // -----------------------------------------------------------------------------
27 
28 ObsChlEuzIntegr::ObsChlEuzIntegr(const ioda::ObsSpace & odb,
29  const eckit::Configuration & config)
30  : ObsOperatorBase(odb, config), varin_()
31 {
32  const std::vector<std::string> vvin{"mass_concentration_of_chlorophyll_in_sea_water",
33  "sea_water_cell_thickness"};
34  varin_.reset(new oops::Variables(vvin));
35  oops::Log::trace() << "ObsChlEuzIntegr created." << std::endl;
36 }
37 
38 // -----------------------------------------------------------------------------
39 
41  oops::Log::trace() << "ObsChlEuzIntegr destructed" << std::endl;
42 }
43 
44 // -----------------------------------------------------------------------------
45 void ObsChlEuzIntegr::simulateObs(const GeoVaLs & gv, ioda::ObsVector & ovec,
46  ObsDiagnostics &) const {
47  int nlocs = ovec.size();
48  int nlevs = gv.nlevs("mass_concentration_of_chlorophyll_in_sea_water");
49 
50  // common vectors storage
51  std::vector <double> tmp(nlocs, 0.0);
52 
53  // Retrieve the chlorophyll and cell thickness
54  std::vector<std::vector<double>> chl;
55  std::vector<std::vector<double>> h;
56  for ( std::size_t k = 0; k < nlevs; ++k ) {
57  gv.getAtLevel(tmp, "sea_water_cell_thickness", k);
58  h.push_back(tmp);
59  gv.getAtLevel(tmp, "mass_concentration_of_chlorophyll_in_sea_water", k);
60  chl.push_back(tmp);
61  }
62 
63  // Calculate mean chlorophyll averaged over euphotic layer (euz_mod)
64  for ( std::size_t i = 0; i < nlocs; ++i ) {
65  double euz = Constants::euzc_0 * pow(chl[0][i], Constants::euzc_1);
66  double euz_mod = 0.0;
67  int elev = 0;
68  for ( std::size_t k = 0; k < nlevs; ++k ) {
69  if (euz_mod < euz) {
70  euz_mod += h[k][i];
71  elev++;
72  }
73  }
74  ovec[i] = 0.0;
75  for ( std::size_t k = 0; k < elev; ++k ) {
76  ovec[i] += chl[k][i] * h[k][i] / euz_mod;
77  }
78  }
79  oops::Log::trace() << "ObsChlEuzIntegr: observation operator run" << std::endl;
80 }
81 
82 // -----------------------------------------------------------------------------
83 
84 void ObsChlEuzIntegr::print(std::ostream & os) const {
85  os << "Chlorophyll Ocean Color obs operator";
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 } // namespace ufo
GeoVaLs: geophysical values at locations.
size_t nlevs(const std::string &var) const
Return number of levels for a specified variable.
Definition: GeoVaLs.cc:310
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
Definition: GeoVaLs.cc:330
std::unique_ptr< const oops::Variables > varin_
void simulateObs(const GeoVaLs &, ioda::ObsVector &, ObsDiagnostics &) const override
Obs Operator.
void print(std::ostream &) const override
ObsChlEuzIntegr(const ioda::ObsSpace &, const eckit::Configuration &)
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
static ObsOperatorMaker< ObsChlEuzIntegr > makerChlEuzIntegr_("Chlorophyll Ocean Color")
static constexpr double euzc_1
Definition: Constants.h:66
static constexpr double euzc_0
Definition: Constants.h:65