nxtomomill 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__init__.py +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__main__.py +72 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/__init__.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/__main__.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/converter.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/setup.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/utils.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__pycache__/version.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/__init__.py +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/__pycache__/__init__.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/__pycache__/tomoedf2nx.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/__pycache__/tomoh52nx.cpython-37.pyc +0 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/tomoedf2nx.py +438 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/app/tomoh52nx.py +83 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/converter.py +719 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/setup.py +43 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/utils.py +160 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/version.py +119 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/PKG-INFO +28 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/SOURCES.txt +17 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/dependency_links.txt +1 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/not-zip-safe +1 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/requires.txt +4 -0
- users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill-0.1.0-py3.7.egg-info/top_level.txt +1 -0
users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__init__.py
ADDED
|
File without changes
|
users/payno/.local/share/virtualenvs/tomwer_venc/lib/python3.7/site-packages/nxtomomill/__main__.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
# /*##########################################################################
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2017 European Synchrotron Radiation Facility
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
# ###########################################################################*/
|
|
26
|
+
"""This module describe nxtomomill applications which are available through
|
|
27
|
+
the silx launcher.
|
|
28
|
+
|
|
29
|
+
Your environment should provide a command `nxtomomill`. You can reach help with
|
|
30
|
+
`tomwer --help`, and check the version with `nxtomomill --version`.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
__authors__ = ["V. Valls", "P. Knobel", "H. Payno"]
|
|
34
|
+
__license__ = "MIT"
|
|
35
|
+
__date__ = "04/01/2018"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
import logging
|
|
39
|
+
logging.basicConfig()
|
|
40
|
+
|
|
41
|
+
import sys
|
|
42
|
+
from silx.utils.launcher import Launcher
|
|
43
|
+
import nxtomomill.version
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main():
|
|
47
|
+
"""Main function of the launcher
|
|
48
|
+
|
|
49
|
+
This function is referenced in the setup.py file, to create a
|
|
50
|
+
launcher script generated by setuptools.
|
|
51
|
+
|
|
52
|
+
:rtype: int
|
|
53
|
+
:returns: The execution status
|
|
54
|
+
"""
|
|
55
|
+
_version = nxtomomill.version.version
|
|
56
|
+
launcher = Launcher(prog="nxtomomill", version=_version)
|
|
57
|
+
launcher.add_command("tomoedf2nx",
|
|
58
|
+
module_name="nxtomomill.app.tomoedf2nx",
|
|
59
|
+
description="convert some scan acquire with edf file "
|
|
60
|
+
"format to nx compliant file format")
|
|
61
|
+
launcher.add_command("tomoh52nx",
|
|
62
|
+
module_name="nxtomomill.app.tomoh52nx",
|
|
63
|
+
description="Compute center of rotation of a scan or "
|
|
64
|
+
"between two projections")
|
|
65
|
+
status = launcher.execute(sys.argv)
|
|
66
|
+
return status
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
# executed when using python -m PROJECT_NAME
|
|
71
|
+
status = main()
|
|
72
|
+
sys.exit(status)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2015-2020 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
This module provides global definitions and methods to transform
|
|
28
|
+
a tomo dataset written in edf into and hdf5/nexus file
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
__authors__ = ["C. Nemoz", "H. Payno", "A.Sole"]
|
|
32
|
+
__license__ = "MIT"
|
|
33
|
+
__date__ = "16/01/2020"
|
|
34
|
+
|
|
35
|
+
import os
|
|
36
|
+
import fabio
|
|
37
|
+
import numpy
|
|
38
|
+
import h5py
|
|
39
|
+
import logging
|
|
40
|
+
from nxtomomill import utils
|
|
41
|
+
from nxtomomill import converter
|
|
42
|
+
from tomoscan.esrf.edfscan import EDFTomoScan
|
|
43
|
+
from ..utils import Progress
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
logging.basicConfig(level=logging.INFO)
|
|
47
|
+
_logger = logging.getLogger(__name__)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
MOTOR_POS = 'motor_pos'
|
|
51
|
+
|
|
52
|
+
MOTOR_MNE = 'motor_mne'
|
|
53
|
+
|
|
54
|
+
ROT_ANGLE = "srot"
|
|
55
|
+
X_TRANS = "sx"
|
|
56
|
+
Y_TRANS = "sy"
|
|
57
|
+
Z_TRANS = "sz"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
TO_IGNORE = ['HST', '_slice_']
|
|
61
|
+
TO_IGNORE = ['_slice_']
|
|
62
|
+
|
|
63
|
+
DARK_NAME = ['darkend', 'dark']
|
|
64
|
+
DARK_ACCUM_FACT = True
|
|
65
|
+
|
|
66
|
+
REFS_NAME = ['ref', 'refHST']
|
|
67
|
+
|
|
68
|
+
key_proj = 0
|
|
69
|
+
key_flat = 1
|
|
70
|
+
key_dark = 2
|
|
71
|
+
key_return = -1
|
|
72
|
+
|
|
73
|
+
def main(argv):
|
|
74
|
+
"""
|
|
75
|
+
"""
|
|
76
|
+
import argparse
|
|
77
|
+
parser = argparse.ArgumentParser(description='convert data acquired as '
|
|
78
|
+
'edf to hdf5 - nexus '
|
|
79
|
+
'compliant file format.')
|
|
80
|
+
parser.add_argument('scan_path', help='folder containing the edf files')
|
|
81
|
+
parser.add_argument('output_file', help='foutput .h5 file')
|
|
82
|
+
parser.add_argument('--file_extension',
|
|
83
|
+
action="store_true",
|
|
84
|
+
default='.h5',
|
|
85
|
+
help='extension of the output file. Valid values are '
|
|
86
|
+
'' + '/'.join(utils.FileExtension.values()))
|
|
87
|
+
print('******set up***********')
|
|
88
|
+
options = parser.parse_args(argv[1:])
|
|
89
|
+
# inputDir = '/lbsram/hair_A1_50nm_tomo3_1_'
|
|
90
|
+
|
|
91
|
+
input_dir = options.scan_path
|
|
92
|
+
scan = EDFTomoScan(input_dir)
|
|
93
|
+
print('input_dir is', input_dir)
|
|
94
|
+
|
|
95
|
+
# in old data, rot ange is unknown. Compute it as a function of the proj number
|
|
96
|
+
compute_rotangle = True
|
|
97
|
+
|
|
98
|
+
fileout_h5 = utils.get_file_name(file_name=options.output_file,
|
|
99
|
+
extension=options.file_extension,
|
|
100
|
+
check=True)
|
|
101
|
+
_logger.info("Output file will be " + fileout_h5)
|
|
102
|
+
|
|
103
|
+
with h5py.File(fileout_h5, "w") as h5d:
|
|
104
|
+
proj_urls = scan.get_proj_urls(scan=scan.path)
|
|
105
|
+
|
|
106
|
+
for dark_to_find in DARK_NAME:
|
|
107
|
+
dk_urls = scan.get_darks_url(scan_path=scan.path,
|
|
108
|
+
prefix=dark_to_find)
|
|
109
|
+
if len(dk_urls) > 0:
|
|
110
|
+
if dark_to_find == 'dark':
|
|
111
|
+
DARK_ACCUM_FACT = False
|
|
112
|
+
break
|
|
113
|
+
|
|
114
|
+
for refs_to_find in REFS_NAME:
|
|
115
|
+
if refs_to_find == 'ref':
|
|
116
|
+
TO_IGNORE.append('HST')
|
|
117
|
+
else:
|
|
118
|
+
TO_IGNORE.remove('HST')
|
|
119
|
+
refs_urls = scan.get_refs_url(scan_path=scan.path,
|
|
120
|
+
prefix=refs_to_find,
|
|
121
|
+
ignore=TO_IGNORE)
|
|
122
|
+
if len(refs_urls) > 0:
|
|
123
|
+
break
|
|
124
|
+
|
|
125
|
+
n_frames = len(proj_urls) + len(refs_urls) + len(dk_urls)
|
|
126
|
+
|
|
127
|
+
# TODO: should be managed by tomoscan as well
|
|
128
|
+
def getExtraInfo(scan):
|
|
129
|
+
projections_urls = scan.projections
|
|
130
|
+
indexes = sorted(projections_urls.keys())
|
|
131
|
+
first_proj_file = projections_urls[indexes[0]]
|
|
132
|
+
fid = fabio.open(first_proj_file.file_path())
|
|
133
|
+
hd = fid.getHeader()
|
|
134
|
+
try:
|
|
135
|
+
rotangle_index = hd[MOTOR_MNE].split(' ').index(ROT_ANGLE)
|
|
136
|
+
except:
|
|
137
|
+
rotangle_index = -1
|
|
138
|
+
try:
|
|
139
|
+
xtrans_index = hd[MOTOR_MNE].split(' ').index(X_TRANS)
|
|
140
|
+
except:
|
|
141
|
+
xtrans_index = -1
|
|
142
|
+
try:
|
|
143
|
+
ytrans_index = hd[MOTOR_MNE].split(' ').index(Y_TRANS)
|
|
144
|
+
except:
|
|
145
|
+
ytrans_index = -1
|
|
146
|
+
try:
|
|
147
|
+
ztrans_index = hd[MOTOR_MNE].split(' ').index(Z_TRANS)
|
|
148
|
+
except:
|
|
149
|
+
ztrans_index = -1
|
|
150
|
+
|
|
151
|
+
frame_type = fid.getByteCode()
|
|
152
|
+
return frame_type, rotangle_index, xtrans_index, ytrans_index, ztrans_index
|
|
153
|
+
|
|
154
|
+
frame_type, rot_angle_index, x_trans_index, y_trans_index, z_trans_index = getExtraInfo(scan=scan)
|
|
155
|
+
|
|
156
|
+
data_dataset = h5d.create_dataset("/entry/instrument/detector/data",
|
|
157
|
+
shape=(n_frames, scan.dim_2, scan.dim_1),
|
|
158
|
+
dtype=frame_type)
|
|
159
|
+
|
|
160
|
+
keys_dataset = h5d.create_dataset("/entry/instrument/detector/image_key",
|
|
161
|
+
shape=(n_frames,),
|
|
162
|
+
dtype=numpy.int32)
|
|
163
|
+
|
|
164
|
+
keys_control_dataset = h5d.create_dataset("/entry/instrument/detector/image_key_control",
|
|
165
|
+
shape=(n_frames,),
|
|
166
|
+
dtype=numpy.int32)
|
|
167
|
+
|
|
168
|
+
h5d["/entry/sample/name"] = os.path.basename(scan.path)
|
|
169
|
+
|
|
170
|
+
proj_angle = scan.scan_range/scan.tomo_n
|
|
171
|
+
|
|
172
|
+
distance = scan.retrieve_information(scan=os.path.abspath(scan.path),
|
|
173
|
+
ref_file=None,
|
|
174
|
+
key='Distance',
|
|
175
|
+
type_=float,
|
|
176
|
+
key_aliases=['distance', ])
|
|
177
|
+
|
|
178
|
+
h5d["/entry/instrument/detector/distance"] = distance
|
|
179
|
+
h5d["/entry/instrument/detector/distance"].attrs["unit"] = u"m"
|
|
180
|
+
|
|
181
|
+
pixel_size = scan.retrieve_information(scan=os.path.abspath(scan.path),
|
|
182
|
+
ref_file=None,
|
|
183
|
+
key='PixelSize',
|
|
184
|
+
type_=float,
|
|
185
|
+
key_aliases=['pixelSize', ])
|
|
186
|
+
h5d["/entry/instrument/detector/x_pixel_size"] = pixel_size
|
|
187
|
+
h5d["/entry/instrument/detector/x_pixel_size"].attrs["unit"] = u"mm"
|
|
188
|
+
h5d["/entry/instrument/detector/y_pixel_size"] = pixel_size
|
|
189
|
+
h5d["/entry/instrument/detector/y_pixel_size"].attrs["unit"] = u"mm"
|
|
190
|
+
|
|
191
|
+
energy = scan.retrieve_information(scan=os.path.abspath(scan.path),
|
|
192
|
+
ref_file=None,
|
|
193
|
+
key='Energy',
|
|
194
|
+
type_=float,
|
|
195
|
+
key_aliases=['energy', ])
|
|
196
|
+
h5d["/entry/beam/incident_energy"] = energy
|
|
197
|
+
h5d["/entry/beam/incident_energy"].attrs["unit"] = u"keV"
|
|
198
|
+
|
|
199
|
+
# rotations values
|
|
200
|
+
rotation_dataset = h5d.create_dataset("/entry/sample/rotation_angle",
|
|
201
|
+
shape=(n_frames,),
|
|
202
|
+
dtype=numpy.float32)
|
|
203
|
+
|
|
204
|
+
# provision for centering motors
|
|
205
|
+
x_dataset = h5d.create_dataset("/entry/sample/x_translation",
|
|
206
|
+
shape=(n_frames,),
|
|
207
|
+
dtype=numpy.float32)
|
|
208
|
+
y_dataset = h5d.create_dataset("/entry/sample/y_translation",
|
|
209
|
+
shape=(n_frames,),
|
|
210
|
+
dtype=numpy.float32)
|
|
211
|
+
z_dataset = h5d.create_dataset("/entry/sample/z_translation",
|
|
212
|
+
shape=(n_frames,),
|
|
213
|
+
dtype=numpy.float32)
|
|
214
|
+
|
|
215
|
+
# ---------> and now fill all datasets!
|
|
216
|
+
|
|
217
|
+
nf = 0
|
|
218
|
+
|
|
219
|
+
def read_url(url) -> tuple:
|
|
220
|
+
data_slice = url.data_slice()
|
|
221
|
+
if data_slice is None:
|
|
222
|
+
data_slice = (0,)
|
|
223
|
+
if data_slice is None or len(data_slice) != 1:
|
|
224
|
+
raise ValueError("Fabio slice expect a single frame, "
|
|
225
|
+
"but %s found" % data_slice)
|
|
226
|
+
index = data_slice[0]
|
|
227
|
+
if not isinstance(index, int):
|
|
228
|
+
raise ValueError("Fabio slice expect a single integer, "
|
|
229
|
+
"but %s found" % data_slice)
|
|
230
|
+
|
|
231
|
+
try:
|
|
232
|
+
fabio_file = fabio.open(url.file_path())
|
|
233
|
+
except Exception:
|
|
234
|
+
_logger.debug("Error while opening %s with fabio",
|
|
235
|
+
url.file_path(), exc_info=True)
|
|
236
|
+
raise IOError("Error while opening %s with fabio (use debug"
|
|
237
|
+
" for more information)" % url.path())
|
|
238
|
+
|
|
239
|
+
if fabio_file.nframes == 1:
|
|
240
|
+
if index != 0:
|
|
241
|
+
raise ValueError(
|
|
242
|
+
"Only a single frame available. Slice %s out of range" % index)
|
|
243
|
+
data = fabio_file.data
|
|
244
|
+
header = fabio_file.header
|
|
245
|
+
else:
|
|
246
|
+
data = fabio_file.getframe(index).data
|
|
247
|
+
header = fabio_file.getframe(index).header
|
|
248
|
+
|
|
249
|
+
fabio_file.close()
|
|
250
|
+
fabio_file = None
|
|
251
|
+
return data, header
|
|
252
|
+
|
|
253
|
+
progress = Progress('write dark')
|
|
254
|
+
progress.set_max_advancement(len(dk_urls))
|
|
255
|
+
|
|
256
|
+
def ignore(file_name):
|
|
257
|
+
for forbid in TO_IGNORE:
|
|
258
|
+
if forbid in file_name:
|
|
259
|
+
return True
|
|
260
|
+
return False
|
|
261
|
+
|
|
262
|
+
# darks
|
|
263
|
+
|
|
264
|
+
#dark in acumulation mode?
|
|
265
|
+
norm_dark = 1.
|
|
266
|
+
if scan.dark_n > 0 and DARK_ACCUM_FACT is True:
|
|
267
|
+
norm_dark = len(dk_urls)/scan.dark_n
|
|
268
|
+
dk_indexes = sorted(dk_urls.keys())
|
|
269
|
+
progress.set_max_advancement(len(dk_urls))
|
|
270
|
+
for dk_index in dk_indexes:
|
|
271
|
+
dk_url = dk_urls[dk_index]
|
|
272
|
+
if ignore(os.path.basename(dk_url.file_path())):
|
|
273
|
+
_logger.info('ignore ' + dk_url.file_path())
|
|
274
|
+
continue
|
|
275
|
+
data, header = read_url(dk_url)
|
|
276
|
+
data_dataset[nf, :, :] = data * norm_dark
|
|
277
|
+
keys_dataset[nf] = key_dark
|
|
278
|
+
keys_control_dataset[nf] = key_dark
|
|
279
|
+
|
|
280
|
+
if MOTOR_POS in header:
|
|
281
|
+
str_mot_val = header[MOTOR_POS].split(' ')
|
|
282
|
+
if rot_angle_index == -1:
|
|
283
|
+
rotation_dataset[nf] = 0.
|
|
284
|
+
else:
|
|
285
|
+
rotation_dataset[nf] = float(str_mot_val[rot_angle_index])
|
|
286
|
+
if x_trans_index == -1:
|
|
287
|
+
x_dataset[nf] = 0.
|
|
288
|
+
else:
|
|
289
|
+
x_dataset[nf] = float(str_mot_val[x_trans_index])
|
|
290
|
+
if y_trans_index == -1:
|
|
291
|
+
y_dataset[nf] = 0.
|
|
292
|
+
else:
|
|
293
|
+
y_dataset[nf] = float(str_mot_val[y_trans_index])
|
|
294
|
+
if z_trans_index == -1:
|
|
295
|
+
z_dataset[nf] = 0.
|
|
296
|
+
else:
|
|
297
|
+
z_dataset[nf] = float(str_mot_val[z_trans_index])
|
|
298
|
+
|
|
299
|
+
nf += 1
|
|
300
|
+
progress.increase_advancement(i=1)
|
|
301
|
+
|
|
302
|
+
ref_indexes = sorted(refs_urls.keys())
|
|
303
|
+
|
|
304
|
+
ref_projs = []
|
|
305
|
+
for irf in ref_indexes:
|
|
306
|
+
pjnum = int(irf)
|
|
307
|
+
if pjnum not in ref_projs:
|
|
308
|
+
ref_projs.append(pjnum)
|
|
309
|
+
|
|
310
|
+
# refs
|
|
311
|
+
def store_refs(refIndexes, tomoN, projnum, refUrls, nF, dataDataset, keysDataset, keysCDataset, xDataset, yDataset, zDataset, rotationDataset, raix, xtix, ytix, ztix):
|
|
312
|
+
nfr=nF
|
|
313
|
+
progress = Progress('write refs')
|
|
314
|
+
progress.set_max_advancement(len(refIndexes))
|
|
315
|
+
for ref_index in refIndexes:
|
|
316
|
+
int_rf = int(ref_index)
|
|
317
|
+
test_val=0
|
|
318
|
+
if int_rf == projnum:
|
|
319
|
+
refUrl = refUrls[ref_index]
|
|
320
|
+
if ignore(os.path.basename(refUrl.file_path())):
|
|
321
|
+
_logger.info('ignore ' + refUrl.file_path())
|
|
322
|
+
continue
|
|
323
|
+
data, header = read_url(refUrl)
|
|
324
|
+
dataDataset[nfr, :, :] = data+test_val
|
|
325
|
+
keysDataset[nfr] = key_flat
|
|
326
|
+
keysCDataset[nfr] = key_flat
|
|
327
|
+
if MOTOR_POS in header:
|
|
328
|
+
str_mot_val = header[MOTOR_POS].split(' ')
|
|
329
|
+
if raix == -1:
|
|
330
|
+
rotationDataset[nfr] = 0.
|
|
331
|
+
else:
|
|
332
|
+
rotationDataset[nfr] = float(str_mot_val[raix])
|
|
333
|
+
if xtix == -1:
|
|
334
|
+
xDataset[nfr] = 0.
|
|
335
|
+
else:
|
|
336
|
+
xDataset[nfr] = float(str_mot_val[xtix])
|
|
337
|
+
if ytix == -1:
|
|
338
|
+
yDataset[nfr] = 0.
|
|
339
|
+
else:
|
|
340
|
+
yDataset[nfr] = float(str_mot_val[ytix])
|
|
341
|
+
if ztix == -1:
|
|
342
|
+
zDataset[nfr] = 0.
|
|
343
|
+
else:
|
|
344
|
+
zDataset[nfr] = float(str_mot_val[ztix])
|
|
345
|
+
|
|
346
|
+
nfr += 1
|
|
347
|
+
progress.increase_advancement(i=1)
|
|
348
|
+
return nfr
|
|
349
|
+
|
|
350
|
+
# projections
|
|
351
|
+
import datetime
|
|
352
|
+
proj_indexes = sorted(proj_urls.keys())
|
|
353
|
+
progress = Progress('write projections')
|
|
354
|
+
progress.set_max_advancement(len(proj_indexes))
|
|
355
|
+
nproj=0
|
|
356
|
+
iref_pj = 0
|
|
357
|
+
|
|
358
|
+
for proj_index in proj_indexes:
|
|
359
|
+
proj_url = proj_urls[proj_index]
|
|
360
|
+
if ignore(os.path.basename(proj_url.file_path())):
|
|
361
|
+
_logger.info('ignore ' + proj_url.file_path())
|
|
362
|
+
continue
|
|
363
|
+
|
|
364
|
+
# store refs if the ref serial number is = projection number
|
|
365
|
+
if iref_pj < len(ref_projs) and ref_projs[iref_pj] == nproj:
|
|
366
|
+
nf = store_refs(ref_indexes, scan.tomo_n,
|
|
367
|
+
ref_projs[iref_pj],
|
|
368
|
+
refs_urls,
|
|
369
|
+
nf,
|
|
370
|
+
data_dataset, keys_dataset, keys_control_dataset,
|
|
371
|
+
x_dataset, y_dataset, z_dataset, rotation_dataset,
|
|
372
|
+
rot_angle_index, x_trans_index, y_trans_index, z_trans_index)
|
|
373
|
+
iref_pj += 1
|
|
374
|
+
print("nf out %d " % nf)
|
|
375
|
+
data, header = read_url(proj_url)
|
|
376
|
+
|
|
377
|
+
data_dataset[nf, :, :] = data
|
|
378
|
+
keys_dataset[nf] = key_proj
|
|
379
|
+
keys_control_dataset[nf] = key_proj
|
|
380
|
+
if nproj >= scan.tomo_n:
|
|
381
|
+
keys_control_dataset[nf] = key_return
|
|
382
|
+
|
|
383
|
+
if MOTOR_POS in header:
|
|
384
|
+
str_mot_val = header[MOTOR_POS].split(' ')
|
|
385
|
+
|
|
386
|
+
# continuous scan - rot angle is unknown. Compute it
|
|
387
|
+
if compute_rotangle is True and nproj < scan.tomo_n:
|
|
388
|
+
rotation_dataset[nf] = nproj*proj_angle
|
|
389
|
+
else:
|
|
390
|
+
if rot_angle_index == -1:
|
|
391
|
+
rotation_dataset[nf] = 0.
|
|
392
|
+
else:
|
|
393
|
+
rotation_dataset[nf] = float(str_mot_val[rot_angle_index])
|
|
394
|
+
|
|
395
|
+
if x_trans_index == -1:
|
|
396
|
+
x_dataset[nf] = 0.
|
|
397
|
+
else:
|
|
398
|
+
x_dataset[nf] = float(str_mot_val[x_trans_index])
|
|
399
|
+
if y_trans_index == -1:
|
|
400
|
+
y_dataset[nf] = 0.
|
|
401
|
+
else:
|
|
402
|
+
y_dataset[nf] = float(str_mot_val[y_trans_index])
|
|
403
|
+
if z_trans_index == -1:
|
|
404
|
+
z_dataset[nf] = 0.
|
|
405
|
+
else:
|
|
406
|
+
z_dataset[nf] = float(str_mot_val[z_trans_index])
|
|
407
|
+
|
|
408
|
+
nf += 1
|
|
409
|
+
nproj+=1
|
|
410
|
+
|
|
411
|
+
progress.increase_advancement(i=1)
|
|
412
|
+
|
|
413
|
+
# store last flat if any remaining in the list
|
|
414
|
+
if iref_pj < len(ref_projs):
|
|
415
|
+
nf = store_refs(ref_indexes, scan.tomo_n,
|
|
416
|
+
ref_projs[iref_pj],
|
|
417
|
+
refs_urls,
|
|
418
|
+
nf,
|
|
419
|
+
data_dataset, keys_dataset, keys_control_dataset,
|
|
420
|
+
x_dataset, y_dataset, z_dataset, rotation_dataset,
|
|
421
|
+
rot_angle_index, x_trans_index, y_trans_index, z_trans_index)
|
|
422
|
+
|
|
423
|
+
# we can add some more NeXus look and feel
|
|
424
|
+
h5d["/entry"].attrs["NX_class"] = u"NXentry"
|
|
425
|
+
h5d["/entry"].attrs["definition"] = u"NXtomo"
|
|
426
|
+
h5d["/entry"].attrs["version"] = converter.CURRENT_OUTPUT_VERSION
|
|
427
|
+
h5d["/entry/instrument"].attrs["NX_class"] = u"NXinstrument"
|
|
428
|
+
h5d["/entry/instrument/detector"].attrs["NX_class"] = u"NXdetector"
|
|
429
|
+
h5d["/entry/instrument/detector/data"].attrs["interpretation"] = u"image"
|
|
430
|
+
h5d["/entry/sample"].attrs["NX_class"] = u"NXsample"
|
|
431
|
+
|
|
432
|
+
h5d.flush()
|
|
433
|
+
exit(0)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
if __name__ == "__main__":
|
|
437
|
+
import sys
|
|
438
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2015-2020 European Synchrotron Radiation Facility
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
This module provides global definitions and methods to transform
|
|
28
|
+
a tomo dataset written in edf into and hdf5/nexus file
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
__authors__ = ["C. Nemoz", "H. Payno", "A.Sole"]
|
|
32
|
+
__license__ = "MIT"
|
|
33
|
+
__date__ = "16/01/2020"
|
|
34
|
+
|
|
35
|
+
import logging
|
|
36
|
+
from nxtomomill import utils
|
|
37
|
+
from nxtomomill.converter import h5_to_nx
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
logging.basicConfig(level=logging.INFO)
|
|
41
|
+
_logger = logging.getLogger(__name__)
|
|
42
|
+
_logger.setLevel(logging.DEBUG)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main(argv):
|
|
46
|
+
"""
|
|
47
|
+
"""
|
|
48
|
+
import argparse
|
|
49
|
+
parser = argparse.ArgumentParser(description='convert data acquired as '
|
|
50
|
+
'hdf5 from bliss to nexus '
|
|
51
|
+
'`NXtomo` classes')
|
|
52
|
+
parser.add_argument('input_file_path', help='master file of the '
|
|
53
|
+
'acquisition')
|
|
54
|
+
parser.add_argument('output_file', help='output .nx or .h5 file')
|
|
55
|
+
parser.add_argument('--file_extension',
|
|
56
|
+
action="store_true",
|
|
57
|
+
default='.nx',
|
|
58
|
+
help='extension of the output file. Valid values are '
|
|
59
|
+
'' + '/'.join(utils.FileExtension.values()))
|
|
60
|
+
parser.add_argument('--single-file',
|
|
61
|
+
help='merge all scan sequence to the same output file. '
|
|
62
|
+
'By default create one file per sequence and '
|
|
63
|
+
'group all sequence in the output file',
|
|
64
|
+
dest='single_file',
|
|
65
|
+
action='store_true',
|
|
66
|
+
default=False)
|
|
67
|
+
parser.add_argument('--no-input',
|
|
68
|
+
help='Do not ask for any',
|
|
69
|
+
dest='request_input',
|
|
70
|
+
action='store_true',
|
|
71
|
+
default=False)
|
|
72
|
+
options = parser.parse_args(argv[1:])
|
|
73
|
+
|
|
74
|
+
h5_to_nx(input_file_path=options.input_file_path,
|
|
75
|
+
output_file=options.output_file, single_file=options.single_file,
|
|
76
|
+
file_extension=options.file_extension,
|
|
77
|
+
request_input=options.request_input)
|
|
78
|
+
exit(0)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
import sys
|
|
83
|
+
main(sys.argv[1:])
|