TECA
The Toolkit for Extreme Climate Analysis
teca_2d_component_area.h
1 #ifndef teca_2d_component_area_h
2 #define teca_2d_component_area_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_2d_component_area)
12 
13 /// An algorithm that computes the areas of labeled regions
14 /**
15  * Given a set of labels on a Cartesian mesh, the algorithm computes the area
16  * of each region. Regions are identified by assigning a unique integer value
17  * to each mesh point that belongs in the region. The component_variable
18  * property names the variable containing the region labels.
19  *
20  * if the region labels start at 0 and are contiguous then an optimization can
21  * be used. Set contiguous_component_ids property to enable the optimization.
22  * Note that TECA's connected component labeler assigns the background (i.e.
23  * cells not inside the segmentation) the label 0. One can identify the
24  * background region and area via this label. When processing data generated
25  * outside of TECA it might be necessary to supply the background label. Use -2
26  * if there is no background.
27  *
28  * the input dataset is passed through and the results of the calculations are
29  * stored in the output dataset metadata in the following keys:
30  *
31  * | name | description |
32  * | ---- | ----------- |
33  * | number_of_components | number of component ids for which area was |
34  * | | computed. Note that this can include a background |
35  * | | component i.e. for cells outside of the segmentation. |
36  * | component_ids | a vector containing the label of each component. This is |
37  * | | always starts with 0, where the label 0 identifies |
38  * | | cells out side of the segmentation, and ranges up |
39  * | | to number_of_components - 1, where the labels from |
40  * | | 1 up to number_of_components - 1 identify |
41  * | | connected regions of cells inside the segmentation. |
42  * | component_area | a vector containing the area for the corresponding |
43  * | | entry in the component_ids array. |
44  * | background_id | the label used for cells outside of the segmentation, |
45  * | | i.e. the background. This can be used to skip processing |
46  * | | of the background when desirable. |
47 */
49 {
50 public:
51  TECA_ALGORITHM_STATIC_NEW(teca_2d_component_area)
52  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_2d_component_area)
53  TECA_ALGORITHM_CLASS_NAME(teca_2d_component_area)
55 
56  /** @name program_options
57  * report/initialize to/from Boost program options objects.
58  */
59  ///@{
60  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
61  TECA_SET_ALGORITHM_PROPERTIES()
62  ///@}
63 
64  /** @name component_variable
65  * Sets the name of the array containing component labels to compute the
66  * area of.
67  */
68  ///@{
69  TECA_ALGORITHM_PROPERTY(std::string, component_variable)
70  ///@}
71 
72  /** @name contiguous_component_ids
73  * set this only if you know for certain that label ids are contiguous and
74  * start at 0. this enables use of a faster implementation.
75  */
76  ///@{
77  TECA_ALGORITHM_PROPERTY(int, contiguous_component_ids)
78  ///@}
79 
80  /** @name background_id
81  * set this to override the component label used for background. By default
82  * this is set to -1 to indicate that the value should be obtained from the
83  * metadata key `background_id`. Note that TECA's connected component
84  * labeler uses the id 0 for the background and passes this in a metadata
85  * key and as a result no action is required.
86  */
87  ///@{
88  TECA_ALGORITHM_PROPERTY(long, background_id)
89  ///@}
90 
91 protected:
93 
94  int get_component_variable(std::string &component_var);
95 
96 private:
97  using teca_algorithm::get_output_metadata;
98 
99  teca_metadata get_output_metadata(
100  unsigned int port,
101  const std::vector<teca_metadata> &input_md) override;
102 
103  std::vector<teca_metadata> get_upstream_request(
104  unsigned int port,
105  const std::vector<teca_metadata> &input_md,
106  const teca_metadata &request) override;
107 
108  const_p_teca_dataset execute(
109  unsigned int port,
110  const std::vector<const_p_teca_dataset> &input_data,
111  const teca_metadata &request) override;
112 
113 private:
114  std::string component_variable;
115  int contiguous_component_ids;
116  long background_id;
117 };
118 
119 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_2d_component_area
An algorithm that computes the areas of labeled regions.
Definition: teca_2d_component_area.h:48
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