This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathold-scanoutput.py
67 lines (53 loc) · 2.04 KB
/
old-scanoutput.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
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 17 13:05:35 2016
@author: xf05id1
"""
from databroker import DataBroker as db, get_table, get_images, get_events
import time
def textout(scan=-1, header=[], userheader={}, column=[], output = True):
'''
scan: can be scan_id (integer) or uid (string). defaul = -1 (last scan run)
'''
scanh= db[scan]
print(scanh.start)
events=list(get_events(scanh))
#convert time stamp to localtime
#timestamp=scanhh.start['time']
#scantime=time.localtime(timestamp)
filedir='/nfs/xf05id1/userdata/2016cycle2/300265_inhouse/'
filename='scan_'+ str(scanh.start['scan_id'])
f = open(filedir+filename, 'w')
staticheader = '# XDI/1.0 MX/2.0\n' \
+'# Beamline.name: '+scanh.start.beamline_id+'\n' \
+'# Facility.name: NSLS-II\n' \
+'# Scan.start.uid: '+scanh.start.uid+'\n' \
+'# Scan.start.time: '+str(scanh.start.time)+'\n' \
+'# Scan.start.ctime: '+time.ctime(scanh.start.time)+'\n' \
+'# Mono.name: Si 111\n' \
f.write(staticheader)
for item in header:
if item in events[0].data.keys():
f.write('# '+item+': '+str(events[0]['data'][item])+'\n')
if output is True:
print(item+' is written')
else:
print(item+' is not in the scan')
for key in userheader:
f.write('# '+key+': '+str(userheader[key])+'\n')
if output is True:
print(key+' is written')
for idx, item in enumerate(column):
if item in events[0].data.keys():
f.write('# Column.'+str(idx+1)+': '+item+'\n')
f.write('# ')
for item in column:
if item in events[0].data.keys():
f.write(str(item)+'\t')
f.write('\n')
for event in events:
for item in column:
if item in events[0].data.keys():
f.write(str(event['data'][item])+'\t')
f.write('\n')
f.close()