mx-bluesky 1.1.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. mx_bluesky/__init__.py +8 -3
  2. mx_bluesky/__main__.py +12 -7
  3. mx_bluesky/_version.py +2 -2
  4. mx_bluesky/beamlines/i04/callbacks/murko_callback.py +14 -4
  5. mx_bluesky/beamlines/i04/thawing_plan.py +48 -10
  6. mx_bluesky/beamlines/i24/serial/__init__.py +3 -0
  7. mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +68 -90
  8. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl +1 -1
  9. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +104 -126
  10. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py +139 -162
  11. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Mapping_py3v1.py +25 -36
  12. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_StartUp_py3v1.py +24 -34
  13. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py +14 -11
  14. mx_bluesky/beamlines/i24/serial/log.py +58 -49
  15. mx_bluesky/beamlines/i24/serial/parameters/fixed_target/cs/cs_maker.json +3 -3
  16. mx_bluesky/beamlines/i24/serial/run_extruder.sh +30 -5
  17. mx_bluesky/beamlines/i24/serial/run_fixed_target.sh +31 -7
  18. mx_bluesky/beamlines/i24/serial/run_serial.py +24 -8
  19. mx_bluesky/beamlines/i24/serial/setup_beamline/ca.py +0 -2
  20. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_beamline.py +1 -1
  21. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_detector.py +8 -18
  22. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_zebra_plans.py +2 -2
  23. mx_bluesky/common/__init__.py +0 -0
  24. mx_bluesky/common/device_setup_plans/read_hardware_for_setup.py +14 -0
  25. mx_bluesky/common/parameters/components.py +221 -0
  26. mx_bluesky/common/parameters/constants.py +133 -0
  27. mx_bluesky/common/plans/__init__.py +1 -0
  28. mx_bluesky/common/plans/do_fgs.py +121 -0
  29. mx_bluesky/common/utils/log.py +116 -0
  30. mx_bluesky/{hyperion → common/utils}/tracing.py +2 -2
  31. mx_bluesky/hyperion/__main__.py +11 -9
  32. mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py +31 -26
  33. mx_bluesky/hyperion/device_setup_plans/read_hardware_for_setup.py +6 -12
  34. mx_bluesky/hyperion/device_setup_plans/setup_oav.py +6 -12
  35. mx_bluesky/hyperion/device_setup_plans/setup_panda.py +1 -2
  36. mx_bluesky/hyperion/device_setup_plans/setup_zebra.py +48 -17
  37. mx_bluesky/hyperion/device_setup_plans/smargon.py +6 -6
  38. mx_bluesky/hyperion/device_setup_plans/utils.py +13 -2
  39. mx_bluesky/hyperion/device_setup_plans/xbpm_feedback.py +4 -4
  40. mx_bluesky/hyperion/experiment_plans/experiment_registry.py +9 -0
  41. mx_bluesky/hyperion/experiment_plans/flyscan_xray_centre_plan.py +59 -108
  42. mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py +7 -5
  43. mx_bluesky/hyperion/experiment_plans/load_centre_collect_full_plan.py +46 -0
  44. mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +19 -18
  45. mx_bluesky/hyperion/experiment_plans/oav_snapshot_plan.py +8 -5
  46. mx_bluesky/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py +4 -4
  47. mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py +17 -17
  48. mx_bluesky/hyperion/experiment_plans/robot_load_and_change_energy.py +241 -0
  49. mx_bluesky/hyperion/experiment_plans/robot_load_then_centre_plan.py +24 -181
  50. mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py +6 -4
  51. mx_bluesky/hyperion/experiment_plans/set_energy_plan.py +3 -11
  52. mx_bluesky/hyperion/external_interaction/callbacks/__main__.py +1 -2
  53. mx_bluesky/hyperion/external_interaction/callbacks/common/callback_util.py +18 -0
  54. mx_bluesky/hyperion/external_interaction/callbacks/common/ispyb_mapping.py +1 -9
  55. mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +18 -13
  56. mx_bluesky/hyperion/external_interaction/callbacks/ispyb_callback_base.py +32 -15
  57. mx_bluesky/hyperion/external_interaction/callbacks/log_uid_tag_callback.py +1 -1
  58. mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py +3 -5
  59. mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +4 -3
  60. mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +23 -18
  61. mx_bluesky/hyperion/external_interaction/config_server.py +22 -10
  62. mx_bluesky/hyperion/external_interaction/ispyb/ispyb_store.py +1 -1
  63. mx_bluesky/hyperion/external_interaction/ispyb/ispyb_utils.py +0 -2
  64. mx_bluesky/hyperion/external_interaction/nexus/nexus_utils.py +2 -2
  65. mx_bluesky/hyperion/external_interaction/nexus/write_nexus.py +1 -1
  66. mx_bluesky/hyperion/log.py +0 -84
  67. mx_bluesky/hyperion/parameters/components.py +1 -242
  68. mx_bluesky/hyperion/parameters/constants.py +22 -118
  69. mx_bluesky/hyperion/parameters/gridscan.py +20 -11
  70. mx_bluesky/hyperion/parameters/load_centre_collect.py +50 -0
  71. mx_bluesky/hyperion/parameters/robot_load.py +16 -0
  72. mx_bluesky/hyperion/parameters/rotation.py +9 -5
  73. mx_bluesky/hyperion/utils/utils.py +17 -0
  74. mx_bluesky/hyperion/utils/validation.py +5 -6
  75. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/METADATA +4 -2
  76. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/RECORD +80 -70
  77. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/WHEEL +1 -1
  78. mx_bluesky/example.py +0 -19
  79. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/LICENSE +0 -0
  80. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/entry_points.txt +0 -0
  81. {mx_bluesky-1.1.0.dist-info → mx_bluesky-1.4.0.dist-info}/top_level.txt +0 -0
@@ -4,13 +4,8 @@ Chip mapping utilities for fixed target
4
4
  This version changed to python3 March2020 by RLO
5
5
  """
6
6
 
7
- import logging
8
- import time
9
-
10
7
  import numpy as np
11
- from matplotlib import pyplot as plt
12
8
 
13
- from mx_bluesky.beamlines.i24.serial import log
14
9
  from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import ChipType
15
10
  from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_StartUp_py3v1 import (
16
11
  check_files,
@@ -19,19 +14,12 @@ from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_StartUp_py3v1 impo
19
14
  read_parameter_file,
20
15
  write_file,
21
16
  )
17
+ from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER, log_on_entry
22
18
  from mx_bluesky.beamlines.i24.serial.parameters import get_chip_format
23
19
  from mx_bluesky.beamlines.i24.serial.parameters.constants import PARAM_FILE_PATH_FT
24
20
 
25
- logger = logging.getLogger("I24ssx.chip_mapping")
26
-
27
-
28
- def setup_logging():
29
- # Log should now change name daily.
30
- logfile = time.strftime("i24_%Y_%m_%d.log").lower()
31
- log.config(logfile)
32
21
 
33
-
34
- @log.log_on_entry
22
+ @log_on_entry
35
23
  def read_file_make_dict(fid, chip_type, switch=False):
36
24
  a_dict = {}
37
25
  b_dict = {}
@@ -52,8 +40,8 @@ def read_file_make_dict(fid, chip_type, switch=False):
52
40
  return a_dict
53
41
 
54
42
 
55
- @log.log_on_entry
56
- def plot_file(fid, chip_type):
43
+ @log_on_entry
44
+ def plot_file(plt, fid, chip_type):
57
45
  chip_dict = read_file_make_dict(fid, chip_type)
58
46
  x_list, y_list, z_list = [], [], []
59
47
  for k in sorted(chip_dict.keys()):
@@ -84,7 +72,7 @@ def plot_file(fid, chip_type):
84
72
  return 1
85
73
 
86
74
 
87
- @log.log_on_entry
75
+ @log_on_entry
88
76
  def convert_chip_to_hex(fid, chip_type):
89
77
  chip_dict = read_file_make_dict(fid, chip_type, True)
90
78
  chip_format = get_chip_format(ChipType(chip_type))
@@ -93,14 +81,14 @@ def convert_chip_to_hex(fid, chip_type):
93
81
  # Normal
94
82
  if chip_type in [ChipType.Oxford, ChipType.OxfordInner]:
95
83
  shot_order_list = get_shot_order(chip_type)
96
- logger.info("Shot Order List: \n")
97
- logger.info(f"{shot_order_list[:14]}")
98
- logger.info(f"{shot_order_list[-14:]}")
84
+ SSX_LOGGER.info("Shot Order List: \n")
85
+ SSX_LOGGER.info(f"{shot_order_list[:14]}")
86
+ SSX_LOGGER.info(f"{shot_order_list[-14:]}")
99
87
  for i, k in enumerate(shot_order_list):
100
88
  if i % 20 == 0:
101
- logger.info("\n")
89
+ SSX_LOGGER.info("\n")
102
90
  else:
103
- logger.info(f"{k}")
91
+ SSX_LOGGER.info(f"{k}")
104
92
  sorted_pres_list = []
105
93
  for addr in shot_order_list:
106
94
  sorted_pres_list.append(chip_dict[addr])
@@ -124,38 +112,39 @@ def convert_chip_to_hex(fid, chip_type):
124
112
  pvar = 5001 + i
125
113
  line = f"P{pvar}=${hex_string}"
126
114
  g.write(line + "\n")
127
- logger.info("hex string: %s" % (hex_string + 4 * "0"))
128
- logger.info(f"line number= {i}")
129
- logger.info(
115
+ SSX_LOGGER.info("hex string: %s" % (hex_string + 4 * "0"))
116
+ SSX_LOGGER.info(f"line number= {i}")
117
+ SSX_LOGGER.info(
130
118
  "right_list: \n{}\n".format("".join(str(x) for x in right_list))
131
119
  )
132
- logger.info(f"PVAR: {line}")
120
+ SSX_LOGGER.info(f"PVAR: {line}")
133
121
  if (i + 1) % windows_per_block == 0:
134
- logger.info(
122
+ SSX_LOGGER.info(
135
123
  "\n %s" % (40 * (" %i" % ((i / windows_per_block) + 2)))
136
124
  )
137
- logger.info(f"hex_length: {hex_length}")
125
+ SSX_LOGGER.info(f"hex_length: {hex_length}")
138
126
  else:
139
- logger.warning("Chip type unknown, no conversion done.")
127
+ SSX_LOGGER.warning("Chip type unknown, no conversion done.")
140
128
  return 0
141
129
 
142
130
 
143
- def main():
144
- setup_logging()
131
+ def main(plt):
145
132
  params = read_parameter_file()
146
133
 
147
134
  check_files("i24", [".spec"])
148
135
  write_file(suffix=".spec", order="shot")
149
136
 
150
- logger.info(f"PARAMETER PATH = {PARAM_FILE_PATH_FT}")
137
+ SSX_LOGGER.info(f"PARAMETER PATH = {PARAM_FILE_PATH_FT}")
151
138
  fid = PARAM_FILE_PATH_FT / f"{params.filename}.spec"
152
- logger.info(f"FID = {fid}")
139
+ SSX_LOGGER.info(f"FID = {fid}")
153
140
 
154
- plot_file(fid, params.chip.chip_type.value)
141
+ plot_file(plt, fid, params.chip.chip_type.value)
155
142
  convert_chip_to_hex(fid, params.chip.chip_type.value)
156
143
 
157
144
 
158
145
  if __name__ == "__main__":
159
- main()
146
+ from matplotlib import pyplot as plt
147
+
148
+ main(plt)
160
149
  plt.show()
161
- plt.close()
150
+ plt.close()
@@ -2,7 +2,6 @@
2
2
  Startup utilities for chip
3
3
  """
4
4
 
5
- import logging
6
5
  import os
7
6
  import string
8
7
  import time
@@ -10,8 +9,8 @@ from pathlib import Path
10
9
 
11
10
  import numpy as np
12
11
 
13
- from mx_bluesky.beamlines.i24.serial import log
14
12
  from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import ChipType
13
+ from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER, log_on_entry
15
14
  from mx_bluesky.beamlines.i24.serial.parameters import (
16
15
  FixedTargetParameters,
17
16
  get_chip_format,
@@ -22,14 +21,6 @@ from mx_bluesky.beamlines.i24.serial.parameters.constants import (
22
21
  PARAM_FILE_PATH_FT,
23
22
  )
24
23
 
25
- logger = logging.getLogger("I24ssx.chip_startup")
26
-
27
-
28
- def setup_logging():
29
- # Log should now change name daily.
30
- logfile = time.strftime("i24fixedtarget_%d%B%y.log").lower()
31
- log.config(logfile)
32
-
33
24
 
34
25
  def read_parameter_file(
35
26
  param_path: Path | str = PARAM_FILE_PATH_FT,
@@ -41,16 +32,16 @@ def read_parameter_file(
41
32
  return params
42
33
 
43
34
 
44
- @log.log_on_entry
35
+ @log_on_entry
45
36
  def fiducials(chip_type: int):
46
37
  fiducial_list: list | None = None
47
38
  if chip_type in [ChipType.Oxford, ChipType.OxfordInner, ChipType.Minichip]:
48
39
  fiducial_list = []
49
40
  elif chip_type == ChipType.Custom:
50
41
  # No fiducial for custom
51
- logger.warning("No fiducials for custom chip")
42
+ SSX_LOGGER.warning("No fiducials for custom chip")
52
43
  else:
53
- logger.warning(f"Unknown chip_type, {chip_type}, in fiducials")
44
+ SSX_LOGGER.warning(f"Unknown chip_type, {chip_type}, in fiducials")
54
45
  return fiducial_list
55
46
 
56
47
 
@@ -118,9 +109,9 @@ def pathli(l_in=None, way="typewriter", reverse=False):
118
109
  for _ in range(25):
119
110
  long_list.append(entry)
120
111
  else:
121
- logger.warning(f"No known path, way = {way}")
112
+ SSX_LOGGER.warning(f"No known path, way = {way}")
122
113
  else:
123
- logger.warning("No list written")
114
+ SSX_LOGGER.warning("No list written")
124
115
  return long_list
125
116
 
126
117
 
@@ -154,11 +145,11 @@ def get_alphanumeric(chip_type: ChipType):
154
145
  for block in block_list:
155
146
  for window in window_list:
156
147
  alphanumeric_list.append(block + "_" + window)
157
- logger.info(f"Length of alphanumeric list = {len(alphanumeric_list)}")
148
+ SSX_LOGGER.info(f"Length of alphanumeric list = {len(alphanumeric_list)}")
158
149
  return alphanumeric_list
159
150
 
160
151
 
161
- @log.log_on_entry
152
+ @log_on_entry
162
153
  def get_shot_order(chip_type: ChipType):
163
154
  cell_format = get_chip_format(chip_type)
164
155
  blk_num = cell_format.x_blocks
@@ -192,11 +183,11 @@ def get_shot_order(chip_type: ChipType):
192
183
  count = 0
193
184
  switch = 0
194
185
 
195
- logger.info(f"Length of collect list = {len(collect_list)}")
186
+ SSX_LOGGER.info(f"Length of collect list = {len(collect_list)}")
196
187
  return collect_list
197
188
 
198
189
 
199
- @log.log_on_entry
190
+ @log_on_entry
200
191
  def write_file(
201
192
  location: str = "i24",
202
193
  suffix: str = ".addr",
@@ -208,7 +199,7 @@ def write_file(
208
199
  params = read_parameter_file(param_file_path)
209
200
  else:
210
201
  msg = f"Unknown location, {location}"
211
- logger.error(msg)
202
+ SSX_LOGGER.error(msg)
212
203
  raise ValueError(msg)
213
204
  chip_file_path = save_path / f"chips/{params.directory}/{params.filename}{suffix}"
214
205
 
@@ -235,10 +226,10 @@ def write_file(
235
226
  line = "\t".join([xtal_name, str(x), str(y), "0.0", pres]) + "\n"
236
227
  g.write(line)
237
228
 
238
- logger.info(f"Write {chip_file_path} completed")
229
+ SSX_LOGGER.info(f"Write {chip_file_path} completed")
239
230
 
240
231
 
241
- @log.log_on_entry
232
+ @log_on_entry
242
233
  def check_files(
243
234
  location: str,
244
235
  suffix_list: list[str],
@@ -249,7 +240,7 @@ def check_files(
249
240
  params = read_parameter_file(param_file_path)
250
241
  else:
251
242
  msg = f"Unknown location, {location}"
252
- logger.error(msg)
243
+ SSX_LOGGER.error(msg)
253
244
  raise ValueError(msg)
254
245
  chip_file_path = save_path / f"chips/{params.directory}/{params.filename}"
255
246
 
@@ -265,12 +256,12 @@ def check_files(
265
256
  full_fid.parent / f"{time_str}_{params.filename}{full_fid.suffix}"
266
257
  )
267
258
  # FIXME hack / fix. Actually move the file
268
- logger.info(f"File {full_fid} Already Exists")
269
- logger.debug("Check files done")
259
+ SSX_LOGGER.info(f"File {full_fid} Already Exists")
260
+ SSX_LOGGER.debug("Check files done")
270
261
  return 1
271
262
 
272
263
 
273
- @log.log_on_entry
264
+ @log_on_entry
274
265
  def write_headers(
275
266
  location: str,
276
267
  suffix_list: list[str],
@@ -305,24 +296,23 @@ def write_headers(
305
296
  )
306
297
  else:
307
298
  msg = f"Unknown location, {location}"
308
- logger.error(msg)
299
+ SSX_LOGGER.error(msg)
309
300
  raise ValueError(msg)
310
- logger.debug("Write headers done")
301
+ SSX_LOGGER.debug("Write headers done")
311
302
 
312
303
 
313
304
  def run():
314
- logger.debug("Run Startup")
305
+ SSX_LOGGER.debug("Run Startup")
315
306
  check_files("i24", [".addr", ".shot"])
316
- logger.info("Checked Files")
307
+ SSX_LOGGER.info("Checked Files")
317
308
  write_headers("i24", [".addr", ".shot"])
318
- logger.info("Written Headers")
319
- logger.info("Writing to Files has been disabled. Headers Only")
309
+ SSX_LOGGER.info("Written Headers")
310
+ SSX_LOGGER.info("Writing to Files has been disabled. Headers Only")
320
311
  # Makes a file with random crystal positions
321
312
  check_files("i24", ["rando.spec"])
322
313
  write_headers("i24", ["rando.spec"])
323
- logger.debug("StartUp Done")
314
+ SSX_LOGGER.debug("StartUp Done")
324
315
 
325
316
 
326
317
  if __name__ == "__main__":
327
- setup_logging()
328
318
  run()
@@ -28,27 +28,31 @@ def _get_beam_centre(oav: OAV):
28
28
  Args:
29
29
  oav (OAV): the OAV device.
30
30
  """
31
- return oav.parameters.beam_centre_i, oav.parameters.beam_centre_j
31
+ beam_x = yield from bps.rd(oav.beam_centre_i)
32
+ beam_y = yield from bps.rd(oav.beam_centre_j)
33
+ return beam_x, beam_y
32
34
 
33
35
 
34
36
  def _calculate_zoom_calibrator(oav: OAV):
35
37
  """Set the scale for the zoom calibrator for the pmac moves."""
36
- currentzoom = yield from bps.rd(oav.zoom_controller.percentage)
38
+ currentzoom = yield from bps.rd(oav.zoom_controller.percentage) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809
37
39
  zoomcalibrator = 1.547 - (0.03 * currentzoom) + (0.0001634 * currentzoom**2)
38
40
  return zoomcalibrator
39
41
 
40
42
 
41
43
  def _move_on_mouse_click_plan(
42
- oav: OAV, pmac: PMAC, beam_centre: Sequence[int], clicked_position: Sequence[int]
44
+ oav: OAV,
45
+ pmac: PMAC,
46
+ clicked_position: Sequence[int],
43
47
  ):
44
48
  """A plan that calculates the zoom calibrator and moves to the clicked \
45
49
  position coordinates.
46
50
  """
47
51
  zoomcalibrator = yield from _calculate_zoom_calibrator(oav)
48
- beamX, beamY = beam_centre
52
+ beamX, beamY = yield from _get_beam_centre(oav)
49
53
  x, y = clicked_position
50
54
  xmove = -1 * (beamX - x) * zoomcalibrator
51
- ymove = -1 * (beamY - y) * zoomcalibrator
55
+ ymove = 1 * (beamY - y) * zoomcalibrator
52
56
  logger.info(f"Moving X and Y {xmove} {ymove}")
53
57
  xmovepmacstring = "#1J:" + str(xmove)
54
58
  ymovepmacstring = "#2J:" + str(ymove)
@@ -62,14 +66,13 @@ def onMouse(event, x, y, flags, param):
62
66
  RE = param[0]
63
67
  pmac = param[1]
64
68
  oav = param[2]
65
- beamX, beamY = _get_beam_centre(oav)
66
69
  logger.info(f"Clicked X and Y {x} {y}")
67
- RE(_move_on_mouse_click_plan(oav, pmac, (beamX, beamY), (x, y)))
70
+ RE(_move_on_mouse_click_plan(oav, pmac, (x, y)))
68
71
 
69
72
 
70
- def update_ui(oav, frame):
73
+ def update_ui(oav, frame, RE):
71
74
  # Get beam x and y values
72
- beamX, beamY = _get_beam_centre(oav)
75
+ beamX, beamY = RE(_get_beam_centre(oav)).plan_result
73
76
 
74
77
  # Overlay text and beam centre
75
78
  cv.ellipse(
@@ -164,7 +167,7 @@ def start_viewer(oav: OAV, pmac: PMAC, RE: RunEngine, oav1: str = OAV1_CAM):
164
167
  while success:
165
168
  success, frame = cap.read()
166
169
 
167
- update_ui(oav, frame)
170
+ update_ui(oav, frame, RE)
168
171
 
169
172
  k = cv.waitKey(1)
170
173
  if k == 113: # Q
@@ -212,7 +215,7 @@ def start_viewer(oav: OAV, pmac: PMAC, RE: RunEngine, oav1: str = OAV1_CAM):
212
215
 
213
216
 
214
217
  if __name__ == "__main__":
215
- RE = RunEngine()
218
+ RE = RunEngine(call_returns_result=True)
216
219
  # Get devices out of dodal
217
220
  oav: OAV = i24.oav()
218
221
  pmac: PMAC = i24.pmac()
@@ -1,39 +1,30 @@
1
1
  import functools
2
2
  import logging
3
3
  import logging.config
4
+ import time
4
5
  from os import environ
5
6
  from pathlib import Path
6
7
 
7
- from dodal.log import (
8
- ERROR_LOG_BUFFER_LINES,
9
- integrate_bluesky_and_ophyd_logging,
10
- set_up_all_logging_handlers,
11
- )
8
+ import bluesky.plan_stubs as bps
9
+ from blueapi.core import MsgGenerator
10
+ from bluesky.log import logger as bluesky_logger
11
+ from dodal.log import DEFAULT_GRAYLOG_PORT, ophyd_async_logger
12
12
  from dodal.log import LOGGER as dodal_logger
13
13
 
14
- VISIT_PATH = Path("/dls_sw/i24/etc/ssx_current_visit.txt")
15
-
16
-
17
- class OphydDebugFilter(logging.Filter): # NOTE yet to be fully tested
18
- """Do not send ophyd debug log messages to stream handler."""
14
+ from mx_bluesky.common.utils.log import do_default_logging_setup
19
15
 
20
- def filter(self, record):
21
- return "ophyd" not in record.getMessage().lower()
16
+ VISIT_PATH = Path("/dls_sw/i24/etc/ssx_current_visit.txt")
22
17
 
23
18
 
24
19
  # Logging set up
25
- logger = logging.getLogger("I24ssx")
26
- logger.addHandler(logging.NullHandler())
27
- logger.parent = dodal_logger
20
+ SSX_LOGGER = logging.getLogger("I24serial")
21
+ SSX_LOGGER.addHandler(logging.NullHandler())
22
+ SSX_LOGGER.parent = dodal_logger
23
+
28
24
 
29
25
  logging_config = {
30
26
  "version": 1,
31
27
  "disable_existing_loggers": False,
32
- "filters": {
33
- "ophyd_filter": {
34
- "()": OphydDebugFilter,
35
- }
36
- },
37
28
  "formatters": {
38
29
  "default": {
39
30
  "class": "logging.Formatter",
@@ -42,18 +33,17 @@ logging_config = {
42
33
  },
43
34
  "handlers": {
44
35
  "console": {
45
- "level": "DEBUG",
36
+ "level": "INFO",
46
37
  "class": "logging.StreamHandler",
47
38
  "formatter": "default",
48
- "filters": ["ophyd_filter"],
49
39
  "stream": "ext://sys.stdout",
50
40
  }
51
41
  },
52
42
  "loggers": {
53
- "I24ssx": {
43
+ "I24serial": {
54
44
  "handlers": ["console"],
55
45
  "level": "DEBUG",
56
- "propagate": True,
46
+ "propagate": False,
57
47
  }
58
48
  },
59
49
  }
@@ -68,10 +58,8 @@ def _read_visit_directory_from_file() -> Path:
68
58
 
69
59
 
70
60
  def _get_logging_file_path() -> Path:
71
- """Get the path to write the artemis log files to.
72
- If on a beamline, this will be written to the according area depending on the
73
- BEAMLINE envrionment variable. If no envrionment variable is found it will default
74
- it to the tmp/dev directory.
61
+ """Get the path to write the serial experiment specific log file to.
62
+ If on a beamline, this will be written to the tmp folder in the current visit.
75
63
  Returns:
76
64
  logging_path (Path): Path to the log file for the file handler to write to.
77
65
  """
@@ -87,24 +75,11 @@ def _get_logging_file_path() -> Path:
87
75
  return logging_path
88
76
 
89
77
 
90
- def default_logging_setup(dev_mode: bool = False):
91
- """ Default log setup for i24 serial.
92
-
93
- - Set up handlers for parent logger (from dodal)
94
- - integrate bluesky and ophyd loggers
95
- - Remove dodal stream handler to avoid double messages (for now, use only the \
96
- i24ssx default stream to keep the output expected by the scientists.)
97
- """
98
- handlers = set_up_all_logging_handlers( # noqa: F841
99
- dodal_logger,
100
- _get_logging_file_path(),
101
- "dodal.log",
102
- dev_mode,
103
- ERROR_LOG_BUFFER_LINES,
104
- )
105
- integrate_bluesky_and_ophyd_logging(dodal_logger)
106
- # Remove dodal StreamHandler to avoid duplication of messages above debug
107
- dodal_logger.removeHandler(dodal_logger.handlers[0])
78
+ def _integrate_bluesky_logs(parent_logger: logging.Logger):
79
+ # Integrate only bluesky and ophyd_async logger
80
+ for log in [bluesky_logger, ophyd_async_logger]:
81
+ log.parent = parent_logger
82
+ log.setLevel(logging.DEBUG)
108
83
 
109
84
 
110
85
  def config(
@@ -124,7 +99,15 @@ def config(
124
99
  dev_mode (bool, optional): If true, will log to graylog on localhost instead \
125
100
  of production. Defaults to False.
126
101
  """
127
- default_logging_setup(dev_mode=dev_mode)
102
+ do_default_logging_setup(
103
+ "mx-bluesky.log",
104
+ DEFAULT_GRAYLOG_PORT,
105
+ dev_mode=dev_mode,
106
+ integrate_all_logs=False,
107
+ )
108
+ # Remove dodal StreamHandler to avoid duplication of messages above debug
109
+ dodal_logger.removeHandler(dodal_logger.handlers[0])
110
+ _integrate_bluesky_logs(dodal_logger)
128
111
 
129
112
  if logfile:
130
113
  logs = _get_logging_file_path() / logfile
@@ -135,14 +118,40 @@ def config(
135
118
  FH = logging.FileHandler(logs, mode=write_mode, encoding="utf-8", delay=delayed)
136
119
  FH.setLevel(logging.DEBUG)
137
120
  FH.setFormatter(fileFormatter)
138
- logger.addHandler(FH)
121
+ SSX_LOGGER.addHandler(FH)
139
122
 
140
123
 
141
124
  def log_on_entry(func):
142
125
  @functools.wraps(func)
143
126
  def decorator(*args, **kwargs):
144
127
  name = func.__name__
145
- logger.debug(f"Running {name} ")
128
+ SSX_LOGGER.debug(f"Running {name} ")
146
129
  return func(*args, **kwargs)
147
130
 
148
131
  return decorator
132
+
133
+
134
+ def setup_collection_logs(expt: str, dev_mode: bool = False) -> MsgGenerator:
135
+ """A small plan to set up the logging from blueapi on start up as we're running \
136
+ on procserv.
137
+ This setup will likely change once the beamline has a cluster.
138
+ """
139
+ if (
140
+ expt == "Serial Fixed"
141
+ ): # SSXType.FIXED: See https://github.com/DiamondLightSource/mx-bluesky/issues/608
142
+ logfile = time.strftime("i24fixedtarget_%d%B%y.log").lower()
143
+ else:
144
+ logfile = time.strftime("i24extruder_%d%B%y.log").lower()
145
+
146
+ config(logfile, dev_mode=dev_mode)
147
+ yield from bps.null()
148
+
149
+
150
+ def clean_up_log_config_at_end() -> MsgGenerator:
151
+ """A small plan for blueapi to tidy up logging configuration."""
152
+ # See https://github.com/DiamondLightSource/mx-bluesky/issues/609
153
+ for handler in SSX_LOGGER.handlers:
154
+ SSX_LOGGER.removeHandler(handler)
155
+ for handler in dodal_logger.handlers:
156
+ dodal_logger.removeHandler(handler)
157
+ yield from bps.null()
@@ -1,8 +1,8 @@
1
1
  {
2
- "scalex": 10004.0,
3
- "scaley": 10005.2,
2
+ "scalex": 10004.7,
3
+ "scaley": 10004.4,
4
4
  "scalez": 10000.0,
5
- "skew": -0.01,
5
+ "skew": 0.120,
6
6
  "Sx_dir": 1,
7
7
  "Sy_dir": 1,
8
8
  "Sz_dir": 1
@@ -1,19 +1,44 @@
1
1
  #!/bin/bash
2
2
 
3
+ NO_PROCESERV_TEST=false
4
+
5
+ case "$2" in
6
+ -t | --test)
7
+ echo "Will run serial in test mode without procserv."
8
+ NO_PROCESERV_TEST=true
9
+ ;;
10
+ esac
11
+
12
+
3
13
  # Get edm path from input
4
14
  edm_path=$1
5
15
 
6
16
  # Get the directory of this script
7
17
  current=$( realpath "$( dirname "$0" )" )
8
18
 
9
- # Run script to start blueapi serve
10
- . $current/start_blueapi.sh
19
+ if [[ $NO_PROCESERV_TEST == true ]]; then
20
+ echo "Start the blueapi sever"
21
+
22
+ # Run script to start blueapi serve
23
+ . $current/start_blueapi.sh
24
+ fi
25
+
26
+ echo "Set up logging configuration"
27
+ blueapi -c "${current}/blueapi_config.yaml" controller run setup_collection_logs '{"expt":"Serial Jet"}'
11
28
 
12
29
  # Open the edm screen for an extruder serial collection
13
30
  echo "Starting extruder edm screen."
14
31
  edm -x "${edm_path}/EX-gui/DiamondExtruder-I24-py3v1.edl"
15
32
 
16
- echo "Edm screen closed, bye!"
33
+ echo "Edm screen closed"
34
+
35
+ echo "Clean up log configuration"
36
+ blueapi -c "${current}/blueapi_config.yaml" controller run clean_up_log_config_at_end
37
+
38
+ if [[ $NO_PROCESERV_TEST == true ]]; then
39
+ # In this case blueapi server needs to be killed.
40
+ pgrep blueapi | xargs kill
41
+ echo "Blueapi process killed"
42
+ fi
17
43
 
18
- pgrep blueapi | xargs kill
19
- echo "Blueapi process killed"
44
+ echo "All done, bye!"
@@ -1,22 +1,46 @@
1
1
  #!/bin/bash
2
2
 
3
+ NO_PROCESERV_TEST=false
4
+
5
+ case "$2" in
6
+ -t | --test)
7
+ echo "Will run serial in test mode without procserv."
8
+ NO_PROCESERV_TEST=true
9
+ ;;
10
+ esac
11
+
3
12
  # Get edm path from input
4
13
  edm_path=$1
5
14
 
6
15
  # Export env variable for the stages edm to work properly
7
16
  export EDMDATAFILES="/dls_sw/prod/R3.14.12.3/support/motor/6-7-1dls14/motorApp/opi/edl"
8
17
 
9
- # Get the directory of this script
10
- current=$( realpath "$( dirname "$0" )" )
18
+ if [[ $NO_PROCESERV_TEST == true ]]; then
19
+ echo "Start the blueapi sever"
20
+
21
+ # Get the directory of this script
22
+ current=$( realpath "$( dirname "$0" )" )
11
23
 
12
- # Run script to start blueapi serve
13
- . $current/start_blueapi.sh
24
+ # Run script to start blueapi serve
25
+ . $current/start_blueapi.sh
26
+ fi
27
+
28
+ echo "Set up logging configuration"
29
+ blueapi -c "${current}/blueapi_config.yaml" controller run setup_collection_logs '{"expt":"Serial Fixed"}'
14
30
 
15
31
  # Open the edm screen for a fixed target serial collection
16
32
  echo "Starting fixed target edm screen."
17
33
  edm -x "${edm_path}/FT-gui/DiamondChipI24-py3v1.edl"
18
34
 
19
- echo "Edm screen closed, bye!"
35
+ echo "Edm screen closed"
36
+
37
+ echo "Clean up log configuration"
38
+ blueapi -c "${current}/blueapi_config.yaml" controller run clean_up_log_config_at_end
39
+
40
+ if [[ $NO_PROCESERV_TEST == true ]]; then
41
+ # In this case blueapi server needs to be killed.
42
+ pgrep blueapi | xargs kill
43
+ echo "Blueapi process killed"
44
+ fi
20
45
 
21
- pgrep blueapi | xargs kill
22
- echo "Blueapi process killed"
46
+ echo "All done, bye!"