UFO
ObsOperatorBase.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 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/ObsOperatorBase.h"
9 
10 #include <vector>
11 
12 #include "eckit/config/Configuration.h"
13 #include "ioda/ObsSpace.h"
14 #include "oops/util/abor1_cpp.h"
15 #include "oops/util/Logger.h"
16 #include "ufo/Locations.h"
17 
18 namespace ufo {
19 
20 // -----------------------------------------------------------------------------
21 
22 std::unique_ptr<Locations> ObsOperatorBase::locations() const {
23  std::vector<float> lons(odb_.nlocs());
24  std::vector<float> lats(odb_.nlocs());
25  std::vector<util::DateTime> times(odb_.nlocs());
26  odb_.get_db("MetaData", "latitude", lats);
27  odb_.get_db("MetaData", "longitude", lons);
28  odb_.get_db("MetaData", "datetime", times);
29  return std::unique_ptr<Locations>(new Locations(lons, lats, times, odb_.distribution()));
30 }
31 
32 // -----------------------------------------------------------------------------
33 
34 oops::Variables ObsOperatorBase::simulatedVars() const {
35  return odb_.obsvariables();
36 }
37 
38 // -----------------------------------------------------------------------------
39 
40 ObsOperatorFactory::ObsOperatorFactory(const std::string & name) {
41  if (getMakers().find(name) != getMakers().end()) {
42  oops::Log::error() << name << " already registered in ufo::ObsOperatorFactory." << std::endl;
43  ABORT("Element already registered in ufo::ObsOperatorFactory.");
44  }
45  getMakers()[name] = this;
46 }
47 
48 // -----------------------------------------------------------------------------
49 
50 ObsOperatorBase * ObsOperatorFactory::create(const ioda::ObsSpace & odb,
51  const ObsOperatorParametersBase & params) {
52  oops::Log::trace() << "ObsOperatorBase::create starting" << std::endl;
53  const std::string &id = params.name.value().value();
54  typename std::map<std::string, ObsOperatorFactory*>::iterator jloc = getMakers().find(id);
55  if (jloc == getMakers().end()) {
56  oops::Log::error() << id << " does not exist in ufo::ObsOperatorFactory." << std::endl;
57  ABORT("Element does not exist in ufo::ObsOperatorFactory.");
58  }
59  ObsOperatorBase * ptr = jloc->second->make(odb, params);
60  oops::Log::trace() << "ObsOperatorBase::create done" << std::endl;
61  return ptr;
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 std::unique_ptr<ObsOperatorParametersBase>
67 ObsOperatorFactory::createParameters(const std::string &name) {
68  typename std::map<std::string, ObsOperatorFactory*>::iterator it =
69  getMakers().find(name);
70  if (it == getMakers().end()) {
71  throw std::runtime_error(name + " does not exist in ufo::ObsOperatorFactory");
72  }
73  return it->second->makeParameters();
74 }
75 
76 // -----------------------------------------------------------------------------
77 
78 } // namespace ufo
Locations class to handle simple lat-lon-time locations.
virtual std::unique_ptr< Locations > locations() const
Locations for GeoVaLs.
virtual oops::Variables simulatedVars() const
List of variables simulated by this operator.
const ioda::ObsSpace & odb_
ObsOperatorFactory(const std::string &name)
Register a maker able to create observation operators of type name.
static ObsOperatorBase * create(const ioda::ObsSpace &, const ObsOperatorParametersBase &params)
Create and return a new observation operator.
static std::map< std::string, ObsOperatorFactory * > & getMakers()
static std::unique_ptr< ObsOperatorParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of ObsOperatorParametersBase storing parameters of obse...
Base class of classes storing configuration parameters of specific observation operators and linear o...
oops::OptionalParameter< std::string > name
Observation operator type.
Definition: RunCRTM.h:27