UFO
Locations.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 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 #include "ufo/Locations.h"
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "eckit/config/Configuration.h"
14 #include "eckit/exception/Exceptions.h"
15 
16 #include "oops/mpi/mpi.h"
17 #include "oops/util/DateTime.h"
18 #include "oops/util/Logger.h"
19 #include "oops/util/Random.h"
20 
22 
23 namespace ufo {
24 
25 // -------------------------------------------------------------------------------------------------
26 
27 Locations::Locations(const eckit::mpi::Comm & comm) : comm_(comm) {
28  int nobs = 0;
30 }
31 
32 // -------------------------------------------------------------------------------------------------
33 
34 Locations::Locations(const ioda::ObsSpace & odb,
35  const util::DateTime & t1, const util::DateTime & t2) : comm_(odb.comm()) {
36  ufo_locs_init_f90(keyLoc_, odb, t1, t2);
37 }
38 
39 // -------------------------------------------------------------------------------------------------
40 /*! UFO Locations Constructor with Configuration
41  *
42  * \details This constructor can be used to generate user-specified
43  * and/or random locations for use with interpolation or other tests
44  *
45  * To generate random locations, the relevant parameters specified in
46  * **StateTest.Locations** section of the config file are:
47  *
48  * * **lats** user-specified latitudes (degrees)
49  * * **lons** user-specified longitudes (degrees)
50  * * **Nrandom** number of random locations desired
51  * * **random_seed** (optional) random seed for reproducibility of results
52  *
53  * \date May, 2018 Created (M. Miesch, JCSDA)
54  *
55  * \sa ufo::ufo_locs_create() ufo::ufo_loc_test() test::testStateInterpolation()
56  *
57  */
58 
59 Locations::Locations(const eckit::Configuration & conf,
60  const eckit::mpi::Comm & comm) : comm_(comm) {
61  const eckit::LocalConfiguration obsconf(conf, "obs space");
62  const util::DateTime bgn = util::DateTime(conf.getString("window begin"));
63  const util::DateTime end = util::DateTime(conf.getString("window end"));
64 
65  ioda::ObsSpace obspace(obsconf, comm, bgn, end, oops::mpi::myself());
66  const int nlocs = obspace.nlocs();
67 
68  std::vector<double> lats(nlocs);
69  std::vector<double> lons(nlocs);
70  obspace.get_db("MetaData", "latitude", lats);
71  obspace.get_db("MetaData", "longitude", lons);
72 
73  ufo_locs_create_f90(keyLoc_, nlocs, obspace, &lats[0], &lons[0]);
74 }
75 
76 // -------------------------------------------------------------------------------------------------
77 
78 Locations::Locations(const Locations & other) : comm_(other.comm_) {
80 }
81 
82 // -------------------------------------------------------------------------------------------------
84  F90locs otherKeyLoc_ = other.toFortran();
85  ufo_locs_concatenate_f90(keyLoc_, otherKeyLoc_);
86  return *this;
87 }
88 
89 // -------------------------------------------------------------------------------------------------
90 
93 }
94 
95 // -------------------------------------------------------------------------------------------------
96 
97 int Locations::nobs() const {
98  int nobs;
100  return nobs;
101 }
102 
103 // -------------------------------------------------------------------------------------------------
104 
105 void Locations::print(std::ostream & os) const {
106  int nobs, indx, max_indx, i(0);
108  ufo_locs_indx_f90(keyLoc_, i, indx, max_indx);
109  os << "Locations: " << nobs << " locations: "
110  << max_indx << " maximum indx:";
111 
112  // Write lat and lon to debug stream
113  double lat, lon;
114 
115  for (int i=0; i < nobs; ++i) {
116  ufo_locs_indx_f90(keyLoc_, i, indx, max_indx);
117  ufo_locs_coords_f90(keyLoc_, i, lat, lon);
118 
119  oops::Log::debug() << "obs " << i << ": " << "gv index = " << indx
120  << std::setprecision(2) << std::fixed
121  << " lat = " << lat << ", lon = " << lon << std::endl;
122  }
123 }
124 
125 // -------------------------------------------------------------------------------------------------
126 
127 } // namespace ufo
ufo::ufo_locs_nobs_f90
void ufo_locs_nobs_f90(const F90locs &, int &)
ufo::ufo_locs_create_f90
void ufo_locs_create_f90(F90locs &, const int &, const ioda::ObsSpace &, const double *, const double *)
ufo::ufo_locs_copy_f90
void ufo_locs_copy_f90(F90locs &, const F90locs &)
ufo::ufo_locs_setup_f90
void ufo_locs_setup_f90(F90locs &, const int &)
ufo_radiancerttov_utils_mod::debug
logical, public debug
Definition: ufo_radiancerttov_utils_mod.F90:100
ufo::ufo_locs_coords_f90
void ufo_locs_coords_f90(const F90locs &, int &, double &, double &)
ufo::Locations
Locations class to handle locations for UFO.
Definition: src/ufo/Locations.h:32
ufo::Locations::operator+=
Locations & operator+=(const Locations &)
Definition: Locations.cc:83
ufo::ufo_locs_delete_f90
void ufo_locs_delete_f90(F90locs &)
ufo::Locations::keyLoc_
F90locs keyLoc_
Definition: src/ufo/Locations.h:50
ufo
Definition: RunCRTM.h:27
ufo::Locations::~Locations
~Locations()
Definition: Locations.cc:91
ufo::Locations::Locations
Locations(const eckit::mpi::Comm &)
Definition: Locations.cc:27
ufo::Locations::nobs
int nobs() const
Definition: Locations.cc:97
ufo::ufo_locs_concatenate_f90
void ufo_locs_concatenate_f90(const F90locs &, const F90locs &)
ufo::Locations::print
void print(std::ostream &os) const
Definition: Locations.cc:105
ufo::F90locs
int F90locs
Definition: Fortran.h:14
ufo::Locations::toFortran
int toFortran() const
Definition: src/ufo/Locations.h:45
ufo::ufo_locs_init_f90
void ufo_locs_init_f90(F90locs &, const ioda::ObsSpace &, const util::DateTime &, const util::DateTime &)
Interface to Fortran UFO Locations routines.
ufo::ufo_locs_indx_f90
void ufo_locs_indx_f90(const F90locs &, int &, int &, int &)
conf
Definition: conf.py:1
Locations.interface.h