TECA
The Toolkit for Extreme Climate Analysis
teca_shape_file_mask.h
1 #ifndef teca_shape_file_mask_h
2 #define teca_shape_file_mask_h
3 
4 #include "teca_config.h"
5 #include "teca_shared_object.h"
6 #include "teca_algorithm.h"
7 #include "teca_metadata.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_shape_file_mask)
13 
14 /// Generates a valid value mask defined by regions in the given ESRI shape file
15 /** The teca_shape_file_mask generates a mask on a 2D mesh where mesh points
16  * are assigned a value of 1 where they fall inside any one of the polygons
17  * defined in the named ESRI shape file, and 0 everywhere else. The input mesh
18  * is passed through to the output with the mask added. By default a transform
19  * on the x coordinates of the polygons from [-180, 180] to [0, 360] is
20  * applied. If this is undesirable it can be disabled by setting the
21  * normalize_coordinates property to 0.
22  *
23  * @attention Currently there is no check on the coordinate system specified in
24  * the shapefile. This could result in a mask of all zeros when the shapefile
25  * and input mesh use a different coodinate system.
26  */
28 {
29 public:
30  TECA_ALGORITHM_STATIC_NEW(teca_shape_file_mask)
31  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_shape_file_mask)
32  TECA_ALGORITHM_CLASS_NAME(teca_shape_file_mask)
34 
35  // report/initialize to/from Boost program options
36  // objects.
37  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
38  TECA_SET_ALGORITHM_PROPERTIES()
39 
40  /** @name shape_file
41  * Set the path to the shape file. This file is read by MPI rank 0 and
42  * distributed to the others in parallel runs
43  */
44  ///@{
45  TECA_ALGORITHM_PROPERTY(std::string, shape_file)
46  ///@}
47 
48  /** @name mask_variables
49  * set the names of the variables to store the generated mask in
50  * each variable will contain a reference to the mask
51  */
52  ///@{
53  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, mask_variable)
54  ///@}
55 
56  /** @name normalize_coordinates
57  * set this flag to transform the x coordinates from [-180, 180] to
58  * [0, 360]
59  */
60  ///@{
61  TECA_ALGORITHM_PROPERTY(int, normalize_coordinates)
62  ///@}
63 
64  /** @name number_of_cuda_streams
65  * sets the number of streams to use when searching the mesh for polygon
66  * intersections.
67  */
68  ///@{
69  TECA_ALGORITHM_PROPERTY(int, number_of_cuda_streams)
70  ///@}
71 
72 protected:
74 
75  /// overriden so that cached data is cleared
76  void set_modified() override;
77 
78  /// generate attributes for the output arrays
79  teca_metadata get_mask_array_attributes(unsigned long size);
80 
81 private:
82  using teca_algorithm::get_output_metadata;
83 
84  teca_metadata get_output_metadata(
85  unsigned int port,
86  const std::vector<teca_metadata> &input_md) override;
87 
88  std::vector<teca_metadata> get_upstream_request(
89  unsigned int port,
90  const std::vector<teca_metadata> &input_md,
91  const teca_metadata &request) override;
92 
93  const_p_teca_dataset execute(
94  unsigned int port,
95  const std::vector<const_p_teca_dataset> &input_data,
96  const teca_metadata &request) override;
97 
98 private:
99  std::string shape_file;
100  std::vector<std::string> mask_variables;
101  int normalize_coordinates;
102  int number_of_cuda_streams;
103 
104  struct internals_t;
105  internals_t *internals;
106 };
107 
108 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
Generates a valid value mask defined by regions in the given ESRI shape file.
Definition: teca_shape_file_mask.h:28
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.