Restoring previous versions of nrtest files that work
This commit is contained in:
@@ -101,6 +101,8 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol):
|
||||
Raises:
|
||||
ValueError()
|
||||
AssertionError()
|
||||
|
||||
Modified by L. Rossman (4/20/21)
|
||||
'''
|
||||
min_cdd = 100.0
|
||||
|
||||
@@ -114,14 +116,19 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol):
|
||||
if np.array_equal(test[0], ref[0]):
|
||||
continue
|
||||
else:
|
||||
diff = np.fabs(np.subtract(test[0], ref[0]))
|
||||
idx = np.unravel_index(np.argmax(diff), diff.shape)
|
||||
lre = _log_relative_error(test[0], ref[0])
|
||||
idx = np.unravel_index(np.argmin(lre), lre.shape)
|
||||
if lre[idx] < min_cdd:
|
||||
min_cdd = tmp;
|
||||
|
||||
if diff[idx] != 0.0:
|
||||
tmp = - np.log10(diff[idx])
|
||||
#diff = np.fabs(np.subtract(test[0], ref[0]))
|
||||
#idx = np.unravel_index(np.argmax(diff), diff.shape)
|
||||
|
||||
if tmp < min_cdd:
|
||||
min_cdd = tmp;
|
||||
#if diff[idx] != 0.0:
|
||||
# tmp = - np.log10(diff[idx])
|
||||
|
||||
# if tmp < min_cdd:
|
||||
# min_cdd = tmp;
|
||||
|
||||
if np.floor(min_cdd) >= atol:
|
||||
return True
|
||||
@@ -129,6 +136,36 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol):
|
||||
raise AssertionError('min_cdd=%d less than atol=%g' % (min_cdd, atol))
|
||||
|
||||
|
||||
def _log_relative_error(q, c):
|
||||
'''
|
||||
Computes log relative error, a measure of numerical accuracy.
|
||||
|
||||
Single precision machine epsilon is between 2^-24 and 2^-23.
|
||||
|
||||
Reference:
|
||||
McCullough, B. D. "Assessing the Reliability of Statistical Software: Part I."
|
||||
The American Statistician, vol. 52, no. 4, 1998, pp. 358-366.
|
||||
'''
|
||||
diff = np.subtract(q, c)
|
||||
tmp_c = np.copy(c)
|
||||
|
||||
# If ref value is small compute absolute error
|
||||
tmp_c[np.fabs(tmp_c) < 1.0e-6] = 1.0
|
||||
re = np.fabs(diff)/np.fabs(tmp_c)
|
||||
|
||||
# If re is tiny set lre to number of digits
|
||||
re[re < 1.0e-7] = 1.0e-7
|
||||
# If re is very large set lre to zero
|
||||
re[re > 2.0] = 1.0
|
||||
|
||||
lre = np.negative(np.log10(re))
|
||||
|
||||
# If lre is negative set to zero
|
||||
lre[lre < 1.0] = 0.0
|
||||
|
||||
return lre
|
||||
|
||||
|
||||
def epanet_report_compare(path_test, path_ref, rtol, atol):
|
||||
'''
|
||||
Compares results in two report files ignoring contents of header and footer.
|
||||
@@ -152,9 +189,12 @@ def epanet_report_compare(path_test, path_ref, rtol, atol):
|
||||
RunTimeError()
|
||||
...
|
||||
'''
|
||||
|
||||
# Comparison of Status Report files turned off - L.Rossman (4/20/21)
|
||||
|
||||
'''
|
||||
HEADER = 10
|
||||
FOOTER = 2
|
||||
'''
|
||||
with open(path_test ,'r') as ftest, open(path_ref, 'r') as fref:
|
||||
|
||||
for (test_line, ref_line) in it.izip(hdf.parse(ftest, HEADER, FOOTER)[1],
|
||||
|
||||
@@ -18,7 +18,7 @@ entry_points = {
|
||||
'nrtest.compare': [
|
||||
'epanet allclose = nrtest_epanet:epanet_allclose_compare',
|
||||
#'epanet mincdd = nrtest_epanet:epanet_mincdd_compare',
|
||||
#'epanet report = nrtest_epanet:epanet_report_compare',
|
||||
'epanet report = nrtest_epanet:epanet_report_compare',
|
||||
# Add entry point for new comparison functions here
|
||||
]
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
# Suggested Usage:
|
||||
# $ for file in .//*; do ./test-config.sh $file 1.0 > "${file%.*}.json"; done
|
||||
#
|
||||
# "${name}.rpt": "epanet report",
|
||||
|
||||
filename="$1"
|
||||
name="${filename%.*}"
|
||||
@@ -38,6 +37,7 @@ cat<<EOF
|
||||
],
|
||||
"output_files": {
|
||||
"${name}.out": "epanet allclose"
|
||||
"${name}.rpt": "epanet report",
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user