TECA
teca_cartesian_mesh_source.h
1 #ifndef teca_cartesian_mesh_source_h
2 #define teca_cartesian_mesh_source_h
3 
4 #include "teca_algorithm.h"
5 #include "teca_metadata.h"
6 
7 #include <functional>
8 #include <map>
9 #include <utility>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cartesian_mesh_source)
12 
13 // f(x, y, z, t)
14 // given spatial coordinate axes x,y,z and the time t, return the field
15 using field_generator_callback = std::function<p_teca_variant_array(
16  const const_p_teca_variant_array &, const const_p_teca_variant_array &,
17  const const_p_teca_variant_array &, double)>;
18 
20 {
21  std::string name;
22  teca_metadata attributes;
23  field_generator_callback generator;
24 };
25 
26 inline
27 bool operator==(const field_generator &l, const field_generator &r)
28 {
29  return l.name == r.name;
30 }
31 
32 inline
33 bool operator!=(const field_generator &l, const field_generator &r)
34 {
35  return l.name != r.name;
36 }
37 
39 
45 {
46 public:
47  TECA_ALGORITHM_STATIC_NEW(teca_cartesian_mesh_source)
48  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_cartesian_mesh_source)
49  TECA_ALGORITHM_CLASS_NAME(teca_cartesian_mesh_source)
51 
52  // report/initialize to/from Boost program options
53  // objects.
54  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
55  TECA_SET_ALGORITHM_PROPERTIES()
56 
57  // set/get the type code for generated coordinates.
58  // default is a 64 bit floating point type. Use
59  // teca_variant_array_code<NT>::get() to get specific type
60  // codes for C++ POD types NT.
61  TECA_ALGORITHM_PROPERTY(unsigned int, coordinate_type_code)
62  TECA_ALGORITHM_PROPERTY(unsigned int, field_type_code)
63 
64  // set/get the global index space extent of the data. the extents are
65  // given by 8 values, 6 spatial plus 2 temporal, in the following order
66  // [i0 i1 j0 j1 k0 k1 q0 q1]
67  // this should be the same on all ranks elements.
68  TECA_ALGORITHM_VECTOR_PROPERTY(unsigned long, whole_extent)
69 
70  // set/get the global bounds of the data. the bounds are 8 values 6 spatial
71  // plus 2 temporal in the following order.
72  // [x0 x1 y0 y1 z0 z1 t0 t1]
73  // this should be the same on all ranks elements.
74  TECA_ALGORITHM_VECTOR_PROPERTY(double, bound)
75 
76  // set the variable to use for the coordinate axes.
77  // the defaults are: x => lon, y => lat, z = plev,
78  // t => time
79  TECA_ALGORITHM_PROPERTY(std::string, x_axis_variable)
80  TECA_ALGORITHM_PROPERTY(std::string, y_axis_variable)
81  TECA_ALGORITHM_PROPERTY(std::string, z_axis_variable)
82  TECA_ALGORITHM_PROPERTY(std::string, t_axis_variable)
83 
84  // set the units of spatial axes. The defaults are:
85  // degrees_east, degrees_north, and pressure_level
86  TECA_ALGORITHM_PROPERTY(std::string, x_axis_units)
87  TECA_ALGORITHM_PROPERTY(std::string, y_axis_units)
88  TECA_ALGORITHM_PROPERTY(std::string, z_axis_units)
89 
90  // set the calendar and time units
91  TECA_ALGORITHM_PROPERTY(std::string, calendar)
92  TECA_ALGORITHM_PROPERTY(std::string, time_units)
93 
94  // set the named callbacks to generate fields on the mesh. A callback
95  // function must have the signature f(x,y,z,t).
96  TECA_ALGORITHM_VECTOR_PROPERTY(field_generator_t, field_generator);
97 
98  // set a callback function f(x,y,z,t) that generates a field named name
99  // x,y,z are coordinate axes in variant arrays, t is the double precision
100  // time value.
101  void append_field_generator(const std::string &name,
102  const teca_metadata &atts, field_generator_callback &callback);
103 
104 protected:
106 
107 private:
108  teca_metadata get_output_metadata(unsigned int port,
109  const std::vector<teca_metadata> &input_md) override;
110 
111  const_p_teca_dataset execute(unsigned int port,
112  const std::vector<const_p_teca_dataset> &input_data,
113  const teca_metadata &request) override;
114 
115  void set_modified() override;
116  void clear_cached_metadata();
117 
118 private:
119  unsigned int coordinate_type_code;
120  unsigned int field_type_code;
121  std::string x_axis_variable;
122  std::string y_axis_variable;
123  std::string z_axis_variable;
124  std::string t_axis_variable;
125  std::string x_axis_units;
126  std::string y_axis_units;
127  std::string z_axis_units;
128  std::string calendar;
129  std::string time_units;
130  std::vector<unsigned long> whole_extents;
131  std::vector<double> bounds;
132 
133  std::vector<field_generator_t> field_generators;
134 
135  struct internals_t;
136  internals_t *internals;
137 };
138 
139 #endif
teca_metadata
Definition: teca_metadata.h:17
field_generator
Definition: teca_cartesian_mesh_source.h:20
teca_cartesian_mesh_source::internals_t
Definition: teca_cartesian_mesh_source.cxx:17
teca_cartesian_mesh_source
Definition: teca_cartesian_mesh_source.h:45
teca_algorithm
Definition: teca_algorithm.h:25