From 8ecd1f36c6ddf796fc25462fb25857f638bae0de Mon Sep 17 00:00:00 2001 From: gac-x11ma Date: Wed, 19 Nov 2025 10:59:01 +0100 Subject: [PATCH] Startup --- config/config.properties | 3 +- config/devices.properties | 4 +- config/settings.properties | 2 +- devices/7.properties | 2 +- devices/76.properties | 2 +- devices/8.properties | 2 +- devices/FE_CX.properties | 2 +- devices/FE_CY.properties | 2 +- devices/Position.properties | 2 +- devices/Time.properties | 2 +- devices/ao0.properties | 12 +- devices/ao1.properties | 12 +- devices/ca_correction.properties | 2 +- devices/ca_motion.properties | 2 +- devices/dp.properties | 2 +- devices/exit_slit.properties | 28 +- devices/exit_slit_motor.properties | 2 +- devices/exit_slit_old.properties | 2 +- devices/fe_slit_H_ctr.properties | 28 +- devices/fe_slit_H_size.properties | 28 +- devices/fe_slit_V_ctr.properties | 28 +- devices/fe_slit_V_size.properties | 28 +- devices/girder_x.properties | 16 +- devices/girder_y.properties | 20 +- devices/m.properties | 2 +- devices/m1.properties | 2 +- devices/m2.properties | 2 +- devices/manip_x.properties | 2 +- devices/manip_y.properties | 2 +- devices/obj_stig_a.properties | 2 +- devices/obj_stig_b.properties | 2 +- devices/objective.properties | 2 +- devices/p1.properties | 2 +- devices/rmu_ry.properties | 30 +- devices/slit_correction.properties | 2 +- devices/slit_motion.properties | 2 +- script/beamline_alignment/0012.json | 70 +++ script/beamline_alignment/AU_cam_scans.py | 0 .../beamline_alignment/BML_save_parameters.py | 219 ++++++++ .../Beamline_configuration.py | 305 +++++++++++ script/beamline_alignment/Write_Data.py | 30 ++ .../beamline_configuration.py | 481 ++++++++++++++++++ .../beamline_alignment/beamline_functions.py | 54 ++ .../beamline_alignment/bml_align_params.json | 148 ++++++ .../beamline_alignment/test_parameters.json | 18 + script/test/test_json_files.py | 25 + 46 files changed, 1493 insertions(+), 142 deletions(-) create mode 100644 script/beamline_alignment/0012.json create mode 100644 script/beamline_alignment/AU_cam_scans.py create mode 100644 script/beamline_alignment/BML_save_parameters.py create mode 100644 script/beamline_alignment/Beamline_configuration.py create mode 100644 script/beamline_alignment/Write_Data.py create mode 100755 script/beamline_alignment/beamline_configuration.py create mode 100755 script/beamline_alignment/beamline_functions.py create mode 100644 script/beamline_alignment/bml_align_params.json create mode 100644 script/beamline_alignment/test_parameters.json create mode 100644 script/test/test_json_files.py diff --git a/config/config.properties b/config/config.properties index 871a1d1..59482d8 100644 --- a/config/config.properties +++ b/config/config.properties @@ -1,4 +1,4 @@ -#Thu Oct 30 14:02:21 CET 2025 +#Wed Nov 19 10:56:25 CET 2025 commandQueueSize=-1 commandStatistics=false commandTimeToLive=600000 @@ -40,6 +40,7 @@ scanStreamerPort=-1 serverCommandsHidden=false serverEnabled=false serverHostName=null +serverHttps=false serverPort=8080 sessionHandling=On terminalEnabled=false diff --git a/config/devices.properties b/config/devices.properties index 3c39d7b..7f26287 100644 --- a/config/devices.properties +++ b/config/devices.properties @@ -116,5 +116,5 @@ temp_readout=ch.psi.pshell.epics.ReadonlyProcessVariable|X11MA-PC-SW:Pt100-K|||t raw=ch.psi.pshell.imaging.CameraSource|eiger|||true image2=ch.psi.pshell.imaging.CameraSource|cam2|||true img_peemcam=ch.psi.pshell.imaging.CameraSource|peemcam|||true -axis=ch.psi.pshell.imaging.MjpegSource|http://axis-x11ma.psi.ch/axis-cgi/mjpg/video.cgi?id=176 true||-200|false -axis2=ch.psi.pshell.imaging.MjpegSource|http://129.129.121.54/axis-cgi/mjpg/video.cgi?id=0 true||-200| +#axis=ch.psi.pshell.camserver.CameraStream|http://axis-x11ma.psi.ch/axis-cgi/mjpg/video.cgi?id=176 true||-200|false +#axis2=ch.psi.pshell.imaging.MjpegSource|http://129.129.121.54/axis-cgi/mjpg/video.cgi?id=0 true||-200| diff --git a/config/settings.properties b/config/settings.properties index 40aac9a..25d6a61 100644 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,4 +1,4 @@ -#Wed Nov 05 15:20:32 CET 2025 +#Wed Nov 19 10:59:00 CET 2025 ALPHA_ID_2=0.0 AUTO_SWITCH_BEAMLINE=false AUTO_SWITCH_SHUTTER=true diff --git a/devices/7.properties b/devices/7.properties index d2d7231..8036aae 100644 --- a/devices/7.properties +++ b/devices/7.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/76.properties b/devices/76.properties index ebc6438..4a6644a 100644 --- a/devices/76.properties +++ b/devices/76.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/8.properties b/devices/8.properties index d84af4f..09474dd 100644 --- a/devices/8.properties +++ b/devices/8.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/FE_CX.properties b/devices/FE_CX.properties index c9a7a97..c51ec42 100644 --- a/devices/FE_CX.properties +++ b/devices/FE_CX.properties @@ -1,10 +1,10 @@ #Mon Oct 20 23:45:55 CEST 2025 +deadband=NaN description=slit X center maxValue=NaN minValue=NaN offset=0.0 precision=4 -resolution=NaN rotation=false scale=1.0 sign_bit=0 diff --git a/devices/FE_CY.properties b/devices/FE_CY.properties index ed95b01..fee9042 100644 --- a/devices/FE_CY.properties +++ b/devices/FE_CY.properties @@ -1,10 +1,10 @@ #Mon Oct 20 23:45:56 CEST 2025 +deadband=NaN description=slit Y center maxValue=NaN minValue=NaN offset=0.0 precision=4 -resolution=NaN rotation=false scale=1.0 sign_bit=0 diff --git a/devices/Position.properties b/devices/Position.properties index 3b2220f..f07e8c6 100644 --- a/devices/Position.properties +++ b/devices/Position.properties @@ -7,4 +7,4 @@ rotation=false precision=-1 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/Time.properties b/devices/Time.properties index 312d4db..33a5931 100644 --- a/devices/Time.properties +++ b/devices/Time.properties @@ -7,4 +7,4 @@ rotation=false precision=-1 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/ao0.properties b/devices/ao0.properties index 7ae69ed..1f608bf 100644 --- a/devices/ao0.properties +++ b/devices/ao0.properties @@ -1,10 +1,10 @@ -#Fri Sep 22 16:15:50 CEST 2023 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.01 +description=Voltage maxValue=10.0 +minValue=-10.0 +offset=0.0 precision=3 scale=2.44140625E-4 -description=Voltage -resolution=0.01 -minValue=-10.0 -unit=V sign_bit=0 +unit=V diff --git a/devices/ao1.properties b/devices/ao1.properties index cfe390f..a0ba927 100644 --- a/devices/ao1.properties +++ b/devices/ao1.properties @@ -1,10 +1,10 @@ -#Sun Sep 24 22:18:39 CEST 2023 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=1.0E-4 +description=Voltage maxValue=10.0 +minValue=-10.0 +offset=0.0 precision=4 scale=3.05175E-4 -description=Voltage -resolution=1.0E-4 -minValue=-10.0 -unit=V sign_bit=0 +unit=V diff --git a/devices/ca_correction.properties b/devices/ca_correction.properties index 4809604..24acf28 100644 --- a/devices/ca_correction.properties +++ b/devices/ca_correction.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/ca_motion.properties b/devices/ca_motion.properties index 4809604..24acf28 100644 --- a/devices/ca_motion.properties +++ b/devices/ca_motion.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/dp.properties b/devices/dp.properties index b509325..2b6f272 100644 --- a/devices/dp.properties +++ b/devices/dp.properties @@ -7,4 +7,4 @@ rotation=false precision=-1 sign_bit=0 scale=1.0 -resolution=NaN +deadband=NaN diff --git a/devices/exit_slit.properties b/devices/exit_slit.properties index 915ec24..df75b63 100644 --- a/devices/exit_slit.properties +++ b/devices/exit_slit.properties @@ -1,19 +1,19 @@ -#Mon Aug 08 11:48:07 CEST 2022 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=1.0 +defaultSpeed=200.0 +description=null +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=200.0 maxValue=3000.0 +minSpeed=10.0 +minValue=-3000.0 +monitorByPosition=false +offset=0.0 precision=5 rotation=false scale=1.0 -description=null -estbilizationDelay=0 -maxSpeed=200.0 -resolution=1.0 -homingType=None -startRetries=1 -minValue=-3000.0 -unit=micron -defaultSpeed=200.0 sign_bit=0 -hasEnable=false -monitorByPosition=false -minSpeed=10.0 +startRetries=1 +unit=micron diff --git a/devices/exit_slit_motor.properties b/devices/exit_slit_motor.properties index 82bd339..b52743f 100644 --- a/devices/exit_slit_motor.properties +++ b/devices/exit_slit_motor.properties @@ -1,4 +1,5 @@ #Mon Jun 07 15:56:05 CEST 2021 +deadband=1.0 offset=0.0 maxValue=3000.0 rotation=false @@ -6,7 +7,6 @@ precision=5 scale=1.0 estbilizationDelay=0 maxSpeed=NaN -resolution=1.0 homingType=None startRetries=1 minValue=-3000.0 diff --git a/devices/exit_slit_old.properties b/devices/exit_slit_old.properties index a9c71be..32d2f3a 100644 --- a/devices/exit_slit_old.properties +++ b/devices/exit_slit_old.properties @@ -1,10 +1,10 @@ #Mon Jun 07 09:49:47 CEST 2021 +deadband=1.0 offset=0.0 maxValue=NaN rotation=false precision=5 scale=1.0 -resolution=1.0 minValue=NaN unit=micron sign_bit=0 diff --git a/devices/fe_slit_H_ctr.properties b/devices/fe_slit_H_ctr.properties index 7e847c4..5e48564 100644 --- a/devices/fe_slit_H_ctr.properties +++ b/devices/fe_slit_H_ctr.properties @@ -1,19 +1,19 @@ -#Mon Aug 08 11:48:07 CEST 2022 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.1 +defaultSpeed=1.0 +description=null +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN maxValue=100.0 +minSpeed=0.1 +minValue=-100.0 +monitorByPosition=false +offset=0.0 precision=5 rotation=false scale=1.0 -description=null -estbilizationDelay=0 -maxSpeed=NaN -resolution=0.1 -homingType=None -startRetries=1 -minValue=-100.0 -unit=mm -defaultSpeed=1.0 sign_bit=0 -hasEnable=false -monitorByPosition=false -minSpeed=0.1 +startRetries=1 +unit=mm diff --git a/devices/fe_slit_H_size.properties b/devices/fe_slit_H_size.properties index 615e03c..1ddcb82 100644 --- a/devices/fe_slit_H_size.properties +++ b/devices/fe_slit_H_size.properties @@ -1,19 +1,19 @@ -#Mon Aug 08 11:48:07 CEST 2022 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.005 +defaultSpeed=1.0 +description=null +estbilizationDelay=0 +hasEnable=false +homingType=null +maxSpeed=NaN maxValue=200.0 +minSpeed=0.1 +minValue=-200.0 +monitorByPosition=false +offset=0.0 precision=3 rotation=false scale=1.0 -description=null -estbilizationDelay=0 -maxSpeed=NaN -resolution=0.005 -homingType=null -startRetries=1 -minValue=-200.0 -unit=mm -defaultSpeed=1.0 sign_bit=0 -hasEnable=false -monitorByPosition=false -minSpeed=0.1 +startRetries=1 +unit=mm diff --git a/devices/fe_slit_V_ctr.properties b/devices/fe_slit_V_ctr.properties index 7e847c4..5e48564 100644 --- a/devices/fe_slit_V_ctr.properties +++ b/devices/fe_slit_V_ctr.properties @@ -1,19 +1,19 @@ -#Mon Aug 08 11:48:07 CEST 2022 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.1 +defaultSpeed=1.0 +description=null +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN maxValue=100.0 +minSpeed=0.1 +minValue=-100.0 +monitorByPosition=false +offset=0.0 precision=5 rotation=false scale=1.0 -description=null -estbilizationDelay=0 -maxSpeed=NaN -resolution=0.1 -homingType=None -startRetries=1 -minValue=-100.0 -unit=mm -defaultSpeed=1.0 sign_bit=0 -hasEnable=false -monitorByPosition=false -minSpeed=0.1 +startRetries=1 +unit=mm diff --git a/devices/fe_slit_V_size.properties b/devices/fe_slit_V_size.properties index a1bc588..d438388 100644 --- a/devices/fe_slit_V_size.properties +++ b/devices/fe_slit_V_size.properties @@ -1,19 +1,19 @@ -#Mon Aug 08 11:48:07 CEST 2022 -offset=0.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.005 +defaultSpeed=1.0 +description=null +estbilizationDelay=0 +hasEnable=false +homingType=null +maxSpeed=NaN maxValue=200.0 +minSpeed=0.01 +minValue=-200.0 +monitorByPosition=false +offset=0.0 precision=3 rotation=false scale=1.0 -description=null -estbilizationDelay=0 -maxSpeed=NaN -resolution=0.005 -homingType=null -startRetries=1 -minValue=-200.0 -unit=mm -defaultSpeed=1.0 sign_bit=0 -hasEnable=false -monitorByPosition=false -minSpeed=0.01 +startRetries=1 +unit=mm diff --git a/devices/girder_x.properties b/devices/girder_x.properties index 5e99f13..be966ae 100644 --- a/devices/girder_x.properties +++ b/devices/girder_x.properties @@ -1,11 +1,11 @@ -#Fri Oct 07 16:45:18 CEST 2022 -offset=0.0 -maxValue=4.0 -rotation=false -precision=3 -scale=1.0 +#Wed Nov 19 10:53:07 CET 2025 +deadband=0.005 description=x set point -resolution=0.005 +maxValue=4.0 minValue=-4.0 -unit=mm +offset=0.0 +precision=3 +rotation=false +scale=1.0 sign_bit=0 +unit=mm diff --git a/devices/girder_y.properties b/devices/girder_y.properties index 06c971b..cb50c23 100644 --- a/devices/girder_y.properties +++ b/devices/girder_y.properties @@ -1,11 +1,11 @@ -#Fri Oct 07 14:17:02 CEST 2022 -minValue=-3.0 -unit=mm -offset=0.0 -maxValue=3.0 -rotation=false -precision=3 -sign_bit=0 -scale=1.0 +#Wed Nov 19 10:53:07 CET 2025 +deadband=NaN description=y set point -resolution=NaN +maxValue=3.0 +minValue=-3.0 +offset=0.0 +precision=3 +rotation=false +scale=1.0 +sign_bit=0 +unit=mm diff --git a/devices/m.properties b/devices/m.properties index 0c5e855..0fbc84c 100644 --- a/devices/m.properties +++ b/devices/m.properties @@ -2,7 +2,7 @@ precision=2 scale=1.0 estbilizationDelay=0 -resolution=NaN +deadband=NaN minValue=-10.0 defaultSpeed=1.0 sign_bit=0 diff --git a/devices/m1.properties b/devices/m1.properties index 8134b99..2770511 100644 --- a/devices/m1.properties +++ b/devices/m1.properties @@ -7,7 +7,7 @@ scale=1.0 description=null estbilizationDelay=0 maxSpeed=10.0 -resolution=NaN +deadband=NaN accessType=ReadWrite startRetries=1 minValue=-10.0 diff --git a/devices/m2.properties b/devices/m2.properties index 8134b99..2770511 100644 --- a/devices/m2.properties +++ b/devices/m2.properties @@ -7,7 +7,7 @@ scale=1.0 description=null estbilizationDelay=0 maxSpeed=10.0 -resolution=NaN +deadband=NaN accessType=ReadWrite startRetries=1 minValue=-10.0 diff --git a/devices/manip_x.properties b/devices/manip_x.properties index a919ff0..3f89909 100644 --- a/devices/manip_x.properties +++ b/devices/manip_x.properties @@ -8,4 +8,4 @@ precision=1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/manip_y.properties b/devices/manip_y.properties index a919ff0..3f89909 100644 --- a/devices/manip_y.properties +++ b/devices/manip_y.properties @@ -8,4 +8,4 @@ precision=1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/obj_stig_a.properties b/devices/obj_stig_a.properties index 415fed3..33ce8e8 100644 --- a/devices/obj_stig_a.properties +++ b/devices/obj_stig_a.properties @@ -4,7 +4,7 @@ maxValue=100.0 rotation=false precision=3 scale=1.0 -resolution=0.5 +deadband=0.5 minValue=-100.0 unit=mA sign_bit=0 diff --git a/devices/obj_stig_b.properties b/devices/obj_stig_b.properties index 7143588..952ea4a 100644 --- a/devices/obj_stig_b.properties +++ b/devices/obj_stig_b.properties @@ -4,7 +4,7 @@ maxValue=100.0 rotation=false precision=3 scale=1.0 -resolution=0.5 +deadband=0.5 minValue=-100.0 unit=mA sign_bit=0 diff --git a/devices/objective.properties b/devices/objective.properties index 903dfce..4d809f2 100644 --- a/devices/objective.properties +++ b/devices/objective.properties @@ -4,7 +4,7 @@ maxValue=1570.0 rotation=false precision=2 scale=1.0 -resolution=0.05 +deadband=0.05 minValue=1350.0 unit=mA sign_bit=0 diff --git a/devices/p1.properties b/devices/p1.properties index 6652021..08ce049 100644 --- a/devices/p1.properties +++ b/devices/p1.properties @@ -8,4 +8,4 @@ rotation=false sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/rmu_ry.properties b/devices/rmu_ry.properties index d9c0c3c..eaefafd 100644 --- a/devices/rmu_ry.properties +++ b/devices/rmu_ry.properties @@ -1,19 +1,19 @@ -#Wed Jun 14 21:28:18 CEST 2023 -offset=0.0 -maxValue=10.0 -rotation=false -precision=3 -scale=1.0 +#Wed Nov 19 10:53:06 CET 2025 +deadband=0.003 +defaultSpeed=NaN description=user input Ry estbilizationDelay=0 -maxSpeed=NaN -resolution=0.003 -homingType=None -startRetries=1 -minValue=-10.0 -unit= -defaultSpeed=NaN hasEnable=false -sign_bit=0 -monitorByPosition=false +homingType=None +maxSpeed=NaN +maxValue=10.0 minSpeed=NaN +minValue=-10.0 +monitorByPosition=false +offset=0.0 +precision=3 +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit= diff --git a/devices/slit_correction.properties b/devices/slit_correction.properties index 1329ee0..d09a730 100644 --- a/devices/slit_correction.properties +++ b/devices/slit_correction.properties @@ -8,4 +8,4 @@ precision=-1 sign_bit=0 scale=1.0 description=null -resolution=NaN +deadband=NaN diff --git a/devices/slit_motion.properties b/devices/slit_motion.properties index c53c04b..3914825 100644 --- a/devices/slit_motion.properties +++ b/devices/slit_motion.properties @@ -5,7 +5,7 @@ rotation=false precision=0 scale=1.0 description=null -resolution=5.0 +deadband=5.0 minValue=-20000.0 unit=um sign_bit=0 diff --git a/script/beamline_alignment/0012.json b/script/beamline_alignment/0012.json new file mode 100644 index 0000000..10eed5b --- /dev/null +++ b/script/beamline_alignment/0012.json @@ -0,0 +1,70 @@ +{ + "CMU": { + "CMU_Ry": { + "value": 0.18337499999999998, + "tolerance": 0.0001 + }, + "CMU_Rx": { + "value": 11.644256250000002, + "tolerance": 0.0001 + }, + "CMU_Rz": { + "value": 3.0822062500000005, + "tolerance": 0.0001 + }, + "CMU_baffle": { + "value": 0.0, + "tolerance": 0.0001 + }, + "CMU_X": { + "value": -0.90653125, + "tolerance": 0.0001 + }, + "CMU_Y": { + "value": 1.6755312500000001, + "tolerance": 0.0001 + }, + "CMU_Z": { + "value": -0.26413437500000003, + "tolerance": 0.0001 + } + }, + "Diag": { + "select": { + "value": "Photodiode", + "tolerance": 0.0 + }, + "position": { + "value": 27.999899999999997, + "tolerance": 0.1 + } + }, + "ESLIT": { + "width": { + "value": 20.0, + "tolerance": 1.0 + }, + "position": { + "value": 12.4625, + "tolerance": 0.1 + } + }, + "SR": { + "SR_orbit-X-RMS": { + "value": 0.12711276155333132, + "tolerance": 0.0001 + }, + "SR_life_time": { + "value": 12.446634499727455, + "tolerance": 0.0001 + }, + "SR_current": { + "value": 399.8668489456177, + "tolerance": 0.0001 + }, + "SR_orbit-Y-RMS": { + "value": 0.12815728431397083, + "tolerance": 0.0001 + } + } +} \ No newline at end of file diff --git a/script/beamline_alignment/AU_cam_scans.py b/script/beamline_alignment/AU_cam_scans.py new file mode 100644 index 0000000..e69de29 diff --git a/script/beamline_alignment/BML_save_parameters.py b/script/beamline_alignment/BML_save_parameters.py new file mode 100644 index 0000000..8370f5d --- /dev/null +++ b/script/beamline_alignment/BML_save_parameters.py @@ -0,0 +1,219 @@ +# VERSION = "1.0" +# AUTHOR = "A. Kleibert" +# LAST_MODIFIED = "2025-11-08" + +# Read ring current: +SR_current = caget("AGEBD-PARAMS:CURRENT") +SR_life_time = caget("AGEBD-PARAMS:LIFETIME") +SR_orbit-X-RMS = caget("ARSGE-CECL-FOFB1:B-ERR-X-RMS-UM") +SR_orbit-Y-RMS = caget("ARSGE-CECL-FOFB1:B-ERR-Y-RMS-UM") + +# Read bumps: +BML_bump_X = caget("X11MA-ORBITBUMP:OFFSET-X") +BML_bump_XP = caget("X11MA-ORBITBUMP:OFFSET-XP") +BML_bump_Y = caget("X11MA-ORBITBUMP:OFFSET-Y") +BML_bump_YP = caget("X11MA-ORBITBUMP:OFFSET-YP") + +MAS_bump_X = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-X") +MAS_bump_XP = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-XP") +MAS_bump_Y = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-Y") +MAS_bump_YP = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-YP") + +TOT_bump_X = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-X-TOTAL") +TOT_bump_XP = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-XP-TOTAL") +TOT_bump_Y = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-Y-TOTAL") +TOT_bump_YP = caget("AGEBD-ORBITBUMP:X11MA-OFFSET-YP-TOTAL") + +# Read ID gap and mode: +ID2_energy= caget("X11MA-UIND2:ENERGY-RBV") +ID2_mode = caget("X11MA-UIND2:MODE") +ID2_gap = caget("X11MA-UIND2:GAP-RBV") +ID2_offset = caget("X11MA-UIND2:ENERGY-OFFS") +# 0 Off +# 1 Linear H +# 2 Linear V+ +# 3 Linear V- +# 4 Circular+ +# 5 Circular- +# 6 +45 deg +# 7 -45 deg + +# Read XBPM1 parameters: +XBPM1_X_motor = caget("X11MA-FE-XBPM1:TRX.RBV") +XBPM1_Y_motor = caget("X11MA-FE-XBPM1:TRY.RBV") + +# Read FE slit size and position: +# Virtual axes: +FE_centerX = caget("X11MA-FE-SL1:CENTERX.RBV") +FE_centerY = caget("X11MA-FE-SL1:CENTERY.RBV") +FE_sizeX = caget("X11MA-FE-SL1:SIZEX.RBV") +FE_sizeY = caget("X11MA-FE-SL1:SIZEY.RBV") +# Physical motors: +FE_TRXR = caget("X11MA-FE-SL1:TRXR.RBV") +FE_TRXW = caget("X11MA-FE-SL1:TRXW.RBV") +FE_TRYB = caget("X11MA-FE-SL1:TRYB.RBV") +FE_TRYT = caget("X11MA-FE-SL1:TRYT.RBV") + +# Read CMU parameters: +CMU_X = caget("X11MA-OP-CM:ox") +CMU_Y = caget("X11MA-OP-CM:oy") +CMU_Z = caget("X11MA-OP-CM:oz") +CMU_Rx = caget("X11MA-OP-CM:oRx") +CMU_Ry = caget("X11MA-OP-CM:oRy") +CMU_Rz = caget("X11MA-OP-CM:oRz") +CMU_baffle = caget("X11MA-OP2-CM:TRB.RBV") + +# Read XBPM2 parameters: +XBPM2_X_motor = caget("X11MA-OP2-BP1:TRX.RBV") +XBPM2_Y_motor = caget("X11MA-OP2-BP1:TRY.RBV") + +# Read AU slit parameters: +# Virtual axes: +AU_centerV = caget("X11MA-OP2-AVcenter") +AU_centerH = caget("X11MA-OP2-AHcenter") +AU_sizeV = caget("X11MA-OP2-AVsize") +AU_sizeH = caget("X11MA-OP2-AHsize") +# Physical motors: +AU_TRZ1 = caget("X11MA-OP2-AU:TRZ1.RBV") +AU_TRZ4 = caget("X11MA-OP2-AU:TRZ4.RBV") +AU_TRY1 = caget("X11MA-OP2-AU:TRY1.RBV") +AU_TRY4 = caget("X11MA-OP2-AU:TRY4.RBV") + +# Read mono parameters: +# Grating and diffration order: +Mono_grating_select = caget("X11MA-PGM:grating") +Mono_grating_change = caget("X11MA-PGM-GRCH:GRATING") +# 0 G1 300 +# 1 G2 1200 +# 2 G3 600 +Mono_diff_order = caget("X11MA-PGM:difforder0") +# 0 1 +# 1 2 +# 2 3 +# Energy, cff, phi: +Mono_energy = caget("X11MA-PGM:rbkenergy") +Mono_cff = caget("X11MA-PGM:rbkcff") +Mono_phi = caget("X11MA-PGM:rbkenergy") +# Angles and offsets: +Mono_theta = caget("X11MA-PGM:rbktheta") +Mono_theta_off1A = caget("X11MA-PGM:THETAOFF1.A") +Mono_theta_off1B = caget("X11MA-PGM:THETAOFF1.B") +Mono_theta_off1C = caget("X11MA-PGM:THETAOFF1.C") +Mono_theta_off2A = caget("X11MA-PGM:THETAOFF2.A") +Mono_theta_off2B = caget("X11MA-PGM:THETAOFF2.B") +Mono_theta_off2C = caget("X11MA-PGM:THETAOFF2.C") +Mono_beta = caget("X11MA-PGM:rbkbeta") +Mono_beta_off1A = caget("X11MA-PGM:BETAOFF1.A") +Mono_beta_off1B = caget("X11MA-PGM:BETAOFF1.B") +Mono_beta_off1C = caget("X11MA-PGM:BETAOFF1.C") +Mono_beta_off2A = caget("X11MA-PGM:BETAOFF2.A") +Mono_beta_off2B = caget("X11MA-PGM:BETAOFF2.B") +Mono_beta_off2C = caget("X11MA-PGM:BETAOFF2.C") +# Mirror and grating position: +Mono_mirror_origin = caget("X11MA:m3.RBV") +Mono_grating_origin = caget("X11MA:m4.RBV") + +# Read FMU aperture jaw: +FMU_TRYT = caget("X11MA-OP-FM:TRYT.RBV") +FMU_TRYB = caget("X11MA-OP-FM:TRYB.RBV") + +# Read FMU position and motors: +# Virtual axes: +FMU_X = caget("X11MA-OP-FM:X.RBV") +FMU_Y = caget("X11MA-OP-FM:Y.RBV") +FMU_PITCH = caget("X11MA-OP-FM:PITCH.RBV") +FMU_ROLL = caget("X11MA-OP-FM:ROLL.RBV") +FMU_YAW = caget("X11MA-OP-FM:YAW.RBV") +# Physical motors: +FMU_TRYD = caget("X11MA-OP-FM:TRYD.RBV") +FMU_TRYUR = caget("X11MA-OP-FM:TRYUR.RBV") +FMU_TRYUW = caget("X11MA-OP-FM:TRYUW.RBV") +FMU_TRX = caget("X11MA-OP-FM:TRX.RBV") +FMU_ROTY = caget("X11MA-OP-FM:ROTY.RBV") + +# Fast shutter positions: +#FMU_TRYD = caget("X11MA-OP-FM:TRYD.RBV") +#FMU_TRYUR = caget("X11MA-OP-FM:TRYUR.RBV") + +# Exit slit +# Monitor and membrane positions: +#FMU_TRYD = caget("X11MA-OP-FM:TRYD.RBV") +#FMU_TRYUR = caget("X11MA-OP-FM:TRYUR.RBV") +ESLIT_width = caget("X11MA-OP2-SL:TRY.RBV") +ESLIT_position = caget("X11MA-OP2-SL:TRX.RBV") + +# Diagnostics unit +DIAG_position = caget("X11MA-OP-DI:HO3.RBV") +DIAG_select = caget("X11MA:DIAG-SET") +# 0 Diag. Out +# 1 YAG +# 2 Photodiode + +# Refocussing mirror unit 1 +# Virtual axes: +RMU1_X = caget("X11MA-OP-RM1:X.RBV") +RMU1_Y = caget("X11MA-OP-RM1:Y.RBV") +RMU1_PITCH = caget("X11MA-OP-RM1:PITCH.RBV") +RMU1_ROLL = caget("X11MA-OP-RM1:ROLL.RBV") +RMU1_YAW = caget("X11MA-OP-RM1:YAW.RBV") +# Physical motors: +RMU1_TRYD = caget("X11MA-OP-RM1:TRYD.RBV") +RMU1_TRYUR = caget("X11MA-OP-RM1:TRYUR.RBV") +RMU1_TRYUW = caget("X11MA-OP-RM1:TRYUW.RBV") +RMU1_TRX = caget("X11MA-OP-RM1:TRX.RBV") +RMU1_ROTY = caget("X11MA-OP-RM1:ROTY.RBV") + +# PEEM Girder +# Virtual axes: +PEEM_girder_X = caget("X11MA-HG:X1") +PEEM_girder_Y = caget("X11MA-HG:Y1") +PEEM_girder_Z = caget("X11MA-HG:Z1") +PEEM_girder_PITCH = caget("X11MA-HG:PITCH1") +PEEM_girder_ROLL = caget("X11MA-HG:YAW1") +PEEM_girder_YAW = caget("X11MA-HG:ROLL1") +# Physical motors: +PEEM_girder_M1 = caget("X11MA-HG:M1.RBV") +PEEM_girder_M2 = caget("X11MA-HG:M2.RBV") +PEEM_girder_M3 = caget("X11MA-HG:M3.RBV") +PEEM_girder_M4 = caget("X11MA-HG:M4.RBV") +PEEM_girder_M5 = caget("X11MA-HG:M5.RBV") +PEEM_girder_M6 = caget("X11MA-HG:M6.RBV") + +# Ptycho double slit +# Virtual axes: +PDS_centerX = caget("X11MA-OP-SL:CENTERX.RBV") +PDS_centerY = caget("X11MA-OP-SL:CENTERY.RBV") +PDS_sizeX = caget("X11MA-OP-SL:SIZEX.RBV") +PDS_sizeY = caget("X11MA-OP-SL:SIZEY.RBV") +# Physical motors: +PDS_TRXR = caget("X11MA-OP-SL:TRXR.RBV") +PDS_TRXW = caget("X11MA-OP-SL:TRXW.RBV") +PDS_TRYB = caget("X11MA-OP-SL:TRYB.RBV") +PDS_TRYT = caget("X11MA-OP-SL:TRYT.RBV") + +# Refocussing mirror unit 2 +RMU2_X = caget("X11MA-OP-RM2:ox") +RMU2_Y = caget("X11MA-OP-RM2:oy") +RMU2_Z = caget("X11MA-OP-RM2:oz") +RMU2_Rx = caget("X11MA-OP-RM2:oRx") +RMU2_Ry = caget("X11MA-OP-RM2:oRy") +RMU2_Rz = caget("X11MA-OP-RM2:oRz") + +##get_string + # get_string(msg, default = None, alternatives = None, password = False) +# Reads a string from UI   Args:     msg(str): display message. +# default(str, optional): value displayed when window is shown.   +# alternatives(list of str, optional): if provided presents a combo +# box instead of an editing field. +# password(boolean, optional): if True hides entered characters.   +# Returns: String entered of null if canceled + +# save_dataset(path, data, type = d, unsigned = False, features = None) +# Save data into a dataset within the current persistence context. +# Args:     path(str): Path to dataset relative to the current persistence context root. +# type(str, optional): array type - 'd'=double (default), 'b'=byte, 'h'=short, 'i'=int, +# 'l'=long, 'f'=float, 'c'=char, 's'=String, 'z'=bool, 'o'=Object +# data (array or list): data to be saved +# unsigned(boolean, optional): create a dataset of unsigned type. +# features(dictionary, optional): See create_dataset. +# Returns: Dictionary diff --git a/script/beamline_alignment/Beamline_configuration.py b/script/beamline_alignment/Beamline_configuration.py new file mode 100644 index 0000000..a89eae5 --- /dev/null +++ b/script/beamline_alignment/Beamline_configuration.py @@ -0,0 +1,305 @@ +import os +import json +# +#RED = "\033[91m" +#RESET = "\033[0m" + + +# see also Python Projekte/Strings in Datei speichern + +BEAMLINE_PARAMETERS_FILE = "/home/gac-x11ma/pshell/home/script/beamline_alignment/bml_align_params.json" + +def save_parameters(): + msg = "Save as ..." + # User inputs the file path + path = get_string(msg, default = "/home/gac-x11ma/pshell/home/script/beamline_alignment/0012.json", alternatives = None, password = False) + + # 1 Check if the user cancelled + if path is None: + print("Aborted by user.") + return # ✅ exit the function immediately + + # 2 Get the parent folder of the file + folder = os.path.dirname(path) +# print(folder) + + # 3 ️⃣Check if the folder existst + if not os.path.isdir(folder): + print ("Aborted. Folder: " + folder + " does not exist.") + return # ✅ exit the function cleanly + + # 4 Mapping from component + parameter to individual read string (Dictionary) Each component contains its parameters, with the corresponding read string and optional tolerance + + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f) + + parameters = {} + nan_occurred = False + + # 5️⃣ Read each parameter from the machine + for comp, param_dict in machine_parameters.items(): + print("\nComponent: " + comp) + parameters[comp] = {} + for p, info in param_dict.items(): + cmd = info["read_cmd"] + #print(cmd) + tol = info["tolerance"] + #print(tol) + try: + value = caget(cmd) + if isinstance(value, str): + display_value = value + else: + #value = string(value) c ensure float + display_value = str(value) + print(comp + "_" + p + " = " + display_value) +# print(value) + except: +# print("Problem") +# value = float('nan') + nan_occurred = True + print(comp + p + " = NaN") + parameters[comp][p] = {"value": value, "tolerance": tol} + +# # 6 Save parameters to JSON file + try: + with open(path, "w") as f: + json.dump(parameters, f, indent=4, allow_nan=True) + print("Parameters successfully saved in: " + path) + except: + print("Error while saving file.") + + # Warn if NaN occurred + if nan_occurred: + print("There were NaN-Values") + +def select_components(selected_components=None): + + #Allows the user (or another function) to select one + #or more components either interactively or + #by providing a list. It validates the selection against + #the available components in the JSON file. + + + msg = "Select components: " + + # Load machine parameters + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f) + except: + print("Error loading machine_parameters.json") + return None + + # Extract component names + all_components = list(machine_parameters.keys()) +# print("Available components:") +# for comp in all_components: +# print("- " + comp) + + # --- determine components to display --- + if selected_components is None: + + # user didn't specify -> use all from JSON + presented_to_select = all_components[:] + presented_to_select.append("all") + + selected = get_string(msg, default = None, alternatives = presented_to_select, password = False) + #print(selected) + if selected is None: + print("Selection aborted by user.") + return None + elif selected == "all": + # Display components + print("Selected components:") + for comp in all_components: + print("- " + comp) + return all_components + + else: + selected_components = [selected] if not isinstance(selected, list) else selected + print("Selected components:") + for comp in selected_components: + print("- " + comp) + return selected_components + + + elif selected_components == "all": + + # Display components + print("Selected components:") + for comp in all_components: + print("- " + comp) + return all_components + + else: + # ensure it is a list + if not isinstance(selected_components, list): + print("Error: selected_components must be a list of the form \"[\"Diag\", \"CMU\", ...]\" or \"all\".") + return + # validate each component + invalid = [c for c in selected_components if c not in all_components] + if invalid: + print("Error: Invalid component(s):") + for comp in invalid: + print("- " + comp) + + print("Valid components are:") + for comp in all_components: + print("- " + comp) + + return None + else: + print("Selected components:") + for comp in selected_components: + print("- " + comp) + return selected_components + + +def display_parameters(selected_components=None): + + + # Displays parameters for selected components. + # - Uses select_components() to choose components. + # - Prints each parameter with its value. + # - If a parameter value is missing or cannot be read, prints NaN. + + + # 1️⃣ Get the selected components (interactive or via argument) + selection = select_components(selected_components) + if selection is None: + return # user cancelled or invalid input + + # 2️⃣ Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f) + except: + print("Error loading machine_parameters.json") + return + + # 3️⃣ Loop through components and display their parameters + for comp in selection: + print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + for key, param_info in params.items(): + + # param_info enthält z.B. den read_cmd + read_cmd = param_info.get("read_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + + try: + display_value = caget(read_cmd) + print(read_cmd + " = " + str(display_value)) + except: + display_value = "NaN" + # print(" " + key + ": " + display_value) + +def restore_parameters(selected_components=None): +# """ +# Restore parameter values from a previously saved JSON file. +# The user selects which components to restore, and only parameters +# marked as "restorable": true in machine_parameters.json will be written back. +# """ + + msg = "Open *.json configuration file ..." + + # User inputs the file path + + # --- Step 1: Select file --- + restore_file = get_string(msg, default = "/home/gac-x11ma/pshell/home/script/beamline_alignment/0012.json", alternatives = None, password = False) + if restore_file is None: + print("Restore aborted: no file specified.") + return + + try: + with open(restore_file, "r") as f: + saved_data = json.load(f) + except: + print("Error loading restore file:", restore_file) + return + + # --- Step 2: Load machine parameters --- + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f) + except: + print("Error loading machine_parameters.json") + return + + # --- Step 3: Select components --- + selection = select_components(selected_components) + + if selection is None: + return # user cancelled or invalid input + + # --- Step 4:️⃣ Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f) + except: + print("Error loading machine_parameters.json") + return + + # --- Step 5: Restore loop --- + + for comp in selection: + print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + saved_params = saved_data.get(comp, {}) + if not saved_params: + print(" No saved values for this component.") + continue + + for key, param_info in params.items(): + + if not param_info.get("restorable", False): + continue + + # --- get saved value --- + saved_entry = saved_params.get(key, None) + if saved_entry is not None and 'value' in saved_entry: + saved_value = saved_entry['value'] + else: + saved_value = "NaN" + + # param_info enthält z.B. den read_cmd + read_cmd = param_info.get("read_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + write_cmd = param_info.get("write_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + tolerance = param_info.get("tolerance") + + try: + display_value = caget(read_cmd) + # print(read_cmd + " = " + str(display_value) + ", saved value = " + str(saved_value)) + # difference = float(display_value) - float(saved_value) + # --- compute difference if possible --- + if saved_value != "NaN" and display_value != "NaN": + try: + difference = abs(float(display_value) - float(saved_value)) + except: + difference = "NaN" + else: + difference = "NaN" + print(read_cmd + " = " + str(display_value) + ", diff = " + str(round(difference, 5)) + ", tolerance = " + str(round(tolerance, 5))) + if float(difference) > float(tolerance): + print("Set " + read_cmd + " to " + str(round(saved_value, 5))) + write_cmd_new = "\"" + write_cmd + "\"" + #print(write_cmd_new) + caput(write_cmd, float(saved_value)) + else: + print("OK.") + except: + display_value = "NaN" + # print(" " + key + ": " + display_value) + + + +# print("Component:", comp) +# run('beamline_init/with_x-rays/functions/SlitCalib.py') \ No newline at end of file diff --git a/script/beamline_alignment/Write_Data.py b/script/beamline_alignment/Write_Data.py new file mode 100644 index 0000000..6f64b1f --- /dev/null +++ b/script/beamline_alignment/Write_Data.py @@ -0,0 +1,30 @@ +#import locale +# System-Standardkodierung anzeigen +#print(locale.getpreferredencoding(False)) + +# Beispiel: Datei in einem bestimmten Ordner speichern +# Pfad zur Datei (z. B. auf Windows) + +from pathlib import Path + +msg = "Save as ..." +path = get_string(msg, default = "/home/gac-x11ma/pshell/home/script/beamline_alignment/0012.txt", alternatives = None, password = False) +index = 0 +status = 0 + +try: + zeilen = ['Das ist die erste Zeile.', 'Hier kommt die zweite Zeile.', 'Und das ist die dritte Zeile.'] + + with open(path, "w") as file1: + for zeile in zeilen: + file1.write(zeile + "\n") + print ("Datei wurde erfolgreich in " + path + " geschrieben.") + +except: + index = 1 + status = "Exception:" #, sys.exc_info()[2] + print ("Aborted by user.") + + # return index, status + + diff --git a/script/beamline_alignment/beamline_configuration.py b/script/beamline_alignment/beamline_configuration.py new file mode 100755 index 0000000..96829f7 --- /dev/null +++ b/script/beamline_alignment/beamline_configuration.py @@ -0,0 +1,481 @@ +from collections import OrderedDict +import os +import json + +# This script contains seveal functions: +# 1 bml_save_current_settings() +# 2 (select_components(selected_components=None) - is called by the following functions) +# 3 bml_display_current_settings(selected_components=None) +# 4 bml_restore_saved_settings(selected_components=None) +# 5 bml_display_saved_settings(selected_components=None) +# 6 bml_show_difference_to_saved_settings(selected_components=None) +# see also Python Projekte/Strings in Datei speichern + +BEAMLINE_PARAMETERS_FILE = "/sls/X11MA/data/X11MA/pshell/home/script/beamline_alignment/bml_align_params.json" +DATA_FILE = "/sls/X11MA/data/X11MA/pshell/home/data/2025_11/20251113/Monocam_AU_083.json" +#DATA_FILE = "/sls/X11MA/data/X11MA/scans/2511/0081.json" + + +def bml_save_current_settings(): + + #Allows the user to save relevant beamline parameters in aJSON file. + + msg = "Save as ..." + # User inputs the file path + path = get_string(msg, default = DATA_FILE, alternatives = None, password = False) + + # 1 Check if the user cancelled + if path is None: + print("Aborted by user.") + return # ✅ exit the function immediately + + # 2 Get the parent folder of the file + folder = os.path.dirname(path) +# print(folder) + + # 3 ️Check if the folder exists + if not os.path.isdir(folder): + print ("Aborted. Folder: " + folder + " does not exist.") + return # ✅ exit the function cleanly + + # 4 Mapping from component + parameter to individual read string (Dictionary) + # Each component contains its parameters, with the corresponding read string + # and optional tolerance + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + + parameters = {} + nan_occurred = False + + # 5️ Read each parameter from the machine + for comp, param_dict in machine_parameters.items(): + print("\nComponent: " + comp) + parameters[comp] = {} + for p, info in param_dict.items(): + cmd = info["read_cmd"] + #print(cmd) + tol = info["tolerance"] + #print(tol) + try: + value = caget(cmd) + if isinstance(value, str): + display_value = value + else: + #value = string(value) c ensure float + display_value = str(value) + print(comp + "_" + p + " = " + display_value) +# print(value) + except: +# print("Problem") +# value = float('nan') + nan_occurred = True + print(comp + p + " = NaN") + parameters[comp][p] = {"value": value, "tolerance": tol} + + # 6 Save parameters to JSON file + try: + with open(path, "w") as f: + json.dump(parameters, f, indent=4, allow_nan=True) + print("Parameters successfully saved in: " + path) + except: + print("Error while saving file.") + + # Warn if NaN occurred + if nan_occurred: + print("There were NaN-Values") + +def select_components(selected_components=None): + + # Allows the user (or another function) to select one + # or more components either interactively or + # by providing a list. It validates the selection against + # the available components in the JSON file. + + msg = "Select components: " + + # 1 Load machine parameters + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return None + + # 2 Extract component names + all_components = list(machine_parameters.keys()) +# print("Available components:") +# for comp in all_components: +# print("- " + comp) + + # 3 determine components to display + if selected_components is None: + + # user didn't specify -> use all from JSON + presented_to_select = all_components[:] + presented_to_select.append("all") + + selected = get_string(msg, default = None, alternatives = presented_to_select, password = False) + #print(selected) + if selected is None: + print("Selection aborted by user.") + return None + elif selected == "all": + # Display components + print("Selected components:") + for comp in all_components: + print("- " + comp) + return all_components + + else: + selected_components = [selected] if not isinstance(selected, list) else selected + print("Selected components:") + for comp in selected_components: + print("- " + comp) + return selected_components + + elif selected_components == "all": + # Display components + print("Selected components:") + for comp in all_components: + print("- " + comp) + return all_components + + else: + # ensure it is a list + if not isinstance(selected_components, list): + print("Error: selected_components must be a list of the form \"[\"Diag\", \"CMU\", ...]\" or \"all\".") + return + # validate each component + invalid = [c for c in selected_components if c not in all_components] + if invalid: + print("Error: Invalid component(s):") + for comp in invalid: + print("- " + comp) + + print("Valid components are:") + for comp in all_components: + print("- " + comp) + + return None + else: + print("Selected components:") + for comp in selected_components: + print("- " + comp) + return selected_components + + +def bml_display_current_settings(selected_components=None): + + # Displays parameters for selected components. + # - Uses select_components() to choose components. + # - Prints each parameter with its value. + # - If a parameter value is missing or cannot be read, prints NaN. + + + # 1️ Get the selected components (interactive or via argument) + selection = select_components(selected_components) + if selection is None: + return # user cancelled or invalid input + + # 2️ Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 3️ Loop through components and display their parameters + for comp in selection: + print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + for key, param_info in params.items(): + + # param_info enthält z.B. den read_cmd + read_cmd = param_info.get("read_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + + try: + display_value = caget(read_cmd) + print(key + " = " + str(display_value)) + except: + display_value = "NaN" + # print(" " + key + ": " + display_value) + +def bml_restore_saved_settings(selected_components=None): + + # Restore parameter values from a previously saved JSON file. + # The user selects which components to restore, and only parameters + # marked as "restorable": true in machine_parameters.json will be written back. + + msg = "Open *.json configuration file ..." + + # 1 Select file + restore_file = get_string(msg, default = DATA_FILE, alternatives = None, password = False) + if restore_file is None: + print("Restore aborted: no file specified.") + return + + try: + with open(restore_file, "r") as f: + saved_data = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading restore file:", restore_file) + return + + # 2 Load machine parameters + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 3 Select components + selection = select_components(selected_components) + + if selection is None: + return # user cancelled or invalid input + + # 4 Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 5 Restore loop + for comp in selection: + # print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + saved_params = saved_data.get(comp, {}) + if not saved_params: + print(" No saved values for this component.") + continue + + for key, param_info in params.items(): + + if not param_info.get("restorable", False): + continue + + # get saved value + saved_entry = saved_params.get(key, None) + if saved_entry is not None and 'value' in saved_entry: + saved_value = saved_entry['value'] + else: + saved_value = "NaN" + + # param_info enthält z.B. den read_cmd + read_cmd = param_info.get("read_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + write_cmd = param_info.get("write_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + tolerance = param_info.get("tolerance") + + try: + display_value = caget(read_cmd) + # print(read_cmd + " = " + str(display_value) + ", saved value = " + str(saved_value)) + # difference = float(display_value) - float(saved_value) + # compute difference if possible + if saved_value != "NaN" and display_value != "NaN": + try: + difference = abs(float(display_value) - float(saved_value)) + except: + difference = "NaN" + else: + difference = "NaN" + # print(read_cmd + " = " + str(display_value) + ", diff = " + str(round(difference, 5)) + ", tolerance = " + str(round(tolerance, 5))) + if float(difference) > float(tolerance): + print(key + " - Not OK. Set to " + str(round(saved_value, 5))) + write_cmd_new = "\"" + write_cmd + "\"" + #print(write_cmd_new) + caput(write_cmd, float(saved_value)) + check_restored_value = caget(read_cmd) + print(key + " - Reads now: " + str(check_restored_value)) + else: + print(key + " - OK.") + except: + display_value = "NaN" + # print(" " + key + ": " + display_value) + +def bml_display_saved_settings(selected_components=None): + + # Diplay parameter values from a previously saved JSON file. + # The user selects which components to restore, and only parameters + # marked as "restorable": true in machine_parameters.json will be written back. + + msg = "Open *.json configuration file ..." + + # 1 Select file + #restore_file = get_string(msg, default = "/sls/X11MA/data/X11MA/scans/2511/0012.json", alternatives = None, password = False) + restore_file = get_string(msg, default = DATA_FILE, alternatives = None, password = False) + if restore_file is None: + print("Restore aborted: no file specified.") + return + + try: + with open(restore_file, "r") as f: + saved_data = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading restore file:", restore_file) + return + + # 2 Load machine parameters + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 3 Select components + selection = select_components(selected_components) + + if selection is None: + return # user cancelled or invalid input + + # 4 Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 5 Display loop + for comp in selection: + print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + saved_params = saved_data.get(comp, {}) + if not saved_params: + print(" No saved values for this component.") + continue + + for key, param_info in params.items(): + +# if not param_info.get("restorable", False): +# continue + + # get saved value + saved_entry = saved_params.get(key, None) + if saved_entry is not None and 'value' in saved_entry: + saved_value = saved_entry['value'] + + else: + saved_value = "NaN" + + print(key + " was: " + str(saved_value)) + +def bml_show_difference_to_saved_settings(selected_components=None): + + # Restore parameter values from a previously saved JSON file. + # The user selects which components to restore, and only parameters + # marked as "restorable": true in machine_parameters.json will be written back. + + msg = "Open *.json configuration file ..." + + # 1 Select file + restore_file = get_string(msg, default = DATA_FILE, alternatives = None, password = False) + #restore_file = get_string(msg, default = "/sls/X11MA/data/X11MA/scans/2511/0012.json", alternatives = None, password = False) + if restore_file is None: + print("Restore aborted: no file specified.") + return + + try: + with open(restore_file, "r") as f: + saved_data = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading restore file:", restore_file) + return + + # 2 Load machine parameters + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 3 Select components + selection = select_components(selected_components) + + if selection is None: + return # user cancelled or invalid input + + # 4 Load the machine parameters JSON + try: + with open(BEAMLINE_PARAMETERS_FILE, "r") as f: + machine_parameters = json.load(f, object_pairs_hook=OrderedDict) + except: + print("Error loading machine_parameters.json") + return + + # 5 Restore loop + for comp in selection: + print("\nComponent: " + comp) + params = machine_parameters.get(comp, {}) + if not params: + print(" No parameters found.") + continue + + saved_params = saved_data.get(comp, {}) + if not saved_params: + print(" No saved values for this component.") + continue + + for key, param_info in params.items(): + +# if not param_info.get("restorable", False): +# continue + + # get saved value + saved_entry = saved_params.get(key, None) + if saved_entry is not None and 'value' in saved_entry: + saved_value = saved_entry['value'] + else: + saved_value = "NaN" + + # param_info enthält z.B. den read_cmd + read_cmd = param_info.get("read_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten +# write_cmd = param_info.get("write_cmd") # JSON muss für jeden Parameter den entsprechenden Befehl enthalten + tolerance = param_info.get("tolerance") + + try: + display_value = caget(read_cmd) + # print(read_cmd + " = " + str(display_value) + ", saved value = " + str(saved_value)) + # difference = float(display_value) - float(saved_value) + # compute difference if possible + if saved_value != "NaN" and display_value != "NaN": + try: + difference = abs(float(display_value) - float(saved_value)) + except: + difference = "NaN" + else: + difference = "NaN" + # print(read_cmd + " = " + str(display_value) + ", diff = " + str(round(difference, 5)) + ", tolerance = " + str(round(tolerance, 5))) + if float(difference) > float(tolerance): + print(key + " - Differs from saved value: " + str(round(saved_value, 5))) +# write_cmd_new = "\"" + write_cmd + "\"" + #print(write_cmd_new) +# caput(write_cmd, float(saved_value)) +# check_restored_value = caget(read_cmd) +# print(key + " - Reads now: " + str(check_restored_value)) + else: + print(key + " - OK.") + except: + display_value = "NaN" + # print(" " + key + ": " + display_value) + + +# print("Component:", comp) +# run('beamline_init/with_x-rays/functions/SlitCalib.py') \ No newline at end of file diff --git a/script/beamline_alignment/beamline_functions.py b/script/beamline_alignment/beamline_functions.py new file mode 100755 index 0000000..3211ea1 --- /dev/null +++ b/script/beamline_alignment/beamline_functions.py @@ -0,0 +1,54 @@ +def close_FE_slits(): + + + BML_FE_sizeX.setSpeed(0.4) + BML_FE_sizeY.setSpeed(0.4) + + BML_FE_sizeX.moveAsync(-0.5) + BML_FE_sizeY.move(-0.5) + + BML_FE_sizeX.setSpeed(0.1) + BML_FE_sizeY.setSpeed(0.1) + +def open_AU_slits(): + + BML_AU_TRYB.moveAsync(-5.0) + BML_AU_TRYT.moveAsync(5.0) + BML_AU_TRXW.moveAsync(-5.0) + BML_AU_TRXR.moveAsync(5.0) + + + +# BML_FE_sizeX.moveAsync(0.5) +# BML_FE_sizeY.moveAsync(0.5) + # retries = 1 +# status = 0 +# +## for i in range(retries): +## try: +## BML_FE_sizeX.move(-0.5) +# print "Set speed BML_FE_sizeX to 0.0" +# except: +# print "Error: " +# status = sys.exc_info()[2] +# return status +# for i in range(retries): +# try: +# stop_eiger() #Set mode single +# eiger.setNumImages(1)# Is it relevant?] +# caputq("X11MA-ES1-SD1:cam1:NumImages",1); +# set_eiger_number_of_frames(1) +# caget("X11MA-ES1-SD1:cam1:NumFrames_RBV") and compares before writing (therefore does nothing) +# if exposure: +# set_exposure_time(exposure, check) +# apply_averaging_detector(is_averaging_detector()) +# caput("X11MA-ES1-SD1:Proc1:EnableFilter", False) +# caput("X11MA-ES1-SD1:Proc1:NumFilter", 1) +# caput("X11MA-ES1-SD1:cam1:NumCycles", 1) +# break +# except: +# if i==(retries-1): +# raise +# else: +# print "Error initializing Eiger, retrying: " + str(sys.exc_info()[1]) + diff --git a/script/beamline_alignment/bml_align_params.json b/script/beamline_alignment/bml_align_params.json new file mode 100644 index 0000000..d67bf14 --- /dev/null +++ b/script/beamline_alignment/bml_align_params.json @@ -0,0 +1,148 @@ +{ + "SR": { + "SR_current": {"read_cmd": "AGEBD-PARAMS:CURRENT", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "SR_life_time": {"read_cmd": "AGEBD-PARAMS:LIFETIME", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "SR_orbit-X-RMS": {"read_cmd": "ARSGE-CECL-FOFB1:B-ERR-X-RMS-UM", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "SR_orbit-Y-RMS": {"read_cmd": "ARSGE-CECL-FOFB1:B-ERR-Y-RMS-UM", "write_cmd": "None", "tolerance": 0.0001, "restorable": false} + }, + "BMPs": { + "BML_bump_X": {"read_cmd": "X11MA-ORBITBUMP:OFFSET-X", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "BML_bump_XP": {"read_cmd": "X11MA-ORBITBUMP:OFFSET-XP", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "BML_bump_Y": {"read_cmd": "X11MA-ORBITBUMP:OFFSET-Y", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "BML_bump_YP": {"read_cmd": "X11MA-ORBITBUMP:OFFSET-YP", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "MAS_bump_X": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-X", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "MAS_bump_XP": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-XP", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "MAS_bump_Y": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-Y", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "MAS_bump_YP": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-YP", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "TOT_bump_X": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-X-TOTAL", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "TOT_bump_XP": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-XP-TOTAL", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "TOT_bump_Y": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-Y-TOTAL", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "TOT_bump_YP": {"read_cmd": "AGEBD-ORBITBUMP:X11MA-OFFSET-YP-TOTAL", "write_cmd": "None", "tolerance": 0.0001, "restorable": false} + }, + "ID2": { + "ID2_energy": {"read_cmd": "X11MA-UIND2:ENERGY-RBV", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "ID2_mode": {"read_cmd": "X11MA-UIND2:MODE", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "ID2_gap": {"read_cmd": "X11MA-UIND2:GAP-RBV", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "ID2_offset": {"read_cmd": "X11MA-UIND2:ENERGY-OFFS", "write_cmd": "None", "tolerance": 0.0001, "restorable": false} + }, + "XBPM1": { + "XBPM1_X_motor": {"read_cmd": "X11MA-FE-XBPM1:TRX.RBV", "write_cmd": "None", "tolerance": 0.0001, "restorable": false}, + "XBPM1_Y_motor": {"read_cmd": "X11MA-FE-XBPM1:TRY.RBV", "write_cmd": "None", "tolerance": 0.0001, "restorable": false} + }, + "FE_slits": { + "FE_centerX": {"read_cmd": "X11MA-FE-SL1:CENTERX.RBV", "write_cmd": "X11MA-FE-SL1:CENTERX", "tolerance": 0.001, "restorable": false}, + "FE_centerY": {"read_cmd": "X11MA-FE-SL1:CENTERY.RBV", "write_cmd": "X11MA-FE-SL1:CENTERY", "tolerance": 0.001, "restorable": false}, + "FE_sizeX": {"read_cmd": "X11MA-FE-SL1:SIZEX.RBV", "write_cmd": "X11MA-FE-SL1:SIZEX", "tolerance": 0.001, "restorable": false}, + "FE_sizeY": {"read_cmd": "X11MA-FE-SL1:SIZEY.RBV", "write_cmd": "X11MA-FE-SL1:SIZEY", "tolerance": 0.001, "restorable": false}, + "FE_TRXR": {"read_cmd": "X11MA-FE-SL1:TRXR.RBV", "write_cmd": "X11MA-FE-SL1:TRXR", "tolerance": 0.001, "restorable": true}, + "FE_TRXW": {"read_cmd": "X11MA-FE-SL1:TRXW.RBV", "write_cmd": "X11MA-FE-SL1:TRXW", "tolerance": 0.001, "restorable": true}, + "FE_TRYB": {"read_cmd": "X11MA-FE-SL1:TRYB.RBV", "write_cmd": "X11MA-FE-SL1:TRYB", "tolerance": 0.001, "restorable": true}, + "FE_TRYT": {"read_cmd": "X11MA-FE-SL1:TRYT.RBV", "write_cmd": "X11MA-FE-SL1:TRYT", "tolerance": 0.001, "restorable": true} + }, + "CMU": { + "CMU_X": {"read_cmd": "X11MA-OP-CM:ox", "write_cmd": "X11MA-OP-CM:x", "tolerance": 0.0001, "restorable": false}, + "CMU_Y": {"read_cmd": "X11MA-OP-CM:oy", "write_cmd": "X11MA-OP-CM:y", "tolerance": 0.0001, "restorable": true}, + "CMU_Z": {"read_cmd": "X11MA-OP-CM:oz", "write_cmd": "X11MA-OP-CM:z", "tolerance": 0.0001, "restorable": true}, + "CMU_Rx": {"read_cmd": "X11MA-OP-CM:oRx", "write_cmd": "X11MA-OP-CM:Rx", "tolerance": 0.0001, "restorable": true}, + "CMU_Ry": {"read_cmd": "X11MA-OP-CM:oRy", "write_cmd": "X11MA-OP-CM:Ry", "tolerance": 0.0001, "restorable": true}, + "CMU_Rz": {"read_cmd": "X11MA-OP-CM:oRz", "write_cmd": "X11MA-OP-CM:Rz", "tolerance": 0.0001, "restorable": true}, + "CMU_baffle": {"read_cmd": "X11MA-OP2-CM:TRB.RBV", "write_cmd": "None", "tolerance": 0.0001, "restorable": false} + }, + "XBPM2": { + "XBPM2_X_motor": {"read_cmd": "X11MA-OP2-BP1:TRX.RBV", "write_cmd": "X11MA-OP2-BP1:TRX", "tolerance": 0.0001, "restorable": false}, + "XBPM2_Y_motor": {"read_cmd": "X11MA-OP2-BP1:TRY.RBV", "write_cmd": "X11MA-OP2-BP1:TRY", "tolerance": 0.0001, "restorable": false} + }, + "AU_slits": { + "AU_centerV": {"read_cmd": "X11MA-OP2-AVcenter", "write_cmd": "X11MA-OP2-AVcenter", "tolerance": 0.001, "restorable": false}, + "AU_centerH": {"read_cmd": "X11MA-OP2-AHcenter", "write_cmd": "X11MA-OP2-AHcenter", "tolerance": 0.001, "restorable": false}, + "AU_sizeV": {"read_cmd": "X11MA-OP2-AVsize", "write_cmd": "X11MA-OP2-AVsize", "tolerance": 0.001, "restorable": false}, + "AU_sizeH": {"read_cmd": "X11MA-OP2-AHsize", "write_cmd": "X11MA-OP2-AHsize", "tolerance": 0.001, "restorable": false}, + "AU_TRXR": {"read_cmd": "X11MA-OP2-AU:TRZ1.RBV", "write_cmd": "X11MA-OP2-AU:TRZ1", "tolerance": 0.001, "restorable": false}, + "AU_TRXW": {"read_cmd": "X11MA-OP2-AU:TRZ4.RBV", "write_cmd": "X11MA-OP2-AU:TRZ4", "tolerance": 0.001, "restorable": false}, + "AU_TRYB": {"read_cmd": "X11MA-OP2-AU:TRY1.RBV", "write_cmd": "X11MA-OP2-AU:TRY1", "tolerance": 0.001, "restorable": false}, + "AU_TRYT": {"read_cmd": "X11MA-OP2-AU:TRY4.RBV", "write_cmd": "X11MA-OP2-AU:TRY4", "tolerance": 0.001, "restorable": false} + }, + "Mono": { + "Mono_energy": {"read_cmd": "X11MA-PGM:rbkenergy", "write_cmd": "X11MA-PGM:energy", "tolerance": 0.001, "restorable": false}, + "Mono_cff_A": {"read_cmd": "X11MA-PGM:rbkcff", "write_cmd": "X11MA-PGM:cff.A", "tolerance": 0.01, "restorable": false}, + "Mono_cff_B": {"read_cmd": "X11MA-PGM:rbkcff", "write_cmd": "X11MA-PGM:cff.B", "tolerance": 0.01, "restorable": false}, + "Mono_cff_C": {"read_cmd": "X11MA-PGM:rbkcff", "write_cmd": "X11MA-PGM:cff.C", "tolerance": 0.01, "restorable": false}, + "Mono_theta": {"read_cmd": "X11MA-PGM:rbktheta", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off1A": {"read_cmd": "X11MA-PGM:THETAOFF1.A", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off1B": {"read_cmd": "X11MA-PGM:THETAOFF1.B", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off1C": {"read_cmd": "X11MA-PGM:THETAOFF1.C", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off2A": {"read_cmd": "X11MA-PGM:THETAOFF2.A", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off2B": {"read_cmd": "X11MA-PGM:THETAOFF2.B", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_theta_off2C": {"read_cmd": "X11MA-PGM:THETAOFF2.C", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_mirror_origin": {"read_cmd": "X11MA:m3.RBV", "write_cmd": "None", "tolerance": 0.001, "restorable": false}, + "Mono_grating_origin": {"read_cmd": "X11MA:m4.RBV", "write_cmd": "None", "tolerance": 0.001, "restorable": false} + }, + "FMU_aperture": { + "top": {"read_cmd": "X11MA-OP-FM:TRYT.RBV", "write_cmd": "None", "tolerance": 1.0, "restorable": false}, + "bottom": {"read_cmd": "X11MA-OP-FM:TRYB.RBV", "write_cmd": "None", "tolerance": 1.0, "restorable": false} + }, + "FMU": { + "FMU_X": {"read_cmd": "X11MA-OP-FM:X.RBV", "write_cmd": "X11MA-OP-FM:X", "tolerance": 0.001, "restorable": false}, + "FMU_Y": {"read_cmd": "X11MA-OP-FM:Y.RBV", "write_cmd": "X11MA-OP-FM:Y", "tolerance": 0.001, "restorable": false}, + "FMU_PITCH": {"read_cmd": "X11MA-OP-FM:PITCH.RBV", "write_cmd": "X11MA-OP-FM:PITCH", "tolerance": 0.001, "restorable": false}, + "FMU_ROLL": {"read_cmd": "X11MA-OP-FM:ROLL.RBV", "write_cmd": "X11MA-OP-FM:ROLL", "tolerance": 0.001, "restorable": false}, + "FMU_YAW": {"read_cmd": "X11MA-OP-FM:YAW.RBV", "write_cmd": "X11MA-OP-FM:YAW", "tolerance": 0.001, "restorable": false}, + "FMU_TRYD": {"read_cmd": "X11MA-OP-FM:TRYD.RBV", "write_cmd": "X11MA-OP-FM:TRYD", "tolerance": 0.001, "restorable": true}, + "FMU_TRYUR": {"read_cmd": "X11MA-OP-FM:TRYUR.RBV", "write_cmd": "X11MA-OP-FM:TRYUR", "tolerance": 0.001, "restorable": true}, + "FMU_TRYUW": {"read_cmd": "X11MA-OP-FM:TRYUW.RBV", "write_cmd": "X11MA-OP-FM:TRYUW", "tolerance": 0.001, "restorable": true}, + "FMU_TRX": {"read_cmd": "X11MA-OP-FM:TRX.RBV", "write_cmd": "X11MA-OP-FM:TRX", "tolerance": 0.001, "restorable": true}, + "FMU_ROTY": {"read_cmd": "X11MA-OP-FM:ROTY.RBV", "write_cmd": "X11MA-OP-FM:ROTY", "tolerance": 0.001, "restorable": true} + }, + "ESLIT": { + "width": {"read_cmd": "X11MA-OP2-SL:TRY.RBV", "write_cmd": "None", "tolerance": 1.0, "restorable": false}, + "position": {"read_cmd": "X11MA-OP2-SL:TRX.RBV", "write_cmd": "None", "tolerance": 0.1, "restorable": false} + }, + "Diag": { + "position": {"read_cmd": "X11MA-OP-DI:HO3.RBV", "tolerance": 0.1, "restorable": false}, + "select": {"read_cmd": "X11MA:DIAG-SET", "tolerance": 0.0, "restorable": false} + }, + "RMU1": { + "RMU1_X": {"read_cmd": "X11MA-OP-RM1:X.RBV", "write_cmd": "X11MA-OP-RM1:X", "tolerance": 0.001, "restorable": false}, + "RMU1_Y": {"read_cmd": "X11MA-OP-RM1:Y.RBV", "write_cmd": "X11MA-OP-RM1:Y", "tolerance": 0.001, "restorable": false}, + "RMU1_PITCH": {"read_cmd": "X11MA-OP-RM1:PITCH.RBV", "write_cmd": "X11MA-OP-RM1:PITCH", "tolerance": 0.001, "restorable": false}, + "RMU1_ROLL": {"read_cmd": "X11MA-OP-RM1:ROLL.RBV", "write_cmd": "X11MA-OP-RM1:ROLL", "tolerance": 0.001, "restorable": false}, + "RMU1_YAW": {"read_cmd": "X11MA-OP-RM1:YAW.RBV", "write_cmd": "X11MA-OP-RM1:YAW", "tolerance": 0.001, "restorable": false}, + "RMU1_TRYD": {"read_cmd": "X11MA-OP-RM1:TRYD.RBV", "write_cmd": "X11MA-OP-RM1:TRYD", "tolerance": 0.001, "restorable": true}, + "RMU1_TRYUR": {"read_cmd": "X11MA-OP-RM1:TRYUR.RBV", "write_cmd": "X11MA-OP-RM1:TRYUR", "tolerance": 0.001, "restorable": true}, + "RMU1_TRYUW": {"read_cmd": "X11MA-OP-RM1:TRYUW.RBV", "write_cmd": "X11MA-OP-RM1:TRYUW", "tolerance": 0.001, "restorable": true}, + "RMU1_TRX": {"read_cmd": "X11MA-OP-RM1:TRX.RBV", "write_cmd": "X11MA-OP-RM1:TRX", "tolerance": 0.001, "restorable": true}, + "RMU1_ROTY": {"read_cmd": "X11MA-OP-RM1:ROTY.RBV", "write_cmd": "X11MA-OP-RM1:ROTY", "tolerance": 0.001, "restorable": true} + }, + "PEEM_Girder": { + "PEEM_girder_X": {"read_cmd": "X11MA-HG:X1", "write_cmd": "X11MA-HG:X_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_Y": {"read_cmd": "X11MA-HG:Y1", "write_cmd": "X11MA-HG:Y_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_Z": {"read_cmd": "X11MA-HG:Z1", "write_cmd": "X11MA-HG:Z_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_PITCH": {"read_cmd": "X11MA-HG:PITCH1", "write_cmd": "X11MA-HG:PITCH_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_ROLL": {"read_cmd": "X11MA-HG:ROLL1", "write_cmd": "X11MA-HG:ROLL_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_YAW":{"read_cmd": "X11MA-HG:YAW1", "write_cmd": "X11MA-HG:YAW_SET", "tolerance": 0.001, "restorable": false}, + "PEEM_girder_M1": {"read_cmd": "X11MA-HG:M1.RBV", "write_cmd": "X11MA-HG:M1", "tolerance": 0.001, "restorable": true}, + "PEEM_girder_M2": {"read_cmd": "X11MA-HG:M2.RBV", "write_cmd": "X11MA-HG:M2", "tolerance": 0.001, "restorable": true}, + "PEEM_girder_M3": {"read_cmd": "X11MA-HG:M3.RBV", "write_cmd": "X11MA-HG:M3", "tolerance": 0.001, "restorable": true}, + "PEEM_girder_M4": {"read_cmd": "X11MA-HG:M4.RBV", "write_cmd": "X11MA-HG:M4", "tolerance": 0.001, "restorable": true}, + "PEEM_girder_M5": {"read_cmd": "X11MA-HG:M5.RBV", "write_cmd": "X11MA-HG:M5", "tolerance": 0.001, "restorable": true}, + "PEEM_girder_M6": {"read_cmd": "X11MA-HG:M6.RBV", "write_cmd": "X11MA-HG:M6", "tolerance": 0.001, "restorable": true} + }, + "Ptycho_slits": { + "PDS_centerX": {"read_cmd": "X11MA-OP-SL:CENTERX.RBV", "write_cmd": "X11MA-OP-SL:CENTERX", "tolerance": 0.001, "restorable": false}, + "PDS_centerY": {"read_cmd": "X11MA-OP-SL:CENTERY.RBV", "write_cmd": "X11MA-OP-SL:CENTERY", "tolerance": 0.001, "restorable": false}, + "PDS_sizeX": {"read_cmd": "X11MA-OP-SL:SIZEX.RBV", "write_cmd": "X11MA-OP-SL:SIZEX", "tolerance": 0.001, "restorable": false}, + "PDS_sizeY": {"read_cmd": "X11MA-OP-SL:SIZEY.RBV", "write_cmd": "XX11MA-OP-SL:SIZEY", "tolerance": 0.001, "restorable": false}, + "PDS_TRXR": {"read_cmd": "X11MA-OP-SL:TRXR.RBV", "write_cmd": "X11MA-OP-SL:TRXR", "tolerance": 0.001, "restorable": true}, + "PDS_TRXW": {"read_cmd": "X11MA-OP-SL:TRXW.RBV", "write_cmd": "X11MA-OP-SL:TRXW", "tolerance": 0.001, "restorable": true}, + "PDS_TRYB": {"read_cmd": "X11MA-OP-SL:TRYB.RBV", "write_cmd": "X11MA-OP-SLTRYB", "tolerance": 0.001, "restorable": true}, + "PDS_TRYT": {"read_cmd": "X11MA-OP-SL:TRYT.RBV", "write_cmd": "X11MA-OP-SL:TRYT", "tolerance": 0.001, "restorable": true} + }, + "RMU2": { + "RMU_X": {"read_cmd": "X11MA-OP-RM2:ox", "write_cmd": "X11MA-OP-RM2:x", "tolerance": 0.0001, "restorable": false}, + "RMU_Y": {"read_cmd": "X11MA-OP-RM2:oy", "write_cmd": "X11MA-OP-RM2:y", "tolerance": 0.0001, "restorable": true}, + "RMU_Z": {"read_cmd": "X11MA-OP-RM2:oz", "write_cmd": "X11MA-OP-RM2:z", "tolerance": 0.0001, "restorable": true}, + "RMU_Rx": {"read_cmd": "X11MA-OP-RM2:oRx", "write_cmd": "X11MA-OP-RM2:Rx", "tolerance": 0.0001, "restorable": true}, + "RMU_Ry": {"read_cmd": "X11MA-OP-RM2:oRy", "write_cmd": "X11MA-OP-RM2:Ry", "tolerance": 0.0001, "restorable": true}, + "RMU_Rz": {"read_cmd": "X11MA-OP-RM2:oRz", "write_cmd": "X11MA-OP-RM2:Rz", "tolerance": 0.0001, "restorable": true} + } +} diff --git a/script/beamline_alignment/test_parameters.json b/script/beamline_alignment/test_parameters.json new file mode 100644 index 0000000..0133a64 --- /dev/null +++ b/script/beamline_alignment/test_parameters.json @@ -0,0 +1,18 @@ +{ + "A": { + "1": { + "value": 12.5, + "tolerance": 0.5 + }, + "2": { + "value": 7.8, + "tolerance": 0.2 + } + }, + "B": { + "1": { + "value": 3.4, + "tolerance": 0.1 + } + } +} \ No newline at end of file diff --git a/script/test/test_json_files.py b/script/test/test_json_files.py new file mode 100644 index 0000000..d19ef64 --- /dev/null +++ b/script/test/test_json_files.py @@ -0,0 +1,25 @@ +import json + +# Testdaten (so ähnlich wie später deine Parameterstruktur) +daten = { + "A": { + "1": {"value": 12.5, "tolerance": 0.5}, + "2": {"value": 7.8, "tolerance": 0.2} + }, + "B": { + "1": {"value": 3.4, "tolerance": 0.1} + } +} + +# Datei speichern +with open("/home/gac-x11ma/pshell/home/script/beamline_alignment/test_parameters.json", "w") as f: + json.dump(daten, f, indent=4) # indent=4 = schön formatiert + +print("Datei erfolgreich geschrieben.") + +# Datei wieder laden +with open("/home/gac-x11ma/pshell/home/script/beamline_alignment/test_parameters.json", "r") as f: + geladene_daten = json.load(f) + +print("\nGeladene Daten:") +print(geladene_daten)