reference.py 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import os
import h5py
import numpy as np

from dorie.testtools.utilities.decorators import evaluation_script
from dorie.parfield.parameter_file import read_parameter_file


@evaluation_script
def evaluate(iniinfo,runtime):
    outfile = iniinfo["general.outputFile"]
    try:
        reference = iniinfo["_reference.path"] + "/" + iniinfo["general.outputFile"]
    except KeyError:
        raise ValueError("The reference evaluator assumes the key _reference.path to be existent in the inifile")

    if not os.path.isfile(reference):
        raise RuntimeError("Reference file {} does not exist".format(reference))

    f1_data, f1_attrs = read_parameter_file(outfile)
    f2_data, f2_attrs = read_parameter_file(reference)

Dion Haefner's avatar
debug  
Dion Haefner committed
23 24
    if f1_data.keys() != f2_data.keys():
        print("Data keys do not match: Got {} and {}".format(" ,".join(f1_data.keys()),
Dion Haefner's avatar
debug  
Dion Haefner committed
25
                                                             " ,".join(f2_data.keys())))
26 27
        return False

Dion Haefner's avatar
debug  
Dion Haefner committed
28 29
    if f1_attrs.keys() != f2_attrs.keys():
        print("Attribute keys do not match: Got {} and {}".format(" ,".join(f1_attrs.keys()),
Dion Haefner's avatar
debug  
Dion Haefner committed
30
                                                                  " ,".join(f2_attrs.keys())))
Dion Haefner's avatar
debug  
Dion Haefner committed
31

32 33
    for key in f1_data.keys():
        if not np.array_equal(f1_data[key],f2_data[key]):
Dion Haefner's avatar
debug  
Dion Haefner committed
34
            print("Attributes do not match: Got {} and {}".format(repr(f1_data),repr(f2_data)))
35 36 37 38 39 40 41 42
            return False

    for key in f1_data.keys():
        if not np.array_equal(f1_data[key],f2_data[key]):
            print("Data does not match in key {}".format(key))
            return False

    return True