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:
64  teca_metadata get_output_metadata(
65  unsigned int port,
66  const std::vector<teca_metadata> &input_md) override;
67 
68  std::vector<teca_metadata> get_upstream_request(
69  unsigned int port,
70  const std::vector<teca_metadata> &input_md,
71  const teca_metadata &request) override;
72 
73  const_p_teca_dataset execute(
74  unsigned int port,
75  const std::vector<const_p_teca_dataset> &input_data,
76  const teca_metadata &request) override;
77 
78  int validate_output_data_type(int val);
79 
80 private:
81  int output_data_type;
82 };
83 
84 #endif
teca_variant_array.h
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_unpack_data::set_output_data_type_to_double
void set_output_data_type_to_double()
set the output data type to single precision floating point
Definition: teca_unpack_data.h:56
teca_shared_object.h
teca_unpack_data
an algorithm that unpacks NetCDF packed values
Definition: teca_unpack_data.h:30
teca_algorithm
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237