process.py 5.13 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
payno's avatar
payno committed
6
from ewoksorange.owsconvert import ows_to_ewoks
payno's avatar
payno committed
7
8
from .utils import get_unit
from .utils import get_url
9
10
from .utils import convert_spectra_dims
from .utils import get_xas_obj
payno's avatar
payno committed
11

12
13
try:
    import h5py
payno's avatar
payno committed
14

15
16
17
18
    has_h5py = True
except:
    has_h5py = False

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


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

154
    options = parser.parse_args(argv[1:])
155
156
157
158
159
160
161
    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(
162
163
164
165
166
167
            options.input_,
            options.input_energy_col_name,
            options.input_abs_col_name,
            options.input_monitor_col_name,
            options.input_scan_title_name,
        ),
168
    )
169
170
171
172
    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
173
174
175
176
    xas_obj = get_xas_obj(input_information=input_information)
    graph = ows_to_ewoks(filename=options.workflow_file)

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

    graph.execute(varinfo=varinfo)
183

payno's avatar
payno committed
184

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