TECA
The Toolkit for Extreme Climate Analysis
teca_derived_quantity.h
1 #ifndef teca_derived_quantity_h
2 #define teca_derived_quantity_h
3 
4 #include "teca_programmable_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_dataset.h"
7 #include "teca_shared_object.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_derived_quantity)
13 
14 /// a programmable algorithm specialized for simple array based computations
15 /**
16  * A programmable algorithm specialized for simple array based computations. A
17  * user provided callable(see set execute_callback) which operates on one or more
18  * arrays(the dependent variables) to produce a new array (the derived quantity).
19  * The purpose of this class is to implement the request and report phases of the
20  * pipeline consistently for this common use case. An implementation specific
21  * context(operation_name) differentiates between multiple instances in the same
22 pipeline.
23 */
25 {
26 public:
27  TECA_ALGORITHM_STATIC_NEW(teca_derived_quantity)
28  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_derived_quantity)
30 
31  //using teca_programmable_algorithm::get_class_name;
32 
33  // report/initialize to/from Boost program options
34  // objects.
35  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
36  TECA_SET_ALGORITHM_PROPERTIES()
37 
38  // set/get the list of arrays that are needed to produce
39  // the derived quantity
40  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, dependent_variable)
41 
42  // set/get the array that is produced
43  TECA_ALGORITHM_PROPERTY(std::string, derived_variable)
44 
45  // set/get the contextual name that differentiates this
46  // instance from others in the same pipeline.
47  void set_operation_name(const std::string &v);
48 
49  const std::string &get_operation_name() const
50  { return this->operation_name; }
51 
52  std::string &get_operation_name()
53  { return this->operation_name; }
54 
55  // set the callable that implements to derived quantity
56  // computation
59 
60 protected:
62 
63 private:
64  // specialized report and request implementations that
65  // process the input and output array lists in a standardized
66  // manner.
67  teca_metadata get_output_metadata(unsigned int port,
68  const std::vector<teca_metadata> &input_md) override;
69 
70  std::vector<teca_metadata> get_upstream_request(
71  unsigned int port, const std::vector<teca_metadata> &input_md,
72  const teca_metadata &request) override;
73 
74  // hide the programmable algorithm report request callbacks
77 
80 
81  // extracts variable from incoming request if the property
82  // is not set
83  std::string get_derived_variable(const teca_metadata &request);
84 
85  // extracts dependent variables from the incoming request
86  // if the coresponding property is not set
87  void get_dependent_variables(const teca_metadata &request,
88  std::vector<std::string> &dep_vars);
89 
90  // set the name used in log files.
91  int set_name(const std::string &name) override;
92 
93 private:
94  std::string operation_name;
95  std::vector<std::string> dependent_variables;
96  std::string derived_variable;
97 };
98 
99 #endif
teca_derived_quantity
a programmable algorithm specialized for simple array based computations
Definition: teca_derived_quantity.h:24
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_programmable_algorithm::get_request_callback
const request_callback_t & get_request_callback() const
Definition: teca_programmable_algorithm.h:129
teca_programmable_algorithm::get_report_callback
const report_callback_t & get_report_callback() const
Definition: teca_programmable_algorithm.h:116
teca_programmable_algorithm::set_execute_callback
void set_execute_callback(const execute_callback_t &v)
Definition: teca_programmable_algorithm.h:141
teca_programmable_algorithm::set_report_callback
void set_report_callback(const report_callback_t &v)
Definition: teca_programmable_algorithm.h:116
teca_programmable_algorithm::get_execute_callback
const execute_callback_t & get_execute_callback() const
Definition: teca_programmable_algorithm.h:141
teca_programmable_algorithm
An algorithm implemented with user provided callbacks.
Definition: teca_programmable_algorithm.h:85
teca_programmable_algorithm::set_request_callback
void set_request_callback(const request_callback_t &v)
Definition: teca_programmable_algorithm.h:129
teca_shared_object.h