saving motor positions after weekly and daily setup routines

This commit is contained in:
x10sa authored and perl_d committed 2026-10-20 16:07:54 +02:00
1 parent 0e8bd2c351
commit 3514053d52
3 files changed
+370

No files matched your search

@@ -0,0 +1,32 @@
timestamp,energy_eV,flux_ph_s,beam_start_x_px,beam_start_y_px,vfm_ydr_start_mm,hfm_xd_start_mm,vfm_ydr_final_mm,hfm_xd_final_mm,beam_final_x_um,beam_final_y_um,vfm_y_mm,vfm_ydr_mm,vfm_pitch_mrad,hfm_x_mm,hfm_xd_mm,hfm_pitch_mrad
2026-09-20T21:16:24,12400,8.60e+12,993,966,-0.84534,1.91200,-0.84534,1.91202,-0.2,0.3,-1.55385,-0.84534,2.98943,1.41177,1.91202,3.00093
2026-09-20T21:24:44,12400,8.57e+12,993,969,-0.84534,1.91201,-0.84534,1.91200,-0.2,-0.1,-1.55385,-0.84534,2.98943,1.41178,1.91200,3.00090
2026-09-20T21:28:14,12400,8.48e+12,992,967,-0.84535,1.91200,-0.84534,1.91200,0.1,0.3,-1.55385,-0.84534,2.98945,1.41178,1.91200,3.00093
2026-09-21T08:55:37,12400,8.46e+12,993,970,-0.84534,1.91199,-0.84533,1.91199,-0.1,-0.3,-1.55384,-0.84533,2.98941,1.41177,1.91199,3.00092
2026-09-21T14:34:03,13000,5.55e+12,1000,968,-0.84513,1.91200,-0.84512,1.91240,-0.1,-0.0,-1.55380,-0.84512,2.98985,1.41197,1.91240,3.00173
2026-09-23T08:53:50,19500,4.06e+11,653,973,-0.84449,1.92951,-0.84448,1.91255,0.1,0.1,-1.55363,-0.84448,2.99111,1.41202,1.91255,3.00201
2026-09-23T08:54:51,20000,1.36e+12,994,967,-0.84449,1.91255,-0.84448,1.91254,-0.1,0.2,-1.55363,-0.84448,2.99111,1.41203,1.91254,3.00207
2026-09-23T13:13:02,20000,7.04e+12,1007,975,-0.84448,1.91250,-0.84449,1.91309,-0.3,-0.9,-1.55365,-0.84449,2.99113,1.41230,1.91309,3.00313
2026-09-24T00:42:05,12400,7.96e+12,994,923,-0.84443,1.91307,-0.84566,1.91306,-0.0,-0.2,-1.55391,-0.84566,2.98872,1.41228,1.91306,3.00309
2026-09-24T00:44:08,12400,8.00e+12,994,968,-0.84567,1.91304,-0.84567,1.91307,0.1,0.2,-1.55391,-0.84567,2.98870,1.41229,1.91307,3.00310
2026-09-24T00:45:03,12402,7.81e+12,993,968,-0.84566,1.91304,-0.84567,1.91305,0.2,-0.0,-1.55390,-0.84566,2.98870,1.41229,1.91308,3.00311
2026-09-24T00:46:04,12400,7.94e+12,990,968,-0.84565,1.91305,-0.84566,1.91306,0.2,0.2,-1.55390,-0.84565,2.98868,1.41230,1.91307,3.00313
2026-09-24T12:08:20,12400,8.42e+12,989,970,-0.84568,1.91305,-0.84570,1.91307,0.9,-0.2,-1.55392,-0.84570,2.98867,1.41230,1.91307,3.00308
2026-09-27T15:10:30,15000,-0.042,6.07e+11,987,963,-0.84510,1.91436,-0.84510,1.91436,0.8,0.8,-1.55386,-0.84510,2.99004,1.41296,1.91436,3.00560
2026-09-27T15:12:34,12400,-0.044,8.30e+12,992,965,-0.84512,1.91435,-0.84511,1.91435,-0.0,0.7,-1.55386,-0.84511,2.99006,1.41295,1.91435,3.00558
2026-09-28T18:13:02,12400,-0.044,8.25e+12,974,965,-0.84509,1.91433,-0.84506,1.91343,0.6,0.6,-1.55386,-0.84506,2.99014,1.41248,1.91343,3.00375
2026-09-28T18:15:15,12400,-0.044,8.23e+12,992,965,-0.84505,1.91343,-0.84505,1.91344,0.1,0.8,-1.55385,-0.84505,2.99016,1.41250,1.91344,3.00375
2026-09-28T18:17:05,12400,-0.044,8.25e+12,992,964,-0.84507,1.91345,-0.84507,1.91343,0.4,0.8,-1.55387,-0.84507,2.99013,1.41248,1.91343,3.00381
2026-09-28T18:26:15,12400,-0.045,9.23e+12,990,965,-0.84507,1.91344,-0.84506,1.91342,0.5,0.5,-1.55386,-0.84506,2.99016,1.41248,1.91342,3.00378
2026-09-28T18:29:25,12400,-0.045,9.25e+12,988,965,-0.84509,1.91343,-0.84506,1.91344,0.4,0.8,-1.55387,-0.84506,2.99014,1.41249,1.91344,3.00377
2026-09-28T18:31:23,12400,-0.045,8.24e+12,992,965,-0.84508,1.91345,-0.84508,1.91342,0.2,0.5,-1.55387,-0.84508,2.99013,1.41248,1.91342,3.00377
2026-09-28T21:37:21,12400,-0.045,8.16e+12,1006,972,-0.84504,1.91341,-0.84505,1.91414,0.2,-0.5,1.17,0.29,-1.55385,-0.84505,2.99013,1.41284,1.91414,3.00520
2026-09-30T20:05:09,12400,-0.043,7.76e+12,1042,902,-0.83715,1.91288,-0.83893,1.91549,0.1,-0.3,10.45,1.36,-1.55113,-0.83893,2.99303,1.41354,1.91549,3.00780
2026-09-30T20:20:59,12400,-0.043,8.27e+12,985,963,-0.83894,1.91541,-0.83893,1.91489,-0.4,0.8,13.04,1.33,-1.55112,-0.83894,2.99308,1.41324,1.91488,3.00663
2026-10-01T08:38:35,12400,-0.043,9.06e+12,979,909,-0.83889,1.91485,-0.84048,1.91407,-0.1,-0.3,9.77,1.35,-1.55147,-0.84046,2.98990,1.41280,1.91409,3.00509
2026-10-01T08:40:31,15000,-0.042,6.32e+11,995,981,-0.84048,1.91408,-0.83981,1.91408,-0.4,0.2,15.46,2.83,-1.55130,-0.83981,2.99123,1.41280,1.91408,3.00513
2026-10-01T08:47:42,15000,-0.042,4.22e+12,991,940,-0.83982,1.91410,-0.84060,1.91407,0.3,-0.2,13.88,1.43,-1.55151,-0.84061,2.98968,1.41281,1.91409,3.00509
2026-10-01T09:24:49,16000,-0.043,3.04e+12,994,969,-0.84058,1.91407,-0.84058,1.91409,0.3,0.1,20.87,1.84,-1.55150,-0.84059,2.98967,1.41281,1.91409,3.00515
2026-10-02T10:16:22,12400,-0.044,9.91e+12,,,,,,,,,,,-1.55143,-0.84055,2.98973,1.41274,1.91402,3.00507
2026-10-02T10:21:56,12400,-0.044,8.22e+12,1001,952,-0.84053,1.91404,-0.84102,1.91453,0.5,-0.5,11.20,1.19,-1.55155,-0.84100,2.98875,1.41302,1.91456,3.00614
2026-10-02T11:46:02,12400,-0.046,7.47e+12,984,963,-0.84101,1.91456,-0.84101,1.91396,-0.5,0.7,10.91,1.12,-1.55155,-0.84101,2.98877,1.41272,1.91395,3.00500
1 timestamp energy_eV flux_ph_s beam_start_x_px beam_start_y_px vfm_ydr_start_mm hfm_xd_start_mm vfm_ydr_final_mm hfm_xd_final_mm beam_final_x_um beam_final_y_um vfm_y_mm vfm_ydr_mm vfm_pitch_mrad hfm_x_mm hfm_xd_mm hfm_pitch_mrad
2 2026-09-20T21:16:24 12400 8.60e+12 993 966 -0.84534 1.91200 -0.84534 1.91202 -0.2 0.3 -1.55385 -0.84534 2.98943 1.41177 1.91202 3.00093
3 2026-09-20T21:24:44 12400 8.57e+12 993 969 -0.84534 1.91201 -0.84534 1.91200 -0.2 -0.1 -1.55385 -0.84534 2.98943 1.41178 1.91200 3.00090
4 2026-09-20T21:28:14 12400 8.48e+12 992 967 -0.84535 1.91200 -0.84534 1.91200 0.1 0.3 -1.55385 -0.84534 2.98945 1.41178 1.91200 3.00093
5 2026-09-21T08:55:37 12400 8.46e+12 993 970 -0.84534 1.91199 -0.84533 1.91199 -0.1 -0.3 -1.55384 -0.84533 2.98941 1.41177 1.91199 3.00092
6 2026-09-21T14:34:03 13000 5.55e+12 1000 968 -0.84513 1.91200 -0.84512 1.91240 -0.1 -0.0 -1.55380 -0.84512 2.98985 1.41197 1.91240 3.00173
7 2026-09-23T08:53:50 19500 4.06e+11 653 973 -0.84449 1.92951 -0.84448 1.91255 0.1 0.1 -1.55363 -0.84448 2.99111 1.41202 1.91255 3.00201
8 2026-09-23T08:54:51 20000 1.36e+12 994 967 -0.84449 1.91255 -0.84448 1.91254 -0.1 0.2 -1.55363 -0.84448 2.99111 1.41203 1.91254 3.00207
9 2026-09-23T13:13:02 20000 7.04e+12 1007 975 -0.84448 1.91250 -0.84449 1.91309 -0.3 -0.9 -1.55365 -0.84449 2.99113 1.41230 1.91309 3.00313
10 2026-09-24T00:42:05 12400 7.96e+12 994 923 -0.84443 1.91307 -0.84566 1.91306 -0.0 -0.2 -1.55391 -0.84566 2.98872 1.41228 1.91306 3.00309
11 2026-09-24T00:44:08 12400 8.00e+12 994 968 -0.84567 1.91304 -0.84567 1.91307 0.1 0.2 -1.55391 -0.84567 2.98870 1.41229 1.91307 3.00310
12 2026-09-24T00:45:03 12402 7.81e+12 993 968 -0.84566 1.91304 -0.84567 1.91305 0.2 -0.0 -1.55390 -0.84566 2.98870 1.41229 1.91308 3.00311
13 2026-09-24T00:46:04 12400 7.94e+12 990 968 -0.84565 1.91305 -0.84566 1.91306 0.2 0.2 -1.55390 -0.84565 2.98868 1.41230 1.91307 3.00313
14 2026-09-24T12:08:20 12400 8.42e+12 989 970 -0.84568 1.91305 -0.84570 1.91307 0.9 -0.2 -1.55392 -0.84570 2.98867 1.41230 1.91307 3.00308
15 2026-09-27T15:10:30 15000 -0.042 6.07e+11 987 963 -0.84510 1.91436 -0.84510 1.91436 0.8 0.8 -1.55386 -0.84510 2.99004 1.41296 1.91436 3.00560
16 2026-09-27T15:12:34 12400 -0.044 8.30e+12 992 965 -0.84512 1.91435 -0.84511 1.91435 -0.0 0.7 -1.55386 -0.84511 2.99006 1.41295 1.91435 3.00558
17 2026-09-28T18:13:02 12400 -0.044 8.25e+12 974 965 -0.84509 1.91433 -0.84506 1.91343 0.6 0.6 -1.55386 -0.84506 2.99014 1.41248 1.91343 3.00375
18 2026-09-28T18:15:15 12400 -0.044 8.23e+12 992 965 -0.84505 1.91343 -0.84505 1.91344 0.1 0.8 -1.55385 -0.84505 2.99016 1.41250 1.91344 3.00375
19 2026-09-28T18:17:05 12400 -0.044 8.25e+12 992 964 -0.84507 1.91345 -0.84507 1.91343 0.4 0.8 -1.55387 -0.84507 2.99013 1.41248 1.91343 3.00381
20 2026-09-28T18:26:15 12400 -0.045 9.23e+12 990 965 -0.84507 1.91344 -0.84506 1.91342 0.5 0.5 -1.55386 -0.84506 2.99016 1.41248 1.91342 3.00378
21 2026-09-28T18:29:25 12400 -0.045 9.25e+12 988 965 -0.84509 1.91343 -0.84506 1.91344 0.4 0.8 -1.55387 -0.84506 2.99014 1.41249 1.91344 3.00377
22 2026-09-28T18:31:23 12400 -0.045 8.24e+12 992 965 -0.84508 1.91345 -0.84508 1.91342 0.2 0.5 -1.55387 -0.84508 2.99013 1.41248 1.91342 3.00377
23 2026-09-28T21:37:21 12400 -0.045 8.16e+12 1006 972 -0.84504 1.91341 -0.84505 1.91414 0.2 -0.5 1.17 0.29 -1.55385 -0.84505 2.99013 1.41284 1.91414 3.00520
24 2026-09-30T20:05:09 12400 -0.043 7.76e+12 1042 902 -0.83715 1.91288 -0.83893 1.91549 0.1 -0.3 10.45 1.36 -1.55113 -0.83893 2.99303 1.41354 1.91549 3.00780
25 2026-09-30T20:20:59 12400 -0.043 8.27e+12 985 963 -0.83894 1.91541 -0.83893 1.91489 -0.4 0.8 13.04 1.33 -1.55112 -0.83894 2.99308 1.41324 1.91488 3.00663
26 2026-10-01T08:38:35 12400 -0.043 9.06e+12 979 909 -0.83889 1.91485 -0.84048 1.91407 -0.1 -0.3 9.77 1.35 -1.55147 -0.84046 2.98990 1.41280 1.91409 3.00509
27 2026-10-01T08:40:31 15000 -0.042 6.32e+11 995 981 -0.84048 1.91408 -0.83981 1.91408 -0.4 0.2 15.46 2.83 -1.55130 -0.83981 2.99123 1.41280 1.91408 3.00513
28 2026-10-01T08:47:42 15000 -0.042 4.22e+12 991 940 -0.83982 1.91410 -0.84060 1.91407 0.3 -0.2 13.88 1.43 -1.55151 -0.84061 2.98968 1.41281 1.91409 3.00509
29 2026-10-01T09:24:49 16000 -0.043 3.04e+12 994 969 -0.84058 1.91407 -0.84058 1.91409 0.3 0.1 20.87 1.84 -1.55150 -0.84059 2.98967 1.41281 1.91409 3.00515
30 2026-10-02T10:16:22 12400 -0.044 9.91e+12 -1.55143 -0.84055 2.98973 1.41274 1.91402 3.00507
31 2026-10-02T10:21:56 12400 -0.044 8.22e+12 1001 952 -0.84053 1.91404 -0.84102 1.91453 0.5 -0.5 11.20 1.19 -1.55155 -0.84100 2.98875 1.41302 1.91456 3.00614
32 2026-10-02T11:46:02 12400 -0.046 7.47e+12 984 963 -0.84101 1.91456 -0.84101 1.91396 -0.5 0.7 10.91 1.12 -1.55155 -0.84101 2.98877 1.41272 1.91395 3.00500
@@ -0,0 +1,12 @@
"timestamp","energy_eV","id_gap_mm","pitch_offset_mrad","fe_x","fe_y","bsf_x","bsf_y","ss_x","ss_y","lu_Xnorm","lu_Ynorm","ss_Xnorm","ss_Ynorm","bcu_Xnorm","bcu_Ynorm","bcu_beam_x","bcu_beam_y"
"2026-09-24T21:42:20",12400,5.307,-0.0426,0.14,0.872,0.099,0.153,0.215,-0.644,,,,,,,,
"2026-09-28T19:57:16",12400,5.307,-0.0445,0.14,0.872,0.105,0.148,0.221,-0.64,,,,,,,,
"2026-09-28T20:08:25",12400,5.307,-0.0444,0.14,0.872,0.104,0.148,0.224,-0.64,-0.0016,-0.0111,-0.014,,0.1135,-0.1181,,
"2026-09-30T08:58:15",12400,5.307,-0.0445,0.14,0.886,0.104,0.17,0.196,-0.22,0.0816,0.4118,0.0335,,-0.1125,-0.8165,,
"2026-09-30T09:08:53",12400,5.307,-0.0425,0.14,0.865,0.104,0.144,0.244,-1.018,-0.064,-0.2892,-0.0794,,0.0347,0.9834,,
"2026-09-30T10:49:14",12400,5.307,-0.042,0.14,0.874,0.103,0.152,0.219,-0.635,0.0121,-0.0176,0.0116,,-0.0384,-0.0568,,
"2026-09-30T11:04:59",12400,5.307,-0.0417,0.14,0.874,0.103,0.152,0.22,-0.641,0.0119,-0.0123,0.0135,-0.0026,-0.0427,-0.0612,,
"2026-09-30T11:39:23",12400,5.307,-0.042,0.14,0.874,0.102,0.152,0.22,-0.641,0.0135,-0.0108,0.0095,0.0004,-0.0371,-0.0659,5.64,-1.65
"2026-09-30T11:45:21",12400,5.307,-0.0417,0.14,0.874,0.102,0.152,0.224,-0.639,0.014,-0.0129,0.0118,-0.0001,-0.0399,-0.0652,6.1,-1.63
2026-09-30T12:07:53,12400,5.307,-0.042,0.14,0.874,0.101,0.152,0.219,-0.639,0.0145,-0.0108,0.0138,0.000447,-0.0467,-0.066,7.24,-1.65
2026-09-30T12:15:59,12400,5.307,-0.0418,0.14,0.874,0.101,0.152,0.221,-0.639,0.0144,-0.0105,0.012,-0.00118,-0.0414,-0.0618,6.36,-1.54
1 timestamp energy_eV id_gap_mm pitch_offset_mrad fe_x fe_y bsf_x bsf_y ss_x ss_y lu_Xnorm lu_Ynorm ss_Xnorm ss_Ynorm bcu_Xnorm bcu_Ynorm bcu_beam_x bcu_beam_y
2 2026-09-24T21:42:20 12400 5.307 -0.0426 0.14 0.872 0.099 0.153 0.215 -0.644
3 2026-09-28T19:57:16 12400 5.307 -0.0445 0.14 0.872 0.105 0.148 0.221 -0.64
4 2026-09-28T20:08:25 12400 5.307 -0.0444 0.14 0.872 0.104 0.148 0.224 -0.64 -0.0016 -0.0111 -0.014 0.1135 -0.1181
5 2026-09-30T08:58:15 12400 5.307 -0.0445 0.14 0.886 0.104 0.17 0.196 -0.22 0.0816 0.4118 0.0335 -0.1125 -0.8165
6 2026-09-30T09:08:53 12400 5.307 -0.0425 0.14 0.865 0.104 0.144 0.244 -1.018 -0.064 -0.2892 -0.0794 0.0347 0.9834
7 2026-09-30T10:49:14 12400 5.307 -0.042 0.14 0.874 0.103 0.152 0.219 -0.635 0.0121 -0.0176 0.0116 -0.0384 -0.0568
8 2026-09-30T11:04:59 12400 5.307 -0.0417 0.14 0.874 0.103 0.152 0.22 -0.641 0.0119 -0.0123 0.0135 -0.0026 -0.0427 -0.0612
9 2026-09-30T11:39:23 12400 5.307 -0.042 0.14 0.874 0.102 0.152 0.22 -0.641 0.0135 -0.0108 0.0095 0.0004 -0.0371 -0.0659 5.64 -1.65
10 2026-09-30T11:45:21 12400 5.307 -0.0417 0.14 0.874 0.102 0.152 0.224 -0.639 0.014 -0.0129 0.0118 -0.0001 -0.0399 -0.0652 6.1 -1.63
11 2026-09-30T12:07:53 12400 5.307 -0.042 0.14 0.874 0.101 0.152 0.219 -0.639 0.0145 -0.0108 0.0138 0.000447 -0.0467 -0.066 7.24 -1.65
12 2026-09-30T12:15:59 12400 5.307 -0.0418 0.14 0.874 0.101 0.152 0.221 -0.639 0.0144 -0.0105 0.012 -0.00118 -0.0414 -0.0618 6.36 -1.54
+326
View File
@@ -0,0 +1,326 @@
# """Weekly beamline checks"""
"""Weekly beamline checks."""
import csv
from dataclasses import dataclass
from datetime import datetime
from pxii_bec.scripts import beamline_context as bl
from pxii_bec.macros.beamline_planner import BeamlineState
# =============================================================================
# Setup
# =============================================================================
def setup_weekly():
"""Put the beamline into standard conditions for weekly checks."""
print("\nSetting up standard weekly-check conditions...")
# Set standard energy and run mono pitch scan
energy_result = daily_energy(
BLSetup.energy,
scan_mono=True,
plot_widget="Plot_1"
)
return {
"ok": True,
"energy": BLSetup.energy,
"gap": get_value(dev.id_gap),
"energy_result": energy_result,
}
# =============================================================================
# Slit scans
# =============================================================================
def weekly_fe_scan():
"""Scan the FE slits to find the centre values."""
print("\nScanning FE slits...")
try:
results = scan_fe()
return {
"ok": True,
"x": results["fe_xcen"],
"y": results["fe_ycen"],
}
except Exception as exc:
reason = str(exc)
print(f"FE slit scan failed: {reason}")
return {
"ok": False,
"error": reason,
}
def weekly_bsf_slits_scan():
"""Scan the BSF slits to find the centre values."""
print("\nScanning BSF slits...")
try:
results = centre_one("bsf", dev.lu_bpmsum)
return {
"ok": True,
"x": get_value(dev.bsf_sl_xcen),
"y": get_value(dev.bsf_sl_ycen),
# "result": results,
}
except Exception as exc:
reason = str(exc)
print(f"BSF slit scan failed: {reason}")
return {
"ok": False,
"error": reason,
}
def weekly_ss_slits_scan():
"""Scan the secondary slits to find the centre values."""
print("\nScanning secondary slits...")
try:
results = centre_one("ss", dev.bcu_bpmsum)
return {
"ok": True,
"x": get_value(dev.ss_sl_xcen),
"y": get_value(dev.ss_sl_ycen),
# "result": results,
}
except Exception as exc:
reason = str(exc)
print(f"SS slit scan failed: {reason}")
return {
"ok": False,
"error": reason,
}
# =============================================================================
# BPM readings
# =============================================================================
def measure_bpm_positions():
lubpm = compute_norm_lu()
ssbpm = compute_norm_ss()
bcubpm = get_bcu_beampos()
results = {}
results["lu"]["X norm"] = lubpm["lu_Xnorm"]
results["lu"]["Y norm"] = lubpm["lu_Ynorm"]
results["ss"]["X norm"] = ssbpm["ss_Xnorm"]
results["ss"]["Y norm"] = ssbpm["ss_Ynorm"]
results["bcu"]["BCU Xnorm"] = bcubpm["bcu_Xnorm"]
results["bcu"]["Ynorm"] = bcubpm["bcu_Xnorm"]
results["bcu"]["bcu_x_um"] = bcubpm["bcu_x_um"]
results["bcu"]["bcu_y_um"] = bcubpm["bcu_y_um"]
return results
# =============================================================================
# Save results
# =============================================================================
def save_weekly_results(results):
"""Append weekly beamline diagnostics to the history CSV."""
filename = bl.env.daily_setup_dir / "weekly_beamline_health.csv"
setup = results.get("setup", {})
energy_result = setup.get("energy_result", {})
fe = results.get("FE", {})
bsf = results.get("BSF", {})
ss = results.get("SS", {})
lubpm = results.get("lubpm", {})
ssbpm = results.get("ssbpm", {})
bcubpm = results.get("bcubpm", {})
row = {
"timestamp": datetime.now().isoformat(timespec="seconds"),
# Energy / machine settings
"energy_eV": format_value(
energy_result.get("energy"), ".0f"
),
"id_gap_mm": format_value(
setup.get("gap"), ".3f"
),
"pitch_offset_mrad": format_value(
energy_result.get("pitch_offset"), ".4f"
),
# Slit centres
"fe_x": format_value(
fe.get("x"), ".3f"
),
"fe_y": format_value(
fe.get("y"), ".3f"
),
"bsf_x": format_value(
bsf.get("x"),".3f"
),
"bsf_y": format_value(
bsf.get("y"), ".3f"
),
"ss_x": format_value(
ss.get("x"), ".3f"
),
"ss_y": format_value(
ss.get("y"),".3f"
),
"lu_Xnorm": format_value(
lubpm.get("lu_Xnorm"), ".4f"
),
"lu_Ynorm": format_value(
lubpm.get("lu_Ynorm"), ".4f"
),
"ss_Xnorm": format_value(
ssbpm.get("ss_Xnorm"), ".4f"
),
"ss_Ynorm": format_value(
ssbpm.get("ss_Ynorm"), ".4f"
),
"bcu_Xnorm": format_value(
bcubpm.get("bcu_Xnorm"), ".4f"
),
"bcu_Ynorm": format_value(
bcubpm.get("bcu_Ynorm"), ".4f"
),
"bcu_beamX": format_value(
bcubpm.get("bcu_x_um"), ".1f"
),
"bcu_beamY": format_value(
bcubpm.get("bcu_y_um"), ".1f"
),
}
fieldnames = list(row.keys())
file_exists = filename.exists()
with open(filename, "a", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if not file_exists:
writer.writeheader()
writer.writerow(row)
print(f"\nWeekly results saved to:")
print(filename)
return filename
# =============================================================================
# SciLog results
# =============================================================================
def send_week_to_scilog():
filename = bl.env.daily_setup_dir / "weekly_beamline_health.csv"
msg = bec.messaging.scilog.new()
msg.add_text("Weekly PXII checks")
msg.add_attachment(filename)
msg.add_tags("weekly-check", "PXII")
msg.send()
# =============================================================================
# Main weekly check
# =============================================================================
def weekly_checks():
"""Run standard weekly beamline checks."""
print("\n========================================")
print("PXII WEEKLY CHECKS")
print("========================================")
results = {}
# ------------------------------------------------------------------
# Standard conditions
# ----------------------------------SS--------------------------------
try:
results["setup"] = setup_weekly()
except Exception as exc:
reason = str(exc)
print(f"Weekly setup failed: {reason}")
results["setup"] = {
"ok": False,
"error": reason,
}
# Don't continue with slit scans if we couldn't establish
# the standard starting conditions.
save_weekly_results(results)
return results
# ------------------------------------------------------------------
# BPM positions
# ------------------------------------------------------------------
results["lubpm"] = compute_norm_lu()
results["ssbpm"] = compute_norm_ss()
results["bcubpm"] = get_bcu_beampos()
# ------------------------------------------------------------------
# Slit scans
# ------------------------------------------------------------------
results["FE"] = weekly_fe_scan()
results["BSF"] = weekly_bsf_slits_scan()
results["SS"] = weekly_ss_slits_scan()
# ------------------------------------------------------------------
# Save results
# ------------------------------------------------------------------
results["filename"] = save_weekly_results(results)
# ------------------------------------------------------------------
# Edge scan
# ------------------------------------------------------------------
results["edge"] = scan_ge(11103, mode="coarse")
# ------------------------------------------------------------------
# Save results to SciLog
# ------------------------------------------------------------------
print("\nWeekly checks complete.")
return results