process.py 5.06 KB
Newer Older
1
2
3
import argparse
import sys
import logging
4
5
from est.io.utils.information import InputInformation
from est.io.utils.information import SpecInputInformation
Henri Payno's avatar
Henri Payno committed
6
from ewoksorange.bindings import ows_to_ewoks
payno's avatar
payno committed
7
8
from .utils import get_unit
from .utils import get_url
9
from .utils import convert_spectra_dims
payno's avatar
payno committed
10

11
try:
payno's avatar
PEP8    
payno committed
12
13
    import h5py  # noqa
except ImportError:
14
    has_h5py = False
payno's avatar
PEP8    
payno committed
15
16
else:
    has_h5py = True
17

18
logging.basicConfig(level=logging.DEBUG)
19
20
21
22
23
24
_logger = logging.getLogger(__name__)


def main(argv):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
payno's avatar
payno committed
25
26
27
        "workflow_file",
        help="Workflow file providing the workflow description (.ows, .xml)",
    )
28
    # single file input option
payno's avatar
payno committed
29
    parser.add_argument(
30
31
        "-i",
        "--input",
payno's avatar
payno committed
32
33
        dest="input_",
        default=None,
34
        help="Input of the workflow. Should be a path to a file",
payno's avatar
payno committed
35
    )
36
    # input url option
payno's avatar
payno committed
37
    parser.add_argument(
38
        "--input-spectra",
39
        "--spectra",
40
41
        dest="input_spectra",
        default=None,
42
        help="Input spectra url",
43
44
45
    )
    parser.add_argument(
        "--input-spectra-dims",
46
        "--spectra-dims",
47
        dest="input_spectra_dims",
48
49
50
51
        default=None,
        help="Input spectra dimension. Should be a tuple of three values: "
        "(X,Y,channel). If None will take the default dimension "
        "according to the input type.",
52
53
    )
    parser.add_argument(
54
        "--input-energy",
55
        "--input-channel",
56
        "--channel",
57
58
        dest="input_channel",
        default=None,
59
        help="Input channel url (usually energy)",
60
61
62
    )
    parser.add_argument(
        "--input-configuration",
63
        "--configuration",
64
65
        dest="input_configuration",
        default=None,
66
67
68
69
        help="Input configuration url",
    )
    parser.add_argument(
        "--input-energy-unit",
70
        "--energy-unit",
71
72
73
        dest="input_energy_unit",
        default="eV",
        help="energy unit",
74
    )
75
76
    parser.add_argument(
        "--input-dimensions",
77
        "--dimensions",
78
        dest="input_dimensions",
payno's avatar
payno committed
79
        default=None,
80
        help="dimension of the input as (Z,Y,X) for example."
81
82
        "If None will take default unit according to the input type",
    )
83
84
85
86
87
    # I0, I1, I2 & mu_ref
    parser.add_argument(
        "--input-I0",
        "--I0",
        dest="input_I0",
payno's avatar
payno committed
88
        default=None,
89
90
91
92
93
94
        help="url to I0",
    )
    parser.add_argument(
        "--input-I1",
        "--I1",
        dest="input_I1",
payno's avatar
payno committed
95
        default=None,
96
97
98
99
100
101
        help="url to I1",
    )
    parser.add_argument(
        "--input-I2",
        "--I2",
        dest="input_I2",
payno's avatar
payno committed
102
        default=None,
103
104
105
106
107
108
        help="url to I2",
    )
    parser.add_argument(
        "--input-mu-ref",
        "--mu-ref",
        dest="input_mu_ref",
payno's avatar
payno committed
109
        default=None,
110
111
        help="url to mu_ref",
    )
112
113
114
115
116
117
118
119
120
121
122
    # spec file specific inputs
    parser.add_argument(
        "--input-energy-col-name",
        "--energy-col-name",
        dest="input_energy_col_name",
        default=None,
        help="Provide name of the energy column for spec file",
    )
    parser.add_argument(
        "--input-abs-col-name",
        "--abs-col-name",
123
124
        "--input-mu-col-name",
        "--mu-col-name",
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        dest="input_abs_col_name",
        default=None,
        help="Provide name of the absorption column for spec file",
    )
    parser.add_argument(
        "--input-monitor-col-name",
        "--monitor-col-name",
        dest="input_monitor_col_name",
        default=None,
        help="Provide name of the monitor column for spec file",
    )
    parser.add_argument(
        "--input-scan-title",
        "--scan-title",
        dest="input_scan_title_name",
        default=None,
        help="Provide scan title name to consider",
    )
143
144
145
146
    # output option
    parser.add_argument(
        "-o",
        "--output",
147
        dest="output_file",
payno's avatar
payno committed
148
149
150
151
        default=None,
        help="Output file of the workflow. Require at most one "
        "instance of XASOutputOW",
    )
152

153
    options = parser.parse_args(argv[1:])
154
155
156
157
158
159
160
    input_information = InputInformation(
        spectra_url=get_url(options.input_spectra),
        channel_url=get_url(options.input_channel),
        dimensions=convert_spectra_dims(options.input_spectra_dims),
        config_url=get_url(options.input_configuration),
        energy_unit=get_unit(options.input_energy_unit),
        spec_input=SpecInputInformation(
161
162
163
164
165
166
            options.input_,
            options.input_energy_col_name,
            options.input_abs_col_name,
            options.input_monitor_col_name,
            options.input_scan_title_name,
        ),
167
    )
168
169
170
171
    input_information.I0 = get_url(options.input_I0)
    input_information.I1 = get_url(options.input_I1)
    input_information.I2 = get_url(options.input_I2)
    input_information.mu_ref = get_url(options.input_mu_ref)
payno's avatar
payno committed
172
173
174
    graph = ows_to_ewoks(filename=options.workflow_file)

    varinfo = {
175
        "input_information": input_information.to_dict(),
payno's avatar
payno committed
176
177
    }
    if options.output_file:
178
        varinfo["output_file"] = options.output_file
payno's avatar
payno committed
179
180

    graph.execute(varinfo=varinfo)
181

payno's avatar
payno committed
182

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