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