forked from aaron-parsons/i14testgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostprocessing.py
More file actions
executable file
·68 lines (57 loc) · 2.39 KB
/
postprocessing.py
File metadata and controls
executable file
·68 lines (57 loc) · 2.39 KB
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
'''
Contains all the post processing tools necessary after the savu process has occured
'''
processed_data = '/dls/i08/data/2017/cm16789-3/processing/aaron/20170705111629_10481/i08-10481_processed.nxs'
outfile = '/dls/i08/data/2017/cm16789-3/processing/aaron/20170705111629_10481/pymca_rgb_converted.dat'
def convert_to_pymca_rgb(processed_data, outfile):
import h5py as h5
f = h5.File(processed_data,'r')
scan_axes = 0,1
det_elem = 0
peak_indices = f['entry/final_result_fluo'].attrs['PeakElements_indices']
elements = list(f['entry/final_result_fluo/PeakElements'][...])
data = f['entry/final_result_fluo/data']
titles = ['row','column']
titles.extend(elements)
titles = [ix.replace(" ", "-") for ix in titles]
titles = " ".join(titles)
k = 0
with open(outfile,'wb') as f:
if k==0:
f.write(titles+"\n")
for row in range(data.shape[0]):
print("%d of %d" % (row, data.shape[0]))
for column in range(data.shape[1]):
line = list(data[row,column,det_elem])
line = [str(ix) for ix in line]
extra = [str(row),str(column)]
extra.extend(line)
line_to_write = " ".join(extra)
f.write(line_to_write+"\n")
#
# def convert_to_pymca_edf(processed_data, outfile):
import h5py as h5
f = h5.File(processed_data,'r')
scan_axes = 0,1
det_elem = 0,#,1,2,3
peak_indices = f['entry/final_result_fluo'].attrs['PeakElements_indices']
elements = list(f['entry/final_result_fluo/PeakElements'][...])
data = f['entry/final_result_fluo/data']
import collections
import numpy as np
from fabio.edfimage import EdfImage
for num, key in enumerate(elements):
for channel in det_elem:
foo = data[:,:,channel,num]
header = collections.OrderedDict()
header['HeaderID'] = 'EH:000001:000000:000000'
header['Image'] = '1'
header['ByteOrder'] = 'LowByteFirst'
header['DataType']= 'DoubleValue'
header['Dim_1'] = str(foo.shape[-1])
header['Dim 2'] = str(foo.shape[-2])
header['Size'] = str(8.0*np.prod(foo.shape))
out_title = "%s_channel_%s" % (key.replace(" ","_"), str(channel))
header['Title'] = out_title
fout = EdfImage(foo, header)
fout.write('/dls/i08/data/2017/cm16789-3/processing/aaron/20170705111629_10481/'+out_title+'.edf')