-
Notifications
You must be signed in to change notification settings - Fork 2
/
1146
4823 lines (4433 loc) · 161 KB
/
1146
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def send_email(subject,
body,
hostname,
port,
user,
password,
recipients,
attachment_path=None):
"""Sends an email, and possibly an attachment, to the given recipients.
Args:
subject: The email subject text.
body: The email body text.
host: Hostname of the SMTP email server.
port: Port on the host to connect on.
user: Email address to send the email from.
password: Password of the sending address.
recipients: A list of email addresses to send the message to.
attachment_path (optional): Path to the attachment file.
"""
# Create message and add body
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = user
msg['To'] = ', '.join(recipients)
msg.attach(MIMEText(body))
# Add attachment to message
if attachment_path != None:
attachment = open(attachment_path, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="{}"'.format(attachment_path))
msg.attach(part)
# Send the message
server = smtplib.SMTP(hostname, port)
server.starttls()
server.login(user, password)
server.sendmail(from_addr = user,
to_addrs = recipients,
msg = msg.as_string())
server.quit()
'''
import numpy as np
import sys
def select_filters(flts=[]):
yield from _close_shutter(simu=False)
for key, item in filters.items():
yield from mv(item, 0)
for ii in flts:
yield from mv(filters["filter" + str(ii)], 1)
def user_scan(
exposure_time,
period,
out_x,
out_y,
out_z,
rs=1,
out_r=0,
xanes_flag=False,
xanes_angle=0,
note="",
):
# Ni
angle_ini = 0
yield from mv(zps.pi_r, angle_ini)
print("start taking tomo and xanes of Ni")
yield from move_zp_ccd(8.35, move_flag=1)
yield from fly_scan(
exposure_time,
relative_rot_angle=180,
period=period,
out_x=out_x,
out_y=out_y,
out_z=out_z,
rs=rs,
parkpos=out_r,
note=note + "_8.35keV",
)
yield from bps.sleep(2)
yield from move_zp_ccd(8.3, move_flag=1)
yield from fly_scan(
exposure_time,
relative_rot_angle=180,
period=period,
out_x=out_x,
out_y=out_y,
out_z=out_z,
rs=rs,
parkpos=out_r,
note=note + "8.3keV",
)
yield from mv(zps.pi_r, xanes_angle)
if xanes_flag:
yield from xanes_scan2(
eng_list_Ni,
exposure_time,
chunk_size=5,
out_x=out_x,
out_y=out_y,
out_z=out_z,
out_r=out_r,
note=note + "_xanes",
)
yield from mv(zps.pi_r, angle_ini)
"""
# Co
print('start taking tomo and xanes of Co')
yield from mv(zps.pi_r, angle_ini)
yield from move_zp_ccd(7.75, move_flag=1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(7.66, move_flag=1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from mv(zps.pi_r, xanes_angle)
if xanes_flag:
yield from xanes_scan2(eng_list_Co, 0.05, chunk_size=5, out_x=out_x, out_y=out_y,note=note)
yield from mv(zps.pi_r, angle_ini)
# Mn
print('start taking tomo and xanes of Mn')
yield from mv(zps.pi_r, angle_ini)
yield from move_zp_ccd(6.59, move_flag=1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(6.49, move_flag=1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from mv(zps.pi_r, xanes_angle)
if xanes_flag:
yield from xanes_scan2(eng_list_Mn, 0.1, chunk_size=5, out_x=out_x, out_y=out_y,note=note)
yield from mv(zps.pi_r, angle_ini)
"""
def user_xanes(out_x, out_y, note=""):
"""
yield from move_zp_ccd(7.4, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from xanes_scan2(eng_list_Co, 0.05, chunk_size=5, out_x=out_x, out_y=out_y, note=note)
yield from bps.sleep(5)
"""
print("please wait for 5 sec...starting Ni xanes")
yield from move_zp_ccd(8.3, move_flag=1)
yield from bps.sleep(1)
yield from xanes_scan2(
eng_list_Ni, 0.05, chunk_size=5, out_x=out_x, out_y=out_y, note=note
)
"""
def user_flyscan(out_x, out_y, note=''):
yield from move_zp_ccd(8.35, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(8.3, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(7.75, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(7.66, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(6.59, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
yield from move_zp_ccd(6.49, move_flag=1, xanes_flag='2D')
yield from bps.sleep(1)
yield from fly_scan(0.05, relative_rot_angle=180, period=0.05, out_x=out_x, out_y=out_y,out_z=0, rs=2, parkpos=0, note=note)
"""
def overnight_fly():
insert_text("start William Zhou in-situ scan at 10min interval for 70 times:")
for i in range(70):
print(f"current scan# {i}")
yield from abs_set(shutter_open, 1)
yield from sleep(1)
yield from abs_set(shutter_open, 1)
yield from sleep(2)
yield from fly_scan(
exposure_time=0.05,
relative_rot_angle=180,
period=0.05,
chunk_size=20,
out_x=0,
out_y=0,
out_z=1000,
out_r=0,
rs=3,
simu=False,
note="WilliamZhou_DOW_Water_drying_insitu_scan@8.6keV,w/filter 1&2",
)
yield from abs_set(shutter_close, 1)
yield from sleep(1)
yield from abs_set(shutter_close, 1)
yield from sleep(2)
yield from bps.sleep(520)
insert_text("finished pin-situ scan")
def insitu_xanes_scan(
eng_list,
exposure_time=0.2,
out_x=0,
out_y=0,
out_z=0,
out_r=0,
repeat_num=1,
sleep_time=1,
note="None",
):
insert_text("start from now on, taking in-situ NMC charge/discharge xanes scan:")
for i in range(repeat_num):
print(f"scan #{i}\n")
yield from xanes_scan2(
eng_list,
exposure_time=exposure_time,
chunk_size=2,
out_x=out_x,
out_y=out_y,
out_z=out_z,
out_r=out_r,
note=f"{note}_#{i}",
)
current_time = str(datetime.now().time())[:8]
print(f"current time is {current_time}")
insert_text(f"current scan finished at: {current_time}")
yield from abs_set(shutter_close, 1)
yield from bps.sleep(1)
yield from abs_set(shutter_close, 1)
print(f"\nI'm sleeping for {sleep_time} sec ...\n")
yield from bps.sleep(sleep_time)
insert_text("finished in-situ xanes scan !!")
def user_fly_scan(
exposure_time=0.1, period=0.1, chunk_size=20, rs=1, note="", simu=False, md=None
):
"""
motor_x_ini = zps.pi_x.position
# motor_x_out = motor_x_ini + txm_out_x
motor_y_ini = zps.sy.position
motor_y_out = motor_y_ini + out_y
motor_z_ini = zps.sz.position
motor_z_out = motor_z_ini + out_z
motor_r_ini = zps.pi_r.position
motor_r_out = motor_r_ini + out_r
"""
motor_r_ini = zps.pi_r.position
motor = [zps.sx, zps.sy, zps.sz, zps.pi_r, zps.pi_x]
dets = [Andor, ic3]
taxi_ang = -2.0 * rs
cur_rot_ang = zps.pi_r.position
# tgt_rot_ang = cur_rot_ang + rel_rot_ang
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
"exposure_time": exposure_time,
"period": period,
"chunk_size": chunk_size,
"rs": rs,
"note": note if note else "None",
},
"plan_name": "fly_scan",
"num_bkg_images": chunk_size,
"num_dark_images": chunk_size,
"chunk_size": chunk_size,
"plan_pattern": "linspace",
"plan_pattern_module": "numpy",
"hints": {},
"operator": "FXI",
"note": note if note else "None",
"motor_pos": wh_pos(print_on_screen=0),
}
_md.update(md or {})
try:
dimensions = [(zps.pi_r.hints["fields"], "primary")]
except (AttributeError, KeyError):
pass
else:
_md["hints"].setdefault("dimensions", dimensions)
yield from _set_andor_param(
exposure_time=exposure_time, period=period, chunk_size=chunk_size
)
print("set rotation speed: {} deg/sec".format(rs))
@stage_decorator(list(dets) + motor)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def inner_scan():
# close shutter, dark images: numer=chunk_size (e.g.20)
print("\nshutter closed, taking dark images...")
yield from _take_dark_image(dets, motor, num_dark=1, simu=simu)
yield from mv(zps.pi_x, 0)
yield from mv(zps.pi_r, -50)
yield from _set_rotation_speed(rs=rs)
# open shutter, tomo_images
yield from _open_shutter(simu=simu)
print("\nshutter opened, taking tomo images...")
yield from mv(zps.pi_r, -50 + taxi_ang)
status = yield from abs_set(zps.pi_r, 50, wait=False)
yield from bps.sleep(2)
while not status.done:
yield from trigger_and_read(list(dets) + motor)
# bkg images
print("\nTaking background images...")
yield from _set_rotation_speed(rs=30)
yield from mv(zps.pi_r, 0)
yield from mv(zps.pi_x, 12)
yield from mv(zps.pi_r, 70)
yield from trigger_and_read(list(dets) + motor)
yield from _close_shutter(simu=simu)
yield from mv(zps.pi_r, 0)
yield from mv(zps.pi_x, 0)
yield from mv(zps.pi_x, 0)
# yield from mv(zps.pi_r, motor_r_ini)
uid = yield from inner_scan()
print("scan finished")
txt = get_scan_parameter()
insert_text(txt)
print(txt)
return uid
def tmp_scan():
x = np.array([0, 1, 2, 3]) * 0.015 * 2560 + zps.sx.position
y = np.array([0, 1, 2, 3]) * 0.015 * 2160 + zps.sy.position
i = 0
j = 0
for xx in x:
i += 1
for yy in y:
j += 1
print(f"current {i}_{j}: x={xx}, y={yy}")
yield from mv(zps.sx, xx, zps.sy, yy)
yield from xanes_scan2(
eng_Ni_list_xanes,
0.05,
chunk_size=4,
out_x=2000,
out_y=0,
out_z=0,
out_r=0,
simu=False,
note="NCM532_72cycle_discharge_{i}_{j}",
)
def mosaic_fly_scan(
x_list,
y_list,
z_list,
r_list,
exposure_time=0.1,
rel_rot_ang=150,
period=0.1,
chunk_size=20,
out_x=None,
out_y=None,
out_z=4400,
out_r=90,
rs=1,
note="",
simu=False,
relative_move_flag=0,
traditional_sequence_flag=0,
):
txt = "start mosaic_fly_scan, containing following fly_scan\n"
insert_text(txt)
insert_text("x_list = ")
insert_text(str(x_list))
insert_text("y_list = ")
insert_text(str(y_list))
insert_text("z_list = ")
insert_text(str(z_list))
insert_text("r_list = ")
insert_text(str(r_list))
nx = len(x_list)
ny = len(y_list)
for i in range(ny):
for j in range(nx):
success = False
count = 1
while not success and count < 20:
try:
RE(
mv(
zps.sx,
x_list[j],
zps.sy,
y_list[i],
zps.sz,
z_list[i],
zps.pi_r,
r_list[i],
)
)
RE(
fly_scan(
exposure_time,
relative_rot_angle,
period,
chunk_size,
out_x,
out_y,
out_z,
out_r,
rs,
note,
simu,
relative_move_flag,
traditional_sequence_flag,
md=None,
)
)
success = True
except:
count += 1
RE.abort()
Andor.unstage()
print("sleeping for 30 sec")
RE(bps.sleep(30))
txt = f"Redo scan at x={x_list[i]}, y={y_list[i]}, z={z_list[i]} for {count} times"
print(txt)
insert_text(txt)
txt = "mosaic_fly_scan finished !!\n"
insert_text(txt)
def mosaic2d_lists(x_start, x_end, x_step, y_start, y_end, y_step, z, r):
x_range = list(range(x_start, x_end + x_step, x_step))
y_range = list(range(y_start, y_end + y_step, y_step))
x_list = x_range * len(y_range)
y_list = []
for y in y_range:
y_list.extend([y] * len(x_range))
z_list = [z] * len(x_list)
r_list = [r] * len(x_list)
return x_list, y_list, z_list, r_list
def multi_pos_3D_xanes(
eng_list,
x_list=[0],
y_list=[0],
z_list=[0],
r_list=[0],
exposure_time=0.05,
rel_rot_ang=182,
rs=2,
):
"""
the sample_out position is in its absolute value:
will move sample to out_x (um) out_y (um) out_z(um) and out_r (um) to take background image
to run:
RE(multi_pos_3D_xanes(Ni_eng_list, x_list=[a, b, c], y_list=[aa,bb,cc], z_list=[aaa,bbb, ccc], r_list=[0, 0, 0], exposure_time=0.05, rel_rot_ang=185, rs=3, out_x=1500, out_y=-1500, out_z=-770, out_r=0, note='NC')
"""
num_pos = len(x_list)
for i in range(num_pos):
print(f"currently, taking 3D xanes at position {i}\n")
yield from mv(
zps.sx, x_list[i], zps.sy, y_list[i], zps.sz, z_list[i], zps.pi_r, r_list[i]
)
yield from bps.sleep(2)
note_pos = note + f"position_{i}"
yield from xanes_3D(
eng_list,
exposure_time=exposure_time,
relative_rot_angle=rel_rot_ang,
period=exposure_time,
out_x=out_x,
out_y=out_y,
out_z=out_z,
out_r=out_r,
rs=rs,
simu=False,
relative_move_flag=0,
traditional_sequence_flag=1,
note=note_pos,
)
insert_text(f"finished 3D xanes scan for {note_pos}")
def mk_eng_list(elem, bulk=False):
if bulk:
eng_list = np.genfromtxt(
"/nsls2/data/fxi-new/shared/config/xanes_ref/"
+ elem.split("_")[0]
+ "/eng_list_"
+ elem.split("_")[0]
+ "_xanes_standard_dense.txt"
)
else:
if elem.split("_")[-1] == "wl":
eng_list = np.genfromtxt(
"/nsls2/data/fxi-new/shared/config/xanes_ref/"
+ elem.split("_")[0]
+ "/eng_list_"
+ elem.split("_")[0]
+ "_xanes_standard_21pnt.txt"
)
elif elem.split("_")[-1] == "101":
eng_list = np.genfromtxt(
"/nsls2/data/fxi-new/shared/config/xanes_ref/"
+ elem.split("_")[0]
+ "/eng_list_"
+ elem.split("_")[0]
+ "_xanes_standard_101pnt.txt"
)
elif elem.split("_")[-1] == "63":
eng_list = np.genfromtxt(
"/nsls2/data/fxi-new/shared/config/xanes_ref/"
+ elem.split("_")[0]
+ "/eng_list_"
+ elem.split("_")[0]
+ "_xanes_standard_63pnt.txt"
)
return eng_list
def sort_in_pos(in_pos_list):
x_list = []
y_list = []
z_list = []
r_list = []
for ii in range(len(in_pos_list)):
x_list.append(
zps.sx.position if in_pos_list[ii][0] is None else in_pos_list[ii][0]
)
y_list.append(
zps.sy.position if in_pos_list[ii][1] is None else in_pos_list[ii][1]
)
z_list.append(
zps.sz.position if in_pos_list[ii][2] is None else in_pos_list[ii][2]
)
r_list.append(
zps.pi_r.position if in_pos_list[ii][3] is None else in_pos_list[ii][3]
)
# if in_pos_list[ii][0] is None:
# x_list.append(zps.sx.position)
# else:
# x_list.append(in_pos_list[ii][0])
# if in_pos_list[ii][1] is None:
# y_list.append(zps.sy.position)
# else:
# y_list.append(in_pos_list[ii][1])
# if in_pos_list[ii][2] is None:
# z_list.append(zps.sz.position)
# else:
# z_list.append(in_pos_list[ii][2])
# if in_pos_list[ii][3] is None:
# r_list.append(zps.pi_r.position)
# else:
# r_list.append(in_pos_list[ii][3])
return (x_list, y_list, z_list, r_list)
def multi_edge_xanes(
elements=["Ni_wl"],
scan_type="3D",
filters={"Ni_filters": [1, 2, 3]},
exposure_time={"Ni_exp": 0.05},
rel_rot_ang=185,
rs=1,
in_pos_list=[[None, None, None, None]],
out_pos=[None, None, None, None],
chunk_size=5,
note="",
relative_move_flag=0,
binning=None,
simu=False,
):
yield from mv(Andor.cam.acquire, 0)
cam_bin = {0: "[1x1]", 1: "[2x2]", 2: "[3x3]", 3: "[4x4]", 4: "[8x8]"}
x_list, y_list, z_list, r_list = sort_in_pos(in_pos_list)
for elem in elements:
for key in filters.keys():
if elem.split("_")[0] == key.split("_")[0]:
yield from select_filters(filters[key])
break
else:
yield from select_filters([])
for key in exposure_time.keys():
if elem.split("_")[0] == key.split("_")[0]:
exposure = exposure_time[key]
print(elem, exposure)
break
else:
exposure = 0.05
print("use default exposure time 0.05s")
eng_list = mk_eng_list(elem, bulk=False)
if scan_type == "2D":
if binning is None:
binning = 0
# ans = input(
# f"You are going to conduct 2D XANES with camera binning of {cam_bin[binning]}. Proceed? (Y/n)"
# )
# if ans.upper() == "N":
# return
if int(binning) not in [0, 1, 2, 3, 4]:
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from mv(Andor.binning, binning)
yield from multipos_2D_xanes_scan2(
eng_list,
x_list,
y_list,
z_list,
r_list,
out_x=out_pos[0],
out_y=out_pos[1],
out_z=out_pos[2],
out_r=out_pos[3],
exposure_time=exposure,
chunk_size=chunk_size,
simu=simu,
relative_move_flag=relative_move_flag,
note=note,
md=None,
sleep_time=0,
repeat_num=1,
)
elif scan_type == "3D":
if binning is None:
binning = 1
# ans = input(
# f"You are going to conduct 3D XANES with camera binning of {cam_bin[binning]}. Proceed? (Y/n)"
# )
# if ans.upper() == "N":
# return
if int(binning) not in [0, 1, 2, 3, 4]:
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from mv(Andor.binning, binning)
yield from multi_pos_xanes_3D(
eng_list,
x_list,
y_list,
z_list,
r_list,
exposure_time=exposure,
relative_rot_angle=rel_rot_ang,
rs=rs,
out_x=out_pos[0],
out_y=out_pos[1],
out_z=out_pos[2],
out_r=out_pos[3],
note=note,
simu=simu,
relative_move_flag=relative_move_flag,
rot_first_flag=1,
sleep_time=0,
repeat=1,
)
else:
print("wrong scan type")
return
def multi_edge_xanes2(
elements=["Ni_wl"],
scan_type="3D",
filters={"Ni_filters": [1, 2, 3]},
exposure_time={"Ni_exp": 0.05},
rel_rot_ang=185,
rs=1,
in_pos_list=[[None, None, None, None]],
out_pos=[None, None, None, None],
note="",
relative_move_flag=0,
binning=None,
bulk=False,
bulk_intgr=10,
simu=False,
sleep=0,
repeat=None,
):
yield from mv(Andor.cam.acquire, 0)
cam_bin = {0: "[1x1]", 1: "[2x2]", 2: "[3x3]", 3: "[4x4]", 4: "[8x8]"}
if repeat is None:
repeat = 1
repeat = int(repeat)
for itr in range(repeat):
x_list, y_list, z_list, r_list = sort_in_pos(in_pos_list)
for elem in elements:
for key in filters.keys():
if elem.split("_")[0] == key.split("_")[0]:
yield from select_filters(filters[key])
else:
yield from select_filters([])
for key in exposure_time.keys():
if elem.split("_")[0] == key.split("_")[0]:
exposure = exposure_time[key]
print(elem, exposure)
else:
exposure = 0.05
print("use default exposure time 0.05s")
eng_list = mk_eng_list(elem, bulk=False)
if scan_type == "2D":
if binning is None:
binning = 0
# ans = input(
# f"You are going to conduct 2D XANES with camera binning of {cam_bin[binning]}. Proceed? (Y/n)"
# )
# if ans.upper() == "N":
# return
if int(binning) not in [0, 1, 2, 3, 4]:
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from mv(Andor.binning, binning)
yield from multipos_2D_xanes_scan2(
eng_list,
x_list,
y_list,
z_list,
r_list,
out_x=out_pos[0],
out_y=out_pos[1],
out_z=out_pos[2],
out_r=out_pos[3],
exposure_time=exposure,
chunk_size=5,
simu=simu,
relative_move_flag=relative_move_flag,
note=note,
md=None,
sleep_time=0,
repeat_num=1,
)
elif scan_type == "3D":
if binning is None:
binning = 1
# ans = input(
# f"You are going to conduct 3D XANES with camera binning of {cam_bin[binning]}. Proceed? (Y/n)"
# )
# if ans.upper() == "N":
# return
if int(binning) not in [0, 1, 2, 3, 4]:
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from mv(Andor.binning, binning)
yield from multi_pos_xanes_3D(
eng_list,
x_list,
y_list,
z_list,
r_list,
exposure_time=exposure,
relative_rot_angle=rel_rot_ang,
rs=rs,
out_x=out_pos[0],
out_y=out_pos[1],
out_z=out_pos[2],
out_r=out_pos[3],
note=note,
simu=simu,
relative_move_flag=relative_move_flag,
rot_first_flag=1,
sleep_time=0,
repeat=1,
)
else:
print("wrong scan type")
if bulk:
eng_list = mk_eng_list(elem, bulk=True)
zpx = zp.x.position
apx = aper.x.position
cdx = clens.x.position
yield from mv(zp.x, -6500 + zpx)
yield from mv(clens.x, 6500 + cds)
yield from mv(aper.x, -4000 + apx)
xxanes_scan(eng_list, delay_time=0.2, intgr=bulk_intgr, note=note)
yield from mv(clens.x, cds)
yield from mv(aper.x, apx)
yield from mv(zp.x, zpx)
if itr != repeat - 1:
yield from bps.sleep(sleep)
print(f"repeat # {itr} finished")
def fly_scan2(
exposure_time=0.05,
start_angle=None,
rel_rot_ang=180,
period=0.05,
out_x=None,
out_y=None,
out_z=None,
out_r=None,
rs=3,
relative_move_flag=1,
rot_first_flag=1,
filters=[],
rot_back_velo=30,
binning=None,
note="",
md=None,
move_to_ini_pos=True,
simu=False,
):
"""
Inputs:
-------
exposure_time: float, in unit of sec
start_angle: float
starting angle
rel_rot_ang: float,
total rotation angles start from current rotary stage (zps.pi_r) position
period: float, in unit of sec
period of taking images, "period" should >= "exposure_time"
out_x: float, default is 0
relative movement of sample in "x" direction using zps.sx to move out sample (in unit of um)
NOTE: BE CAUSION THAT IT WILL ROTATE SAMPLE BY "out_r" FIRST, AND THEN MOVE X, Y, Z
out_y: float, default is 0
relative movement of sample in "y" direction using zps.sy to move out sample (in unit of um)
NOTE: BE CAUSION THAT IT WILL ROTATE SAMPLE BY "out_r" FIRST, AND THEN MOVE X, Y, Z
out_z: float, default is 0
relative movement of sample in "z" direction using zps.sz to move out sample (in unit of um)
NOTE: BE CAUSION THAT IT WILL ROTATE SAMPLE BY "out_r" FIRST, AND THEN MOVE X, Y, Z
out_r: float, default is 0
relative movement of sample by rotating "out_r" degrees, using zps.pi_r to move out sample
NOTE: BE CAUSION THAT IT WILL ROTATE SAMPLE BY "out_r" FIRST, AND THEN MOVE X, Y, Z
rs: float, default is 1
rotation speed in unit of deg/sec
note: string
adding note to the scan
simu: Bool, default is False
True: will simulate closing/open shutter without really closing/opening
False: will really close/open shutter
"""
yield from mv(Andor.cam.acquire, 0)
if binning is None:
binning = 0
if int(binning) not in [0, 1, 2, 3, 4]:
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from mv(Andor.binning, binning)
global ZONE_PLATE
motor_x_ini = zps.sx.position
motor_y_ini = zps.sy.position
motor_z_ini = zps.sz.position
motor_r_ini = zps.pi_r.position
if not (start_angle is None):
yield from mv(zps.pi_r, start_angle)
if relative_move_flag:
motor_x_out = motor_x_ini + out_x if not (out_x is None) else motor_x_ini
motor_y_out = motor_y_ini + out_y if not (out_y is None) else motor_y_ini
motor_z_out = motor_z_ini + out_z if not (out_z is None) else motor_z_ini
motor_r_out = motor_r_ini + out_r if not (out_r is None) else motor_r_ini
else:
motor_x_out = out_x if not (out_x is None) else motor_x_ini
motor_y_out = out_y if not (out_y is None) else motor_y_ini
motor_z_out = out_z if not (out_z is None) else motor_z_ini
motor_r_out = out_r if not (out_r is None) else motor_r_ini
motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
dets = [Andor, ic3]
taxi_ang = -1 * rs
cur_rot_ang = zps.pi_r.position
tgt_rot_ang = cur_rot_ang + rel_rot_ang
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
"exposure_time": exposure_time,
"start_angle": start_angle,
"relative_rot_angle": rel_rot_ang,
"period": period,
"out_x": out_x,
"out_y": out_y,
"out_z": out_z,
"out_r": out_r,
"rs": rs,
"relative_move_flag": relative_move_flag,
"rot_first_flag": rot_first_flag,
"filters": [t.name for t in filters] if filters else "None",
"binning": "None" if binning is None else binning,
"note": note if note else "None",
"zone_plate": ZONE_PLATE,
},
"plan_name": "fly_scan",
"num_bkg_images": 20,
"num_dark_images": 20,
"plan_pattern": "linspace",
"plan_pattern_module": "numpy",
"hints": {},
"operator": "FXI",
"note": note if note else "None",
"zone_plate": ZONE_PLATE,
#'motor_pos': wh_pos(print_on_screen=0),
}
_md.update(md or {})
try:
dimensions = [(zps.pi_r.hints["fields"], "primary")]
except (AttributeError, KeyError):
pass
else:
_md["hints"].setdefault("dimensions", dimensions)
yield from _set_andor_param(
exposure_time=exposure_time, period=period, chunk_size=20, binning=binning
)
yield from _set_rotation_speed(rs=np.abs(rs))
print("set rotation speed: {} deg/sec".format(rs))
@stage_decorator(list(dets) + motor)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
select_filters(flts=[])
yield from bps.sleep(1)
# close shutter, dark images: numer=chunk_size (e.g.20)
print("\nshutter closed, taking dark images...")
yield from _take_dark_image(
dets, motor, num=1, chunk_size=20, stream_name="dark", simu=simu
)
# open shutter, tomo_images
true_period = yield from rd(Andor.cam.acquire_period)
rot_time = np.abs(rel_rot_ang) / np.abs(rs)
num_img = int(rot_time / true_period) + 2
yield from _open_shutter(simu=simu)
print("\nshutter opened, taking tomo images...")
yield from _set_Andor_chunk_size(dets, chunk_size=num_img)
# yield from mv(zps.pi_r, cur_rot_ang + taxi_ang)
status = yield from abs_set(zps.pi_r, tgt_rot_ang, wait=False)
# yield from bps.sleep(1)
yield from _take_image(dets, motor, num=1, stream_name="primary")
while not status.done:
yield from bps.sleep(0.01)
# yield from trigger_and_read(list(dets) + motor)
# bkg images
print("\nTaking background images...")
yield from _set_rotation_speed(rs=rot_back_velo)
# yield from abs_set(zps.pi_r.velocity, rs)
yield from _take_bkg_image(
motor_x_out,
motor_y_out,