TECA
The Toolkit for Extreme Climate Analysis
teca_dataset_diff.h
1 #ifndef teca_dataset_diff_h
2 #define teca_dataset_diff_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 #include "teca_table.h"
8 #include "teca_mesh.h"
9 #include "teca_cartesian_mesh.h"
10 #include "teca_curvilinear_mesh.h"
11 #include "teca_arakawa_c_grid.h"
12 #include "teca_array_collection.h"
13 
14 #include <vector>
15 #include <string>
16 
17 TECA_SHARED_OBJECT_FORWARD_DECL(teca_dataset_diff)
18 
19 /// compute the element wise difference between to datasets
20 /**
21  * a two input algorithm that compares datasets by examining each element of their
22  * contained arrays. a threshold is used to detect when an element is different. a
23  * report containing the string FAIL is issued to stderr stream when a difference
24  * is detected. this algorithm is the core of TECA's regression test suite.
25  *
26  * by convention the first input produces the reference dataset, and the second
27  * input produces the dataset to validate. this is primarilly to support
28  * map-reduce implementation where after the reduction only rank 0 has data.
29 */
31 {
32 public:
33  TECA_ALGORITHM_STATIC_NEW(teca_dataset_diff)
34  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_dataset_diff)
35  TECA_ALGORITHM_CLASS_NAME(teca_dataset_diff)
37 
38  // report/initialize to/from Boost program options objects.
39  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
40  TECA_SET_ALGORITHM_PROPERTIES()
41 
42  /** @name relative_tolerance
43  * Relative tolerance below which two floating-point numbers a and b are
44  * considered equal. if |a - b| <= max(|a|,|b|)*tol then a is equal to b.
45  * the relative tolerance is used with numbers not close to zero.
46  */
47  ///@{
48  TECA_ALGORITHM_PROPERTY(double, relative_tolerance)
49  ///@}
50 
51  /** @name absolute_tolerance
52  * The absolute tolerance below which two floating point numbers a and b
53  * are considered equal. if |a - b| <= tol then a is equal to b. The
54  * absolute tolerance is used with numbers close to zero.
55  */
56  ///@{
57  TECA_ALGORITHM_PROPERTY(double, absolute_tolerance)
58  ///@}
59 
60  /** @name skip_arrays
61  * A list of arrays that are ignored during tests.
62  */
63  ///@{
64  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, skip_array)
65  ///@}
66 
67 protected:
69 
70  // Comparison methods.
71  int compare_tables(const_p_teca_table table1, const_p_teca_table table2);
72 
73  int compare_meshes(
74  const_p_teca_mesh reference_mesh,
75  const_p_teca_mesh data_mesh);
76 
77  int compare_cartesian_meshes(
78  const_p_teca_cartesian_mesh reference_mesh,
79  const_p_teca_cartesian_mesh data_mesh);
80 
81  int compare_curvilinear_meshes(
82  const_p_teca_curvilinear_mesh reference_mesh,
83  const_p_teca_curvilinear_mesh data_mesh);
84 
85  int compare_arakawa_c_grids(
86  const_p_teca_arakawa_c_grid reference_mesh,
87  const_p_teca_arakawa_c_grid data_mesh);
88 
89  int compare_array_collections(
90  const_p_teca_array_collection reference_arrays,
91  const_p_teca_array_collection data_arrays);
92 
93  // Reporting methods.
94 
95  // Call this with contextual information when datasets differ. You can use
96  // printf formatting.
97  void datasets_differ(const char* info, ...);
98 
99 private:
100  using teca_algorithm::get_output_metadata;
101 
102  teca_metadata get_output_metadata(unsigned int port,
103  const std::vector<teca_metadata> &input_md) override;
104 
105  std::vector<teca_metadata> get_upstream_request(
106  unsigned int port, const std::vector<teca_metadata> &input_md,
107  const teca_metadata &request) override;
108 
109  const_p_teca_dataset execute(unsigned int port,
110  const std::vector<const_p_teca_dataset> &input_data,
111  const teca_metadata &request) override;
112 
113  double get_abs_tol() const;
114  double get_rel_tol() const;
115 
116 private:
117  double relative_tolerance;
118  double absolute_tolerance;
119  std::vector<std::string> skip_arrays;
120 };
121 
122 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
compute the element wise difference between to datasets
Definition: teca_dataset_diff.h:31
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.