From 3d4ffb462485749acaf3f7a48a69151f33b54680 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Sep 2021 16:01:34 +0200 Subject: [PATCH] Summer 2021 --- camera_environment | 2 +- .../camera_config/SARCL01-DSCR170.json | 18 ++- .../camera_config/SARES20-CAMS142-C1.json | 12 +- .../camera_config/SARES20-CAMS142-C2.json | 14 +- .../camera_config/SARES20-CAMS142-M3.json | 12 +- .../camera_config/SARES20-CAMS142-M5.json | 4 +- .../camera_config/SARES20-PROF141-M1.json | 12 +- .../camera_config/SARES20-PROF142-M1.json | 12 +- .../camera_config/SARFE10-PPRM053.json | 4 +- .../camera_config/SARFE10-PPRM064.json | 4 +- .../camera_config/SARFE10-PSSS059.json | 6 +- .../camera_config/SAROP11-PPRM117.json | 10 +- .../camera_config/SAROP11-PPRM130.json | 21 --- .../camera_config/SAROP21-PPRM094.json | 3 +- .../camera_config/SAROP21-PPRM102.json | 3 +- .../camera_config/SAROP21-PPRM138.json | 6 +- .../camera_config/SAROP21-PSCR097.json | 3 +- .../camera_config/SAROP21-PSRD103.json | 3 +- .../camera_config/SATBD01-DSCR120.json | 18 ++- .../camera_config/SATBD01-DSCR210.json | 16 +- .../camera_config/SATBD02-DSCR050.json | 12 +- .../camera_config/SATES21-CAMS154-GIGE4.json | 6 +- .../camera_config/SATES21-CAMS154-M1.json | 8 +- .../camera_config/SATES24-CAMS161-M1.json | 9 +- .../camera_config/SATES30-CAMS182-GIGE1.json | 22 +++ .../camera_config/SATOP31-PPRM176.json | 26 +++ .../camera_config/SATOP31-PSCR095.json | 25 +++ .../camera_config/SATOP31-PSRD175.json | 25 +++ configuration/camera_config/jungfrau.json | 25 +++ configuration/camera_config/servers.json | 14 ++ .../SARES11-SPEC125-M2_psen_db.json | 4 +- .../SARES20-CAMS142-M5_psen_db.json | 2 +- .../SARES20-PROF141-M1_ib.json | 12 ++ .../pipeline_config/SARFE10-PBPS053_proc.json | 50 +++--- .../pipeline_config/SAROP21-ATT01_proc.json | 19 +++ .../SATES21-CAMS154-M1_psen_db.json | 28 ++-- .../SATES24-CAMS161-M1_psen_db.json | 4 +- .../pipeline_config/jungfrau_direct.json | 7 + .../pipeline_config/jungfrau_proc.json | 17 ++ .../pipeline_config/permanent_instances.json | 5 +- configuration/pipeline_config/servers.json | 22 ++- .../user_scripts/SARFE10-PBPS053_proc.py | 152 ++++++++++++------ .../user_scripts/SAROP21-ATT01_proc.py | 100 ++++++++++++ configuration/user_scripts/jungfrau.py | 149 +++++++++++++++++ configuration/user_scripts/jungfrau_direct.py | 15 ++ configuration/user_scripts/jungfrau_proc.py | 46 ++++++ 46 files changed, 793 insertions(+), 194 deletions(-) delete mode 100644 configuration/camera_config/SAROP11-PPRM130.json create mode 100644 configuration/camera_config/SATES30-CAMS182-GIGE1.json create mode 100644 configuration/camera_config/SATOP31-PPRM176.json create mode 100644 configuration/camera_config/SATOP31-PSCR095.json create mode 100644 configuration/camera_config/SATOP31-PSRD175.json create mode 100644 configuration/camera_config/jungfrau.json create mode 100644 configuration/pipeline_config/SARES20-PROF141-M1_ib.json create mode 100644 configuration/pipeline_config/SAROP21-ATT01_proc.json create mode 100644 configuration/pipeline_config/jungfrau_direct.json create mode 100644 configuration/pipeline_config/jungfrau_proc.json create mode 100644 configuration/user_scripts/SAROP21-ATT01_proc.py create mode 100644 configuration/user_scripts/jungfrau.py create mode 100644 configuration/user_scripts/jungfrau_direct.py create mode 100644 configuration/user_scripts/jungfrau_proc.py diff --git a/camera_environment b/camera_environment index 3408f5e..01b44ba 100644 --- a/camera_environment +++ b/camera_environment @@ -1,3 +1,3 @@ -EPICS_CA_ADDR_LIST=172.26.0.255 172.26.2.255 172.26.8.255 172.26.16.255 172.26.24.255 172.26.32.255 172.26.40.255 172.26.110.255 172.26.111.255 172.26.120.255 172.27.0.255 129.129.242.255 129.129.243.255 +EPICS_CA_ADDR_LIST=172.26.0.255 172.26.2.255 172.26.8.255 172.26.16.255 172.26.24.255 172.26.32.255 172.26.40.255 172.26.110.255 172.26.111.255 172.26.120.255 172.27.0.255 saresa-cagw.psi.ch:5062 saresb-cagw.psi.ch:5062 saresc-cagw.psi.ch:5062 satese-cagw.psi.ch:5062 satesf-cagw.psi.ch:5062 EPICS_CA_AUTO_ADDR_LIST=NO EPICS_CA_MAX_ARRAY_BYTES=40000000 diff --git a/configuration/camera_config/SARCL01-DSCR170.json b/configuration/camera_config/SARCL01-DSCR170.json index 14d81d4..71ee4df 100644 --- a/configuration/camera_config/SARCL01-DSCR170.json +++ b/configuration/camera_config/SARCL01-DSCR170.json @@ -1,22 +1,26 @@ { "camera_calibration": { "reference_marker": [ - 695, - 21, - 1381, - 1825 + 633, + 796, + 1465, + 1080 ], "reference_marker_width": 6000.0, - "reference_marker_height": 16000.0, + "reference_marker_height": 2000.0, "angle_horizontal": 8.0, "angle_vertical": 0.0 }, "mirror_x": true, "mirror_y": true, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "name": "SARCL01-DSCR170", "source": "SARCL01-DSCR170", - "group": ["Electrons"], + "group": [ + "Electrons" + ], "alias": [] -} +} \ No newline at end of file diff --git a/configuration/camera_config/SARES20-CAMS142-C1.json b/configuration/camera_config/SARES20-CAMS142-C1.json index 8941cab..71e8634 100644 --- a/configuration/camera_config/SARES20-CAMS142-C1.json +++ b/configuration/camera_config/SARES20-CAMS142-C1.json @@ -1,13 +1,13 @@ { "camera_calibration": { "reference_marker": [ - 1310, - 1096, - 1331, - 1119 + 1347, + 1025, + 1501, + 1289 ], - "reference_marker_width": 21.0, - "reference_marker_height": 23.0, + "reference_marker_width": 102.9, + "reference_marker_height": 176.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, diff --git a/configuration/camera_config/SARES20-CAMS142-C2.json b/configuration/camera_config/SARES20-CAMS142-C2.json index 29a0b13..8743e7f 100644 --- a/configuration/camera_config/SARES20-CAMS142-C2.json +++ b/configuration/camera_config/SARES20-CAMS142-C2.json @@ -1,19 +1,19 @@ { "camera_calibration": { "reference_marker": [ - 507, - 842, - 529, - 853 + 1000, + 684, + 1053, + 732 ], - "reference_marker_width": 188.0, - "reference_marker_height": 94.0, + "reference_marker_width": 1.0, + "reference_marker_height": 1.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, "mirror_x": false, "mirror_y": false, - "rotate": 1, + "rotate": 0, "roi": null, "image_background": null, "source_type": "epics", diff --git a/configuration/camera_config/SARES20-CAMS142-M3.json b/configuration/camera_config/SARES20-CAMS142-M3.json index 0249c3d..a8784f8 100644 --- a/configuration/camera_config/SARES20-CAMS142-M3.json +++ b/configuration/camera_config/SARES20-CAMS142-M3.json @@ -1,13 +1,13 @@ { "camera_calibration": { "reference_marker": [ - 1894, - 1030, - 1905, - 1041 + 1321, + 974, + 1355, + 1113 ], - "reference_marker_width": 15.0, - "reference_marker_height": 14.5, + "reference_marker_width": 44.8, + "reference_marker_height": 183.1, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, diff --git a/configuration/camera_config/SARES20-CAMS142-M5.json b/configuration/camera_config/SARES20-CAMS142-M5.json index 8773bae..9d3ebea 100644 --- a/configuration/camera_config/SARES20-CAMS142-M5.json +++ b/configuration/camera_config/SARES20-CAMS142-M5.json @@ -32,8 +32,8 @@ "roi_signal": [ 10, 2190, - 691, - 300 + 200, + 500 ], "roi_background": [ 10, diff --git a/configuration/camera_config/SARES20-PROF141-M1.json b/configuration/camera_config/SARES20-PROF141-M1.json index 80f962e..ba4127a 100644 --- a/configuration/camera_config/SARES20-PROF141-M1.json +++ b/configuration/camera_config/SARES20-PROF141-M1.json @@ -1,13 +1,13 @@ { "camera_calibration": { "reference_marker": [ - 319, - 79, - 411, - 169 + 249, + 182, + 493, + 378 ], - "reference_marker_width": 500.0, - "reference_marker_height": 500.0, + "reference_marker_width": 200.0, + "reference_marker_height": 200.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, diff --git a/configuration/camera_config/SARES20-PROF142-M1.json b/configuration/camera_config/SARES20-PROF142-M1.json index 8e7a78e..bb75b70 100644 --- a/configuration/camera_config/SARES20-PROF142-M1.json +++ b/configuration/camera_config/SARES20-PROF142-M1.json @@ -1,13 +1,13 @@ { "camera_calibration": { "reference_marker": [ - 59, - 42, - 461, - 448 + 62, + 456, + 199, + 471 ], - "reference_marker_width": 300.0, - "reference_marker_height": 300.0, + "reference_marker_width": 102.0, + "reference_marker_height": 11.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, diff --git a/configuration/camera_config/SARFE10-PPRM053.json b/configuration/camera_config/SARFE10-PPRM053.json index 17e007e..832601e 100644 --- a/configuration/camera_config/SARFE10-PPRM053.json +++ b/configuration/camera_config/SARFE10-PPRM053.json @@ -21,7 +21,9 @@ "source": "SARFE10-PPRM053", "group": [ "Photonics", - "Bernina" + "Alvra", + "Bernina", + "Beamline Aramis" ], "alias": [] } \ No newline at end of file diff --git a/configuration/camera_config/SARFE10-PPRM064.json b/configuration/camera_config/SARFE10-PPRM064.json index 62f394e..0fdc2ce 100644 --- a/configuration/camera_config/SARFE10-PPRM064.json +++ b/configuration/camera_config/SARFE10-PPRM064.json @@ -21,7 +21,9 @@ "source": "SARFE10-PPRM064", "group": [ "Photonics", - "Bernina" + "Alvra", + "Bernina", + "Beamline Aramis" ], "alias": [ "camera (SARFE10-PPRM064)" diff --git a/configuration/camera_config/SARFE10-PSSS059.json b/configuration/camera_config/SARFE10-PSSS059.json index dd5d734..75f3a9e 100644 --- a/configuration/camera_config/SARFE10-PSSS059.json +++ b/configuration/camera_config/SARFE10-PSSS059.json @@ -24,8 +24,10 @@ "buffer_size": 100, "group": [ "Photonics", - "Bernina" + "Alvra", + "Bernina", + "Beamline Aramis" ], "alias": [], "protocol": "tcp" -} +} \ No newline at end of file diff --git a/configuration/camera_config/SAROP11-PPRM117.json b/configuration/camera_config/SAROP11-PPRM117.json index c4f878a..5605598 100644 --- a/configuration/camera_config/SAROP11-PPRM117.json +++ b/configuration/camera_config/SAROP11-PPRM117.json @@ -14,9 +14,15 @@ "mirror_x": true, "mirror_y": false, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "name": "SAROP11-PPRM117", "source": "SAROP11-PPRM117", - "group": ["Photonics"], + "group": [ + "Photonics", + "Bernina", + "Beamline Aramis" + ], "alias": [] -} +} \ No newline at end of file diff --git a/configuration/camera_config/SAROP11-PPRM130.json b/configuration/camera_config/SAROP11-PPRM130.json deleted file mode 100644 index 0c437ff..0000000 --- a/configuration/camera_config/SAROP11-PPRM130.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "camera_calibration": { - "angle_vertical": 0.0, - "angle_horizontal": 0.0, - "reference_marker_height": 100.0, - "reference_marker": [ - 0, - 0, - 100, - 100 - ], - "reference_marker_width": 100.0 - }, - "name": "SAROP11-PPRM130", - "source": "SAROP11-PPRM130", - "rotate": 0, - "mirror_y": false, - "mirror_x": false, - "group": ["Photonics"], - "alias": [] -} diff --git a/configuration/camera_config/SAROP21-PPRM094.json b/configuration/camera_config/SAROP21-PPRM094.json index 3b8c8ee..0193485 100644 --- a/configuration/camera_config/SAROP21-PPRM094.json +++ b/configuration/camera_config/SAROP21-PPRM094.json @@ -21,7 +21,8 @@ "source": "SAROP21-PPRM094", "group": [ "Photonics", - "Bernina" + "Bernina", + "Beamline Aramis" ], "alias": [ "camera (SAROP21-PPRM094)" diff --git a/configuration/camera_config/SAROP21-PPRM102.json b/configuration/camera_config/SAROP21-PPRM102.json index 6af968c..5c9c701 100644 --- a/configuration/camera_config/SAROP21-PPRM102.json +++ b/configuration/camera_config/SAROP21-PPRM102.json @@ -21,7 +21,8 @@ "source": "SAROP21-PPRM102", "group": [ "Photonics", - "Bernina" + "Bernina", + "Beamline Aramis" ], "alias": [ "camera (SAROP21-PPRM102)" diff --git a/configuration/camera_config/SAROP21-PPRM138.json b/configuration/camera_config/SAROP21-PPRM138.json index 4836568..305c8ea 100644 --- a/configuration/camera_config/SAROP21-PPRM138.json +++ b/configuration/camera_config/SAROP21-PPRM138.json @@ -2,9 +2,9 @@ "camera_calibration": { "reference_marker": [ 332, - 276, + 271, 367, - 319 + 314 ], "reference_marker_width": 500.0, "reference_marker_height": 500.0, @@ -16,7 +16,7 @@ "rotate": 0, "roi": null, "image_background": null, - "source_type": "epics", + "source_type": "bsread", "name": "SAROP21-PPRM138", "source": "SAROP21-PPRM138", "group": [ diff --git a/configuration/camera_config/SAROP21-PSCR097.json b/configuration/camera_config/SAROP21-PSCR097.json index f8dca1f..6743464 100644 --- a/configuration/camera_config/SAROP21-PSCR097.json +++ b/configuration/camera_config/SAROP21-PSCR097.json @@ -21,7 +21,8 @@ "source": "SAROP21-PSCR097", "group": [ "Photonics", - "Bernina" + "Bernina", + "Beamline Aramis" ], "alias": [] } \ No newline at end of file diff --git a/configuration/camera_config/SAROP21-PSRD103.json b/configuration/camera_config/SAROP21-PSRD103.json index 2a68823..2841c7b 100644 --- a/configuration/camera_config/SAROP21-PSRD103.json +++ b/configuration/camera_config/SAROP21-PSRD103.json @@ -21,7 +21,8 @@ "source": "SAROP21-PSRD103", "group": [ "Photonics", - "Bernina" + "Bernina", + "Beamline Aramis" ], "alias": [] } \ No newline at end of file diff --git a/configuration/camera_config/SATBD01-DSCR120.json b/configuration/camera_config/SATBD01-DSCR120.json index e62cd1e..5a84d4a 100644 --- a/configuration/camera_config/SATBD01-DSCR120.json +++ b/configuration/camera_config/SATBD01-DSCR120.json @@ -1,22 +1,26 @@ { "camera_calibration": { "reference_marker": [ - 468, - 41, - 1142, - 1844 + 363, + 798, + 1255, + 1105 ], "reference_marker_width": 6000.0, - "reference_marker_height": 16000.0, + "reference_marker_height": 2000.0, "angle_horizontal": 8.0, "angle_vertical": 0.0 }, "mirror_x": true, "mirror_y": true, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "name": "SATBD01-DSCR120", "source": "SATBD01-DSCR120", - "group": ["Electrons"], + "group": [ + "Electrons" + ], "alias": [] -} +} \ No newline at end of file diff --git a/configuration/camera_config/SATBD01-DSCR210.json b/configuration/camera_config/SATBD01-DSCR210.json index ba678fd..d3196d7 100644 --- a/configuration/camera_config/SATBD01-DSCR210.json +++ b/configuration/camera_config/SATBD01-DSCR210.json @@ -1,10 +1,10 @@ { "camera_calibration": { "reference_marker": [ - 810, - 558, - 1146, - 1454 + 955, + 585, + 1291, + 1476 ], "reference_marker_width": 6000.0, "reference_marker_height": 16000.0, @@ -14,9 +14,13 @@ "mirror_x": true, "mirror_y": false, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "source": "SATBD01-DSCR210", "name": "SATBD01-DSCR210", - "group": ["Electrons"], + "group": [ + "Electrons" + ], "alias": [] -} +} \ No newline at end of file diff --git a/configuration/camera_config/SATBD02-DSCR050.json b/configuration/camera_config/SATBD02-DSCR050.json index cdec1cd..690ec2c 100644 --- a/configuration/camera_config/SATBD02-DSCR050.json +++ b/configuration/camera_config/SATBD02-DSCR050.json @@ -1,9 +1,9 @@ { "camera_calibration": { "reference_marker": [ - 1105, + 1139, 166, - 1807, + 1821, 1984 ], "reference_marker_width": 6000.0, @@ -14,9 +14,13 @@ "mirror_x": true, "mirror_y": true, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "name": "SATBD02-DSCR050", "source": "SATBD02-DSCR050", - "group": ["Electrons"], + "group": [ + "Electrons" + ], "alias": [] -} +} \ No newline at end of file diff --git a/configuration/camera_config/SATES21-CAMS154-GIGE4.json b/configuration/camera_config/SATES21-CAMS154-GIGE4.json index 8ca0140..e268f7b 100644 --- a/configuration/camera_config/SATES21-CAMS154-GIGE4.json +++ b/configuration/camera_config/SATES21-CAMS154-GIGE4.json @@ -6,14 +6,16 @@ 100, 100 ], - "reference_marker_width": 100.0, - "reference_marker_height": 100.0, + "reference_marker_width": 1.0, + "reference_marker_height": 5.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 }, "mirror_x": false, "mirror_y": false, "rotate": 0, + "roi": null, + "image_background": null, "source_type": "epics", "name": "SATES21-CAMS154-GIGE4", "source": "SATES21-CAMS154-GIGE4" diff --git a/configuration/camera_config/SATES21-CAMS154-M1.json b/configuration/camera_config/SATES21-CAMS154-M1.json index f45d5cf..30cce5e 100644 --- a/configuration/camera_config/SATES21-CAMS154-M1.json +++ b/configuration/camera_config/SATES21-CAMS154-M1.json @@ -18,8 +18,8 @@ "name": "SATES21-CAMS154-M1", "prefix": "SATES21-CAMS154-M1", "source": "SATES21-CAMS154-M1", - "connections": 4, + "connections": 2, "buffer_size": 100, - "buffer_logs":true, - "protocol": "tcp" -} + "buffer_logs": false, + "protocol": "icp" +} \ No newline at end of file diff --git a/configuration/camera_config/SATES24-CAMS161-M1.json b/configuration/camera_config/SATES24-CAMS161-M1.json index 8053fc9..88dd25b 100644 --- a/configuration/camera_config/SATES24-CAMS161-M1.json +++ b/configuration/camera_config/SATES24-CAMS161-M1.json @@ -2,11 +2,11 @@ "camera_calibration": { "reference_marker": [ 0, - 100, + 0, 100, 100 ], - "reference_marker_width": 666.0, + "reference_marker_width": 100.0, "reference_marker_height": 100.0, "angle_horizontal": 0.0, "angle_vertical": 0.0 @@ -19,12 +19,13 @@ "source_type": "bsread", "source": "SATES24-CAMS161-M1", "name": "SATES24-CAMS161-M1", - "connections": 4, + "connections": 2, "buffer_size": 100, "prefix": "SATES24-CAMS161-M1", "group": [ "Photonics", "Maloja" ], - "alias": [] + "alias": [], + "protocol": "icp" } \ No newline at end of file diff --git a/configuration/camera_config/SATES30-CAMS182-GIGE1.json b/configuration/camera_config/SATES30-CAMS182-GIGE1.json new file mode 100644 index 0000000..bc21a79 --- /dev/null +++ b/configuration/camera_config/SATES30-CAMS182-GIGE1.json @@ -0,0 +1,22 @@ +{ + "camera_calibration": { + "reference_marker": [ + 0, + 0, + 100, + 100 + ], + "reference_marker_width": 100.0, + "reference_marker_height": 100.0, + "angle_horizontal": 0.0, + "angle_vertical": 0.0 + }, + "mirror_x": false, + "mirror_y": false, + "rotate": 0, + "roi": null, + "image_background": null, + "source_type": "epics", + "source": "SATES30-CAMS182-GIGE1", + "name": "SATES30-CAMS182-GIGE1" +} \ No newline at end of file diff --git a/configuration/camera_config/SATOP31-PPRM176.json b/configuration/camera_config/SATOP31-PPRM176.json new file mode 100644 index 0000000..9327589 --- /dev/null +++ b/configuration/camera_config/SATOP31-PPRM176.json @@ -0,0 +1,26 @@ +{ + "camera_calibration": { + "reference_marker": [ + 0, + 0, + 100, + 100 + ], + "reference_marker_width": 100.0, + "reference_marker_height": 100.0, + "angle_horizontal": 0.0, + "angle_vertical": 0.0 + }, + "mirror_x": false, + "mirror_y": false, + "rotate": 0, + "roi": null, + "image_background": null, + "source_type": "epics", + "alias": [], + "group": [ + "Photonics" + ], + "name": "SATOP31-PPRM176", + "source": "SATOP31-PPRM176" +} \ No newline at end of file diff --git a/configuration/camera_config/SATOP31-PSCR095.json b/configuration/camera_config/SATOP31-PSCR095.json new file mode 100644 index 0000000..f0f262d --- /dev/null +++ b/configuration/camera_config/SATOP31-PSCR095.json @@ -0,0 +1,25 @@ +{ + "camera_calibration": { + "reference_marker": [ + 0, + 0, + 100, + 100 + ], + "reference_marker_width": 100.0, + "reference_marker_height": 100.0, + "angle_horizontal": 0.0, + "angle_vertical": 0.0 + }, + "mirror_x": false, + "mirror_y": false, + "rotate": 0, + "roi": null, + "image_background": null, + "source_type": "epics", + "name": "SATOP31-PSCR095", + "source": "SATOP31-PSCR095", + "group": [ + "Photonics" + ] +} \ No newline at end of file diff --git a/configuration/camera_config/SATOP31-PSRD175.json b/configuration/camera_config/SATOP31-PSRD175.json new file mode 100644 index 0000000..d4fd3bc --- /dev/null +++ b/configuration/camera_config/SATOP31-PSRD175.json @@ -0,0 +1,25 @@ +{ + "camera_calibration": { + "reference_marker": [ + 0, + 0, + 100, + 100 + ], + "reference_marker_width": 100.0, + "reference_marker_height": 100.0, + "angle_horizontal": 0.0, + "angle_vertical": 0.0 + }, + "mirror_x": false, + "mirror_y": false, + "rotate": 0, + "roi": null, + "image_background": null, + "source_type": "epics", + "group": [ + "Photonics" + ], + "name": "SATOP31-PSRD175", + "source": "SATOP31-PSRD175" +} \ No newline at end of file diff --git a/configuration/camera_config/jungfrau.json b/configuration/camera_config/jungfrau.json new file mode 100644 index 0000000..36d31be --- /dev/null +++ b/configuration/camera_config/jungfrau.json @@ -0,0 +1,25 @@ +{ + "camera_calibration": { + "reference_marker": [ + 0, + 0, + 100, + 100 + ], + "reference_marker_width": 100.0, + "reference_marker_height": 100.0, + "angle_horizontal": 0.0, + "angle_vertical": 0.0 + }, + "mirror_x": false, + "mirror_y": false, + "rotate": 0, + "source_type": "custom", + "class": "jungfrau", + "name": "jungfrau", + "source": "tcp://129.129.241.46:9002", + "dtype": "uint16", + "group": [], + "alias": [], + "protocol": "tcp" +} \ No newline at end of file diff --git a/configuration/camera_config/servers.json b/configuration/camera_config/servers.json index d2684e7..1705bb7 100644 --- a/configuration/camera_config/servers.json +++ b/configuration/camera_config/servers.json @@ -1,19 +1,31 @@ { + "http://sf-daq-4.psi.ch:8880": { + "enabled": true, + "expanding": false, + "instances": [ + "simulation_3", + "jungfrau" + ] + }, "http://sf-daqsync-01.psi.ch:8880": { + "enabled": true, "expanding": true, "instances": [] }, "http://sf-daqsync-02.psi.ch:8880": { + "enabled": true, "expanding": false, "instances": [ "SARFE10-PSSS059" ] }, "http://sf-daqsync-03.psi.ch:8880": { + "enabled": true, "expanding": false, "instances": [] }, "http://sf-daqsync-04.psi.ch:8880": { + "enabled": true, "expanding": false, "instances": [ "SATES21-CAMS154-M1", @@ -28,6 +40,7 @@ ] }, "http://sf-daqsync-06.psi.ch:8880": { + "enabled": true, "expanding": true, "instances": [ "SARES20-CAMS142-M1", @@ -36,6 +49,7 @@ ] }, "http://sf-daqsync-09.psi.ch:8880": { + "enabled": true, "expanding": true, "instances": [] }, diff --git a/configuration/pipeline_config/SARES11-SPEC125-M2_psen_db.json b/configuration/pipeline_config/SARES11-SPEC125-M2_psen_db.json index b9d8312..6270bef 100644 --- a/configuration/pipeline_config/SARES11-SPEC125-M2_psen_db.json +++ b/configuration/pipeline_config/SARES11-SPEC125-M2_psen_db.json @@ -13,13 +13,13 @@ "roi_background": [ 0, 2047, - 0, + 50, 300 ], "roi_signal": [ 0, 2047, - 500, + 550, 300 ] } \ No newline at end of file diff --git a/configuration/pipeline_config/SARES20-CAMS142-M5_psen_db.json b/configuration/pipeline_config/SARES20-CAMS142-M5_psen_db.json index ba02636..ad63c76 100644 --- a/configuration/pipeline_config/SARES20-CAMS142-M5_psen_db.json +++ b/configuration/pipeline_config/SARES20-CAMS142-M5_psen_db.json @@ -13,7 +13,7 @@ "roi_signal": [ 300, 2040, - 300, + 500, 100 ], "roi_background": [ diff --git a/configuration/pipeline_config/SARES20-PROF141-M1_ib.json b/configuration/pipeline_config/SARES20-PROF141-M1_ib.json new file mode 100644 index 0000000..f1be01b --- /dev/null +++ b/configuration/pipeline_config/SARES20-PROF141-M1_ib.json @@ -0,0 +1,12 @@ +{ + "image_background_enable": false, + "image_background": null, + "image_threshold": null, + "image_region_of_interest": null, + "image_good_region": null, + "image_slices": null, + "pipeline_type": "store", + "camera_name": "SARES20-PROF141-M1", + "name": "SARES20-PROF141-M1_ib", + "stream_port": 0 +} \ No newline at end of file diff --git a/configuration/pipeline_config/SARFE10-PBPS053_proc.json b/configuration/pipeline_config/SARFE10-PBPS053_proc.json index 69e2b72..bfe9cd1 100644 --- a/configuration/pipeline_config/SARFE10-PBPS053_proc.json +++ b/configuration/pipeline_config/SARFE10-PBPS053_proc.json @@ -8,7 +8,7 @@ "SARFE10-CVME-PHO6212:Lnk9Ch14-DATA-SUM", "SARFE10-CVME-PHO6212:Lnk9Ch15-DATA-SUM" ], - "mode": "PUB", + "mode": "PUSH", "function": "SARFE10-PBPS053_proc.py", "reload": true, "no_client_timeout": 0, @@ -23,21 +23,35 @@ "right_calib": 0.2598, "horiz_calib": -4.2696, "vert_calib": -7.722, - "uJ_calib": 1, - "threshold": 0.3, - "queue_length": 512, - "intensity_pvname": "SLAAR11-GEN:LAS-XRAY", - "proc_pv": "SLAAR11-GEN:LAS-EVR", - "fft_x_pos_all_X_pvname": "SLAAR21-LSCP1-FNS:WFM1-X", - "fft_x_pos_all_Y_pvname": "SLAAR21-LSCP1-FNS:WFM1-Y", - "fft_x_pos_odd_X_pvname": "SLAAR21-LSCP1-FNS:WFM2-X", - "fft_x_pos_odd_Y_pvname": "SLAAR21-LSCP1-FNS:WFM2-Y", - "fft_x_pos_even_X_pvname": "SLAAR21-LSCP1-FNS:WFM3-X", - "fft_x_pos_even_Y_pvname": "SLAAR21-LSCP1-FNS:WFM3-Y", - "fft_y_pos_all_X_pvname": "SLAAR21-LSCP1-FNS:WFM4-X", - "fft_y_pos_all_Y_pvname": "SLAAR21-LSCP1-FNS:WFM4-Y", - "fft_y_pos_odd_X_pvname": "SLAAR21-LSCP1-FNS:WFM5-X", - "fft_y_pos_odd_Y_pvname": "SLAAR21-LSCP1-FNS:WFM5-Y", - "fft_y_pos_even_X_pvname": "", - "fft_y_pos_even_Y_pvname": "" + "uJ_calib": 605.4608924473305, + "threshold": 0, + "queue_length": 1000, + "xpos_all_x_pvname": "SARFE10-PBPS053:XPOS-ALL-HIST-X", + "xpos_all_y_pvname": "SARFE10-PBPS053:XPOS-ALL-HIST-Y", + "xpos_all_m_pvname": "SARFE10-PBPS053:XPOS-ALL-HIST-M", + "xpos_all_w_pvname": "SARFE10-PBPS053:XPOS-ALL-HIST-W", + "ypos_all_x_pvname": "SARFE10-PBPS053:YPOS-ALL-HIST-X", + "ypos_all_y_pvname": "SARFE10-PBPS053:YPOS-ALL-HIST-Y", + "ypos_all_m_pvname": "SARFE10-PBPS053:YPOS-ALL-HIST-M", + "ypos_all_w_pvname": "SARFE10-PBPS053:YPOS-ALL-HIST-W", + "xpos_evn_x_pvname": "SARFE10-PBPS053:XPOS-EVN-HIST-X", + "xpos_evn_y_pvname": "SARFE10-PBPS053:XPOS-EVN-HIST-Y", + "xpos_evn_m_pvname": "SARFE10-PBPS053:XPOS-EVN-HIST-M", + "xpos_evn_w_pvname": "SARFE10-PBPS053:XPOS-EVN-HIST-W", + "ypos_evn_x_pvname": "SARFE10-PBPS053:YPOS-EVN-HIST-X", + "ypos_evn_y_pvname": "SARFE10-PBPS053:YPOS-EVN-HIST-Y", + "ypos_evn_m_pvname": "SARFE10-PBPS053:YPOS-EVN-HIST-M", + "ypos_evn_w_pvname": "SARFE10-PBPS053:YPOS-EVN-HIST-W", + "xpos_odd_x_pvname": "SARFE10-PBPS053:XPOS-ODD-HIST-X", + "xpos_odd_y_pvname": "SARFE10-PBPS053:XPOS-ODD-HIST-Y", + "xpos_odd_m_pvname": "SARFE10-PBPS053:XPOS-ODD-HIST-M", + "xpos_odd_w_pvname": "SARFE10-PBPS053:XPOS-ODD-HIST-W", + "ypos_odd_x_pvname": "SARFE10-PBPS053:YPOS-ODD-HIST-X", + "ypos_odd_y_pvname": "SARFE10-PBPS053:YPOS-ODD-HIST-Y", + "ypos_odd_m_pvname": "SARFE10-PBPS053:YPOS-ODD-HIST-M", + "ypos_odd_w_pvname": "SARFE10-PBPS053:YPOS-ODD-HIST-W", + "xpos_dif_m_pvname": "SARFE10-PBPS053:XPOS-DIF-HIST-M", + "xpos_dif_w_pvname": "SARFE10-PBPS053:XPOS-DIF-HIST-W", + "ypos_dif_m_pvname": "SARFE10-PBPS053:YPOS-DIF-HIST-M", + "ypos_dif_w_pvname": "SARFE10-PBPS053:YPOS-DIF-HIST-W" } \ No newline at end of file diff --git a/configuration/pipeline_config/SAROP21-ATT01_proc.json b/configuration/pipeline_config/SAROP21-ATT01_proc.json new file mode 100644 index 0000000..255bc28 --- /dev/null +++ b/configuration/pipeline_config/SAROP21-ATT01_proc.json @@ -0,0 +1,19 @@ +{ + "image_background_enable": true, + "image_background": "SARFE10-PSSS059:FPICTURE_12044327802_100", + "image_threshold": null, + "image_region_of_interest": null, + "image_good_region": null, + "image_slices": null, + "pipeline_type": "processing", + "camera_name": "SARFE10-PSSS059", + "name": "SAROP21-ATT01_proc", + "function": "psss_test.py", + "mode": "PUSH", + "no_client_timeout": 0, + "port": "8889", + "reload": true, + "processing_threads": 6, + "thread_buffer_size": 30, + "abort_on_error": false +} \ No newline at end of file diff --git a/configuration/pipeline_config/SATES21-CAMS154-M1_psen_db.json b/configuration/pipeline_config/SATES21-CAMS154-M1_psen_db.json index 436adf3..cbb7c05 100644 --- a/configuration/pipeline_config/SATES21-CAMS154-M1_psen_db.json +++ b/configuration/pipeline_config/SATES21-CAMS154-M1_psen_db.json @@ -1,5 +1,5 @@ { - "image_background_enable": true, + "image_background_enable": false, "image_background": null, "image_threshold": null, "image_region_of_interest": null, @@ -11,20 +11,18 @@ "name": "SATES21-CAMS154-M1_psen_db", "mode": "PUSH", "roi_background": [ - 300, - 1548, - 600, - 400 + 250, + 1600, + 420, + 700 ], "roi_signal": [ - 300, - 1548, - 1150, - 400 - ], - "no_client_timeout": 0, - "processing_threads": 6, + 250, + 1600, + 420, + 700 + ], + "processing_threads": 4, "thread_buffer_size": 30, - "abort_on_error": false, - "reload": true -} \ No newline at end of file +"reload": true +} diff --git a/configuration/pipeline_config/SATES24-CAMS161-M1_psen_db.json b/configuration/pipeline_config/SATES24-CAMS161-M1_psen_db.json index ead0929..bf0fdfa 100644 --- a/configuration/pipeline_config/SATES24-CAMS161-M1_psen_db.json +++ b/configuration/pipeline_config/SATES24-CAMS161-M1_psen_db.json @@ -23,5 +23,7 @@ 700 ], "reload": true, + "processing_threads": 4, + "thread_buffer_size": 30, "project_axis": 1 -} \ No newline at end of file +} diff --git a/configuration/pipeline_config/jungfrau_direct.json b/configuration/pipeline_config/jungfrau_direct.json new file mode 100644 index 0000000..8919617 --- /dev/null +++ b/configuration/pipeline_config/jungfrau_direct.json @@ -0,0 +1,7 @@ +{ + "pipeline_type": "custom", + "name": "jungfrau_pip", + "mode": "PUB", + "function": "jungfrau_direct", + "max_frame_rate": 2 +} diff --git a/configuration/pipeline_config/jungfrau_proc.json b/configuration/pipeline_config/jungfrau_proc.json new file mode 100644 index 0000000..e3f6eae --- /dev/null +++ b/configuration/pipeline_config/jungfrau_proc.json @@ -0,0 +1,17 @@ +{ + "image_background_enable": false, + "image_background": null, + "image_threshold": null, + "image_region_of_interest": null, + "image_good_region": null, + "image_slices": null, + "pipeline_type": "processing", + "camera_name": "jungfrau", + "name": "jungfrau_proc", + "function": "jungfrau_proc", + "processing_threads": 4, + "thread_buffer_size": 30, + "multiprocessing": true, + "visualisation_socket": "tcp://localhost:5555", + "visualisation": false +} \ No newline at end of file diff --git a/configuration/pipeline_config/permanent_instances.json b/configuration/pipeline_config/permanent_instances.json index 8982169..7f25f6b 100644 --- a/configuration/pipeline_config/permanent_instances.json +++ b/configuration/pipeline_config/permanent_instances.json @@ -8,6 +8,7 @@ "SARES20-CAMS142-M5_psen_db": "SARES20-CAMS142-M5_psen_db1", "SARES20-CAMS142-M5_psen_ib": "SARES20-CAMS142-M5_psen_ib1", "SARES20-DSDPPRM_proc": "SARES20-DSDPPRM_proc", + "SARES20-PROF141-M1_ib": "SARES20-PROF141-M1_ib", "SARES20-PROF141-M1_proc": "SARES20-PROF141-M1_proc1", "SARES20-PROF142-M1_ib": "SARES20-PROF142-M1_ib1", "SARES20-PROF142-M1_proc": "SARES20-PROF142-M1_proc1", @@ -15,10 +16,12 @@ "SARFE10-PBPS053_proc": "SARFE10-PBPS053_proc1", "SARFE10-PSSS059_psss": "SARFE10-PSSS059_psss1", "SARFE10-PSSS059_store": "SARFE10-PSSS059_store1", - "SAROP21-PPRM138_proc": "SAROP21-PPRM138_proc1", + "SAROP21-ATT01_proc": "SAROP21-ATT01_proc", + "SAROP21-PPRM138_proc": "SAROP21-PPRM138_proc", "SATES21-CAMS154-M1_psen_db": "SATES21-CAMS154-M1_psen_db1", "SATES21-CAMS154-M1_psen_ib": "SATES21-CAMS154-M1_psen_ib1", "SATES24-CAMS161-M1_psen_db": "SATES24-CAMS161-M1_psen_db1", "SATES24-CAMS161-M1_psen_ib": "SATES24-CAMS161-M1_psen_ib1", + "jungfrau_proc": "jungfrau_proc", "testdb_ib": "testdb_ib" } \ No newline at end of file diff --git a/configuration/pipeline_config/servers.json b/configuration/pipeline_config/servers.json index 6ce00a2..1c13446 100644 --- a/configuration/pipeline_config/servers.json +++ b/configuration/pipeline_config/servers.json @@ -1,6 +1,21 @@ { + "http://sf-daq-4.psi.ch:8881": { + "cameras": [ + "simulation_3", + "jungfrau" + ], + "enabled": true, + "expanding": false, + "instances": [ + "jungfrau_proc:9000", + "jungfrau_sp", + "jungfrau_direct", + "simulation_3_sp" + ] + }, "http://sf-daqsync-01.psi.ch:8881": { "cameras": [], + "enabled": true, "expanding": true, "instances": [] }, @@ -20,11 +35,13 @@ "simulation_2", "simulation" ], + "enabled": true, "expanding": false, "instances": [ "testdb_ib:9005", "simulation_2_sp", - "SARFE10-PBPS053_proc:9004" + "SARFE10-PBPS053_proc:9004", + "SAROP21-ATT01_proc:9003" ] }, "http://sf-daqsync-04.psi.ch:8881": { @@ -52,6 +69,7 @@ "Alvra_spatial_encoding", "Alvra_spectral_encoding" ], + "enabled": true, "expanding": false, "instances": [ "SARES11-SPEC125-M1_psen_ib:9000", @@ -90,6 +108,7 @@ "SAROP21-PPRM138_sp", "SARES20-PROF141-M1_sp", "SARES20-PROF141-M1_proc:9016", + "SARES20-PROF141-M1_ib:9013", "SARES20-PROF146-M1_sp", "SARES20-PROF146-M1_proc:9018", "SARES20-DSDPPRM_proc:9014", @@ -99,6 +118,7 @@ }, "http://sf-daqsync-09.psi.ch:8881": { "cameras": [], + "enabled": true, "expanding": true, "instances": [] }, diff --git a/configuration/user_scripts/SARFE10-PBPS053_proc.py b/configuration/user_scripts/SARFE10-PBPS053_proc.py index 588f492..865ef5d 100644 --- a/configuration/user_scripts/SARFE10-PBPS053_proc.py +++ b/configuration/user_scripts/SARFE10-PBPS053_proc.py @@ -2,74 +2,123 @@ import time from collections import defaultdict, deque from functools import partial from logging import getLogger -from threading import RLock, Thread +from threading import Thread import epics import numpy as np from cam_server.utils import create_thread_pvs -from scipy.fftpack import fft _logger = getLogger(__name__) -intensity_pv = None initialized = False +dif_vals = { + "xpos_odd_m": np.nan, + "xpos_odd_w": np.nan, + "ypos_odd_m": np.nan, + "ypos_odd_w": np.nan, + "xpos_evn_m": np.nan, + "xpos_evn_w": np.nan, + "ypos_evn_m": np.nan, + "ypos_evn_w": np.nan, +} + # this is to avoid exceptions in the 'process' function upon appending to buffers if not all of # them were created in the 'initialize' function buffers = defaultdict(partial(deque, maxlen=1)) def initialize(params): - global intensity_pv, device, initialized + global device, initialized epics.ca.clear_cache() - [intensity_pv] = create_thread_pvs([params["intensity_pvname"]]) - intensity_pv.wait_for_connection() - # If raising this exception then the pipeline won't start - if not intensity_pv.connected: - raise ("Cannot connect to " + params["intensity_pvname"]) - for label in ("x_pos_all", "y_pos_all", "x_pos_odd", "y_pos_odd", "x_pos_even", "y_pos_even"): - out_x_pvname = params[f"fft_{label}_X_pvname"] - out_y_pvname = params[f"fft_{label}_Y_pvname"] + for label in ("xpos_all", "ypos_all", "xpos_odd", "ypos_odd", "xpos_evn", "ypos_evn"): + x_pvname = params[f"{label}_x_pvname"] + y_pvname = params[f"{label}_y_pvname"] + m_pvname = params[f"{label}_m_pvname"] + w_pvname = params[f"{label}_w_pvname"] - if out_x_pvname and out_y_pvname: + if x_pvname and y_pvname and m_pvname and w_pvname: buffer = deque(maxlen=params["queue_length"]) buffers[label] = buffer - thread = Thread(target=calculate_fft, args=(buffer, out_x_pvname, out_y_pvname)) + thread = Thread(target=update_PVs, args=(label, buffer, x_pvname, y_pvname, m_pvname, w_pvname)) thread.start() + # diff PVs + xpos_dif_m_pvname = params["xpos_dif_m_pvname"] + xpos_dif_w_pvname = params["xpos_dif_w_pvname"] + ypos_dif_m_pvname = params["ypos_dif_m_pvname"] + ypos_dif_w_pvname = params["ypos_dif_w_pvname"] + + thread = Thread(target=update_dif_PVs, args=(xpos_dif_m_pvname, xpos_dif_w_pvname, ypos_dif_m_pvname, ypos_dif_w_pvname)) + thread.start() + device, _ = params["up"].split(":", 1) initialized = True -# Processing the buffer every second and setting result to EPICS channel -def calculate_fft(buffer, out_x_pvname, out_y_pvname): - _logger.info("Start buffer processing thread") - try: - out_x_pv, out_y_pv = create_thread_pvs([out_x_pvname, out_y_pvname]) +def update_PVs(label, buffer, x_pvname, y_pvname, m_pvname, w_pvname): + x_pv, y_pv, m_pv, w_pv = create_thread_pvs([x_pvname, y_pvname, m_pvname, w_pvname]) - out_x_pv.wait_for_connection() - out_y_pv.wait_for_connection() - if not (out_x_pv.connected and out_y_pv.connected): - raise ("Cannot connect to fft PVs.") + x_pv.wait_for_connection() + y_pv.wait_for_connection() + m_pv.wait_for_connection() + w_pv.wait_for_connection() + if not (x_pv.connected and y_pv.connected and m_pv.connected and w_pv.connected): + raise (f"Cannot connect to {label} PVs.") - out_x_pv.put(np.arange(buffer.maxlen)) - out_y_pv.put(np.zeros(buffer.maxlen)) + x_pv.put(np.arange(buffer.maxlen)) + y_pv.put(np.zeros(buffer.maxlen)) + m_pv.put(0) + w_pv.put(0) - while True: - _buffer = buffer.copy() - if len(_buffer) == _buffer.maxlen: - out_y_pv.put(np.abs(fft(np.array(_buffer)))) + while True: + time.sleep(3) + if len(buffer) != buffer.maxlen: + continue - time.sleep(1.0) + _buffer = np.array(buffer) + _buffer = _buffer[~np.isnan(_buffer)] - except Exception as e: - _logger.error("Error on buffer processing thread %s" % (str(e))) - finally: - _logger.info("Exit buffer processing thread") + # histogram + y_hist, x_hist = np.histogram(_buffer, bins=50) + x_hist = (x_hist[1:] + x_hist[:-1]) / 2 + + x_pv.put(x_hist) + y_pv.put(y_hist) + + # stats + mean_val = np.mean(_buffer) + std_val = np.std(_buffer) + + m_pv.put(mean_val) + w_pv.put(std_val) + + dif_vals[f"{label}_m"] = mean_val + dif_vals[f"{label}_w"] = std_val + + +def update_dif_PVs(xpos_dif_m_pvname, xpos_dif_w_pvname, ypos_dif_m_pvname, ypos_dif_w_pvname): + xpos_dif_m_pv, xpos_dif_w_pv, ypos_dif_m_pv, ypos_dif_w_pv = create_thread_pvs( + [xpos_dif_m_pvname, xpos_dif_w_pvname, ypos_dif_m_pvname, ypos_dif_w_pvname] + ) + + xpos_dif_m_pv.wait_for_connection() + xpos_dif_w_pv.wait_for_connection() + ypos_dif_m_pv.wait_for_connection() + ypos_dif_w_pvname.wait_for_connection() + if not (xpos_dif_m_pv.connected and xpos_dif_w_pv.connected and ypos_dif_m_pv.connected and ypos_dif_w_pvname.connected): + raise (f"Cannot connect to dif PVs.") + + while True: + time.sleep(3) + xpos_dif_m_pv.put(dif_vals["xpos_odd_m"] - dif_vals["xpos_evn_m"]) + xpos_dif_w_pv.put(dif_vals["xpos_odd_w"] - dif_vals["xpos_evn_w"]) + ypos_dif_m_pv.put(dif_vals["ypos_odd_m"] - dif_vals["ypos_evn_m"]) + ypos_dif_w_pv.put(dif_vals["ypos_odd_w"] - dif_vals["ypos_evn_w"]) def process(data, pulse_id, timestamp, params): @@ -88,35 +137,32 @@ def process(data, pulse_id, timestamp, params): intensity = down + up + left + right intensity_uJ = intensity * params["uJ_calib"] except: - intensity = float("nan") - intensity_uJ = float("nan") + intensity = np.nan + intensity_uJ = np.nan if intensity > params["threshold"]: - x_pos = ((right - left) / (right + left)) * params["horiz_calib"] - y_pos = ((up - down) / (up + down)) * params["vert_calib"] + xpos = ((right - left) / (right + left)) * params["horiz_calib"] + ypos = ((up - down) / (up + down)) * params["vert_calib"] else: - x_pos = float("nan") - y_pos = float("nan") + xpos = np.nan + ypos = np.nan # Update buffers - buffers["x_pos_all"].append(x_pos) - buffers["y_pos_all"].append(y_pos) + buffers["xpos_all"].append(xpos) + buffers["ypos_all"].append(ypos) if pulse_id % 2: - buffers["x_pos_odd"].append(x_pos) - buffers["y_pos_odd"].append(y_pos) + buffers["xpos_odd"].append(xpos) + buffers["ypos_odd"].append(ypos) else: - buffers["x_pos_even"].append(x_pos) - buffers["y_pos_even"].append(y_pos) - - # Update intensity EPICS channel - intensity_pv.put(intensity) + buffers["xpos_evn"].append(xpos) + buffers["ypos_evn"].append(ypos) # Set bs outputs output = {} - output[f"{device}:intensity"] = intensity - output[f"{device}:intensity_uJ"] = intensity_uJ - output[f"{device}:x_pos"] = x_pos - output[f"{device}:y_pos"] = y_pos + output[f"{device}:INTENSITY"] = intensity + output[f"{device}:INTENSITY_UJ"] = intensity_uJ + output[f"{device}:XPOS"] = xpos + output[f"{device}:YPOS"] = ypos return output diff --git a/configuration/user_scripts/SAROP21-ATT01_proc.py b/configuration/user_scripts/SAROP21-ATT01_proc.py new file mode 100644 index 0000000..03ebe4d --- /dev/null +++ b/configuration/user_scripts/SAROP21-ATT01_proc.py @@ -0,0 +1,100 @@ +from collections import deque +from logging import getLogger +from scipy.signal import savgol_filter +import numpy as np + +_logger = getLogger(__name__) + +initialized = False + + +def initialize(params): + global initialized, buffer, device, step_length, edge_type, refinement, dark_event, fel_on_event, use_dark, calib, use_filter, filter_window + + device = params["device"] + step_length = params["step_length"] + edge_type = params["edge_type"] + refinement = params["refinement"] + dark_event = params["dark_event"] + fel_on_event = params["fel_on_event"] + buffer = deque(maxlen=params["buffer_length"]) + use_dark = params["use_dark"] + calib = params["calib"] + filter_window = params["filter_window"] + use_filter = params['filter'] + initialized = True + + +def _interpolate_row(y_known, x_known, x_interp): + y_interp = np.interp(x_interp, x_known, y_known) + return y_interp + + +def find_edge(data, step_length=50, edge_type="falling", refinement=1): + # refine data + data_length = data.shape[1] + refined_data = np.apply_along_axis( + _interpolate_row, + axis=1, + arr=data, + x_known=np.arange(data_length), + x_interp=np.arange(0, data_length - 1, refinement), + ) + + # prepare a step function and refine it + step_waveform = np.ones(shape=(step_length,)) + if edge_type == "rising": + step_waveform[: int(step_length / 2)] = -1 + elif edge_type == "falling": + step_waveform[int(step_length / 2) :] = -1 + + step_waveform = np.interp( + x=np.arange(0, step_length - 1, refinement), xp=np.arange(step_length), fp=step_waveform + ) + + # find edges + xcorr = np.apply_along_axis(np.correlate, 1, refined_data, v=step_waveform, mode="valid") + edge_position = np.argmax(xcorr, axis=1).astype(float) * refinement + xcorr_amplitude = np.amax(xcorr, axis=1) + + # correct edge_position for step_length + edge_position += np.floor(step_length / 2) + + return {"edge_pos": edge_position, "xcorr": xcorr, "xcorr_ampl": xcorr_amplitude, "signal":data} + + +def process(data, pulse_id, timestamp, params): + if not initialized: + initialize(params) + + # Read stream inputs + prof_sig = data[params["prof_sig"]] + if use_filter: + prof_sig = savgol_filter(prof_sig,filter_window,3) + events = data[params["events"]] + + if prof_sig.ndim == 1: + prof_sig = prof_sig[np.newaxis, :] + + if events[dark_event] and use_dark: + buffer.append(prof_sig) + edge_results = {"edge_pos": np.nan, "xcorr": np.nan, "xcorr_ampl": np.nan, "signal":np.nan} + else: + if events[fel_on_event] and buffer: + prof_sig = prof_sig / np.mean(buffer, axis=0) + edge_results = find_edge(prof_sig, step_length, edge_type, refinement) + elif events[fel_on_event] and not use_dark: + edge_results = find_edge(prof_sig, step_length, edge_type, refinement) + else: + edge_results = {"edge_pos": np.nan, "xcorr": np.nan, "xcorr_ampl": np.nan, "signal":np.nan} + + # calib edge + edge_results["arrival_time"] = edge_results["edge_pos"] * calib + + # Set bs outputs + output = {} + for key, value in edge_results.items(): + output[f"{device}:{key}"] = value + + return output + diff --git a/configuration/user_scripts/jungfrau.py b/configuration/user_scripts/jungfrau.py new file mode 100644 index 0000000..1848201 --- /dev/null +++ b/configuration/user_scripts/jungfrau.py @@ -0,0 +1,149 @@ +import numpy +import sys +import zmq +import time + +from cam_server.camera.source.camera import * + +from logging import getLogger +from cam_server import config +from cam_server.camera.sender import * +from cam_server.camera.source.common import transform_image +from copy import copy +from cam_server.utils import set_statistics, on_message_sent, init_statistics, MaxLenDict + +import jungfrau_utils as ju + + +_logger = getLogger(__name__) + + +class jungfrau(Camera): + def __init__(self, camera_config): + Camera.__init__(self, camera_config, check_sender_data=False) + self.camera_config = camera_config + self.backend = self.camera_config.get_source() + self.backend = "tcp://192.168.30.8:9102" + self.timeout = self.camera_config.parameters.get("timeout") + if self.timeout is None: + self.timeout = 5.0 + self.ju_stream_adapter = ju.StreamAdapter() + + self.zmq_context = zmq.Context(io_threads=4) + self.poller = zmq.Poller() + + # Width and height of the raw image + self.width_raw = 0 + self.height_raw = 0 + self.pid = None + self.metadata = {} + + self.init=True + + def get_raw_geometry(self): + return self.width_raw, self.height_raw + + def verify_camera_online(self): + return + + def connect(self): + """ + flags=0 + zmq_context = zmq.Context(io_threads=4) + poller = zmq.Poller() + backend_socket = zmq_context.socket(zmq.PULL) + backend_socket.connect(self.backend) + poller.register(backend_socket, zmq.POLLIN) + for i in range(5): + events = dict(poller.poll(2000)) + if backend_socket in events: + metadata = backend_socket.recv_json(flags) + image = backend_socket.recv(flags, copy=False, track=False) + _logger.info(f"got it {metadata}") + else: + _logger.info("nothing") + """ + try: + _logger.info("Connecting to Jungfrau: " + str(self.backend)) + self.verify_camera_online() + self.backend_socket = self.zmq_context.socket(zmq.PULL) + self.backend_socket.connect(self.backend) + self.poller.register(self.backend_socket, zmq.POLLIN) + image = self.get_image() + self.height_raw, self.width_raw = image.shape + #metadata, image = self._read() + #self.width_raw, self.height_raw = metadata['shape'][1], metadata['shape'][0] + _logger.info("Connected to Jungfrau - shape: " + str(self.width_raw) + "x" + str(self.height_raw)) + except: + _logger.warning("Error connecting to Jungfrau: " + str(sys.exc_info()[1])) + raise + + def disconnect(self): + try: + self.backend_socket.disconnect() + except: + pass + + def _read(self): + flags=0 + start = time.time() + try: + while True: + events = dict(self.poller.poll(20)) # check every 2 seconds in each worker + if self.backend_socket in events: + metadata = self.backend_socket.recv_json(flags) + data = self.backend_socket.recv(flags, copy=False, track=False) + image = numpy.frombuffer(data, dtype=metadata['type']).reshape(metadata['shape']) + results = copy(metadata) + # we may not send each frame(real image) every time, to save bandwidth. If image is not sent, we send "2x2 dummy image" + if results['shape'][0] == 2 and results['shape'][1] == 2: + #_logger.info("Dummy") + pass + else: + return results, image + if self.timeout>0: + if (time.time() - start) > self.timeout: + raise Exception("Timeout") + except: + raise Exception("Cannot get data from detector: " + str(sys.exc_info()[1])) + + def read(self): + try: + #width, height = self.get_raw_geometry() + #return numpy.random.randint(1, 101, width * height, "uint16").reshape((height, width)) + self.metadata, image = self._read() + #double_pixel_action = results.get('double_pixels_action', "mask") + #image = self.ju_stream_adapter.process(image, results, double_pixels=double_pixel_action) + #image=image.astype(dtype="uint16", copy=False) + #self.pid = self.metadata.get('pulse_id', None) + return image + except: + _logger.warning("Error reading from Jungfrau: " + str(sys.exc_info()[1])) + raise + + def get_data(self): + image = self.get_image() + timestamp=time.time() + return image, time.time(), self.metadata.get('pulse_id', None) + + def register_channels(self, sender): + Camera.register_channels(self, sender) #default channels + sender.add_channel("frame",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "int64"}) + sender.add_channel("is_good_frame",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "int64"}) + sender.add_channel("daq_rec",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "int64"}) + sender.add_channel("number_frames_expected",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "int64"}) + sender.add_channel("daq_rec",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "int64"}) + sender.add_channel("pedestal_file",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + sender.add_channel("gain_file",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + sender.add_channel("run_name",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + sender.add_channel("detector_name",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + sender.add_channel("htype",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + sender.add_channel("type",metadata={"compression": config.CAMERA_BSREAD_SCALAR_COMPRESSION, "type": "string"}) + + def get_send_channels(self, default_channels): + for channel in ("frame", "is_good_frame","daq_rec","number_frames_expected","daq_rec","pedestal_file","gain_file", "run_name", "detector_name", "htype","type"): + default_channels[channel] = self.metadata.get(channel, None) + return default_channels + + def process(self, stop_event, statistics, parameter_queue, port): + return Camera.process(self, stop_event, statistics, parameter_queue, port) diff --git a/configuration/user_scripts/jungfrau_direct.py b/configuration/user_scripts/jungfrau_direct.py new file mode 100644 index 0000000..8c86194 --- /dev/null +++ b/configuration/user_scripts/jungfrau_direct.py @@ -0,0 +1,15 @@ +import time +import numpy +from collections import OrderedDict + +def process(parameters, init=False): + stream_data = OrderedDict() + stream_data["scalar"] = 10.0 + stream_data["waveform"] = numpy.random.randint(1, 101, 10, "uint16") + stream_data["image"] = numpy.random.randint(1, 101, 200, "uint16").reshape((10, 20)) + stream_data["str"] = str(init) + timestamp = time.time() + pulse_id = None + data_size = stream_data["image"].size + return stream_data, timestamp, pulse_id, data_size + diff --git a/configuration/user_scripts/jungfrau_proc.py b/configuration/user_scripts/jungfrau_proc.py new file mode 100644 index 0000000..cde4484 --- /dev/null +++ b/configuration/user_scripts/jungfrau_proc.py @@ -0,0 +1,46 @@ +import jungfrau_utils as ju +import zmq +import numpy +from logging import getLogger +_logger = getLogger(__name__) + +flags=0 + +ju_stream_adapter = None +visualisation_socket = None +zmq_context = None +#metadata = {'frame': 68544604, 'is_good_frame': 1, 'daq_rec': 3856, 'pulse_id': 12711246781, 'pedestal_file': '/sf/jungfrau/data/pedestal/JF02T09V02/20210816_183002.h5', 'gain_file': '/sf/jungfrau/config/gainMaps/JF02T09V02/gains.h5', 'number_frames_expected': 10000, 'run_name': '12711240000', 'detector_name': 'JF02T09V02', 'htype': 'array-1.0', 'type': 'uint16', 'shape': [4608, 1024]} + +def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, metadata): + global ju_stream_adapter, flags,visualisation_socket,zmq_context + + visualisation = parameters["visualisation"] + + if ju_stream_adapter is None: + ju_stream_adapter = ju.StreamAdapter() + if visualisation: + zmq_context = zmq.Context(io_threads=4) + visualisation_socket = zmq_context.socket(zmq.PUB) + visualisation_socket.connect(parameters["visualisation_socket"]) + visualisation_socket.set_hwm(10) + + image = ju_stream_adapter.process(image,metadata) + + if parameters.get("threshold") is not None: + image[image < parameters.get("threshold")] = 0.0 + + shape = [2,2] if image is None else [image.shape[0],image.shape[1]] + metadata['shape']=shape + metadata['pulse_id']=pulse_id + metadata['type']= str(image.dtype) if (image is not None) else "" + for key,value in metadata.items(): + if isinstance(value, numpy.integer): + metadata[key] = int(value) + + if visualisation_socket is not None: + if image is not None: + visualisation_socket.send_json(metadata, flags | zmq.SNDMORE) + visualisation_socket.send(image, flags, copy=True, track=True) + + return metadata +