diff --git a/test_jobs/check_workflow_results.py b/test_jobs/check_workflow_results.py index 07290963d6c570b32e04f6eaa2cd04424166cf7f..03db786ce173e8fce4214f1ce106fa0affeb0e1a 100755 --- a/test_jobs/check_workflow_results.py +++ b/test_jobs/check_workflow_results.py @@ -4,6 +4,7 @@ Checks the outputs of a workflow run """ import argparse from argparse import RawTextHelpFormatter +from filecmp import dircmp import h5py import sys import numpy as np @@ -14,16 +15,30 @@ def main(check, control): Parameters ---------- - results_path : str + check_path : str Path to output results directory of job control_path : str Path to control results directory """ + error = False + + #Check that all expected output files are present + dcmp = dircmp(check, control) + if len(dcmp.left_only) > 0 or len(dcmp.right_only) > 0: + if len(dcmp.left_only) > 0: + print('ERROR: The following files are present in the output but not in the ' + 'control: {}'.format(dcmp.left_only)) + if len(dcmp.right_only) > 0: + print('ERROR: The following files are present in the control but not in the ' + 'output: {}'.format(dcmp.right_only)) + error = True + check_path = check + '/cal_values/cal_solutions.h5' control_path = control + '/cal_values/cal_solutions.h5' check_h5 = h5py.File(check_path, 'r') control_h5 = h5py.File(control_path, 'r') + # Check that the calibration solutions match the control ones for matching frequencies for solsetname in check_h5: soltabnames = [name for name in check_h5[solsetname] if name not in ('source', 'antenna')] @@ -41,7 +56,7 @@ def main(check, control): check_soltabval = check_h5[solsetname][soltabname]['val'] control_soltabval = control_h5[solsetname][soltabname]['val'] matching_vals = control_soltabval - if 'freq' in check_h5[solsetname][soltabname].keys(): + if 'freq' in check_h5[solsetname][soltabname].keys() and args.allow-frequency-subset: check_axes = check_soltabval.attrs['AXES'].decode('utf-8').split(',') freq_axis_index = check_axes.index('freq') check_soltabfreq = check_h5[solsetname][soltabname]['freq'][:] @@ -53,6 +68,7 @@ def main(check, control): axis=freq_axis_index) if not np.allclose(check_soltabval, matching_vals, rtol=1e-03, atol=1e-03, equal_nan=True): + error = True print("Val array of soltab {} does not match the control".format(soltabname)) with open("check_soltab.{}.val".format(soltabname), "w") as f: f.write(str(check_soltabval[:])) @@ -62,14 +78,17 @@ def main(check, control): print("Val array of soltab {} matches the control".format(soltabname)) check_h5.close() control_h5.close() - sys.exit(0) + sys.exit(error) if __name__ == '__main__': descriptiontext = "Checks the output of a workflow run.\n" parser = argparse.ArgumentParser(description=descriptiontext, formatter_class=RawTextHelpFormatter) - parser.add_argument('results_path', help='Path to output results') + parser.add_argument('check_path', help='Path to output results') parser.add_argument('control_path', help='Path to control results') + parser.add_argument('--allow-frequency-subset', + help='Use if frequency range in control differs from those in output', + action='store_true') args = parser.parse_args() - main(args.results_path, args.control_path) + main(args.check_path, args.control_path)