-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmirror_scan.py
executable file
·609 lines (499 loc) · 25.7 KB
/
mirror_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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Slits scan. Execute scan on a pair of slits.
'''
import gevent
import sys
try:
import tango
except ImportError:
import PyTango as tango
import traceback
import logging
import time
import itertools
import os
import pickle
import numpy as np
import pylab
import glob
import itertools
from xray_experiment import xray_experiment
from scipy.constants import eV, h, c, angstrom, kilo, degree
from motor import tango_motor
from monitor import xray_camera, analyzer
from camera import camera
from redis import StrictRedis
from slit_scan import slit_scan
from analysis import slit_scan_analysis
class mirror_scan_analysis(slit_scan_analysis):
def analyze(self, observation_fields=['chronos', 'gaussian_fit_center_x', 'gaussian_fit_center_y', 'gaussianfit_amplitude', 'gaussianfit_width_x', 'gaussianfit_width_y', 'max', 'mean', 'com_x', 'com_y']):
if not os.path.isfile(self.parameters_filename):
return
parameters = self.get_parameters()
results = self.get_results()
print('self.monitor', self.monitor)
for lame_name in list(results.keys()):
actuator_chronos, actuator_position = self.get_observations(results[lame_name], 'actuator_monitor')
fast_shutter_chronos, fast_shutter_state = self.get_observations(results[lame_name], 'fast_shutter')
try:
monitor_chronos, monitor_points = self.get_observations(results[lame_name], self.monitor)
except:
monitor_points = []
if len(monitor_points) == 0:
return
actuator_scan_indices = self.get_illuminated_indices(fast_shutter_chronos, fast_shutter_state, actuator_chronos)
actuator_scan_chronos = actuator_chronos[actuator_scan_indices]
actuator_scan_position = actuator_position[actuator_scan_indices]
position_chronos_predictor = self.get_position_chronos_predictor(actuator_scan_chronos, actuator_scan_position)
observation_indices = self.get_illuminated_indices(fast_shutter_chronos, fast_shutter_state, monitor_chronos)
observation_chronos = monitor_chronos[observation_indices]
observation_position = position_chronos_predictor(observation_chronos)
if 'analysis' not in results[lame_name]:
results[lame_name]['analysis'] = {}
if self.monitor not in results[lame_name]['analysis']:
results[lame_name]['analysis'][self.monitor] = {}
results[lame_name]['analysis'][self.monitor]['actuator_position'] = observation_position
print('monitor_points.shape', monitor_points.shape)
for k, field in enumerate(observation_fields[1:]):
observation = monitor_points[k, :][observation_indices]
#mask = np.logical_or(observation>256, observation<0)
#monitor_points[mask] = np.nan
results[lame_name]['analysis'][self.monitor][field] = observation
self.save_results(results)
try:
import urllib2
except ImportError:
import urllib.request as urllib2
import base64
class adaptive_mirror(object):
mirror_address = {'vfm': 'i11-ma-c05/op/mir2-vfm', 'hfm': 'i11-ma-c05/op/mir3-hfm'}
reset_page = 'http://bimorph:8080/cgi-bin/rackconfig_user/channeltest'
def __init__(self, mirror='vfm', check_time=1.):
self.mirror = mirror
self.check_time = check_time
self.mirror_device = tango.DeviceProxy(self.mirror_address[self.mirror])
channel_base = self.mirror_address[mirror].replace(mirror, 'ch.%02d')
self.channels = [tango.DeviceProxy(channel_base % k) for k in range(12)]
self.pitch = tango_motor(self.mirror_address[mirror].replace('mir2-vfm', 'mir.2-mt_rx').replace('mir3-hfm', 'mir.3-mt_rz'))
self.translation = tango_motor(self.mirror_address[mirror].replace('mir2-vfm', 'mir.2-mt_tz').replace('mir3-hfm', 'mir.3-mt_tx'))
def get_channel_values(self):
return [getattr(c, 'voltage') for c in self.channels]
def get_channel_target_values(self):
return [getattr(c, 'targetVoltage') for c in self.channels]
def set_channel_target_values(self, channel_values, number_of_channels=12):
if len(channel_values) == 0:
print('not modifying target values as none specified')
elif len(channel_values) != number_of_channels:
print('not modifying target values as the value vector length is not consistent with number of channels (%d)' % number_of_channels)
else:
for k, c in enumerate(channel_values):
if c not in [None, np.nan]:
setattr(self.channels[k], 'targetVoltage', c)
gevent.sleep(1)
else:
print('not modifying channel %+d, current value %.1f' % (k, getattr(c, 'voltage')))
print('current target voltages: %s' % self.get_channel_target_values())
def set_voltages(self, channel_values):
current_channel_values = self.get_channel_values()
_start = time.time()
if np.allclose(channel_values, current_channel_values):
print('current channel values', current_channel_values)
print('values requested are identical, moving on ...')
else:
print('Setting %s mirror voltages' % self.mirror)
print('Please wait for %s mirror tensions to settle ...' % self.mirror)
self.set_channel_target_values(channel_values)
self.mirror_device.SetChannelsTargetVoltage()
while not np.allclose(channel_values, self.get_channel_values()):
gevent.sleep(self.check_time)
self.wait()
_end = time.time()
print()
print('done!')
print('%s mirror tensions converged' % self.mirror)
print('set_voltages() took %.2f' % (_end-_start))
def wait(self):
while self.mirror_device.State().name != 'STANDBY':
gevent.sleep(self.check_time)
def get_pitch_position(self):
return self.pitch.get_position()
def get_translation_position(self):
return self.translation.get_position()
def set_pitch_position(self, position):
self.pitch.set_position(position)
def set_translation_position(self, position):
self.translation.set_position(position)
def reload_firmware(self, key='cG93ZXJ1c2VyOnBvd2VydXNlcg=='):
req = urllib2.Request(self.reset_page)
req.add_header("Authorization", "Basic %s" % key)
handle = urllib2.urlopen(req)
return handle
class mirror_scan(slit_scan):
mirrors = {'vfm': 'i11-ma-c05/op/mir2-vfm', 'hfm': 'i11-ma-c05/op/mir3-hfm'}
specific_parameter_fields = [{'name': 'mirror_name', 'type': 'str', 'description': 'Target mirror'},
{'name': 'channel_values', 'type': 'list', 'description': 'Mirror tensions'},
{'name': 'channel_values_intention', 'type': 'list', 'description': 'Mirror tensions'},
{'name': 'mirror_pitch', 'type': 'float', 'description': 'Mirror pitch'},
{'name': 'mirror_translation', 'type': 'float', 'description': 'Mirror translation'}]
def __init__(self,
name_pattern,
directory,
mirror_name='vfm',
channel_values=[],
start_position=1.0,
end_position=-1.0,
scan_gap=0.05,
scan_speed=None,
darkcurrent_time=1.,
photon_energy=None,
diagnostic=True,
analysis=None,
conclusion=None,
simulation=None,
display=False,
extract=False):
if hasattr(self, 'parameter_fields'):
self.parameter_fields += mirror_scan.specific_parameter_fields
else:
self.parameter_fields = mirror_scan.specific_parameter_fields[:]
slit_scan.__init__(self,
name_pattern,
directory,
slits=3,
start_position=start_position,
end_position=end_position,
scan_speed=scan_speed,
scan_gap=scan_gap,
darkcurrent_time=darkcurrent_time,
photon_energy=photon_energy,
diagnostic=diagnostic,
analysis=analysis,
conclusion=conclusion,
simulation=simulation,
display=display,
extract=extract)
self.description = 'Scan of %s mirror scan scan between %6.1f and %6.1f mm, Proxima 2A, SOLEIL, %s' % (mirror_name, start_position, end_position, time.ctime(self.timestamp))
self.channel_values_intention = channel_values
self.mirror_name = mirror_name
self.mirror = adaptive_mirror(self.mirror_name)
self.redis = StrictRedis()
def set_up_monitor(self):
self.redis.set('beam_scan', 1)
#self.monitor_device = xray_camera(continuous_monitor_name='focus_monitor')
#self.monitors_dictionary['xray_camera'] = self.monitor_device
#self.monitor_names += ['xray_camera']
#self.monitors += [self.monitor_device]
#self.auxiliary_monitor_device = analyzer(continuous_monitor_name='analyzer_monitor')
#self.monitors_dictionary['analyzer'] = self.auxiliary_monitor_device
#self.monitor_names += ['analyzer']
#self.monitors += [self.auxiliary_monitor_device]
def get_clean_slits(self):
return [1, 2, 5, 6]
def get_alignment_actuators(self):
alignment_actuators = self.alignment_slits.get_alignment_actuators()
print('alignment_actuators', alignment_actuators)
if self.mirror_name == 'vfm':
actuators = alignment_actuators[1]
else:
actuators = alignment_actuators[0]
print('actuators', actuators)
return actuators
def get_channel_values(self):
return self.mirror.get_channel_values()
def get_mirror_pitch(self):
return self.mirror.get_pitch_position()
def get_mirror_translation(self):
return self.mirror.get_translation_position()
def prepare(self):
super(mirror_scan, self).prepare()
try:
self.mirror.set_voltages(self.channel_values_intention)
except:
print('did not succeed to set the tensions')
print(traceback.print_exc())
def handle_monitor_insertion(self):
return
def run(self):
print('run', self.get_template())
self.res = {}
actuator = self.get_alignment_actuators()
k = 1 if self.mirror_name == 'vfm' else 0
print('actuator', actuator)
self.actuator = actuator
#self.actuator_names = [self.actuator.get_name()]
actuator.wait()
actuator.set_position(self.start_position, timeout=None, wait=True)
actuator.set_speed(self.scan_speed)
if self.slit_type == 2:
self.alignment_slits.set_pencil_scan_gap(k, scan_gap=self.get_scan_gap(), wait=True)
self.start_monitor()
self._observe_start = time.time()
print('sleep for darkcurrent_time while observation is already running')
gevent.sleep(self.darkcurrent_time)
self.fast_shutter.open()
move = gevent.spawn(actuator.set_position, self.end_position, timeout=None, wait=True)
move.join()
actuator.set_speed(self.default_speed)
self.fast_shutter.close()
gevent.sleep(self.darkcurrent_time)
self._observe_stop = time.time()
self.stop_monitor()
self.redis.set('beam_scan', 0)
#os.system('/nfs/data3/Martin/Research/experimental_methods/history_saver.py -d %s -n %s_basler -e %.4f -s %.4f -m xray_camera &' % (self.directory, self.name_pattern, self._observe_stop, self._observe_start))
os.system('/nfs/data3/Martin/Research/experimental_methods/history_saver.py -d %s -n %s_prosilica -e %.4f -s %.4f -m prosilica &' % (self.directory, self.name_pattern, self._observe_stop, self._observe_start))
actuator.wait()
#if self.slit_type == 2:
#self.alignment_slits.set_pencil_scan_gap(k, scan_gap=self.default_gap, wait=True)
#actuator.set_position(0.)
#elif self.slit_type == 1:
#actuator.set_position(self.start_position, wait=True)
res = self.get_results()
self.res[actuator.get_name()] = res
def analyze(self):
#a = mirror_scan_analysis(os.path.join(self.directory, '%s_parameters.pickle' % self.name_pattern), monitor='xray_camera')
#a.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
a = mirror_scan_analysis(os.path.join(self.directory, '%s_parameters.pickle' % self.name_pattern), monitor='prosilica')
a.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
#a = mirror_scan_analysis(os.path.join(self.directory, '%s_parameters.pickle' % self.name_pattern), monitor='analyzer')
#a.analyze() #observation_fields=['chronos', 'com_y', 'com_x'])
def conclude(self):
pass
def main():
import optparse
usage = '''Program will execute a slit scan
./mirror_scan.py <options>
'''
parser = optparse.OptionParser(usage=usage)
parser.add_option('-d', '--directory', type=str, default='/tmp/slit_scan', help='Directory to store the results (default=%default)')
parser.add_option('-n', '--name_pattern', type=str, default='slit_scan', help='name_pattern')
parser.add_option('-m', '--mirror_name', type=str, default='vfm', help='mirror_name')
parser.add_option('-b', '--start_position', type=float, default=1., help='Start position')
parser.add_option('-e', '--end_position', type=float, default=-1., 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', '--conclusion', 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'
mscan = mirror_scan(**vars(options))
if not os.path.isfile(filename):
mscan.execute()
if options.analysis == True:
mscan.analyze()
if options.conclusion == True:
mscan.conclude()
def scan_mirror_step_by_step(mirror_name, start_stop, filename, nsteps=30):
from slits import slits3
from fast_shutter import fast_shutter
s3 = slits3()
xc = xray_camera()
cam = camera()
fs = fast_shutter()
fs.open()
start, stop = start_stop
positions = np.linspace(start, stop, nsteps)
values = []
for p in positions:
if mirror_name == 'hfm':
s3.set_horizontal_position(p)
values.append([xc.get_com_x(), cam.get_com_x()])
else:
s3.set_vertical_position(p)
values.append([xc.get_com_y(), cam.get_com_y()])
fs.close()
values = np.array(values)
np.save(filename, np.vstack([positions, values.T]).T)
def get_close_pairs(max_distance=2, nchannels=12):
close_pairs = []
for k in range(nchannels):
for l in range(nchannels):
if k != l:
if (k, l) not in close_pairs and (l, k) not in close_pairs and abs(k-l) <= max_distance and k<l:
close_pairs.append((k, l))
return close_pairs
def get_close_triplets(max_distance=2, nchannels=12):
close_triplets = []
for k in range(nchannels):
for l in range(nchannels):
for m in range(nchannels):
if k!=l and l!=m and k!=m:
if max([abs(k-l), abs(l-m), abs(k-m)]) <= max_distance and k<l and l<m:
if (k, l, m) not in close_triplets:
close_triplets.append((k, l, m))
return close_triplets
def get_total_increments(values=[50, 0, -50], triplets=True):
total_increments = []
if triplets:
increments = list(itertools.product(values, values, values))
close = get_close_triplets()
for triplet in close:
for increment in increments:
to_add = [0]*12
to_add[triplet[0]] = increment[0]
to_add[triplet[1]] = increment[1]
to_add[triplet[2]] = increment[2]
if to_add not in total_increments:
total_increments.append(to_add)
else:
increments = list(itertools.product(values, values))
close = get_close_pairs()
for pair in close:
for increment in increments:
to_add = [0]*12
to_add[pair[0]] = increment[0]
to_add[pair[1]] = increment[1]
if to_add not in total_increments:
total_increments.append(to_add)
return total_increments
def scan_mirror(special_directory='2020-07-16_%s_a', mirror_name='vfm', base_directory='/nfs/data3/Martin/Commissioning/mirrors', start_stop = [-0.8, 0.8]):
if mirror_name == 'vfm':
mirror = adaptive_mirror('vfm')
#base_voltages = [50.0, 50.0, -25.0, 150.0, 150.0, 550.0, 322.0, 188.0, 40.0, -100.0, -100.0, -150.0]
base_voltages = [100.0, 100.0, -75.0, 150.0, 150.0, 550.0, 322.0, 188.0, 40.0, -100.0, -100.0, -200.0]
else:
mirror = adaptive_mirror('hfm')
#base_voltages = [600.0, 250.0, 200.0, 50.0, 100.0, 50.0, 0.0, -150.0, -250.0, -250.0, -350.0, -400.0]
#base_voltages = [500.0, 250.0, 200.0, 50.0, 150.0, 100.0, 50.0, -150.0, -250.0, -250.0, -350.0, -400.0]
base_voltages = [500.0, 250.0, 200.0, 50.0, 200.0, 150.0, 100.0, -200.0, -250.0, -250.0, -350.0, -400.0]
#original_vfm_voltages = [255.0, 215.0, 12.0, 170.0, 185.0, 443.0, 322.0, 188.0, 40.0, -47.0, -3.0, 88.0] # vfm.get_channel_values()
#original_hfm_voltages = [290.0, 320.0, 265.0, 56.0, 102.0, 415.0, 37.0, -247.0, -534.0, -703.0, -1089.0, -1400.0] # hfm.get_channel_values()
#base_voltages = [0.0, 50.0, -25.0, 150.0, 150.0, 550.0, 322.0, 188.0, 40.0, -100.0, -100.0, -100.0]
#base_voltages = [500.0, 250.0, 200.0, 150.0, 100.0, 50.0, -50.0, -100.0, -200.0, -250.0, -350.0, -400.0] #[0.0] * 12
directory = os.path.join(base_directory, special_directory % mirror_name)
print('directory', directory)
for letter in ['a']: # 'b', 'c']:
#mscan = mirror_scan('base_voltages_%s' % letter , directory, mirror_name=mirror_name, channel_values=base_voltages, start_position=start_stop[0], end_position=start_stop[1])
#mscan.execute()
#start_stop = start_stop[::-1]
try:
man = mirror_scan_analysis('%s/base_voltages_%s_parameters.pickle' % (directory, letter), monitor='prosilica')
man.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
except:
print(traceback.print_exc())
for ti in get_total_increments():
print('total increment', ti)
new_voltages = np.array(base_voltages[:])
new_voltages += np.array(ti)
name_pattern = 'increment_%s' % '_'.join(map(str, ti))
#mscan = mirror_scan(name_pattern, directory, mirror_name=mirror_name, channel_values=new_voltages, start_position=start_stop[0], end_position=start_stop[1])
#mscan.execute()
#start_stop = start_stop[::-1]
try:
man = mirror_scan_analysis('%s/%s_parameters.pickle' % (directory, name_pattern), monitor='prosilica')
man.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
except:
print(traceback.print_exc())
#for increment in [+50, -50]: #, -40, +40, +60, -60, -80, +80, +100, -100]:
#for k in range(12):
#print('channel %02d, increment %+d' % (k, increment))
#new_voltages = base_voltages[:]
#new_voltages[k] += increment
#for letter in ['a']: #, 'b']:
##mscan = mirror_scan('channel_%02d_increment_%d_%s' % (k, increment, letter), directory, mirror_name=mirror_name, channel_values=new_voltages, start_position=start_stop[0], end_position=start_stop[1])
##mscan.execute()
#try:
#man = mirror_scan_analysis('%s/channel_%02d_increment_%d_%s_parameters.pickle' % (directory, k, increment, letter), monitor='prosilica')
#man.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
#except:
#print(traceback.print_exc())
for letter in ['d']: #, 'd']:
#mscan = mirror_scan('base_voltages_%s' % letter , directory, mirror_name=mirror_name, channel_values=base_voltages, start_position=start_stop[0], end_position=start_stop[1])
#mscan.execute()
try:
man = mirror_scan_analysis('%s/base_voltages_%s_parameters.pickle' % (directory, letter), monitor='prosilica')
man.analyze(observation_fields=['chronos', 'com_y', 'com_x'])
except:
print(traceback.print_exc())
#if mirror_name == 'vfm':
#mscan.slits3.set_vertical_gap(4)
#mscan.slits3.set_vertical_position(0)
#else:
#mscan.slits3.set_horizontal_gap(4)
#mscan.slits3.set_horizontal_position(0)
def plot_results(directory='/nfs/data3/Martin/Commissioning/mirrors/2020-07-16_vfm_a'):
if 'hfm' in directory:
lame_name = 'i11-ma-c05/ex/fent_h.3-mt_tx'
point_of_interrest = 'com_x'
else:
lame_name='i11-ma-c05/ex/fent_v.3-mt_tz'
point_of_interrest = 'com_y'
base = glob.glob(os.path.join(directory, 'base*_results.pickle'))
bases = []
grid = np.linspace(-1, 1, 2000)
for f in base: #[1::2]:
r = pickle.load(open(f))[lame_name]
p = r['analysis']['prosilica']['actuator_position']
b = r['analysis']['prosilica'][point_of_interrest]
bi = np.interp(grid, p, b)
bases.append(bi)
bases = np.array(bases)
print('bases.shape', bases.shape)
pylab.figure()
pylab.title('base')
pylab.plot(grid, bases.mean(axis=0))
results = glob.glob(os.path.join(directory, 'increment*_results.pickle'))
for f in results:
print('result', f)
pylab.figure()
pylab.title(os.path.basename(f).replace('increment_', '').replace('_results.pickle', ''))
pylab.plot(grid, np.mean(bases, axis=0), label='base')
try:
r = pickle.load(open(f))[lame_name]
p = r['analysis']['prosilica']['actuator_position']
for field in [point_of_interrest]:
b = r['analysis']['prosilica'][field]
label = '%s_%s' % (f.replace('_results.pickle', '').replace('channel_', '').replace('increment_','').replace(directory, ''), field)
pylab.plot(p, b, label=label)
except:
print(traceback.print_exc())
pylab.legend()
#for k in range(12):
#chan = '%02d' % k
#print('chan', chan)
#rf = glob.glob(os.path.join(directory, 'channel_%s_*_results.pickle' % chan))
#pylab.figure()
#pylab.title(chan)
#pylab.plot(grid, np.mean(bases, axis=0), label='base')
#for f in rf:
#try:
#r = pickle.load(open(f))[lame_name]
#p = r['analysis']['prosilica']['actuator_position']
#for field in [point_of_interrest]:
#b = r['analysis']['prosilica'][field]
#label = '%s_%s' % (f.replace('_results.pickle', '').replace('channel_', '').replace('_increment','').replace(directory, ''), field)
#pylab.plot(p, b, label=label)
#except:
#print(traceback.print_exc())
#pylab.legend()
pylab.show()
def plot_results_sbs(directory='/nfs/data3/Martin/Commissioning/mirrors/2020-07-15_hfm_b'):
b = np.load(os.path.join(directory, 'base_voltages_a_step_by_step.npy'))
pb, vb = b[:, 0], b[:, 1]
pylab.figure()
pylab.title('base')
pylab.plot(pb, vb)
for k in range(0, 6):
pylab.figure()
for f in glob.glob(os.path.join(directory, 'channel_%02d_*.npy' % k)):
r = np.load(f)
p = r[:, 0]
if np.allclose(p, pb):
v = r[:, 2] #- vb
else:
v = r[:, 2] #- vb[::-1]
pylab.plot(p, v, label=os.path.basename(f).replace('channel_', '').replace('_increment', '').replace('_a_step_by_step.npy', ''))
pylab.title('%02d' % k)
#pylab.ylim(-10, 10)
pylab.legend()
pylab.show()
if __name__ == '__main__':
#main()
#for mirror_name in ['vfm', 'hfm']:
#scan_mirror(mirror_name=mirror_name)
plot_results('/nfs/data3/Martin/Commissioning/mirrors/2020-07-16_hfm_a')
#plot_results_sbs('/nfs/data3/Martin/Commissioning/mirrors/2020-07-15_hfm_a')