TECA
The Toolkit for Extreme Climate Analysis
teca_surface_integral.h
1 #ifndef teca_surface_integral_h
2 #define teca_surface_integral_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 #include "teca_array_attributes.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_surface_integral)
13 
14 /// Compute the integral over a geographic region on the surface of the Earth.
15 /** Compute the integral over a geographic region on the surface of the Earth.
16  * This is esepcially useful for calculating net flux normal to the surface
17  * over the specified region and may be useful for integrating other variables
18  * which have units of something over square meters.
19  *
20  * The surface inetgral of a variable \f$F\f$ over a region enclosed by curve
21  * \f$C\f$ is given by:
22  *
23  * \f[
24  * F_{net} = -r_e^2 \iint\limits_{C} F \; sin \phi \; d \theta d \phi
25  * \f]
26  *
27  * where:
28  *
29  * F : a 2D field in units of something per square meter <br>
30  * \f$C\f$ : A curve enclosing a region on the surface of the Earth <br>
31  * \f$\phi\f$ : \f$(90 - \f$degrees latitude\f$) \frac{\pi}{180}\f$ radians <br>
32  * \f$\theta\f$ : \f$(\f$degrees longitude\f$) \frac{\pi}{180}\f$ radians <br>
33  *
34  * Note: the minus sign out front is because we flip the limits of integration
35  * when going from latitude to \f$phi\f$ coordinates.
36  *
37  * Requirements:
38  * 1. A list of surface variables
39  * 2. A list of names to use when packaging the results
40  * 3. A 2D mask where non-zero entries define the geographic region of
41  * interest. ::teca_shape_file_mask is an algorithm that can be used
42  * to generate such a mask from an ESRI shapefile.
43  *
44  * Produces a table with one column for each calculation made and
45  * columns for time step and time.
46  *
47  * @attention This algorithm does not currently handle missing values.
48  */
50 {
51 public:
52  TECA_ALGORITHM_STATIC_NEW(teca_surface_integral)
53  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_surface_integral)
54  TECA_ALGORITHM_CLASS_NAME(teca_surface_integral)
56 
57  // report/initialize to/from Boost program options
58  // objects.
59  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
60  TECA_SET_ALGORITHM_PROPERTIES()
61 
62  /** @name input_variables
63  * Set the name of the variables to integrate.
64  */
65  ///@{
66  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, input_variable)
67  ///@}
68 
69  /** @name output_variables
70  * Set the name of variables storing the results.
71  */
72  ///@{
73  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, output_variable)
74  ///@}
75 
76  /** @name region_mask_variable
77  * Set the name of the variable containing the mask defining the region of
78  * interest.
79  */
80  ///@{
81  TECA_ALGORITHM_PROPERTY(std::string, region_mask_variable)
82  ///@}
83 
84  /** @name output_prefix
85  * Set a string to prepend to the output variable name
86  */
87  ///@{
88  TECA_ALGORITHM_PROPERTY(std::string, output_prefix)
89  ///@}
90 
91 protected:
93 
94 private:
95  using teca_algorithm::get_output_metadata;
96 
97  teca_metadata get_output_metadata(unsigned int port,
98  const std::vector<teca_metadata> &input_md) override;
99 
100  std::vector<teca_metadata> get_upstream_request(
101  unsigned int port,
102  const std::vector<teca_metadata> &input_md,
103  const teca_metadata &request) override;
104 
105  const_p_teca_dataset execute(
106  unsigned int port,
107  const std::vector<const_p_teca_dataset> &input_data,
108  const teca_metadata &request) override;
109 
110 private:
111  std::vector<std::string> input_variables;
112  std::vector<std::string> output_variables;
113  std::vector<teca_array_attributes> output_attributes;
114  std::string region_mask_variable;
115  std::string output_prefix;
116 };
117 
118 #endif
119 
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
Compute the integral over a geographic region on the surface of the Earth.
Definition: teca_surface_integral.h:50
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
A convenience container for conventional array attributes necessary and/or useful when producing NetC...
Definition: teca_array_attributes.h:32