7.3.8. Compare Module
- parflow.tools.compare.msig_diff(data1, data2, m, abs_zero=0.0)
Python version of the C MSigDiff function.
Two nd arrays are given as the first two arguments. The grid point at which the number of digits in agreement (significant digits) is fewest is determined. If m >= 0 then the coordinate whose two values differ in more than m significant digits will be computed. If m < 0 then the coordinate whose values have a minimum number of significant digits will be computed. The number of the fewest significant digits is determined, and the maximum absolute difference is computed. The only coordinates that will be considered will be those whose differences are greater than absolute zero.
- Parameters:
data1 (numpy.ndarray) – first ndarray
data2 (numpy.ndarray) – second ndarray
m (int) – number of significant digits
abs_zero (float) – threshold below which all numbers are considered to be 0
- Returns:
[[i j k s] max_adiff]
where i, j, and k are the coordinates computed, sd is the minimum number of significant digits computed, and max_adiff is the maximum absolute difference computed.
- Return type:
A list of the following form is returned upon success
- Raises:
ValueError – If data1 and data2 do not have the same shape.
- parflow.tools.compare.pf_test_equal(a, b, message)
- parflow.tools.compare.pf_test_file(file, correct_file, message, sig_digits=6)
Python version of the tcl pftestFile procedure.
Two file paths are given as the first two arguments. The function reads them into ndarrays and calls a comparison function (msig_diff) to check if the files differ by more than sig_digits significant digits in any coordinate. If they do, the function prints an error message and the coordinate in which the files have the greatest difference.
- Parameters:
file (string) – path to test output file
correct_file (string) – path to reference output file
message (string) – message to print in case of test failure
sig_digits (int) – number of significant digits
- Returns:
- True if files differ in no more than sig_digits
significant digits in all coordinates. False otherwise.
- Return type:
bool
- Raises:
FileNotFoundError – If file or correct_file do not exist.
Exception – If the function fails to read either file into an ndarray.
- parflow.tools.compare.pf_test_file_with_abs(file, correct_file, message, abs_value, sig_digits=6)
Python version of the tcl pftestFileWithAbs procedure.
Two file paths are given as the first two arguments. The function reads them into ndarrays and calls a comparison function (msig_diff) to check if the files differ by more than sig_digits significant digits in any coordinate. If they do, the function checks if the difference in that coordinate is greater than abs_value. If it is, it prints an error message and the coordinate in which the files have the greatest difference.
- Parameters:
file (string) – path to test output file
correct_file (string) – path to reference output file
message (string) – message to print in case of test failure
abs_value (float) – threshold to determine if two files differ enough to fail the test
sig_digits (int) – number of significant digits
- Returns:
- True if files differ in no more than sig_digits
significant digits in all coordinates. False otherwise.
- Return type:
bool
- Raises:
FileNotFoundError – If file or correct_file do not exist.
Exception – If the function fails to read either file into an ndarray.