Commit 0fd64127 authored by William Roberts's avatar William Roberts
Browse files

Fix compare and dmv_to_ncdf

parent a88f0aa9
......@@ -20,7 +20,9 @@ class tcolor:
def isclose(a, b, percent_error=0.0):
return abs(a - b) <= percent_error / 100 * abs(a)
if a != 0:
return abs(a - b) <= percent_error / 100 * abs(a)
return abs(a - b) <= percent_error / 100 * abs(b)
'''
......@@ -192,13 +194,17 @@ def run_diff(file1, file2, percent_error=0.0, ignore=[]):
for l, r in zip(left, right):
for lw, rw in zip(re.findall(r"([-]?\d*\.?\d+)", l),
re.findall(r"([-]?\d*\.?\d+)", r)):
l.replace(lw, '')
r.replace(rw, '')
l = l.replace(lw, '')
r = r.replace(rw, '')
lf = float(lw)
rf = float(rw)
if not isclose(lf, rf, percent_error=percent_error):
if rf != 0:
error = abs(lf-rf) / abs(rf) * 100
else:
error = abs(lf-rf) / abs(lf) * 100
print(f'{tcolor.BLUE}< {lw}\n> {rw}\n Allowed % error {percent_error:.4f}% | '\
f'actual % error: {(abs(lf-rf)/rf * 100):.4f}%{tcolor.ENDC}')
f'actual % error: {error:.4f}%{tcolor.ENDC}')
ret = -1
# if the lines are still different after removing floats
if l != r:
......
......@@ -40,13 +40,15 @@ if __name__=='__main__':
parser.add_argument('-o','--output-dir',
help='output directory name')
parser.add_argument('-e','--extensions',
nargs="+",
default=['.CXS', '.SUM', '.RNC'],
action='append',
help='dmv file extensions to convert')
args = parser.parse_args()
extensions = args.extensions
if extensions is None:
extensions = ['.CXS', '.SUM', '.RNC']
if isdir(args.input_file):
ae_dirs = file_finder.getFiles(args.input_file, extensions=args.extensions)
ae_dirs = file_finder.getFiles(args.input_file, extensions=extensions)
for d, files in ae_dirs.items():
for f in files:
process(join(d,f), args.output_dir, args.verbose)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment