TECA
The Toolkit for Extreme Climate Analysis
teca_wrf_reader.h
1 #ifndef teca_wrf_reader_h
2 #define teca_wrf_reader_h
3 
4 #include "teca_config.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 #include "teca_shared_object.h"
8 
9 #include <vector>
10 #include <string>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_wrf_reader)
13 
14 class teca_wrf_reader_internals;
15 using p_teca_wrf_reader_internals = std::shared_ptr<teca_wrf_reader_internals>;
16 
17 /// A reader for data stored in WRF ARW format.
18 /**
19  * Reads a set of arrays from single time step into an Arakawa C grid
20  * mesh. The mesh is optionally subset.
21  *
22  * ### metadata keys:
23  *
24  * | key | description |
25  * | ---- | ----------- |
26  * | variables | a list of all available variables |
27  * | [var] | a metadata object holding all NetCDF attributes for the |
28  * | | variable named [var] |
29  * | time variables | a list of all variables with time as the only |
30  * | | dimension |
31  * | coordinates | a metadata object holding names and arrays of the |
32  * | | coordinate axes |
33  * | x_axis_variable | name of x axis variable |
34  * | y_axis_variable | name of y axis variable |
35  * | z_axis_variable | name of z axis variable |
36  * | t_axis_variable | name of t axis variable |
37  * | x | array of x coordinates |
38  * | y | array of y coordinates |
39  * | z | array of z coordinates |
40  * | t | array of t coordinates |
41  * | files | list of files in this dataset |
42  * | step_count | list of the number of steps in each file |
43  * | number_of_time_steps | total number of time steps in all files |
44  * | whole_extent | index space extent describing (nodal) dimensions of the |
45  * | | mesh |
46  *
47  * ### request keys:
48  *
49  * | key | description |
50  * | ---- | ----------- |
51  * | time_step | the time step to read
52  * | arrays | list of arrays to read
53  * | extent | index space extents describing the subset of data to read
54  *
55  * ### output:
56  *
57  * generates a 2 or 3D teca_arakawa_c_grid mesh for the requested timestep on
58  * the requested extent with the requested point based arrays and value at this
59  * timestep for all time variables.
60  */
62 {
63 public:
64  TECA_ALGORITHM_STATIC_NEW(teca_wrf_reader)
65  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_wrf_reader)
66  TECA_ALGORITHM_CLASS_NAME(teca_wrf_reader)
67  ~teca_wrf_reader();
68 
69  // report/initialize to/from Boost program options
70  // objects.
71  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
72  TECA_SET_ALGORITHM_PROPERTIES()
73 
74  // list of file names to open. if this is set the files_regex
75  // is ignored.
76  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, file_name)
77 
78  // describe the set of files comprising the dataset. This
79  // should contain the full path and regex describing the
80  // file name pattern
81  TECA_ALGORITHM_PROPERTY(std::string, files_regex)
82 
83  // the directory where metadata should be cached. if this is not specified
84  // metadata is cached either with the data, in the CWD, or in the user's
85  // home dir, which ever location succeeds first.
86  TECA_ALGORITHM_PROPERTY(std::string, metadata_cache_dir)
87 
88  // set if the dataset has periodic boundary conditions
89  TECA_ALGORITHM_PROPERTY(int, periodic_in_x)
90  TECA_ALGORITHM_PROPERTY(int, periodic_in_y)
91  TECA_ALGORITHM_PROPERTY(int, periodic_in_z)
92 
93  // time calendar and time unit if the user wants to
94  // specify them
95  TECA_ALGORITHM_PROPERTY(std::string, calendar)
96  TECA_ALGORITHM_PROPERTY(std::string, t_units)
97 
98  // a way to infer time from the filename if the time axis is not
99  // stored in the file itself. strftime format codes are used.
100  // For example for the files:
101  //
102  // my_file_20170516_00.nc
103  // my_file_20170516_03.nc
104  // ...
105  //
106  // the template would be
107  //
108  // my_file_%Y%m%d_%H.nc
109  TECA_ALGORITHM_PROPERTY(std::string, filename_time_template)
110 
111  // time values to use instead if time variable doesn't
112  // exist.
113  TECA_ALGORITHM_VECTOR_PROPERTY(double, t_value)
114 
115  // set/get the number of threads in the pool. setting
116  // to less than 1 results in 1 - the number of cores.
117  // the default is 1.
118  TECA_ALGORITHM_PROPERTY(int, thread_pool_size)
119 
120 protected:
121  teca_wrf_reader();
122  void clear_cached_metadata();
123 
124 private:
125  using teca_algorithm::get_output_metadata;
126 
127  teca_metadata get_output_metadata(
128  unsigned int port,
129  const std::vector<teca_metadata> &input_md) override;
130 
131  const_p_teca_dataset execute(
132  unsigned int port,
133  const std::vector<const_p_teca_dataset> &input_data,
134  const teca_metadata &request) override;
135 
136  virtual void set_modified() override;
137 
138 private:
139  std::vector<std::string> file_names;
140  std::string files_regex;
141  std::string metadata_cache_dir;
142  std::string m_x_axis_variable;
143  std::string m_y_axis_variable;
144  std::string u_x_axis_variable;
145  std::string u_y_axis_variable;
146  std::string v_x_axis_variable;
147  std::string v_y_axis_variable;
148  std::string m_z_axis_variable;
149  std::string w_z_axis_variable;
150  std::string t_axis_variable;
151  std::string calendar;
152  std::string t_units;
153  std::string filename_time_template;
154  std::vector<double> t_values;
155  int periodic_in_x;
156  int periodic_in_y;
157  int periodic_in_z;
158  int thread_pool_size;
159  p_teca_wrf_reader_internals internals;
160 };
161 
162 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
A reader for data stored in WRF ARW format.
Definition: teca_wrf_reader.h:62
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.