TECA
The Toolkit for Extreme Climate Analysis
teca_unpack_data.h
1 #ifndef teca_unpack_data_h
2 #define teca_unpack_data_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 #include "teca_variant_array.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_unpack_data)
13 
14 /// an algorithm that unpacks NetCDF packed values
15 /**
16  * Applies a data transform according to the NetCDF attribute conventions for
17  * packed data values.
18  * https://www.unidata.ucar.edu/software/netcdf/docs/attribute_conventions.html
19  *
20  * Variables in the input dataset are scanned for the presence
21  * of the `scale_factor` and `add_offset` attributes. When both are present
22  * an element wise transformation is applied such that
23  *
24  * out[i] = scale_factor * in[i] + add_offset
25  *
26  * The input array is expected to be an integer type while the type of the output
27  * array may be either float or double. Valid value masks may be necessary for
28  * correct results, see `teca_valid_value_mask`.
29 */
31 {
32 public:
33  TECA_ALGORITHM_STATIC_NEW(teca_unpack_data)
34  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_unpack_data)
35  TECA_ALGORITHM_CLASS_NAME(teca_unpack_data)
37 
38  // report/initialize to/from Boost program options
39  // objects.
40  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
41  TECA_SET_ALGORITHM_PROPERTIES()
42 
43  /** @name output_data_type
44  * set the output data type. use teca_variant_array_code<T>::get() to get
45  * the numeric code corresponding to the data type T. The default output
46  * data type is single precision floating point.
47  */
48  ///@{
49  TECA_ALGORITHM_PROPERTY_V(int, output_data_type)
50 
51  /// set the output data type to double precision floating point
52  void set_output_data_type_to_float()
53  { this->set_output_data_type(teca_variant_array_code<float>::get()); }
54 
55  /// set the output data type to single precision floating point
57  { this->set_output_data_type(teca_variant_array_code<double>::get()); }
58  ///@}
59 
60 protected:
62 
63 private:
65 
66  teca_metadata get_output_metadata(
67  unsigned int port,
68  const std::vector<teca_metadata> &input_md) override;
69 
70  std::vector<teca_metadata> get_upstream_request(
71  unsigned int port,
72  const std::vector<teca_metadata> &input_md,
73  const teca_metadata &request) override;
74 
75  const_p_teca_dataset execute(
76  unsigned int port,
77  const std::vector<const_p_teca_dataset> &input_data,
78  const teca_metadata &request) override;
79 
80  int validate_output_data_type(int val);
81 
82 private:
83  int output_data_type;
84 };
85 
86 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
virtual teca_metadata get_output_metadata(unsigned int port, const std::vector< teca_metadata > &input_md)
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
an algorithm that unpacks NetCDF packed values
Definition: teca_unpack_data.h:31
void set_output_data_type_to_double()
set the output data type to single precision floating point
Definition: teca_unpack_data.h:56
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.