mx-bluesky 0.0.2__py3-none-any.whl → 1.1.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 (150) hide show
  1. mx_bluesky/__main__.py +1 -2
  2. mx_bluesky/_version.py +14 -2
  3. mx_bluesky/beamlines/i04/__init__.py +3 -0
  4. mx_bluesky/beamlines/i04/callbacks/murko_callback.py +45 -0
  5. mx_bluesky/beamlines/i04/thawing_plan.py +85 -0
  6. mx_bluesky/beamlines/i24/serial/__init__.py +49 -0
  7. mx_bluesky/beamlines/i24/serial/blueapi_config.yaml +12 -0
  8. mx_bluesky/{I24 → beamlines/i24}/serial/dcid.py +53 -41
  9. mx_bluesky/{I24 → beamlines/i24}/serial/extruder/EX-gui-edm/DetStage.edl +3 -4
  10. mx_bluesky/{I24 → beamlines/i24}/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl +28 -32
  11. mx_bluesky/{I24 → beamlines/i24}/serial/extruder/EX-gui-edm/microdrop_alignment.edl +0 -1
  12. mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +516 -0
  13. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/CustomChip_py3v1.edl +3 -4
  14. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/DetStage.edl +3 -4
  15. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl +273 -223
  16. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/ME14E-GeneralPurpose.edl +0 -1
  17. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/MappingLite-oxford_py3v1.edl +12 -13
  18. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/PMAC_Command.edl +0 -1
  19. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/Shutter_Control.edl +0 -1
  20. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/microdrop_alignment.edl +0 -1
  21. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/nudgechip.edl +0 -1
  22. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/FT-gui-edm/pumpprobe-py3v1.edl +273 -143
  23. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/short1-laser.png +0 -0
  24. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/short2-laser.png +0 -0
  25. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/ft_utils.py +24 -1
  26. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +808 -0
  27. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py +377 -416
  28. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/i24ssx_Chip_Mapping_py3v1.py +34 -40
  29. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_StartUp_py3v1.py +328 -0
  30. mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/i24ssx_moveonclick.py +66 -48
  31. mx_bluesky/{I24 → beamlines/i24}/serial/log.py +66 -19
  32. mx_bluesky/beamlines/i24/serial/parameters/__init__.py +15 -0
  33. mx_bluesky/beamlines/i24/serial/parameters/constants.py +47 -0
  34. mx_bluesky/beamlines/i24/serial/parameters/experiment_parameters.py +103 -0
  35. mx_bluesky/beamlines/i24/serial/parameters/fixed_target/cs/cs_maker.json +9 -0
  36. mx_bluesky/{I24 → beamlines/i24}/serial/parameters/fixed_target/cs/motor_direction.txt +1 -1
  37. mx_bluesky/{I24 → beamlines/i24}/serial/parameters/fixed_target/pvar_files/minichip-oxford.pvar +1 -1
  38. mx_bluesky/beamlines/i24/serial/parameters/utils.py +42 -0
  39. mx_bluesky/beamlines/i24/serial/run_extruder.sh +19 -0
  40. mx_bluesky/beamlines/i24/serial/run_fixed_target.sh +22 -0
  41. mx_bluesky/beamlines/i24/serial/run_serial.py +36 -0
  42. mx_bluesky/{I24 → beamlines/i24}/serial/set_visit_directory.sh +6 -1
  43. mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/pv.py +1 -62
  44. mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/pv_abstract.py +6 -7
  45. mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/setup_beamline.py +90 -269
  46. mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/setup_detector.py +47 -40
  47. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_zebra_plans.py +459 -0
  48. mx_bluesky/beamlines/i24/serial/start_blueapi.sh +28 -0
  49. mx_bluesky/beamlines/i24/serial/write_nexus.py +105 -0
  50. mx_bluesky/example.py +4 -4
  51. mx_bluesky/hyperion/__init__.py +1 -0
  52. mx_bluesky/hyperion/__main__.py +374 -0
  53. mx_bluesky/hyperion/device_setup_plans/__init__.py +0 -0
  54. mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py +134 -0
  55. mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py +110 -0
  56. mx_bluesky/hyperion/device_setup_plans/position_detector.py +16 -0
  57. mx_bluesky/hyperion/device_setup_plans/read_hardware_for_setup.py +60 -0
  58. mx_bluesky/hyperion/device_setup_plans/setup_oav.py +87 -0
  59. mx_bluesky/hyperion/device_setup_plans/setup_panda.py +210 -0
  60. mx_bluesky/hyperion/device_setup_plans/setup_zebra.py +214 -0
  61. mx_bluesky/hyperion/device_setup_plans/smargon.py +25 -0
  62. mx_bluesky/hyperion/device_setup_plans/utils.py +44 -0
  63. mx_bluesky/hyperion/device_setup_plans/xbpm_feedback.py +93 -0
  64. mx_bluesky/hyperion/exceptions.py +47 -0
  65. mx_bluesky/hyperion/experiment_plans/__init__.py +30 -0
  66. mx_bluesky/hyperion/experiment_plans/experiment_registry.py +84 -0
  67. mx_bluesky/hyperion/experiment_plans/flyscan_xray_centre_plan.py +528 -0
  68. mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py +209 -0
  69. mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +173 -0
  70. mx_bluesky/hyperion/experiment_plans/oav_snapshot_plan.py +81 -0
  71. mx_bluesky/hyperion/experiment_plans/optimise_attenuation_plan.py +463 -0
  72. mx_bluesky/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py +119 -0
  73. mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py +164 -0
  74. mx_bluesky/hyperion/experiment_plans/robot_load_then_centre_plan.py +322 -0
  75. mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py +436 -0
  76. mx_bluesky/hyperion/experiment_plans/set_energy_plan.py +68 -0
  77. mx_bluesky/hyperion/external_interaction/__init__.py +9 -0
  78. mx_bluesky/hyperion/external_interaction/callbacks/__init__.py +10 -0
  79. mx_bluesky/hyperion/external_interaction/callbacks/__main__.py +148 -0
  80. mx_bluesky/hyperion/external_interaction/callbacks/aperture_change_callback.py +22 -0
  81. mx_bluesky/hyperion/external_interaction/callbacks/common/__init__.py +0 -0
  82. mx_bluesky/hyperion/external_interaction/callbacks/common/callback_util.py +46 -0
  83. mx_bluesky/hyperion/external_interaction/callbacks/common/ispyb_mapping.py +70 -0
  84. mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +88 -0
  85. mx_bluesky/hyperion/external_interaction/callbacks/ispyb_callback_base.py +203 -0
  86. mx_bluesky/hyperion/external_interaction/callbacks/log_uid_tag_callback.py +20 -0
  87. mx_bluesky/hyperion/external_interaction/callbacks/logging_callback.py +29 -0
  88. mx_bluesky/hyperion/external_interaction/callbacks/plan_reactive_callback.py +101 -0
  89. mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py +88 -0
  90. mx_bluesky/hyperion/external_interaction/callbacks/rotation/__init__.py +0 -0
  91. mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +174 -0
  92. mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_mapping.py +17 -0
  93. mx_bluesky/hyperion/external_interaction/callbacks/rotation/nexus_callback.py +102 -0
  94. mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/__init__.py +0 -0
  95. mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +269 -0
  96. mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_mapping.py +53 -0
  97. mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/nexus_callback.py +95 -0
  98. mx_bluesky/hyperion/external_interaction/callbacks/zocalo_callback.py +92 -0
  99. mx_bluesky/hyperion/external_interaction/config_server.py +35 -0
  100. mx_bluesky/hyperion/external_interaction/exceptions.py +13 -0
  101. mx_bluesky/hyperion/external_interaction/ispyb/__init__.py +0 -0
  102. mx_bluesky/hyperion/external_interaction/ispyb/data_model.py +95 -0
  103. mx_bluesky/hyperion/external_interaction/ispyb/exp_eye_store.py +125 -0
  104. mx_bluesky/hyperion/external_interaction/ispyb/ispyb_store.py +276 -0
  105. mx_bluesky/hyperion/external_interaction/ispyb/ispyb_utils.py +29 -0
  106. mx_bluesky/hyperion/external_interaction/nexus/__init__.py +0 -0
  107. mx_bluesky/hyperion/external_interaction/nexus/nexus_utils.py +148 -0
  108. mx_bluesky/hyperion/external_interaction/nexus/write_nexus.py +114 -0
  109. mx_bluesky/hyperion/log.py +99 -0
  110. mx_bluesky/hyperion/parameters/__init__.py +2 -0
  111. mx_bluesky/hyperion/parameters/cli.py +68 -0
  112. mx_bluesky/hyperion/parameters/components.py +253 -0
  113. mx_bluesky/hyperion/parameters/constants.py +158 -0
  114. mx_bluesky/hyperion/parameters/gridscan.py +216 -0
  115. mx_bluesky/hyperion/parameters/rotation.py +160 -0
  116. mx_bluesky/hyperion/resources/panda/panda-gridscan.yaml +964 -0
  117. mx_bluesky/hyperion/tracing.py +28 -0
  118. mx_bluesky/hyperion/utils/context.py +84 -0
  119. mx_bluesky/hyperion/utils/utils.py +25 -0
  120. mx_bluesky/hyperion/utils/validation.py +196 -0
  121. mx_bluesky/jupyter_example.ipynb +3 -2
  122. {mx_bluesky-0.0.2.dist-info → mx_bluesky-1.1.0.dist-info}/METADATA +53 -32
  123. mx_bluesky-1.1.0.dist-info/RECORD +136 -0
  124. {mx_bluesky-0.0.2.dist-info → mx_bluesky-1.1.0.dist-info}/WHEEL +1 -1
  125. mx_bluesky-1.1.0.dist-info/entry_points.txt +8 -0
  126. mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +0 -476
  127. mx_bluesky/I24/serial/fixed_target/FT-gui-edm/ME14E-motors.edl +0 -1874
  128. mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +0 -706
  129. mx_bluesky/I24/serial/fixed_target/i24ssx_Chip_StartUp_py3v1.py +0 -463
  130. mx_bluesky/I24/serial/parameters/__init__.py +0 -5
  131. mx_bluesky/I24/serial/parameters/constants.py +0 -39
  132. mx_bluesky/I24/serial/parameters/fixed_target/cs/cs_maker.json +0 -9
  133. mx_bluesky/I24/serial/parameters/fixed_target/cs/fiducial_1.txt +0 -4
  134. mx_bluesky/I24/serial/parameters/fixed_target/cs/fiducial_2.txt +0 -4
  135. mx_bluesky/I24/serial/parameters/fixed_target/litemaps/currentchip.map +0 -81
  136. mx_bluesky/I24/serial/parameters/fixed_target/parameters.txt +0 -13
  137. mx_bluesky/I24/serial/run_serial.py +0 -52
  138. mx_bluesky/I24/serial/write_nexus.py +0 -113
  139. mx_bluesky-0.0.2.dist-info/RECORD +0 -58
  140. mx_bluesky-0.0.2.dist-info/entry_points.txt +0 -4
  141. /mx_bluesky/{I24 → beamlines}/__init__.py +0 -0
  142. /mx_bluesky/{I24/serial → beamlines/i24}/__init__.py +0 -0
  143. /mx_bluesky/{I24 → beamlines/i24}/serial/extruder/__init__.py +0 -0
  144. /mx_bluesky/{I24 → beamlines/i24}/serial/fixed_target/__init__.py +0 -0
  145. /mx_bluesky/{I24 → beamlines/i24}/serial/parameters/fixed_target/pvar_files/oxford.pvar +0 -0
  146. /mx_bluesky/{I24 → beamlines/i24}/serial/run_ssx.sh +0 -0
  147. /mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/__init__.py +0 -0
  148. /mx_bluesky/{I24 → beamlines/i24}/serial/setup_beamline/ca.py +0 -0
  149. {mx_bluesky-0.0.2.dist-info → mx_bluesky-1.1.0.dist-info}/LICENSE +0 -0
  150. {mx_bluesky-0.0.2.dist-info → mx_bluesky-1.1.0.dist-info}/top_level.txt +0 -0
@@ -2,9 +2,7 @@
2
2
  Chip manager for fixed target
3
3
  This version changed to python3 March2020 by RLO
4
4
  """
5
- from __future__ import annotations
6
5
 
7
- import argparse
8
6
  import json
9
7
  import logging
10
8
  import re
@@ -12,31 +10,59 @@ import shutil
12
10
  import sys
13
11
  import time
14
12
  from pathlib import Path
13
+ from pprint import pformat
15
14
  from time import sleep
16
15
 
16
+ import bluesky.plan_stubs as bps
17
17
  import numpy as np
18
-
19
- from mx_bluesky.I24.serial import log
20
- from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_Mapping_py3v1 as mapping
21
- from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_StartUp_py3v1 as startup
22
- from mx_bluesky.I24.serial.fixed_target.ft_utils import ChipType, MappingType
23
- from mx_bluesky.I24.serial.parameters.constants import (
18
+ from blueapi.core import MsgGenerator
19
+ from dodal.beamlines import i24
20
+ from dodal.common import inject
21
+ from dodal.devices.i24.beamstop import Beamstop, BeamstopPositions
22
+ from dodal.devices.i24.dual_backlight import BacklightPositions, DualBacklight
23
+ from dodal.devices.i24.i24_detector_motion import DetectorMotion
24
+ from dodal.devices.i24.pmac import PMAC, EncReset, LaserSettings
25
+
26
+ from mx_bluesky.beamlines.i24.serial import log
27
+ from mx_bluesky.beamlines.i24.serial.fixed_target import (
28
+ i24ssx_Chip_Mapping_py3v1 as mapping,
29
+ )
30
+ from mx_bluesky.beamlines.i24.serial.fixed_target import (
31
+ i24ssx_Chip_StartUp_py3v1 as startup,
32
+ )
33
+ from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import (
34
+ ChipType,
35
+ Fiducials,
36
+ MappingType,
37
+ )
38
+ from mx_bluesky.beamlines.i24.serial.parameters import get_chip_format
39
+ from mx_bluesky.beamlines.i24.serial.parameters.constants import (
24
40
  CS_FILES_PATH,
25
41
  FULLMAP_PATH,
26
42
  LITEMAP_PATH,
43
+ PARAM_FILE_NAME,
27
44
  PARAM_FILE_PATH_FT,
28
45
  PVAR_FILE_PATH,
29
46
  )
30
- from mx_bluesky.I24.serial.setup_beamline import caget, caput, pv
31
- from mx_bluesky.I24.serial.setup_beamline.setup_detector import get_detector_type
47
+ from mx_bluesky.beamlines.i24.serial.setup_beamline import Pilatus, caget, caput, pv
48
+ from mx_bluesky.beamlines.i24.serial.setup_beamline.setup_detector import (
49
+ get_detector_type,
50
+ )
32
51
 
33
52
  logger = logging.getLogger("I24ssx.chip_manager")
34
53
 
35
-
36
- def _coerce_to_path(path: Path | str) -> Path:
37
- if not isinstance(path, Path):
38
- return Path(path)
39
- return path
54
+ # An approximation of the chip size for the move during fiducials alignment.
55
+ CHIP_MOVES = {
56
+ ChipType.Oxford: 25.40,
57
+ ChipType.OxfordInner: 24.60,
58
+ ChipType.Custom: 25.40,
59
+ ChipType.Minichip: 25.40,
60
+ }
61
+ CHIPTYPE_PV = pv.me14e_gp1
62
+ MAPTYPE_PV = pv.me14e_gp2
63
+ NUM_EXPOSURES_PV = pv.me14e_gp3
64
+ PUMP_REPEAT_PV = pv.me14e_gp4
65
+ MAP_FILEPATH_PV = pv.me14e_gp5
40
66
 
41
67
 
42
68
  def setup_logging():
@@ -46,47 +72,40 @@ def setup_logging():
46
72
 
47
73
 
48
74
  @log.log_on_entry
49
- def initialise():
50
- # commented out filter lines 230719 as this stage not connected
51
- logger.info("Setting VMAX VELO ACCL HHL LLM pvs")
52
-
53
- caput(pv.me14e_stage_x + ".VMAX", 20)
54
- caput(pv.me14e_stage_y + ".VMAX", 20)
55
- caput(pv.me14e_stage_z + ".VMAX", 20)
56
- # caput(pv.me14e_filter + '.VMAX', 20)
57
- caput(pv.me14e_stage_x + ".VELO", 20)
58
- caput(pv.me14e_stage_y + ".VELO", 20)
59
- caput(pv.me14e_stage_z + ".VELO", 20)
60
- # caput(pv.me14e_filter + '.VELO', 20)
61
- caput(pv.me14e_stage_x + ".ACCL", 0.01)
62
- caput(pv.me14e_stage_y + ".ACCL", 0.01)
63
- caput(pv.me14e_stage_z + ".ACCL", 0.01)
64
- # caput(pv.me14e_filter + '.ACCL', 0.01)
65
- caput(pv.me14e_stage_x + ".HLM", 30)
66
- caput(pv.me14e_stage_x + ".LLM", -29)
67
- caput(pv.me14e_stage_y + ".HLM", 30)
68
- caput(pv.me14e_stage_y + ".LLM", -30)
69
- # caput(pv.me14e_stage_x + '.LLM', -30)
70
- caput(pv.me14e_stage_z + ".HLM", 5.1)
71
- caput(pv.me14e_stage_z + ".LLM", -4.1)
72
- # caput(pv.me14e_filter + '.HLM', 45.0)
73
- # caput(pv.me14e_filter + '.LLM', -45.0)
74
- caput(pv.me14e_gp1, 1)
75
- caput(pv.me14e_gp2, 0)
76
- caput(pv.me14e_gp3, 1)
77
- caput(pv.me14e_gp4, 0)
75
+ def initialise_stages(
76
+ pmac: PMAC = inject("pmac"),
77
+ ) -> MsgGenerator:
78
+ """Initialise the portable stages PVs, usually used only once right after setting \
79
+ up the stages either after use at different facility.
80
+ """
81
+ setup_logging()
82
+ group = "initialise_stages"
83
+ logger.info("Setting velocity, acceleration and limits for stages")
84
+
85
+ yield from bps.abs_set(pmac.x.velocity, 20, group=group)
86
+ yield from bps.abs_set(pmac.y.velocity, 20, group=group)
87
+ yield from bps.abs_set(pmac.z.velocity, 20, group=group)
88
+ yield from bps.abs_set(pmac.x.acceleration_time, 0.01, group=group)
89
+ yield from bps.abs_set(pmac.y.acceleration_time, 0.01, group=group)
90
+ yield from bps.abs_set(pmac.z.acceleration_time, 0.01, group=group)
91
+ yield from bps.abs_set(pmac.x.high_limit_travel, 30, group=group)
92
+ yield from bps.abs_set(pmac.x.low_limit_travel, -29, group=group)
93
+ yield from bps.abs_set(pmac.y.high_limit_travel, 30, group=group)
94
+ yield from bps.abs_set(pmac.y.low_limit_travel, -30, group=group)
95
+ yield from bps.abs_set(pmac.z.high_limit_travel, 5.1, group=group)
96
+ yield from bps.abs_set(pmac.z.low_limit_travel, -4.1, group=group)
97
+ caput(CHIPTYPE_PV, 1) # chip type
98
+ caput(MAPTYPE_PV, 0) # map type
99
+ caput(NUM_EXPOSURES_PV, 1) # num exposures
100
+ caput(PUMP_REPEAT_PV, 0) # pump repeat
78
101
  caput(pv.me14e_filepath, "test")
79
102
  caput(pv.me14e_chip_name, "albion")
80
103
  caput(pv.me14e_dcdetdist, 1480)
81
104
  caput(pv.me14e_exptime, 0.01)
82
- caput(pv.me14e_pmac_str, "m508=100 m509=150")
83
- caput(pv.me14e_pmac_str, "m608=100 m609=150")
84
- caput(pv.me14e_pmac_str, "m708=100 m709=150")
85
- caput(pv.me14e_pmac_str, "m808=100 m809=150")
86
-
87
- # Define detector in use
88
- logger.debug("Define detector in use.")
89
- det_type = get_detector_type()
105
+ yield from bps.abs_set(pmac.enc_reset, EncReset.ENC5, group=group)
106
+ yield from bps.abs_set(pmac.enc_reset, EncReset.ENC6, group=group)
107
+ yield from bps.abs_set(pmac.enc_reset, EncReset.ENC7, group=group)
108
+ yield from bps.abs_set(pmac.enc_reset, EncReset.ENC8, group=group)
90
109
 
91
110
  caput(pv.pilat_cbftemplate, 0)
92
111
 
@@ -98,95 +117,76 @@ def initialise():
98
117
  sys.stdout.write(".")
99
118
  sys.stdout.flush()
100
119
 
101
- caput(pv.me14e_gp100, "press set params to read visit")
102
- caput(pv.me14e_gp101, det_type.name)
103
-
104
- logger.info("Initialisation Complete")
120
+ logger.info("Initialisation of the stages complete")
121
+ yield from bps.wait(group=group)
105
122
 
106
123
 
107
124
  @log.log_on_entry
108
- def write_parameter_file(param_path: Path | str = PARAM_FILE_PATH_FT):
109
- param_path = _coerce_to_path(param_path)
125
+ def write_parameter_file(
126
+ detector_stage: DetectorMotion,
127
+ ) -> MsgGenerator:
128
+ param_path: Path = PARAM_FILE_PATH_FT
129
+ # Create directory if it doesn't yet exist.
110
130
  param_path.mkdir(parents=True, exist_ok=True)
111
131
 
112
- param_fid = "parameters.txt"
113
- logger.info("Writing Parameter File: %s" % (param_path / param_fid).as_posix())
114
-
115
- visit = caget(pv.me14e_gp100)
132
+ logger.info(f"Writing Parameter File: {(param_path / PARAM_FILE_NAME).as_posix()}")
116
133
 
117
134
  filename = caget(pv.me14e_chip_name)
118
-
119
- exptime = caget(pv.me14e_exptime)
120
- dcdetdist = caget(pv.me14e_dcdetdist)
121
- protein_name = caget(pv.me14e_filepath)
122
- pump_repeat = caget(pv.me14e_gp4)
123
- pumpexptime = caget(pv.me14e_gp103)
124
- pumpdelay = caget(pv.me14e_gp110)
125
- prepumpexptime = caget(pv.me14e_gp109)
126
- n_exposures = caget(pv.me14e_gp3)
127
- map_type = caget(pv.me14e_gp2)
128
- chip_type = caget(pv.me14e_gp1)
129
- det_type = get_detector_type()
130
-
131
- checkerpattern = bool(caget(pv.me14e_gp111))
135
+ det_type = yield from get_detector_type(detector_stage)
136
+ chip_params = get_chip_format(ChipType(int(caget(CHIPTYPE_PV))))
137
+ map_type = int(caget(MAPTYPE_PV))
138
+ pump_repeat = int(caget(PUMP_REPEAT_PV))
132
139
 
133
140
  # If file name ends in a digit this causes processing/pilatus pain.
134
141
  # Append an underscore
135
- if det_type == "pilatus":
142
+ if isinstance(det_type, Pilatus):
136
143
  caput(pv.pilat_cbftemplate, 0)
137
144
  m = re.search(r"\d+$", filename)
138
145
  if m is not None:
139
146
  # Note for future reference. Appending underscore causes more hassle and
140
147
  # high probability of users accidentally overwriting data. Use a dash
141
148
  filename = filename + "-"
142
- logger.info(
143
- "Requested filename ends in a number. Appended dash: %s" % filename
149
+ logger.debug(
150
+ f"Requested filename ends in a number. Appended dash: {filename}"
144
151
  )
145
152
 
146
- # historical - use chip_name instead of filename
147
- chip_name = filename
148
-
149
- with open(param_path / param_fid, "w") as f:
150
- f.write("visit \t\t%s\n" % visit)
151
- f.write("chip_name \t%s\n" % chip_name)
152
- f.write("protein_name \t%s\n" % protein_name)
153
- f.write("n_exposures \t%s\n" % n_exposures)
154
- f.write("chip_type \t%s\n" % chip_type)
155
- f.write("map_type \t%s\n" % map_type)
156
- f.write("pump_repeat \t%s\n" % pump_repeat)
157
- f.write("pumpexptime \t%s\n" % pumpexptime)
158
- f.write("pumpdelay \t%s\n" % pumpdelay)
159
- f.write("prepumpexptime \t%s\n" % prepumpexptime)
160
- f.write("exptime \t%s\n" % exptime)
161
- f.write("dcdetdist \t%s\n" % dcdetdist)
162
- f.write("det_type \t%s\n" % str(det_type))
163
- f.write("checkerpattern \t%s\n" % str(checkerpattern))
164
-
165
- logger.info("Information written to file")
166
- logger.info(f"visit: {visit}")
167
- logger.info(f"filename: {chip_name}")
168
- logger.info(f"protein_name: {protein_name}")
169
- logger.info(f"n_exposures: {n_exposures}")
170
- logger.info(f"chip_type: {chip_type}")
171
- logger.info(f"map_type: {map_type}")
172
- logger.info(f"pump_repeat: {pump_repeat}")
173
- logger.info(f"pumpexptime: {pumpexptime}")
174
- logger.info(f"pumpdelay: {pumpdelay}")
175
- logger.info(f"prepumpexptime: {prepumpexptime}")
176
- logger.info(f"detector type: {str(det_type)}")
177
- logger.info(f"checker pattern: {checkerpattern}")
153
+ params_dict = {
154
+ "visit": log._read_visit_directory_from_file().as_posix(), # noqa
155
+ "directory": caget(pv.me14e_filepath),
156
+ "filename": filename,
157
+ "exposure_time_s": caget(pv.me14e_exptime),
158
+ "detector_distance_mm": caget(pv.me14e_dcdetdist),
159
+ "detector_name": str(det_type),
160
+ "num_exposures": int(caget(NUM_EXPOSURES_PV)),
161
+ "chip": chip_params.dict(),
162
+ "map_type": map_type,
163
+ "pump_repeat": pump_repeat,
164
+ "checker_pattern": bool(caget(pv.me14e_gp111)),
165
+ "laser_dwell_s": float(caget(pv.me14e_gp103)) if pump_repeat != 0 else None,
166
+ "laser_delay_s": float(caget(pv.me14e_gp110)) if pump_repeat != 0 else None,
167
+ "pre_pump_exposure_s": float(caget(pv.me14e_gp109))
168
+ if pump_repeat != 0
169
+ else None,
170
+ }
171
+
172
+ with open(param_path / PARAM_FILE_NAME, "w") as f:
173
+ json.dump(params_dict, f, indent=4)
174
+
175
+ logger.info("Information written to file \n")
176
+ logger.info(pformat(params_dict))
177
+
178
178
  if map_type == MappingType.Full:
179
179
  # This step creates some header files (.addr, .spec), containing the parameters,
180
180
  # that are only needed when full mapping is in use.
181
- logger.debug("Running start up now.")
181
+ logger.info("Full mapping in use. Running start up now.")
182
182
  startup.run()
183
+ yield from bps.null()
183
184
 
184
185
 
185
- def scrape_pvar_file(fid: str, pvar_dir: Path | str = PVAR_FILE_PATH):
186
+ def scrape_pvar_file(fid: str, pvar_dir: Path = PVAR_FILE_PATH):
186
187
  block_start_list = []
187
- pvar_dir = _coerce_to_path(pvar_dir)
188
188
 
189
- with open(pvar_dir / fid, "r") as f:
189
+ with open(pvar_dir / fid) as f:
190
190
  lines = f.readlines()
191
191
  for line in lines:
192
192
  line = line.rstrip()
@@ -210,40 +210,40 @@ def scrape_pvar_file(fid: str, pvar_dir: Path | str = PVAR_FILE_PATH):
210
210
  @log.log_on_entry
211
211
  def define_current_chip(
212
212
  chipid: str = "oxford",
213
- param_path: Path | str = PVAR_FILE_PATH,
214
- ):
213
+ pmac: PMAC = inject("pmac"),
214
+ ) -> MsgGenerator:
215
+ setup_logging()
215
216
  logger.debug("Run load stock map for just the first block")
216
- load_stock_map("Just The First Block")
217
+ yield from load_stock_map("Just The First Block")
217
218
  """
218
219
  Not sure what this is for:
219
220
  print 'Setting Mapping Type to Lite'
220
221
  caput(pv.me14e_gp2, 1)
221
222
  """
222
- chip_type = int(caget(pv.me14e_gp1))
223
- logger.info("Chip type:%s Chipid:%s" % (chip_type, chipid))
223
+ chip_type = int(caget(CHIPTYPE_PV))
224
+ logger.info(f"Chip type:{chip_type} Chipid:{chipid}")
224
225
  if chipid == "oxford":
225
- caput(pv.me14e_gp1, 1)
226
-
227
- param_path = _coerce_to_path(param_path)
226
+ caput(CHIPTYPE_PV, 0)
228
227
 
229
- with open(param_path / f"{chipid}.pvar", "r") as f:
230
- logger.info("Opening %s.pvar" % chipid)
228
+ with open(PVAR_FILE_PATH / f"{chipid}.pvar") as f:
229
+ logger.info(f"Opening {chipid}.pvar")
231
230
  for line in f.readlines():
232
231
  if line.startswith("#"):
233
232
  continue
234
233
  line_from_file = line.rstrip("\n")
235
- logger.info("%s" % line_from_file)
236
- caput(pv.me14e_pmac_str, line_from_file)
234
+ logger.info(f"{line_from_file}")
235
+ yield from bps.abs_set(pmac.pmac_string, line_from_file)
237
236
 
238
237
 
239
238
  @log.log_on_entry
240
- def save_screen_map(litemap_path: Path | str = LITEMAP_PATH):
241
- litemap_path = _coerce_to_path(litemap_path)
239
+ def save_screen_map() -> MsgGenerator:
240
+ setup_logging()
241
+ litemap_path: Path = LITEMAP_PATH
242
242
  litemap_path.mkdir(parents=True, exist_ok=True)
243
243
 
244
- logger.info("Saving %s currentchip.map" % litemap_path.as_posix())
244
+ logger.info(f"Saving {litemap_path.as_posix()} currentchip.map")
245
245
  with open(litemap_path / "currentchip.map", "w") as f:
246
- logger.info("Printing only blocks with block_val == 1")
246
+ logger.debug("Printing only blocks with block_val == 1")
247
247
  for x in range(1, 82):
248
248
  block_str = "ME14E-MO-IOC-01:GP%i" % (x + 10)
249
249
  block_val = int(caget(block_str))
@@ -251,23 +251,23 @@ def save_screen_map(litemap_path: Path | str = LITEMAP_PATH):
251
251
  logger.info("%s %d" % (block_str, block_val))
252
252
  line = "%02dstatus P3%02d1 \t%s\n" % (x, x, block_val)
253
253
  f.write(line)
254
- return 0
254
+ yield from bps.null()
255
255
 
256
256
 
257
257
  @log.log_on_entry
258
- def upload_parameters(
259
- chipid: str = "oxford",
260
- litemap_path: Path | str = LITEMAP_PATH,
261
- ):
262
- logger.info("Uploading Parameters to the GeoBrick")
263
- if chipid == "oxford":
264
- caput(pv.me14e_gp1, 0)
265
- width = 8
266
- litemap_path = _coerce_to_path(litemap_path)
258
+ def upload_parameters(pmac: PMAC = inject("pmac")) -> MsgGenerator:
259
+ setup_logging()
260
+ logger.info("Uploading Parameters for Oxford Chip to the GeoBrick")
261
+ caput(CHIPTYPE_PV, 0)
262
+ width = 8
267
263
 
268
- with open(litemap_path / "currentchip.map", "r") as f:
269
- logger.info("Chipid %s" % chipid)
270
- logger.info("width %d" % width)
264
+ map_file: Path = LITEMAP_PATH / "currentchip.map"
265
+ if not map_file.exists():
266
+ raise FileNotFoundError(f"The file {map_file} has not yet been created")
267
+
268
+ with open(map_file) as f:
269
+ logger.info(f"Chipid {ChipType.Oxford}")
270
+ logger.info(f"width {width}")
271
271
  x = 1
272
272
  for line in f.readlines()[: width**2]:
273
273
  cols = line.split()
@@ -285,33 +285,42 @@ def upload_parameters(
285
285
  x = 1
286
286
  else:
287
287
  x += 1
288
- caput(pv.me14e_pmac_str, s)
288
+ yield from bps.abs_set(pmac.pmac_string, s, wait=True)
289
289
  sleep(0.02)
290
290
 
291
291
  logger.warning("Automatic Setting Mapping Type to Lite has been disabled")
292
292
  logger.debug("Upload parameters done.")
293
+ yield from bps.null()
293
294
 
294
295
 
295
296
  @log.log_on_entry
296
- def upload_full(fullmap_path: Path | str = FULLMAP_PATH):
297
- fullmap_path = _coerce_to_path(fullmap_path)
297
+ def upload_full(pmac: PMAC | None = None) -> MsgGenerator:
298
+ setup_logging()
299
+ if not pmac:
300
+ pmac = i24.pmac()
298
301
 
299
- with open(fullmap_path / "currentchip.full", "r") as fh:
302
+ map_file: Path = FULLMAP_PATH / "currentchip.full"
303
+ if not map_file.exists():
304
+ raise FileNotFoundError(f"The file {map_file} has not yet been created")
305
+ with open(map_file) as fh:
300
306
  f = fh.readlines()
301
307
 
302
- for i in range(len(f) // 2):
308
+ for _i in range(len(f) // 2):
303
309
  pmac_list = []
304
- for j in range(2):
310
+ for _j in range(2):
305
311
  pmac_list.append(f.pop(0).rstrip("\n"))
306
312
  writeline = " ".join(pmac_list)
307
- logger.info("%s" % writeline)
308
- caput(pv.me14e_pmac_str, writeline)
309
- sleep(0.02)
313
+ logger.info(f"{writeline}")
314
+ yield from bps.abs_set(pmac.pmac_string, writeline, wait=True)
315
+ yield from bps.sleep(0.02)
310
316
  logger.debug("Upload fullmap done")
317
+ yield from bps.null()
311
318
 
312
319
 
313
320
  @log.log_on_entry
314
- def load_stock_map(map_choice: str = "clear"):
321
+ def load_stock_map(map_choice: str = "clear") -> MsgGenerator:
322
+ # TODO See https://github.com/DiamondLightSource/mx_bluesky/issues/122
323
+ setup_logging()
315
324
  logger.info("Adjusting Lite Map EDM Screen")
316
325
  logger.debug("Please wait, adjusting lite map")
317
326
  #
@@ -406,7 +415,7 @@ def load_stock_map(map_choice: str = "clear"):
406
415
  28,
407
416
  27,
408
417
  10,
409
- ] + x77
418
+ ] + x77 # noqa
410
419
  x44 = [22, 21, 20, 19, 30, 35, 46, 45, 44, 43, 38, 27, 28, 29, 36, 37]
411
420
  x49 = [x + 1 for x in range(49)]
412
421
  x66 = [
@@ -496,24 +505,26 @@ def load_stock_map(map_choice: str = "clear"):
496
505
  map_dict["half1"] = half1
497
506
  map_dict["half2"] = half2
498
507
 
499
- logger.info("Clearing GP 10-74")
508
+ logger.info("Clearing GP 10-74") # Actually 11-44
500
509
  for i in range(1, 65):
501
510
  pvar = "ME14E-MO-IOC-01:GP" + str(i + 10)
502
511
  caput(pvar, 0)
503
512
  sys.stdout.write(".")
504
513
  sys.stdout.flush()
505
514
  logger.info("Map cleared")
506
- logger.info("Loading Map Choice %s" % map_choice)
515
+ logger.info(f"Loading Map Choice {map_choice}")
507
516
  for i in map_dict[map_choice]:
508
517
  pvar = "ME14E-MO-IOC-01:GP" + str(i + 10)
509
518
  caput(pvar, 1)
510
519
  logger.debug("Load stock map done.")
520
+ yield from bps.null()
511
521
 
512
522
 
513
523
  @log.log_on_entry
514
- def load_lite_map(litemap_path: Path | str = LITEMAP_PATH):
524
+ def load_lite_map() -> MsgGenerator:
525
+ setup_logging()
515
526
  logger.debug("Run load stock map with 'clear' setting.")
516
- load_stock_map("clear")
527
+ yield from load_stock_map("clear")
517
528
  # fmt: off
518
529
  # Oxford_block_dict is wrong (columns and rows need to flip) added in script below to generate it automatically however kept this for backwards compatiability/reference
519
530
  oxford_block_dict = { # noqa: F841
@@ -527,7 +538,7 @@ def load_lite_map(litemap_path: Path | str = LITEMAP_PATH):
527
538
  'H1': '64', 'H2': '63', 'H3': '62', 'H4': '61', 'H5': '60', 'H6': '59', 'H7': '58', 'H8': '57',
528
539
  }
529
540
  # fmt: on
530
- chip_type = int(caget(pv.me14e_gp1))
541
+ chip_type = int(caget(CHIPTYPE_PV))
531
542
  if chip_type in [ChipType.Oxford, ChipType.OxfordInner]:
532
543
  logger.info("Oxford Block Order")
533
544
  rows = ["A", "B", "C", "D", "E", "F", "G", "H"]
@@ -555,14 +566,14 @@ def load_lite_map(litemap_path: Path | str = LITEMAP_PATH):
555
566
  label = "%02.d" % (lab_num + 1)
556
567
  btn_names[button_name] = label
557
568
  block_dict = btn_names
569
+ else:
570
+ raise ValueError(f"{chip_type=} unrecognised")
558
571
 
559
- litemap_path = _coerce_to_path(litemap_path)
560
-
561
- litemap_fid = str(caget(pv.me14e_gp5)) + ".lite"
572
+ litemap_fid = f"{caget(MAP_FILEPATH_PV)}.lite"
562
573
  logger.info("Please wait, loading LITE map")
563
- logger.info("Loading Lite Map")
564
- logger.info("Opening %s" % (litemap_path / litemap_fid))
565
- with open(litemap_path / litemap_fid, "r") as fh:
574
+ logger.debug("Loading Lite Map")
575
+ logger.info("Opening %s" % (LITEMAP_PATH / litemap_fid))
576
+ with open(LITEMAP_PATH / litemap_fid) as fh:
566
577
  f = fh.readlines()
567
578
  for line in f:
568
579
  entry = line.split()
@@ -570,151 +581,140 @@ def load_lite_map(litemap_path: Path | str = LITEMAP_PATH):
570
581
  yesno = entry[1]
571
582
  block_num = block_dict[block_name]
572
583
  pvar = "ME14E-MO-IOC-01:GP" + str(int(block_num) + 10)
573
- logger.info("Block: %s \tScanned: %s \tPVAR: %s" % (block_name, yesno, pvar))
584
+ logger.info(f"Block: {block_name} \tScanned: {yesno} \tPVAR: {pvar}")
574
585
  logger.debug("Load lite map done")
586
+ yield from bps.null()
575
587
 
576
588
 
577
589
  @log.log_on_entry
578
- def load_full_map(fullmap_path: Path | str = FULLMAP_PATH):
579
- (
580
- chip_name,
581
- visit,
582
- sub_dir,
583
- n_exposures,
584
- chip_type,
585
- map_type,
586
- ) = startup.scrape_parameter_file()
587
- fullmap_path = _coerce_to_path(fullmap_path)
588
-
589
- fullmap_fid = fullmap_path / f"{str(caget(pv.me14e_gp5))}.spec"
590
- logger.info("Opening %s" % fullmap_fid)
591
- mapping.plot_file(fullmap_fid, chip_type)
592
- mapping.convert_chip_to_hex(fullmap_fid, chip_type)
593
- shutil.copy2(fullmap_fid.with_suffix(".full"), fullmap_path / "currentchip.full")
590
+ def load_full_map() -> MsgGenerator:
591
+ setup_logging()
592
+ params = startup.read_parameter_file()
593
+
594
+ fullmap_fid = FULLMAP_PATH / f"{caget(MAP_FILEPATH_PV)}.spec"
595
+ logger.info(f"Opening {fullmap_fid}")
596
+ mapping.plot_file(fullmap_fid, params.chip.chip_type.value)
597
+ mapping.convert_chip_to_hex(fullmap_fid, params.chip.chip_type.value)
598
+ shutil.copy2(fullmap_fid.with_suffix(".full"), FULLMAP_PATH / "currentchip.full")
594
599
  logger.info(
595
- "Copying %s to %s"
596
- % (fullmap_fid.with_suffix(".full"), fullmap_path / "currentchip.full")
600
+ "Copying {} to {}".format(
601
+ fullmap_fid.with_suffix(".full"), FULLMAP_PATH / "currentchip.full"
602
+ )
597
603
  )
598
604
  logger.debug("Load full map done")
605
+ yield from bps.null()
599
606
 
600
607
 
601
608
  @log.log_on_entry
602
- def moveto(place: str = "origin"):
603
- logger.info("Move to: %s" % place)
604
- chip_type = int(caget(pv.me14e_gp1))
605
- logger.info("Chip type is%s" % chip_type)
606
-
607
- if chip_type == ChipType.Oxford or chip_type == ChipType.Minichip:
608
- # Oxford and minichip
609
- # As minichip is nothing more than a smaller oxford,
610
- # they should move the same way
611
- logger.info("Oxford Move")
612
- if place == "origin":
613
- caput(pv.me14e_stage_x, 0.0)
614
- caput(pv.me14e_stage_y, 0.0)
615
- if place == "f1":
616
- caput(pv.me14e_stage_x, 25.40)
617
- caput(pv.me14e_stage_y, 0.0)
618
- if place == "f2":
619
- caput(pv.me14e_stage_x, 0.0)
620
- caput(pv.me14e_stage_y, 25.40)
621
-
622
- elif chip_type == ChipType.OxfordInner:
623
- logger.info("Oxford Inner Move")
624
- if place == "origin":
625
- caput(pv.me14e_stage_x, 0.0)
626
- caput(pv.me14e_stage_y, 0.0)
627
- if place == "f1":
628
- caput(pv.me14e_stage_x, 24.60)
629
- caput(pv.me14e_stage_y, 0.0)
630
- if place == "f2":
631
- caput(pv.me14e_stage_x, 0.0)
632
- caput(pv.me14e_stage_y, 24.60)
633
-
634
- elif chip_type == ChipType.Custom:
635
- logger.info("Custom Chip Move")
636
- if place == "origin":
637
- caput(pv.me14e_stage_x, 0.0)
638
- caput(pv.me14e_stage_y, 0.0)
639
- if place == "f1":
640
- caput(pv.me14e_stage_x, 25.40)
641
- caput(pv.me14e_stage_y, 0.0)
642
- if place == "f2":
643
- caput(pv.me14e_stage_x, 0.0)
644
- caput(pv.me14e_stage_y, 25.40)
645
-
646
- else:
609
+ def moveto(place: str = "origin", pmac: PMAC = inject("pmac")) -> MsgGenerator:
610
+ setup_logging()
611
+ logger.info(f"Move to: {place}")
612
+ if place == Fiducials.zero:
613
+ logger.info("Chip aspecific move.")
614
+ yield from bps.trigger(pmac.to_xyz_zero)
615
+ return
616
+
617
+ chip_type = ChipType(int(caget(CHIPTYPE_PV)))
618
+ logger.info(f"Chip type is {chip_type}")
619
+ if chip_type not in list(ChipType):
647
620
  logger.warning("Unknown chip_type move")
621
+ return
622
+
623
+ logger.info(f"{str(chip_type)} Move")
624
+ chip_move = CHIP_MOVES[chip_type]
625
+
626
+ if place == Fiducials.origin:
627
+ yield from bps.mv(pmac.x, 0.0, pmac.y, 0.0)
628
+ if place == Fiducials.fid1:
629
+ yield from bps.mv(pmac.x, chip_move, pmac.y, 0.0)
630
+ if place == Fiducials.fid2:
631
+ yield from bps.mv(pmac.x, 0.0, pmac.y, chip_move)
632
+
633
+
634
+ @log.log_on_entry
635
+ def moveto_preset(
636
+ place: str,
637
+ pmac: PMAC = inject("pmac"),
638
+ beamstop: Beamstop = inject("beamstop"),
639
+ backlight: DualBacklight = inject("backlight"),
640
+ det_stage: DetectorMotion = inject("detector_motion"),
641
+ ) -> MsgGenerator:
642
+ setup_logging()
648
643
 
649
644
  # Non Chip Specific Move
650
645
  if place == "zero":
651
- logger.info("Moving to %s" % place)
652
- caput(pv.me14e_pmac_str, "!x0y0z0")
646
+ logger.info(f"Moving to {place}")
647
+ yield from bps.trigger(pmac.to_xyz_zero)
653
648
 
654
649
  elif place == "load_position":
655
650
  logger.info("load position")
656
- caput(pv.bs_mp_select, "Robot")
657
- caput(pv.bl_mp_select, "Out")
658
- caput(pv.det_z, 1300)
651
+ yield from bps.abs_set(
652
+ beamstop.pos_select, BeamstopPositions.ROBOT, group=place
653
+ )
654
+ yield from bps.abs_set(backlight, BacklightPositions.OUT, group=place)
655
+ yield from bps.abs_set(det_stage.z, 1300, group=place)
656
+ yield from bps.wait(group=place)
659
657
 
660
658
  elif place == "collect_position":
661
659
  logger.info("collect position")
662
660
  caput(pv.me14e_filter, 20)
663
- caput(pv.me14e_stage_x, 0.0)
664
- caput(pv.me14e_stage_y, 0.0)
665
- caput(pv.me14e_stage_z, 0.0)
666
- caput(pv.bs_mp_select, "Data Collection")
667
- caput(pv.bl_mp_select, "In")
661
+ yield from bps.mv(pmac.x, 0.0, pmac.y, 0.0, pmac.z, 0.0)
662
+ yield from bps.abs_set(
663
+ beamstop.pos_select, BeamstopPositions.DATA_COLLECTION, group=place
664
+ )
665
+ yield from bps.abs_set(backlight, BacklightPositions.IN, group=place)
666
+ yield from bps.wait(group=place)
668
667
 
669
668
  elif place == "microdrop_position":
670
669
  logger.info("microdrop align position")
671
- caput(pv.me14e_stage_x, 6.0)
672
- caput(pv.me14e_stage_y, -7.8)
673
- caput(pv.me14e_stage_z, 0.0)
670
+ yield from bps.mv(pmac.x, 6.0, pmac.y, -7.8, pmac.z, 0.0)
674
671
 
675
- elif place == "laser1on": # these are in laser edm
672
+
673
+ @log.log_on_entry
674
+ def laser_control(laser_setting: str, pmac: PMAC = inject("pmac")) -> MsgGenerator:
675
+ setup_logging()
676
+ logger.info(f"Move to: {laser_setting}")
677
+ if laser_setting == "laser1on": # these are in laser edm
676
678
  logger.info("Laser 1 /BNC2 shutter is open")
677
679
  # Use M712 = 0 if triggering on falling edge. M712 =1 if on rising edge
678
680
  # Be sure to also change laser1off
679
681
  # caput(pv.me14e_pmac_str, ' M712=0 M711=1')
680
- caput(pv.me14e_pmac_str, " M712=1 M711=1")
682
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_1_ON, wait=True)
681
683
 
682
- elif place == "laser1off":
684
+ elif laser_setting == "laser1off":
683
685
  logger.info("Laser 1 shutter is closed")
684
- caput(pv.me14e_pmac_str, " M712=0 M711=1")
686
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_1_OFF, wait=True)
685
687
 
686
- elif place == "laser2on":
688
+ elif laser_setting == "laser2on":
687
689
  logger.info("Laser 2 / BNC3 shutter is open")
688
- caput(pv.me14e_pmac_str, " M812=1 M811=1")
690
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_2_ON, wait=True)
689
691
 
690
- elif place == "laser2off":
692
+ elif laser_setting == "laser2off":
691
693
  logger.info("Laser 2 shutter is closed")
692
- caput(pv.me14e_pmac_str, " M812=0 M811=1")
694
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_2_OFF, wait=True)
693
695
 
694
- elif place == "laser1burn":
696
+ elif laser_setting == "laser1burn":
695
697
  led_burn_time = caget(pv.me14e_gp103)
696
698
  logger.info("Laser 1 on")
697
- logger.info("Burn time is %s s" % led_burn_time)
698
- caput(pv.me14e_pmac_str, " M712=1 M711=1")
699
- sleep(int(float(led_burn_time)))
699
+ logger.info(f"Burn time is {led_burn_time} s")
700
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_1_ON, wait=True)
701
+ yield from bps.sleep(led_burn_time)
700
702
  logger.info("Laser 1 off")
701
- caput(pv.me14e_pmac_str, " M712=0 M711=1")
703
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_1_OFF, wait=True)
702
704
 
703
- elif place == "laser2burn":
705
+ elif laser_setting == "laser2burn":
704
706
  led_burn_time = caget(pv.me14e_gp109)
705
707
  logger.info("Laser 2 on")
706
- logger.info("burntime %s s" % led_burn_time)
707
- caput(pv.me14e_pmac_str, " M812=1 M811=1")
708
- sleep(int(float(led_burn_time)))
708
+ logger.info(f"burntime {led_burn_time} s")
709
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_2_ON, wait=True)
710
+ yield from bps.sleep(led_burn_time)
709
711
  logger.info("Laser 2 off")
710
- caput(pv.me14e_pmac_str, " M812=0 M811=1")
712
+ yield from bps.abs_set(pmac.laser, LaserSettings.LASER_2_OFF, wait=True)
711
713
 
712
714
 
713
715
  @log.log_on_entry
714
- def scrape_mtr_directions(param_path: Path | str = CS_FILES_PATH):
715
- param_path = _coerce_to_path(param_path)
716
-
717
- with open(param_path / "motor_direction.txt", "r") as f:
716
+ def scrape_mtr_directions(motor_file_path: Path = CS_FILES_PATH):
717
+ with open(motor_file_path / "motor_direction.txt") as f:
718
718
  lines = f.readlines()
719
719
  mtr1_dir, mtr2_dir, mtr3_dir = 1.0, 1.0, 1.0
720
720
  for line in lines:
@@ -726,62 +726,57 @@ def scrape_mtr_directions(param_path: Path | str = CS_FILES_PATH):
726
726
  mtr3_dir = float(line.split("=")[1])
727
727
  else:
728
728
  continue
729
- logger.info("mt1_dir %s mtr2_dir %s mtr3_dir %s" % (mtr1_dir, mtr2_dir, mtr3_dir))
729
+ logger.debug(f"mt1_dir {mtr1_dir} mtr2_dir {mtr2_dir} mtr3_dir {mtr3_dir}")
730
730
  return mtr1_dir, mtr2_dir, mtr3_dir
731
731
 
732
732
 
733
733
  @log.log_on_entry
734
- def fiducial(point: int = 1, param_path: Path | str = CS_FILES_PATH):
734
+ def fiducial(point: int = 1, pmac: PMAC = inject("pmac")) -> MsgGenerator:
735
+ setup_logging()
735
736
  scale = 10000.0 # noqa: F841
736
- param_path = _coerce_to_path(param_path)
737
-
738
- mtr1_dir, mtr2_dir, mtr3_dir = scrape_mtr_directions(param_path)
739
737
 
740
- rbv_1 = float(caget(pv.me14e_stage_x + ".RBV"))
741
- rbv_2 = float(caget(pv.me14e_stage_y + ".RBV"))
742
- rbv_3 = float(caget(pv.me14e_stage_z + ".RBV"))
738
+ mtr1_dir, mtr2_dir, mtr3_dir = scrape_mtr_directions(CS_FILES_PATH)
743
739
 
744
- raw_1 = float(caget(pv.me14e_stage_x + ".RRBV"))
745
- raw_2 = float(caget(pv.me14e_stage_y + ".RRBV"))
746
- raw_3 = float(caget(pv.me14e_stage_z + ".RRBV"))
740
+ rbv_1 = yield from bps.rd(pmac.x.user_readback)
741
+ rbv_2 = yield from bps.rd(pmac.y.user_readback)
742
+ rbv_3 = yield from bps.rd(pmac.z.user_readback)
747
743
 
748
- f_x = rbv_1
749
- f_y = rbv_2
750
- f_z = rbv_3
751
-
752
- logger.info("Writing Fiducial File %s/fiducial_%s.txt" % (param_path, point))
744
+ output_param_path = PARAM_FILE_PATH_FT
745
+ output_param_path.mkdir(parents=True, exist_ok=True)
746
+ logger.info(f"Writing Fiducial File {output_param_path}/fiducial_{point}.txt")
753
747
  logger.info("MTR\tRBV\tRAW\tCorr\tf_value")
754
- logger.info("MTR1\t%1.4f\t%i\t%i\t%1.4f" % (rbv_1, raw_1, mtr1_dir, f_x))
755
- logger.info("MTR2\t%1.4f\t%i\t%i\t%1.4f" % (rbv_2, raw_2, mtr2_dir, f_y))
756
- logger.info("MTR3\t%1.4f\t%i\t%i\t%1.4f" % (rbv_3, raw_3, mtr3_dir, f_z))
757
-
758
- with open(param_path / f"fiducial_{point}.txt", "w") as f:
759
- f.write("MTR\tRBV\tRAW\tCorr\tf_value\n")
760
- f.write("MTR1\t%1.4f\t%i\t%i\t%1.4f\n" % (rbv_1, raw_1, mtr1_dir, f_x))
761
- f.write("MTR2\t%1.4f\t%i\t%i\t%1.4f\n" % (rbv_2, raw_2, mtr2_dir, f_y))
762
- f.write("MTR3\t%1.4f\t%i\t%i\t%1.4f" % (rbv_3, raw_3, mtr3_dir, f_z))
748
+ logger.info("MTR1\t%1.4f\t%i" % (rbv_1, mtr1_dir))
749
+ logger.info("MTR2\t%1.4f\t%i" % (rbv_2, mtr2_dir))
750
+ logger.info("MTR3\t%1.4f\t%i" % (rbv_3, mtr3_dir))
751
+
752
+ with open(output_param_path / f"fiducial_{point}.txt", "w") as f:
753
+ f.write("MTR\tRBV\tCorr\n")
754
+ f.write("MTR1\t%1.4f\t%i\n" % (rbv_1, mtr1_dir))
755
+ f.write("MTR2\t%1.4f\t%i\n" % (rbv_2, mtr2_dir))
756
+ f.write("MTR3\t%1.4f\t%i" % (rbv_3, mtr3_dir))
763
757
  logger.info(f"Fiducial {point} set.")
758
+ yield from bps.null()
764
759
 
765
760
 
766
- def scrape_mtr_fiducials(point: int, param_path: Path | str = CS_FILES_PATH):
767
- param_path = _coerce_to_path(param_path)
768
-
769
- with open(param_path / f"fiducial_{point}.txt", "r") as f:
761
+ def scrape_mtr_fiducials(
762
+ point: int, param_path: Path = PARAM_FILE_PATH_FT
763
+ ) -> tuple[float, float, float]:
764
+ with open(param_path / f"fiducial_{point}.txt") as f:
770
765
  f_lines = f.readlines()[1:]
771
- f_x = float(f_lines[0].rsplit()[4])
772
- f_y = float(f_lines[1].rsplit()[4])
773
- f_z = float(f_lines[2].rsplit()[4])
766
+ f_x = float(f_lines[0].rsplit()[1])
767
+ f_y = float(f_lines[1].rsplit()[1])
768
+ f_z = float(f_lines[2].rsplit()[1])
774
769
  return f_x, f_y, f_z
775
770
 
776
771
 
777
772
  @log.log_on_entry
778
- def cs_maker():
773
+ def cs_maker(pmac: PMAC = inject("pmac")) -> MsgGenerator:
779
774
  """
780
775
  Coordinate system.
781
776
 
782
777
  Values for scalex, scaley, scalez, and skew, as well as the sign of
783
778
  Sx, Sy, Sz are stored in a .json file and should be modified there.
784
- Location of file: src/mx_bluesky/I24/serial/parameters/cs_maker.json
779
+ Location of file: src/mx_bluesky/i24/serial/parameters/cs_maker.json
785
780
 
786
781
  Theory
787
782
  Rx: rotation about X-axis, pitch
@@ -805,24 +800,25 @@ def cs_maker():
805
800
  This should be measured in situ prior to expriment, ie. measure by hand using
806
801
  opposite and adjacent RBV after calibration of scale factors.
807
802
  """
808
- chip_type = int(caget(pv.me14e_gp1))
803
+ setup_logging()
804
+ chip_type = int(caget(CHIPTYPE_PV))
809
805
  fiducial_dict = {}
810
806
  fiducial_dict[0] = [25.400, 25.400]
811
807
  fiducial_dict[1] = [24.600, 24.600]
812
808
  fiducial_dict[2] = [25.400, 25.400]
813
809
  fiducial_dict[3] = [18.25, 18.25]
814
- logger.info("Chip type is %s with size %s" % (chip_type, fiducial_dict[chip_type]))
810
+ logger.info(f"Chip type is {chip_type} with size {fiducial_dict[chip_type]}")
815
811
 
816
812
  mtr1_dir, mtr2_dir, mtr3_dir = scrape_mtr_directions()
817
813
  f1_x, f1_y, f1_z = scrape_mtr_fiducials(1)
818
814
  f2_x, f2_y, f2_z = scrape_mtr_fiducials(2)
819
- logger.info("mtr1 direction: %s" % mtr1_dir)
820
- logger.info("mtr2 direction: %s" % mtr2_dir)
821
- logger.info("mtr3 direction: %s" % mtr3_dir)
815
+ logger.info(f"mtr1 direction: {mtr1_dir}")
816
+ logger.info(f"mtr2 direction: {mtr2_dir}")
817
+ logger.info(f"mtr3 direction: {mtr3_dir}")
822
818
 
823
819
  # Scale parameters saved in json file
824
820
  try:
825
- with open(CS_FILES_PATH / "cs_maker.json", "r") as fh:
821
+ with open(CS_FILES_PATH / "cs_maker.json") as fh:
826
822
  cs_info = json.load(fh)
827
823
  except json.JSONDecodeError:
828
824
  logger.error("Invalid JSON file.")
@@ -857,22 +853,22 @@ def cs_maker():
857
853
  Sz1 = -1 * f1_y / fiducial_dict[chip_type][0]
858
854
  Sz2 = f2_x / fiducial_dict[chip_type][1]
859
855
  Sz = Sz_dir * ((Sz1 + Sz2) / 2)
860
- Cz = np.sqrt((1 - Sz**2))
861
- logger.info("Sz1 , %1.4f, %1.4f" % (Sz1, np.degrees(np.arcsin(Sz1))))
862
- logger.info("Sz2 , %1.4f, %1.4f" % (Sz2, np.degrees(np.arcsin(Sz2))))
863
- logger.info("Sz , %1.4f, %1.4f" % (Sz, np.degrees(np.arcsin(Sz))))
864
- logger.info("Cz , %1.4f, %1.4f" % (Cz, np.degrees(np.arcsin(Cz))))
856
+ Cz = np.sqrt(1 - Sz**2)
857
+ logger.info(f"Sz1 , {Sz1:1.4f}, {np.degrees(np.arcsin(Sz1)):1.4f}")
858
+ logger.info(f"Sz2 , {Sz2:1.4f}, {np.degrees(np.arcsin(Sz2)):1.4f}")
859
+ logger.info(f"Sz , {Sz:1.4f}, {np.degrees(np.arcsin(Sz)):1.4f}")
860
+ logger.info(f"Cz , {Cz:1.4f}, {np.degrees(np.arcsin(Cz)):1.4f}")
865
861
  # Rotation Around Y
866
862
  Sy = Sy_dir * f1_z / fiducial_dict[chip_type][0]
867
- Cy = np.sqrt((1 - Sy**2))
868
- logger.info("Sy , %1.4f, %1.4f" % (Sy, np.degrees(np.arcsin(Sy))))
869
- logger.info("Cy , %1.4f, %1.4f" % (Cy, np.degrees(np.arcsin(Cy))))
863
+ Cy = np.sqrt(1 - Sy**2)
864
+ logger.info(f"Sy , {Sy:1.4f}, {np.degrees(np.arcsin(Sy)):1.4f}")
865
+ logger.info(f"Cy , {Cy:1.4f}, {np.degrees(np.arcsin(Cy)):1.4f}")
870
866
  # Rotation Around X
871
867
  # If stages upsidedown (I24) change sign of Sx
872
868
  Sx = Sx_dir * f2_z / fiducial_dict[chip_type][1]
873
- Cx = np.sqrt((1 - Sx**2))
874
- logger.info("Sx , %1.4f, %1.4f" % (Sx, np.degrees(np.arcsin(Sx))))
875
- logger.info("Cx , %1.4f, %1.4f" % (Cx, np.degrees(np.arcsin(Cx))))
869
+ Cx = np.sqrt(1 - Sx**2)
870
+ logger.info(f"Sx , {Sx:1.4f}, {np.degrees(np.arcsin(Sx)):1.4f}")
871
+ logger.info(f"Cx , {Cx:1.4f}, {np.degrees(np.arcsin(Cx)):1.4f}")
876
872
 
877
873
  x1factor = mtr1_dir * scalex * (Cy * Cz)
878
874
  y1factor = mtr2_dir * scaley * (-1.0 * Cx * Sz)
@@ -886,14 +882,14 @@ def cs_maker():
886
882
  y3factor = mtr2_dir * scaley * ((Cx * Sy * Sz) + (Sx * Cz))
887
883
  z3factor = mtr3_dir * scalez * (Cx * Cy)
888
884
 
889
- logger.info("Skew being used is: %1.4f" % skew)
885
+ logger.info(f"Skew being used is: {skew:1.4f}")
890
886
  s1 = np.degrees(np.arcsin(Sz1))
891
887
  s2 = np.degrees(np.arcsin(Sz2))
892
888
  rot = np.degrees(np.arcsin((Sz1 + Sz2) / 2))
893
889
  calc_skew = (s1 - rot) - (s2 - rot)
894
- logger.info("s1:%1.4f s2:%1.4f rot:%1.4f" % (s1, s2, rot))
895
- logger.info("Calculated rotation from current fiducials is: %1.4f" % rot)
896
- logger.info("Calculated Skew from current fiducials is: %1.4f" % calc_skew)
890
+ logger.info(f"s1:{s1:1.4f} s2:{s2:1.4f} rot:{rot:1.4f}")
891
+ logger.info(f"Calculated rotation from current fiducials is: {rot:1.4f}")
892
+ logger.info(f"Calculated Skew from current fiducials is: {calc_skew:1.4f}")
897
893
  logger.info("Calculated Skew has been known to have the wrong sign")
898
894
 
899
895
  sinD = np.sin((skew / 2) * (np.pi / 180))
@@ -903,10 +899,10 @@ def cs_maker():
903
899
  new_x2factor = (x2factor * cosD) + (y2factor * sinD)
904
900
  new_y2factor = (x2factor * sinD) + (y2factor * cosD)
905
901
 
906
- cs1 = "#1->%+1.3fX%+1.3fY%+1.3fZ" % (new_x1factor, new_y1factor, z1factor)
907
- cs2 = "#2->%+1.3fX%+1.3fY%+1.3fZ" % (new_x2factor, new_y2factor, z2factor)
908
- cs3 = "#3->%+1.3fX%+1.3fY%+1.3fZ" % (x3factor, y3factor, z3factor)
909
- logger.info("PMAC strings. \ncs1: %s \ncs2: %scs3: %s" % (cs1, cs2, cs3))
902
+ cs1 = f"#1->{new_x1factor:+1.3f}X{new_y1factor:+1.3f}Y{z1factor:+1.3f}Z"
903
+ cs2 = f"#2->{new_x2factor:+1.3f}X{new_y2factor:+1.3f}Y{z2factor:+1.3f}Z"
904
+ cs3 = f"#3->{x3factor:+1.3f}X{y3factor:+1.3f}Y{z3factor:+1.3f}Z"
905
+ logger.info(f"PMAC strings. \ncs1: {cs1} \ncs2: {cs2}cs3: {cs3}")
910
906
  logger.info(
911
907
  """These next values should be 1.
912
908
  This is the sum of the squares of the factors divided by their scale."""
@@ -914,52 +910,70 @@ def cs_maker():
914
910
  sqfact1 = np.sqrt(x1factor**2 + y1factor**2 + z1factor**2) / scalex
915
911
  sqfact2 = np.sqrt(x2factor**2 + y2factor**2 + z2factor**2) / scaley
916
912
  sqfact3 = np.sqrt(x3factor**2 + y3factor**2 + z3factor**2) / scalez
917
- logger.info("%1.4f \n %1.4f \n %1.4f" % (sqfact1, sqfact2, sqfact3))
918
- logger.info("Long wait, please be patient")
919
- caput(pv.me14e_pmac_str, "!x0y0z0")
913
+ logger.info(f"{sqfact1:1.4f} \n {sqfact2:1.4f} \n {sqfact3:1.4f}")
914
+ logger.debug("Long wait, please be patient")
915
+ yield from bps.trigger(pmac.to_xyz_zero)
920
916
  sleep(2.5)
921
- caput(pv.me14e_pmac_str, "&2")
922
- caput(pv.me14e_pmac_str, cs1)
923
- caput(pv.me14e_pmac_str, cs2)
924
- caput(pv.me14e_pmac_str, cs3)
925
- caput(pv.me14e_pmac_str, "!x0y0z0")
917
+ yield from set_pmac_strings_for_cs(pmac, {"cs1": cs1, "cs2": cs2, "cs3": cs3})
918
+ yield from bps.trigger(pmac.to_xyz_zero)
926
919
  sleep(0.1)
927
- caput(pv.me14e_pmac_str, "#1hmz#2hmz#3hmz")
920
+ yield from bps.trigger(pmac.home, wait=True)
928
921
  sleep(0.1)
929
- logger.info("Chip_type is %s" % chip_type)
922
+ logger.debug(f"Chip_type is {chip_type}")
930
923
  if chip_type == 0:
931
- caput(pv.me14e_pmac_str, "!x0.4y0.4")
924
+ yield from bps.abs_set(pmac.pmac_string, "!x0.4y0.4", wait=True)
932
925
  sleep(0.1)
933
- caput(pv.me14e_pmac_str, "#1hmz#2hmz#3hmz")
926
+ yield from bps.trigger(pmac.home, wait=True)
934
927
  else:
935
- caput(pv.me14e_pmac_str, "#1hmz#2hmz#3hmz")
928
+ yield from bps.trigger(pmac.home, wait=True)
936
929
  logger.debug("CSmaker done.")
930
+ yield from bps.null()
937
931
 
938
932
 
939
- def cs_reset():
940
- cs1 = "#1->-10000X+0Y+0Z"
941
- cs2 = "#2->+0X+10000Y+0Z"
942
- cs3 = "#3->0X+0Y+10000Z"
933
+ def cs_reset(pmac: PMAC = inject("pmac")) -> MsgGenerator:
934
+ """Used to clear CS when using Custom Chip"""
935
+ setup_logging()
936
+ cs1 = "#1->10000X+0Y+0Z"
937
+ cs2 = "#2->+0X-10000Y+0Z"
938
+ cs3 = "#3->0X+0Y-10000Z"
943
939
  strg = "\n".join([cs1, cs2, cs3])
944
940
  print(strg)
945
- caput(pv.me14e_pmac_str, "&2")
946
- sleep(0.5)
947
- caput(pv.me14e_pmac_str, cs1)
948
- sleep(0.5)
949
- caput(pv.me14e_pmac_str, cs2)
950
- sleep(0.5)
951
- caput(pv.me14e_pmac_str, cs3)
941
+ yield from set_pmac_strings_for_cs(pmac, {"cs1": cs1, "cs2": cs2, "cs3": cs3})
952
942
  logger.debug("CSreset Done")
943
+ yield from bps.null()
944
+
945
+
946
+ def set_pmac_strings_for_cs(pmac: PMAC, cs_str: dict):
947
+ """ A plan to set the pmac_string for the (x,y,z) axes while making or resetting \
948
+ the coordinate system.
949
+
950
+ Args:
951
+ pmac (PMAC): PMAC device
952
+ cs_str (dict): A dictionary containing a string for each axis, in the format: \
953
+ {
954
+ "cs1": "#1->1X+0Y+0Z",
955
+ "cs2": "#2->...",
956
+ "cs3": "#3->...",
957
+ }
958
+
959
+ Note. On the PMAC the axes allocations are: #1 - X, #2 - Y, #3 - Z.
960
+ """
961
+ yield from bps.abs_set(pmac.pmac_string, "&2", wait=True)
962
+ yield from bps.abs_set(pmac.pmac_string, cs_str["cs1"], wait=True)
963
+ yield from bps.abs_set(pmac.pmac_string, cs_str["cs2"], wait=True)
964
+ yield from bps.abs_set(pmac.pmac_string, cs_str["cs3"], wait=True)
953
965
 
954
966
 
955
967
  @log.log_on_entry
956
- def pumpprobe_calc():
968
+ def pumpprobe_calc() -> MsgGenerator:
969
+ # TODO See https://github.com/DiamondLightSource/mx_bluesky/issues/122
970
+ setup_logging()
957
971
  logger.info("Calculate and show exposure and dwell time for each option.")
958
972
  exptime = float(caget(pv.me14e_exptime))
959
973
  pumpexptime = float(caget(pv.me14e_gp103))
960
974
  movetime = 0.008
961
- logger.info("X-ray exposure time %s" % exptime)
962
- logger.info("Laser dwell time %s" % pumpexptime)
975
+ logger.info(f"X-ray exposure time {exptime}")
976
+ logger.info(f"Laser dwell time {pumpexptime}")
963
977
  repeat1 = 2 * 20 * (movetime + (pumpexptime + exptime) / 2)
964
978
  repeat2 = 4 * 20 * (movetime + (pumpexptime + exptime) / 2)
965
979
  repeat3 = 6 * 20 * (movetime + (pumpexptime + exptime) / 2)
@@ -974,17 +988,19 @@ def pumpprobe_calc():
974
988
  ):
975
989
  rounded = round(repeat, 4)
976
990
  caput(pv_name, rounded)
977
- logger.info("Repeat (%s): %s s" % (pv_name, rounded))
978
- # logger.info("repeat10 (%s): %s s" % (pv.me14e_gp108, round(repeat10, 4)))
991
+ logger.info(f"Repeat ({pv_name}): {rounded} s")
979
992
  logger.debug("PP calculations done")
993
+ yield from bps.null()
980
994
 
981
995
 
982
996
  @log.log_on_entry
983
- def block_check():
997
+ def block_check(pmac: PMAC = inject("pmac")) -> MsgGenerator:
998
+ setup_logging()
999
+ # TODO See https://github.com/DiamondLightSource/mx_bluesky/issues/117
984
1000
  caput(pv.me14e_gp9, 0)
985
1001
  while True:
986
1002
  if int(caget(pv.me14e_gp9)) == 0:
987
- chip_type = int(caget(pv.me14e_gp1))
1003
+ chip_type = int(caget(CHIPTYPE_PV))
988
1004
  if chip_type == ChipType.Minichip:
989
1005
  logger.info("Oxford mini chip in use.")
990
1006
  block_start_list = scrape_pvar_file("minichip_oxford.pvar")
@@ -1003,72 +1019,17 @@ def block_check():
1003
1019
  sleep(1.0)
1004
1020
  break
1005
1021
  block, x, y = entry
1006
- logger.info("Block: %s -> (x=%s y=%s)" % (block, x, y))
1007
- caput(pv.me14e_pmac_str, "!x%sy%s" % (x, y))
1022
+ logger.debug(f"Block: {block} -> (x={x} y={y})")
1023
+ yield from bps.abs_set(pmac.pmac_string, f"!x{x}y{y}", wait=True)
1008
1024
  time.sleep(0.4)
1009
1025
  else:
1010
1026
  logger.warning("Block Check Aborted due to GP 9 not equalling 0")
1011
1027
  break
1012
1028
  break
1013
1029
  logger.debug("Block check done")
1030
+ yield from bps.null()
1014
1031
 
1015
1032
 
1016
- def parse_args_and_run_parsed_function(args):
1017
- print(f"Run with {args}")
1018
- parser = argparse.ArgumentParser()
1019
- subparsers = parser.add_subparsers(
1020
- help="Choose command.",
1021
- required=True,
1022
- dest="sub-command",
1023
- )
1024
- parser_init = subparsers.add_parser(
1025
- "initialise",
1026
- )
1027
- parser_init.set_defaults(func=initialise)
1028
- parser_moveto = subparsers.add_parser(
1029
- "moveto",
1030
- )
1031
- parser_moveto.add_argument("place", type=str)
1032
- parser_moveto.set_defaults(func=moveto)
1033
- parser_fid = subparsers.add_parser("fiducial")
1034
- parser_fid.add_argument("point", type=int)
1035
- parser_fid.set_defaults(func=fiducial)
1036
- parser_csm = subparsers.add_parser("cs_maker")
1037
- parser_csm.set_defaults(func=cs_maker)
1038
- parser_pp = subparsers.add_parser("pumpprobe_calc")
1039
- parser_pp.set_defaults(func=pumpprobe_calc)
1040
- parser_write = subparsers.add_parser("write_parameter_file")
1041
- parser_write.set_defaults(func=write_parameter_file)
1042
- parser_def = subparsers.add_parser("define_current_chip")
1043
- parser_def.add_argument("chipid", type=str)
1044
- parser_def.set_defaults(func=define_current_chip)
1045
- parser_stockmap = subparsers.add_parser("load_stock_map")
1046
- parser_stockmap.add_argument("map_choice", type=str)
1047
- parser_stockmap.set_defaults(func=load_stock_map)
1048
- parser_litemap = subparsers.add_parser("load_lite_map")
1049
- parser_litemap.set_defaults(func=load_lite_map)
1050
- parser_fullmap = subparsers.add_parser("load_full_map")
1051
- parser_fullmap.set_defaults(func=load_full_map)
1052
- parser_save = subparsers.add_parser("save_screen_map")
1053
- parser_save.set_defaults(func=save_screen_map)
1054
- parser_upld = subparsers.add_parser("upload_full")
1055
- parser_upld.set_defaults(func=upload_full)
1056
- parser_params = subparsers.add_parser("upload_parameters")
1057
- parser_params.add_argument("chipid", type=str)
1058
- parser_params.set_defaults(func=upload_parameters)
1059
- parser_csr = subparsers.add_parser("cs_reset")
1060
- parser_csr.set_defaults(func=cs_reset)
1061
- parser_block = subparsers.add_parser("block_check")
1062
- parser_block.set_defaults(func=block_check)
1063
-
1064
- args = parser.parse_args(args)
1065
-
1066
- args_dict = vars(args)
1067
- args_dict.pop("sub-command")
1068
- args_dict.pop("func")(**args_dict)
1069
-
1070
-
1071
- if __name__ == "__main__":
1072
- setup_logging()
1073
-
1074
- parse_args_and_run_parsed_function(sys.argv[1:])
1033
+ # setup_logging now called in all functions.
1034
+ # TODO See logging issue on blueapi
1035
+ # https://github.com/DiamondLightSource/blueapi/issues/494