TECA
The Toolkit for Extreme Climate Analysis
teca_bayesian_ar_detect.h
1 #ifndef teca_bayesian_ar_detect_h
2 #define teca_bayesian_ar_detect_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <string>
9 #include <vector>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_bayesian_ar_detect)
12 
13 /// The TECA BARD atmospheric river detector.
14 /**
15  * Given a point wise IVT (integrated vapor transport) field and a training
16  * parameter table computes the point wise probability of an atmospheric river
17  * using the TECA BARD algorithm.
18  *
19  * Required inputs:
20  *
21  * 1. IVT (integrated vapor transport) array on a Cartesian nesh.
22  * 2. a compatible parameter table. columns of which are : min IVT,
23  * component area, HWHM lattitude
24  *
25  * The names of the input varibale and columns can be specified at run time
26  * through algorithm properties.
27  *
28  * Produces:
29  *
30  * A Cartesian mesh with probability of an AR stored in the point centered
31  * array named "ar_probability". The diagnostic quantites "ar_count" amd
32  * "parameter_table_row" are stored in information arrays.
33  *
34  * For more information see:
35  *
36  * O’Brien, T. A., Risser, M. D., Loring, B., Elbashandy, A. A., Krishnan, H.,
37  * Johnson, J., Patricola, C. M., O’Brien, J. P., Mahesh, A., Arriaga Ramirez,
38  * S., Rhoades, A. M., Charn, A., Inda Díaz, H., & Collins, W. D. (2020).
39  * Detection of atmospheric rivers with inline uncertainty quantification:
40  * TECA-BARD v1.0.1. Geoscientific Model Development, 13(12), 6131–6148.
41  * https://doi.org/10.5194/gmd-13-6131-2020
42 */
44 {
45 public:
46  TECA_ALGORITHM_STATIC_NEW(teca_bayesian_ar_detect)
47  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_bayesian_ar_detect)
48  TECA_ALGORITHM_CLASS_NAME(teca_bayesian_ar_detect)
50 
51  // report/initialize to/from Boost program options
52  // objects.
53  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
54  TECA_SET_ALGORITHM_PROPERTIES()
55 
56  /** @name ivt_variable
57  * Sets the name of the array containing the IVT field to detect ARs in.
58  */
59  ///@{
60  TECA_ALGORITHM_PROPERTY(std::string, ivt_variable)
61  ///@}
62 
63  /** @name min_ivt_variable
64  * Set the names of the minimum IVT column in the parameter table.
65  */
66  ///@{
67  TECA_ALGORITHM_PROPERTY(std::string, min_ivt_variable)
68  ///@}
69 
70  /** @name min_component_area_variable
71  * Set the names of the minimum area column in the parameter table.
72  */
73  ///@{
74  TECA_ALGORITHM_PROPERTY(std::string, min_component_area_variable)
75  ///@}
76 
77  /** @name hwhm_latitude_variable
78  * Set the names of the HWHM column in the parameter table.
79  */
80  ///@{
81  TECA_ALGORITHM_PROPERTY(std::string, hwhm_latitude_variable)
82  ///@}
83 
84  /** @name probability variable
85  * Set the name of the variable to store output probability as.
86  */
87  ///@{
88  TECA_ALGORITHM_PROPERTY(std::string, ar_probability_variable)
89  ///@}
90 
91  /** Set the number of threads in the pool. Setting to -1 results in a
92  * thread per core factoring in all MPI ranks running on the node. the
93  * default is -1.
94  * @note this constructs the thread pool. properties that affect the thread
95  * pool must be set before construction.
96  */
97  void set_thread_pool_size(int n_threads);
98 
99  /// Get the number of threads in the pool.
100  unsigned int get_thread_pool_size() const noexcept;
101 
102  /** @name bind_threads
103  * set/get thread affinity mode. When 0 threads are not bound CPU cores,
104  * allowing for migration among all cores. This will likely degrade
105  * performance. Default is 1.
106  */
107  ///@{
108  TECA_ALGORITHM_PROPERTY(int, bind_threads)
109  ///@}
110 
111  /** @name stream_size
112  * set the smallest number of datasets to gather per call to execute. the
113  * default (-1) results in all datasets being gathered. In practice more
114  * datasets will be returned if ready
115  */
116  ///@{
117  TECA_ALGORITHM_PROPERTY(int, stream_size)
118  ///@}
119 
120  /** @name poll_interval
121  * set the duration in nanoseconds to wait between checking for completed
122  * tasks
123  */
124  ///@{
125  TECA_ALGORITHM_PROPERTY(long long, poll_interval)
126  ///@}
127 
128  /** @name threads_per_device
129  * Set the number of threads to service each GPU/device. Other threads will
130  * use the CPU.
131  */
132  ///@{
133  TECA_ALGORITHM_PROPERTY(int, threads_per_device)
134  ///@}
135 
136  /** @name ranks_per_device
137  * Set the number of ranks that have access to each GPU/device. Other ranks
138  * will use the CPU.
139  */
140  ///@{
141  TECA_ALGORITHM_PROPERTY(int, ranks_per_device)
142  ///@}
143 
144  /** @name propagate_device_assignment
145  * When set device assignment is taken from down stream request.
146  * Otherwise the thread executing the pipeline will provide the assignment.
147  */
148  ///@{
149  TECA_ALGORITHM_PROPERTY(int, propagate_device_assignment)
150  ///@}
151 
152  /** override the input connections because we are going to take the first
153  * input and use it to generate metadata. the second input then becomes
154  * the only one the pipeline knows about.
155  */
156  void set_input_connection(unsigned int id,
157  const teca_algorithm_output_port &port) override;
158 
159 protected:
161 
162  std::string get_label_variable(const teca_metadata &request);
163 
164 private:
165  using teca_algorithm::get_output_metadata;
166 
167  teca_metadata get_output_metadata(unsigned int port,
168  const std::vector<teca_metadata> &input_md) override;
169 
170  std::vector<teca_metadata> get_upstream_request(
171  unsigned int port, const std::vector<teca_metadata> &input_md,
172  const teca_metadata &request) override;
173 
174  const_p_teca_dataset execute(unsigned int port,
175  const std::vector<const_p_teca_dataset> &input_data,
176  const teca_metadata &request) override;
177 
178  void set_modified() override;
179 
180 private:
181  std::string ivt_variable;
182  std::string min_component_area_variable;
183  std::string min_ivt_variable;
184  std::string hwhm_latitude_variable;
185  std::string ar_probability_variable;
186  int thread_pool_size;
187  int bind_threads;
188  int stream_size;
189  long long poll_interval;
190  int threads_per_device;
191  int ranks_per_device;
192  int propagate_device_assignment;
193 
194  struct internals_t;
195  internals_t *internals;
196 };
197 
198 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
The TECA BARD atmospheric river detector.
Definition: teca_bayesian_ar_detect.h:44
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.