reprocessing.py 2.46 KB
Newer Older
payno's avatar
payno committed
1
2
3
import argparse
import sys
import logging
payno's avatar
payno committed
4
5
from est.core.types import XASObject
from est.core.reprocessing import get_process_instance_frm_h5_desc
payno's avatar
payno committed
6

payno's avatar
payno committed
7
8
try:
    import h5py
payno's avatar
payno committed
9

payno's avatar
payno committed
10
11
12
13
14
15
16
17
    has_h5py = True
except:
    has_h5py = False

logging.basicConfig(level=logging.DEBUG)
_logger = logging.getLogger(__name__)


payno's avatar
payno committed
18
19
20
def exec_(
    h5_file, entry="scan1", spectra_path=None, energy_path=None, configuration_path=None
):
payno's avatar
payno committed
21
22

    try:
payno's avatar
payno committed
23
24
25
26
27
28
29
        xas_obj = XASObject.from_file(
            h5_file=h5_file,
            entry=entry or "scan1",
            spectra_path=spectra_path or "data/absorbed_beam",
            energy_path=energy_path or "data/energy",
            configuration_path=configuration_path,
        )
payno's avatar
payno committed
30
31
32
33
34
35
        xas_obj.link_to_h5(h5_file=h5_file)
    except Exception as e:
        _logger.error(e)
        xas_obj = None

    if not xas_obj:
payno's avatar
payno committed
36
        _logger.error("Unable to create an object from the given file and path")
payno's avatar
payno committed
37
38
39

    xas_processes = xas_obj.get_process_flow()
    if len(xas_processes) == 0:
payno's avatar
payno committed
40
        _logger.warning("no xas process found in the given h5 file")
payno's avatar
payno committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        return
    xas_obj.clean_process_flow()
    for i_process, process in xas_processes.items():
        process_ins = get_process_instance_frm_h5_desc(process)
        xas_obj = process_ins(xas_obj)

    return xas_obj


def getinputinfo():
    return "xas reprocessing workflow_file.h5"


def getInputFrmHdf5(file_path):
    raise NotImplementedError()


def main(argv):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
payno's avatar
payno committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        "workflow_file", help="Workflow file providing the workflow description (.h5)"
    )
    parser.add_argument(
        "--spectra_path",
        dest="spectra_path",
        default=None,
        help="path to the spectra data",
    )
    parser.add_argument(
        "--energy_path",
        dest="energy_path",
        default=None,
        help="path to the energy data",
    )
    parser.add_argument(
        "--configuration_path",
        dest="configuration_path",
        default=None,
        help="path to the process configuration",
    )
    parser.add_argument(
        "--entry",
        dest="entry to load",
        default=None,
        help="path to the process configuration",
    )
payno's avatar
payno committed
87
    options = parser.parse_args(argv[1:])
payno's avatar
payno committed
88
89
90
91
92
93
    exec_(
        h5_file=options.workflow_file,
        spectra_path=options.spectra_path,
        energy_path=options.energy_path,
        configuration_path=options.configuration_path,
    )
payno's avatar
payno committed
94
95
96
97


if __name__ == "__main__":
    main(sys.argv)