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 protected:
62 
63  // Comparison methods.
64  int compare_tables(const_p_teca_table table1, const_p_teca_table table2);
65 
66  int compare_meshes(
67  const_p_teca_mesh reference_mesh,
68  const_p_teca_mesh data_mesh);
69 
70  int compare_cartesian_meshes(
71  const_p_teca_cartesian_mesh reference_mesh,
72  const_p_teca_cartesian_mesh data_mesh);
73 
74  int compare_curvilinear_meshes(
75  const_p_teca_curvilinear_mesh reference_mesh,
76  const_p_teca_curvilinear_mesh data_mesh);
77 
78  int compare_arakawa_c_grids(
79  const_p_teca_arakawa_c_grid reference_mesh,
80  const_p_teca_arakawa_c_grid data_mesh);
81 
82  int compare_array_collections(
83  const_p_teca_array_collection reference_arrays,
84  const_p_teca_array_collection data_arrays);
85 
86  // Reporting methods.
87 
88  // Call this with contextual information when datasets differ. You can use
89  // printf formatting.
90  void datasets_differ(const char* info, ...);
91 
92 private:
93  using teca_algorithm::get_output_metadata;
94 
95  teca_metadata get_output_metadata(unsigned int port,
96  const std::vector<teca_metadata> &input_md) override;
97 
98  std::vector<teca_metadata> get_upstream_request(
99  unsigned int port, const std::vector<teca_metadata> &input_md,
100  const teca_metadata &request) override;
101 
102  const_p_teca_dataset execute(unsigned int port,
103  const std::vector<const_p_teca_dataset> &input_data,
104  const teca_metadata &request) override;
105 
106  double get_abs_tol() const;
107  double get_rel_tol() const;
108 
109 private:
110  double relative_tolerance;
111  double absolute_tolerance;
112 };
113 
114 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_dataset_diff
compute the element wise difference between to datasets
Definition: teca_dataset_diff.h:30
teca_shared_object.h
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
teca_algorithm
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237