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