TECA
The Toolkit for Extreme Climate Analysis
teca_valid_value_mask.h
1 #ifndef teca_valid_value_mask_h
2 #define teca_valid_value_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 /// @name mask type aliases
13 ///@{
14 using NT_MASK = char;
19 using SP_MASK = std::shared_ptr<NT_MASK>;
20 using CSP_MASK = std::shared_ptr<const NT_MASK>;
21 ///@}
22 
23 TECA_SHARED_OBJECT_FORWARD_DECL(teca_valid_value_mask)
24 
25 /// an algorithm that computes a mask identifying valid values
26 /**
27  * For each requested mask, from its associated input array, compute a mask set to
28  * 1 where the data is valid and 0 everywhere else. Downstream algorithms then
29  * may look for the mask array and process the data in such a way as to produce
30  * valid results in the presence of missing data.
31  *
32  * Validity is determined by comparing the array's elements to the fill value as
33  * specified in the array's attributes _FillValue or missing_value field. If
34  * neither of these attribute fields are present then no mask is computed.
35  *
36  * The masks generated are stored in the output mesh with the same centering as
37  * the input variable they were generated from, and named using the variable's
38  * name with the string "_valid" appended. For example if a mask was generated for
39  * a variable named "V" it will be named "V_valid".
40  *
41  * Masks are requested for specific arrays in one of two ways. One may use the
42  * mask_arrays algorithm property to explicitly name the list of variables to
43  * compute masks for. Alternatively, a heuristic applied to incoming requests
44  * determines if masks should be generated. Specifically the string "_valid" is
45  * looked for at the end of each requested array. If it is found then the mask
46  * for the variable named by removing "_valid" is generated. For example the
47  * request for "V_valid" would result in the mask being generated for the variable
48  * "V".
49 */
51 {
52 public:
53  TECA_ALGORITHM_STATIC_NEW(teca_valid_value_mask)
54  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_valid_value_mask)
55  TECA_ALGORITHM_CLASS_NAME(teca_valid_value_mask)
57 
58  // report/initialize to/from Boost program options
59  // objects.
60  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
61  TECA_SET_ALGORITHM_PROPERTIES()
62 
63  /** @name mask_arrays
64  * explicitly set a list of input arrays to process. By default
65  * all arrays are processed. Use this property to compute masks
66  * for a subset of the arrays,
67  */
68  ///@{
69  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, mask_array)
70  ///@}
71 
72  /** @name enable_valid_range
73  * enable the use of valid_range, valid_min, valid_max attributes.
74  * by default this is off.
75  */
76  ///@{
77  TECA_ALGORITHM_PROPERTY(int, enable_valid_range)
78  ///@}
79 
80 protected:
82 
83 private:
84  using teca_algorithm::get_output_metadata;
85 
86  teca_metadata get_output_metadata(unsigned int port,
87  const std::vector<teca_metadata> &input_md) override;
88 
89  std::vector<teca_metadata> get_upstream_request(
90  unsigned int port, const std::vector<teca_metadata> &input_md,
91  const teca_metadata &request) override;
92 
93  const_p_teca_dataset execute(unsigned int port,
94  const std::vector<const_p_teca_dataset> &input_data,
95  const teca_metadata &request) override;
96 
97 private:
98  std::vector<std::string> mask_arrays;
99  int enable_valid_range;
100 };
101 
102 #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
an algorithm that computes a mask identifying valid values
Definition: teca_valid_value_mask.h:51
The concrete implementation of our type agnostic container for contiguous arrays.
Definition: teca_variant_array_impl.h:380
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
std::shared_ptr< const teca_variant_array_impl< T > > const_p_teca_variant_array_impl
Definition: teca_variant_array_impl.h:44
std::shared_ptr< teca_variant_array_impl< T > > p_teca_variant_array_impl
Definition: teca_variant_array_impl.h:44