TECA
The Toolkit for Extreme Climate Analysis
teca_temporal_reduction.h
1 #ifndef teca_cpp_temporal_reduction_h
2 #define teca_cpp_temporal_reduction_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_threaded_algorithm.h"
6 #include "teca_variant_array.h"
7 #include "teca_metadata.h"
8 
9 #include <string>
10 #include <vector>
11 #include <map>
12 
13 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cpp_temporal_reduction)
14 
15 /**
16  * Reduce a mesh across the time dimensions by a defined increment using
17  * a defined operation.
18  *
19  * time increments: daily, monthly, seasonal, yearly, n_steps, all
20  * reduction operations: average, summation, minimum, maximum
21  *
22  * The output time axis will be defined using the selected increment.
23  * The output data will be accumulated/reduced using the selected
24  * operation.
25  *
26  * By default the fill value will be obtained from metadata stored in the
27  * NetCDF CF file (_FillValue). One may override this by explicitly calling
28  * set_fill_value method with the desired fill value.
29  *
30  * For minimum and maximum operations, at given grid point only valid values
31  * over the interval are used in the calculation. If there are no valid
32  * values over the interval at the grid point it is set to the fill_value.
33  *
34  * For the averaging operation, during summation missing values are treated
35  * as 0.0 and a per-grid point count of valid values over the interval is
36  * maintained and used in the average. Grid points with no valid values over
37  * the interval are set to the fill value.
38  */
40 {
41 public:
42  TECA_ALGORITHM_STATIC_NEW(teca_cpp_temporal_reduction)
43  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_cpp_temporal_reduction)
44  TECA_ALGORITHM_CLASS_NAME(teca_cpp_temporal_reduction)
46 
47  // report/initialize to/from Boost program options
48  // objects.
49  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
50  TECA_SET_ALGORITHM_PROPERTIES()
51 
52  /** @name point_arrays
53  * Set the list of arrays to reduce
54  */
55  ///@{
56  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, point_array)
57  ///@}
58 
59  /** @name operation
60  * Set the reduction operation
61  * default average
62  */
63  ///@{
64  enum {
65  average, ///< Set the reduction operation to average
66  summation, ///< Set the reduction operation to summation
67  minimum, ///< Set the reduction operation to minimum
68  maximum ///< Set the reduction operation to maximum
69  };
70 
71  TECA_ALGORITHM_PROPERTY(int, operation)
72 
73  int set_operation(const std::string &operation);
74 
75  std::string get_operation_name();
76  ///@}
77 
78  /** @name interval
79  * Set the type of interval iterator to create
80  * default monthly
81  */
82  ///@{
83  enum {
84  daily = 2, ///< Set the time increment to daily
85  monthly = 3, ///< Set the time increment to monthly
86  seasonal = 4, ///< Set the time increment to seasonal
87  yearly = 5, ///< Set the time increment to yearly
88  n_steps = 6, ///< Set the time increment to n steps
89  all = 7 ///< Set the time increment to all
90  };
91 
92  TECA_ALGORITHM_PROPERTY(int, interval)
93 
94  int set_interval(const std::string &interval);
95 
96  std::string get_interval_name();
97  ///@}
98 
99  /** @number_of_steps
100  * For n_steps interval iterator,
101  * the desired number of steps should be set.
102  * default 0
103  */
104  ///@{
105  TECA_ALGORITHM_PROPERTY(long, number_of_steps)
106  ///@}
107 
108  /** @name fill_value
109  * Set the _FillValue attribute for the output data
110  * default -1
111  */
112  ///@{
113  TECA_ALGORITHM_PROPERTY(double, fill_value)
114  ///@}
115 
116  /** @step_per_request
117  * Set the number of time steps per request
118  * default 1
119  */
120  ///@{
121  TECA_ALGORITHM_PROPERTY(long, steps_per_request)
122  ///@}
123 
124 protected:
126 
127 private:
128  teca_metadata get_output_metadata(
129  unsigned int port,
130  const std::vector<teca_metadata> &md_in) override;
131 
132  std::vector<teca_metadata> get_upstream_request(
133  unsigned int port,
134  const std::vector<teca_metadata> &md_in,
135  const teca_metadata &req_in) override;
136 
137  const_p_teca_dataset execute(
138  unsigned int port,
139  const std::vector<const_p_teca_dataset> &data_in,
140  const teca_metadata &req_in,
141  int streaming) override;
142 
143  using teca_algorithm::get_output_metadata;
144  using teca_threaded_algorithm::execute;
145 
146 private:
147  std::vector<std::string> point_arrays;
148  int operation;
149  int interval;
150  long number_of_steps;
151  double fill_value;
152  long steps_per_request;
153 
154  class internals_t;
155  internals_t *internals;
156 };
157 
158 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
Definition: teca_temporal_reduction.h:40
@ average
Set the reduction operation to average.
Definition: teca_temporal_reduction.h:65
@ minimum
Set the reduction operation to minimum.
Definition: teca_temporal_reduction.h:67
@ summation
Set the reduction operation to summation.
Definition: teca_temporal_reduction.h:66
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
This is the base class defining a threaded algorithm.
Definition: teca_threaded_algorithm.h:71
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.