TECA
The Toolkit for Extreme Climate Analysis
teca_binary_segmentation.h
1 #ifndef teca_binary_segmentation_h
2 #define teca_binary_segmentation_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_binary_segmentation)
12 
13 /// An algorithm that computes a binary segmentation.
14 /**
15  * an algorithm that computes a binary segmentation for 1D, 2D, and 3D data.
16  * The segmentation is computed using threshold operation where values in a
17  * range (low, high] are in the segmentation (assigned 1). Values outside the
18  * range are outside of the segmentation (assigned 0).
19  *
20  * The algorithm has 2 modes, BY_VALUE and BY_PERCENTILE. In the BY_VALUE mode,
21  * the test for inclusion is applied on the raw data. In the BY_PERCENTILE mode
22  * the range is given in percentiles and each data point is converted to a
23  * percentile before applying the test for inclusion.
24 */
26 {
27 public:
28  TECA_ALGORITHM_STATIC_NEW(teca_binary_segmentation)
29  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_binary_segmentation)
30  TECA_ALGORITHM_CLASS_NAME(teca_binary_segmentation)
32 
33  /** @name segmentation_variable
34  * set the name of the output array to store the resulting segmentation in
35  */
36  ///@{
37  TECA_ALGORITHM_PROPERTY(std::string, segmentation_variable)
38  ///@}
39 
40 
41  /** @name segmentation_variable_attributes
42  * set extra metadata for the segmentation variable
43  */
44  ///@{
45  TECA_ALGORITHM_PROPERTY(teca_metadata, segmentation_variable_attributes)
46  ///@}
47 
48 
49  /** @name threshold_variable
50  * set the name of the input array to segment
51  */
52  ///@{
53  TECA_ALGORITHM_PROPERTY(std::string, threshold_variable)
54  ///@}
55 
56  /** @name low_threshold_value
57  * Set the threshold range. The defaults are (-infinity, infinity].
58  */
59  ///@{
60  TECA_ALGORITHM_PROPERTY(double, low_threshold_value)
61  ///@}
62 
63  /** @name high_threshold_value
64  * Set the threshold range. The defaults are (-infinity, infinity].
65  */
66  ///@{
67  TECA_ALGORITHM_PROPERTY(double, high_threshold_value)
68  ///@}
69 
70  /** @name threshold_mode
71  * Set the threshold mode. In BY_PERCENTILE mode low and high thresholds
72  * define the percentiles (0 to 100) between which data is in the
73  * segmentation. default is BY_VALUE.
74  */
75  ///@{
76  /// The threshold_mode modes
77  enum {BY_VALUE=0, BY_PERCENTILE=1};
78 
79  TECA_ALGORITHM_PROPERTY(int, threshold_mode)
80 
81  /// Set the threshold_mode to percentile.
82  void set_threshold_by_percentile() { set_threshold_mode(BY_PERCENTILE); }
83 
84  /// Set the threshold_mode to value.
85  void set_threshold_by_value() { set_threshold_mode(BY_VALUE); }
86  ///@}
87 
88 protected:
90 
91  int get_segmentation_variable(std::string &segmentation_var);
92  int get_threshold_variable(std::string &threshold_var);
93 
94 private:
96 
97  teca_metadata get_output_metadata(unsigned int port,
98  const std::vector<teca_metadata> &input_md) override;
99 
100  std::vector<teca_metadata> get_upstream_request(
101  unsigned int port, const std::vector<teca_metadata> &input_md,
102  const teca_metadata &request) override;
103 
104  const_p_teca_dataset execute(unsigned int port,
105  const std::vector<const_p_teca_dataset> &input_data,
106  const teca_metadata &request) override;
107 
108 private:
109  std::string segmentation_variable;
110  teca_metadata segmentation_variable_attributes;
111  std::string threshold_variable;
112  double low_threshold_value;
113  double high_threshold_value;
114  int threshold_mode;
115 };
116 
117 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_algorithm::get_output_metadata
virtual teca_metadata get_output_metadata(unsigned int port, const std::vector< teca_metadata > &input_md)
teca_binary_segmentation
An algorithm that computes a binary segmentation.
Definition: teca_binary_segmentation.h:25
teca_binary_segmentation::set_threshold_by_value
void set_threshold_by_value()
Set the threshold_mode to value.
Definition: teca_binary_segmentation.h:85
teca_shared_object.h
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
teca_algorithm
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237