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 #include "teca_array_attributes.h"
9 
10 #include <string>
11 #include <vector>
12 
13 #if defined(__CUDACC__)
14 #pragma nv_diag_suppress = partial_override
15 #endif
16 
17 TECA_SHARED_OBJECT_FORWARD_DECL(teca_derived_quantity)
18 
19 /// a programmable algorithm specialized for simple array based computations
20 /**
21  * A programmable algorithm specialized for simple array based computations. A
22  * user provided callable(see set execute_callback) which operates on one or more
23  * arrays(the dependent variables) to produce a new array (the derived quantity).
24  * The purpose of this class is to implement the request and report phases of the
25  * pipeline consistently for this common use case. An implementation specific
26  * context(operation_name) differentiates between multiple instances in the same
27  * pipeline.
28  */
30 {
31 public:
32  TECA_ALGORITHM_STATIC_NEW(teca_derived_quantity)
33  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_derived_quantity)
35 
36  //using teca_programmable_algorithm::get_class_name;
37 
38  // report/initialize to/from Boost program options
39  // objects.
40  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
41  TECA_SET_ALGORITHM_PROPERTIES()
42 
43  /// @name dependent_variables
44  /** Set/get the list of arrays that are needed to produce the derived
45  * quantity. This should include valid value masks if needed. See
46  * teca_valid_value_mask for more information.
47  */
48  /// @{
49  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, dependent_variable)
50  /// @}
51 
52  /// @name derived_variable
53  /** Set/get the names of the arrays and their attributes that are produced.
54  */
55  /// @{
56  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, derived_variable)
57  TECA_ALGORITHM_VECTOR_PROPERTY(teca_array_attributes, derived_variable_attribute)
58 
59  /** Add the names and attributes of the derived variables. Array attributes
60  * must be provided for parallel I/O using the teca_cf_writer.
61  */
62  void append_derived_variable(const std::string &name,
63  const teca_array_attributes &atts)
64  {
65  this->append_derived_variable(name);
66  this->append_derived_variable_attribute(atts);
67  }
68 
69  /** Set the name and attributes of the derived variable. Array attributes
70  * must be provided for parallel I/O using the teca_cf_writer.
71  */
72  void set_derived_variables(const std::vector<std::string> &names,
73  const std::vector<teca_array_attributes> &atts)
74  {
75  this->set_derived_variables(names);
76  this->set_derived_variable_attributes(atts);
77  }
78  /// @}
79 
80  /// @name operation name
81  /** Set the contextual name that differentiates this instance from others
82  * in the same pipeline.
83  */
84  /// @{
85  /// set the operation name
86  void set_operation_name(const std::string &op_name);
87 
88  /// get the operation name
89  const std::string &get_operation_name() const
90  { return this->operation_name; }
91 
92  /// get the operation name
93  std::string &get_operation_name()
94  { return this->operation_name; }
95  /// @}
96 
97  // set the callable that implements to derived quantity
98  // computation
101 
102 protected:
104 
105 private:
106  //using teca_algorithm::get_output_metadata;
107 
108  // specialized report and request implementations that
109  // process the input and output array lists in a standardized
110  // manner.
111  teca_metadata get_output_metadata(unsigned int port,
112  const std::vector<teca_metadata> &input_md) override;
113 
114  std::vector<teca_metadata> get_upstream_request(
115  unsigned int port, const std::vector<teca_metadata> &input_md,
116  const teca_metadata &request) override;
117 
118  // hide the programmable algorithm report request callbacks
121 
124 
125  // set the name used in log files.
126  int set_name(const std::string &name) override;
127 
128 private:
129  std::string operation_name;
130  std::vector<std::string> dependent_variables;
131  std::vector<std::string> derived_variables;
132  std::vector<teca_array_attributes> derived_variable_attributes;
133 };
134 
135 #if defined(__CUDACC__)
136 #pragma nv_diag_default = partial_override
137 #endif
138 #endif
a programmable algorithm specialized for simple array based computations
Definition: teca_derived_quantity.h:30
const std::string & get_operation_name() const
get the operation name
Definition: teca_derived_quantity.h:89
void set_derived_variables(const std::vector< std::string > &names, const std::vector< teca_array_attributes > &atts)
Definition: teca_derived_quantity.h:72
void set_operation_name(const std::string &op_name)
std::string & get_operation_name()
get the operation name
Definition: teca_derived_quantity.h:93
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
An algorithm implemented with user provided callbacks.
Definition: teca_programmable_algorithm.h:87
void set_request_callback(const request_callback_t &v)
Definition: teca_programmable_algorithm.h:153
const execute_callback_t & get_execute_callback() const
Definition: teca_programmable_algorithm.h:167
void set_report_callback(const report_callback_t &v)
Definition: teca_programmable_algorithm.h:140
const report_callback_t & get_report_callback() const
Definition: teca_programmable_algorithm.h:140
const request_callback_t & get_request_callback() const
Definition: teca_programmable_algorithm.h:153
void set_execute_callback(const execute_callback_t &v)
Definition: teca_programmable_algorithm.h:167
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
A convenience container for conventional array attributes necessary and/or useful when producing NetC...
Definition: teca_array_attributes.h:32