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