UFO
MetOfficeRMatrixRadiance.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 Met Office
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 #include <assert.h>
9 #include <vector>
10 
11 #include "oops/util/abor1_cpp.h"
12 #include "oops/util/Logger.h"
14 
15 namespace ufo {
16 
17 // -----------------------------------------------------------------------------
18 /// \brief Constructor
19 MetOfficeRMatrixRadiance::MetOfficeRMatrixRadiance(const eckit::Configuration & config):
20  nchans_(0), wmoid_(0), rtype_(0), channels_(), errors_()
21 {
22  oops::Log::trace() << "MetOfficeRMatrixRadiance constructor starting" << std::endl;
23 
24  // Read rmatrix file into Fortran object
27 
28  // Only diagonal setup at the moment
29  // OPS 1=full; 2=diagonal; 3=band diagonal
30  if (rtype_ != 2) {
31  ABORT("R-matrix type not currently in use - only diagonal");
32  }
33 
34  // Map Fortran data to c++
35  std::vector<int> chans_data(nchans_);
36  std::vector<float> elements_data(nchans_);
38  chans_data.data(), elements_data.data());
39  channels_ = chans_data;
40  errors_ = elements_data;
41 
42  // Remove Fortran object as no longer needed
44 
45  oops::Log::trace() << "MetOfficeRMatrixRadiance constructor end" << std::endl;
46 }
47 // -----------------------------------------------------------------------------
48 /// \brief Add r matrix variance onto input array
49 void MetOfficeRMatrixRadiance::add(const std::vector<int> & chans_used,
50  const Eigen::MatrixXf & in,
51  Eigen::MatrixXf & out) const {
52  int matrows = in.rows();
53  int matcols = in.cols();
54  oops::Log::debug() << "matrows, matcols = " << matrows << " " << matcols << std::endl;
55  assert(matrows == chans_used.size());
56  assert(matcols == chans_used.size());
57  out = in;
58  if (rtype_ == 2) {
59  for (size_t ichan = 0; ichan < chans_used.size(); ++ichan) {
60  auto it = std::find(channels_.begin(), channels_.end(), chans_used[ichan]);
61  if (it == channels_.end()) {
62  oops::Log::error() << "Channel not found in R-matrix: "
63  << chans_used[ichan] << std::endl;
64  ABORT("Invalid channel specified for R-matrix");
65  } else {
66  size_t index = it - channels_.begin();
67  out(ichan, ichan) += errors_[index] * errors_[index];
68  }
69  }
70  } else {
71  ABORT("R-matrix type not currently in use - only diagonal");
72  }
73 }
74 // -----------------------------------------------------------------------------
75 /// \brief Print
76 void MetOfficeRMatrixRadiance::print(std::ostream & os) const {
77  os << "MetOfficeRMatrixRadiance: print starting" << std::endl;
78  os << "nchans_ = " << nchans_ << std::endl;
79  os << "wmoid_ = " << wmoid_ << std::endl;
80  os << "rtype_ = " << rtype_ << std::endl;
81  if (nchans_ < 30) {
82  os << "channels = ";
83  for (std::vector<int>::const_iterator i = channels_.begin(); i != channels_.end(); ++i)
84  os << *i << ' ';
85  os << std::endl;
86  os << "errors (stdevs) = ";
87  for (std::vector<float>::const_iterator i = errors_.begin(); i != errors_.end(); ++i)
88  os << *i << ' ';
89  os << std::endl;
90  } else {
91  os << "channels[0] = " << channels_[0] << std::endl;
92  os << "errors[0] (stdev) = " << errors_[0] << std::endl;
93  }
94  os << "MetOfficeRMatrixRadiance: print end" << std::endl;
95 }
96 // -----------------------------------------------------------------------------
97 } // namespace ufo
void add(const std::vector< int > &, const Eigen::MatrixXf &, Eigen::MatrixXf &) const
Add r matrix variance onto input array.
void print(std::ostream &) const override
Print.
MetOfficeRMatrixRadiance(const eckit::Configuration &)
Constructor.
Definition: RunCRTM.h:27
void ufo_metoffice_rmatrixradiance_delete_f90(const F90obfilter &)
void ufo_metoffice_rmatrixradiance_getelements_f90(const F90obfilter &, const size_t &, int *, float *)
void ufo_metoffice_rmatrixradiance_setup_f90(const F90obfilter &, const eckit::Configuration &, size_t &, size_t &, size_t &)