-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonochromator_pitch_scan.py
executable file
·190 lines (140 loc) · 7.12 KB
/
monochromator_pitch_scan.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
!#/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Monochromator pitch scan. Execute scan on monochromator pitch motor.
'''
import gevent
from gevent.monkey import patch_all
patch_all()
import traceback
import logging
import time
import os
import pickle
import numpy as np
import pylab
import sys
from xray_experiment import xray_experiment
from scipy.constants import eV, h, c, angstrom, kilo, degree
from monitor import Si_PIN_diode
import optparse
from motor import monochromator_pitch_motor
#from analysis import fast_shutter_scan_analysis
class monochromator_pitch_scan(xray_experiment):
specific_parameter_fields = [{'name': 'darkcurrent_time', 'type': 'float', 'description': 'Period of measuring the dark current'},
{'name': 'default_position', 'type', 'float', 'description': 'default position'},
{'name': 'start_position', 'type', 'float', 'description': 'Scan start position'},
{'name': 'end_position', 'type', 'float', 'description': 'Scan end position'}]
def __init__(self,
name_pattern,
directory,
start_position=-0.8,
end_position=0.,
default_position=-0.4400,
darkcurrent_time=5.,
photon_energy=None,
diagnostic=True,
analysis=None,
conclusion=None,
simulation=None,
display=False,
extract=False):
if hasattr(self, 'parameter_fields'):
self.parameter_fields += monochromator_pitch_scan.specific_parameter_fields
else:
self.parameter_fields = monochromator_pitch_scan.specific_parameter_fields[:]
xray_experiment.__init__(self,
name_pattern,
directory,
photon_energy=photon_energy,
diagnostic=diagnostic,
analysis=analysis,
conclusion=conclusion,
simulation=simulation)
self.description = 'Monochromator rocking curve. Scan between %6.1f and %6.1f mm, Proxima 2A, SOLEIL, %s' % (start_position, end_position, time.ctime(self.timestamp))
self.start_position = start_position
self.end_position = end_position
self.default_position = default_position
self.darkcurrent_time = darkcurrent_time
self.diagnostic = diagnostic
self.display = display
self.extract = extract
self.calibrated_diode = Si_PIN_diode()
self.monitors_dictionary['calibrated_diode'] = self.calibrated_diode
self.monitor_names += ['calibrated_diode']
self.monitors += [self.calibrated_diode]
self.actuator = monochromator_pitch_motor()
def prepare(self):
self.check_directory(self.directory)
self.write_destination_namepattern(self.directory, self.name_pattern)
initial_settings = []
if self.simulation != True:
initial_settings.append(gevent.spawn(self.goniometer.set_transfer_phase, wait=True))
initial_settings.append(gevent.spawn(self.set_photon_energy, self.photon_energy, wait=True))
for k in [1, 2, 3, 5, 6]:
initial_settings.append(gevent.spawn(getattr(getattr(self, 'slits%d' % k), 'set_horizontal_gap'), 4))
initial_settings.append(gevent.spawn(getattr(getattr(self, 'slits%d' % k), 'set_vertical_gap'), 4))
initial_settings.append(gevent.spawn(getattr(getattr(self, 'slits%d' % k), 'set_horizontal_position'), 0))
initial_settings.append(gevent.spawn(getattr(getattr(self, 'slits%d' % k), 'set_vertical_position'), 0))
initial_settings.append(gevent.spawn(self.calibrated_diode.insert))
if self.safety_shutter.closed():
initial_settings.append(gevent.spawn(self.safety_shutter.open))
gevent.joinall(initial_settings)
self.actuator.wait()
self.actuator.set_position(self.start_position, timeout=None, wait=True)
def run(self):
gevent.sleep(self.darkcurrent_time)
self.fast_shutter.open()
move = gevent.spawn(self.actuator.set_position, self.end_position, timeout=None, wait=True)
move.join()
self.fast_shutter.close()
gevent.sleep(self.darkcurrent_time)
def clean(self):
self.actuator.set_position(self.default_position)
self.save_parameters()
self.save_results()
self.save_log()
#self.save_plot()
final_settings = []
if self.extract:
final_settings.append(gevent.spawn(self.calibrated_diode.extract))
gevent.joinall(final_settings)
def analyze(self):
pass
def conclude(self):
pass
def main():
usage = '''Program will execute a fast shutter scan
./monochromator_pitch_motor.py <options>
'''
parser = optparse.OptionParser(usage=usage)
parser.add_option('-d', '--directory', type=str, default='/tmp/fast_shutter_scan', help='Directory to store the results (default=%default)')
parser.add_option('-n', '--name_pattern', type=str, default='fast_shutter_scan', help='name_pattern')
parser.add_option('-V', '--start_position', type=float, default=-0.8, help='start position')
parser.add_option('-R', '--end_position', type=float, default=0., help='end position')
parser.add_option('-p', '--photon_energy', type=float, default=12650, help='Photon energy')
parser.add_option('-D', '--display', action='store_true', help='display plot')
parser.add_option('-E', '--extract', action='store_true', help='Extract the calibrated diode after the scan')
parser.add_option('-A', '--analysis', action='store_true', help='Analyze the scan')
parser.add_option('-C', '--conclude', action='store_true', help='Apply the offsets')
options, args = parser.parse_args()
print('options', options)
print('args', args)
filename = os.path.join(options.directory, options.name_pattern) + '_parameters.pickle'
#if os.path.isfile(filename):
#ssa = slit_scan_analysis(filename)
#if options.analysis == True:
#ssa.analyze()
#if options.conclude == True:
#ssa.conclude()
#else:
mpscan = monochromator_pitch_scan(options.name_pattern,
options.directory,
start_position=options.start_position,
end_position=options.end_position,
photon_energy=options.photon_energy,
display=options.display,
extract=options.extract)
mpscan.execute()
if __name__ == '__main__':
main()