Skip to content
Snippets Groups Projects
Commit 222ddc10 authored by Matthijs van der Wild's avatar Matthijs van der Wild
Browse files

Merge branch 'fix-h5parm-compare' into 'master'

Fix h5parm compare

See merge request eosc/prefactor3-cwl!42
parents 847f75ac bb63e058
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ Checks the outputs of a workflow run ...@@ -4,6 +4,7 @@ Checks the outputs of a workflow run
""" """
import argparse import argparse
from argparse import RawTextHelpFormatter from argparse import RawTextHelpFormatter
from filecmp import dircmp
import h5py import h5py
import sys import sys
import numpy as np import numpy as np
...@@ -14,16 +15,30 @@ def main(check, control): ...@@ -14,16 +15,30 @@ def main(check, control):
Parameters Parameters
---------- ----------
results_path : str check_path : str
Path to output results directory of job Path to output results directory of job
control_path : str control_path : str
Path to control results directory 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' check_path = check + '/cal_values/cal_solutions.h5'
control_path = control + '/cal_values/cal_solutions.h5' control_path = control + '/cal_values/cal_solutions.h5'
check_h5 = h5py.File(check_path, 'r') check_h5 = h5py.File(check_path, 'r')
control_h5 = h5py.File(control_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: for solsetname in check_h5:
soltabnames = [name for name in check_h5[solsetname] soltabnames = [name for name in check_h5[solsetname]
if name not in ('source', 'antenna')] if name not in ('source', 'antenna')]
...@@ -41,7 +56,7 @@ def main(check, control): ...@@ -41,7 +56,7 @@ def main(check, control):
check_soltabval = check_h5[solsetname][soltabname]['val'] check_soltabval = check_h5[solsetname][soltabname]['val']
control_soltabval = control_h5[solsetname][soltabname]['val'] control_soltabval = control_h5[solsetname][soltabname]['val']
matching_vals = control_soltabval 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(',') check_axes = check_soltabval.attrs['AXES'].decode('utf-8').split(',')
freq_axis_index = check_axes.index('freq') freq_axis_index = check_axes.index('freq')
check_soltabfreq = check_h5[solsetname][soltabname]['freq'][:] check_soltabfreq = check_h5[solsetname][soltabname]['freq'][:]
...@@ -53,6 +68,7 @@ def main(check, control): ...@@ -53,6 +68,7 @@ def main(check, control):
axis=freq_axis_index) axis=freq_axis_index)
if not np.allclose(check_soltabval, matching_vals, if not np.allclose(check_soltabval, matching_vals,
rtol=1e-03, atol=1e-03, equal_nan=True): rtol=1e-03, atol=1e-03, equal_nan=True):
error = True
print("Val array of soltab {} does not match the control".format(soltabname)) print("Val array of soltab {} does not match the control".format(soltabname))
with open("check_soltab.{}.val".format(soltabname), "w") as f: with open("check_soltab.{}.val".format(soltabname), "w") as f:
f.write(str(check_soltabval[:])) f.write(str(check_soltabval[:]))
...@@ -62,14 +78,17 @@ def main(check, control): ...@@ -62,14 +78,17 @@ def main(check, control):
print("Val array of soltab {} matches the control".format(soltabname)) print("Val array of soltab {} matches the control".format(soltabname))
check_h5.close() check_h5.close()
control_h5.close() control_h5.close()
sys.exit(0) sys.exit(error)
if __name__ == '__main__': if __name__ == '__main__':
descriptiontext = "Checks the output of a workflow run.\n" descriptiontext = "Checks the output of a workflow run.\n"
parser = argparse.ArgumentParser(description=descriptiontext, formatter_class=RawTextHelpFormatter) 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('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() args = parser.parse_args()
main(args.results_path, args.control_path) main(args.check_path, args.control_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment