-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec_DAC.py
181 lines (138 loc) · 8.39 KB
/
rec_DAC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
"""
.. module:: rec_DAC.py
:platform: Unix
:synopsis: Reconstruct the DAC experiment data collected at the APS 32-ID TXM
:Author:
`Francesco De Carlo <mailto: decarlof@gmail.com>`_
:Organization:
Argonne National Laboratory, Argonne, IL 60439 USA
"""
# tomoPy: https://github.com/tomopy/tomopy
import tomopy
import numpy as np
import matplotlib.pylab as pl
def rec_test(file_name, sino_start, sino_end):
print '\n#### Processing '+ file_name
sino_start = sino_start + 200
sino_end = sino_start + 2
print "Test reconstruction of slice [%d]" % sino_start
# Read HDF5 file.
prj, flat, dark = tomopy.io.exchange.read_aps_32id(file_name, sino=(sino_start, sino_end))
# Manage the missing angles:
theta = tomopy.angles(prj.shape[0])
prj = np.concatenate((prj[0:miss_angles[0],:,:], prj[miss_angles[1]+1:-1,:,:]), axis=0)
theta = np.concatenate((theta[0:miss_angles[0]], theta[miss_angles[1]+1:-1]))
# normalize the prj
prj = tomopy.normalize(prj, flat, dark)
# reconstruct
rec = tomopy.recon(prj, theta, center=best_center, algorithm='gridrec', emission=False)
# Write data as stack of TIFs.
tomopy.io.writer.write_tiff_stack(rec, fname=output_name)
print "Slice saved as [%s_00000.tiff]" % output_name
# show the reconstructed slice
pl.gray()
pl.axis('off')
pl.imshow(rec[0])
def rec_full(file_name, sino_start, sino_end):
print '\n#### Processing '+ file_name
chunks = 10 # number of data chunks for the reconstruction
nSino_per_chunk = (sino_end - sino_start)/chunks
print "Reconstructing [%d] slices from slice [%d] to [%d] in [%d] chunks of [%d] slices each" % ((sino_end - sino_start), sino_start, sino_end, chunks, nSino_per_chunk)
for iChunk in range(0,chunks):
print '\n -- chunk # %i' % (iChunk+1)
sino_chunk_start = sino_start + nSino_per_chunk*iChunk
sino_chunk_end = sino_start + nSino_per_chunk*(iChunk+1)
print '\n --------> [%i, %i]' % (sino_chunk_start, sino_chunk_end)
if sino_chunk_end > sino_end:
break
# Read HDF5 file.
prj, flat, dark = tomopy.io.exchange.read_aps_32id(file_name, sino=(sino_chunk_start, sino_chunk_end))
# Manage the missing angles:
theta = tomopy.angles(prj.shape[0])
prj = np.concatenate((prj[0:miss_angles[0],:,:], prj[miss_angles[1]+1:-1,:,:]), axis=0)
theta = np.concatenate((theta[0:miss_angles[0]], theta[miss_angles[1]+1:-1]))
# normalize the prj
prj = tomopy.normalize(prj, flat, dark)
# reconstruct
rec = tomopy.recon(prj, theta, center=best_center, algorithm='gridrec', emission=False)
print output_name
# Write data as stack of TIFs.
tomopy.io.writer.write_tiff_stack(rec, fname=output_name, start=sino_chunk_start)
reconstruction_test = True
##################################### Inputs ##########################################################
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_3kbar_.h5' # best_center = 1232
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_3kbar/Ce6Al4_3kbar_rec'
best_center = 1232; sino_start = 740; sino_end = 1700; miss_angles = [141,226]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_5P7kbar_.h5' # best_center = 1321
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_5P7kbar/CCe6Al4_5P7kbar_rec'
best_center = 1321; sino_start = 1000; sino_end = 1440; miss_angles = [141,228]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_8P59GPa_.h5' # best_center = 1219
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_8P59GPa/Ce6Al4_8P59GPa_rec'
best_center = 1219; sino_start = 550; sino_end = 1370; miss_angles = [147,233]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_13P37GPa_.h5' # best_center = 1286
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_13P37GPa/Ce6Al4_13P37GPa_rec'
best_center = 1286; sino_start = 740; sino_end = 1500; miss_angles = [142,227]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_17p44GPa_.h5' # best_center = 1292
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_17p44GPa/Ce6Al4_17p44GPa_rec'
best_center = 1292; sino_start = 620; sino_end = 1320; miss_angles = [140,226]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_19GPa_decrease_.h5' # best_center = 1116
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_19GPa_decrease/Ce6Al4_19GPa_decrease_rec'
best_center = 1116; sino_start = 800; sino_end = 1200; miss_angles = [140,225]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_20kbar_.h5' # best_center = 1314
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_20kbar/Ce6Al4_20kbar_rec'
best_center = 1314; sino_start = 610; sino_end = 1500; miss_angles = [71,113]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_21p39GPa_.h5' # best_center = 1140
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_21p39GPa/Ce6Al4_21p39GPa_rec'
best_center = 1140; sino_start = 610; sino_end = 1200; miss_angles = [140,226]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_26p17GPa_.h5' # best_center = 1124
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_26p17GPa/Ce6Al4_26p17GPa_rec'
best_center = 1124; sino_start = 740; sino_end = 1270; miss_angles = [140,227]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_29P5GPa_decrease_.h5' # best_center = 1338
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_29P5GPa_decrease/Ce6Al4_29P5GPa_decrease_rec'
best_center = 1338; sino_start = 760; sino_end = 1180; miss_angles = [140,227]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_33p07GPa_.h5' # best_center = 1232
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_33p07GPa/Ce6Al4_33p07GPa_rec'
best_center = 1232; sino_start = 710; sino_end = 1210; miss_angles = [140,227]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_41p88GPa_.h5' # best_center = 1292
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_41p88GPa/Ce6Al4_41p88GPa_rec'
best_center = 1292; sino_start = 700; sino_end = 1180; miss_angles = [138,225]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_47p89GPa_.h5' # best_center = 1114
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_47p89GPa/Ce6Al4_47p89GPa_rec'
best_center = 1114; sino_start = 740; sino_end = 1210; miss_angles = [141,228]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_54p73GPa_.h5' # best_center = 1352
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_54p73GPa/Ce6Al4_54p73GPa_rec'
best_center = 1352; sino_start = 750; sino_end = 1230; miss_angles = [138, 224]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)
file_name = '/local/dataraid/2014_11/haozhe/Ce6Al4_59GPa_.h5' # best_center = 1352
output_name = '/local/dataraid/2014_11/haozhe/rec/Ce6Al4_59GPa/Ce6Al4_59GPa_rec'
best_center = 1352; sino_start = 630; sino_end = 1100; miss_angles = [138, 224]
if reconstruction_test: rec_test(file_name, sino_start, sino_end)
else: rec_full(file_name, sino_start, sino_end)