Demo the spec file writer callback#
[1]:
from bluesky import RunEngine
RE = RunEngine()
[2]:
from ophyd import EpicsMotor, EpicsSignal
m1 = EpicsMotor("gp:m1", name="m1")
signal = EpicsSignal("gp:userCalc8", name="signal")
[14]:
print(f"{m1.position=:.5f}")
print(f"{signal.get()=:.3f}")
m1.position=0.00000
signal.get()=24.514
[15]:
from apstools.callbacks import SpecWriterCallback
specwriter = SpecWriterCallback()
[17]:
RE.subscribe(specwriter.receiver)
[17]:
0
[18]:
from bluesky import plans as bp
[20]:
specwriter.spec_filename
[20]:
PosixPath('20230329-141656.dat')
[21]:
%pycat 20230329-141656.dat
Error: no such file, variable, URL, history range or macro
[23]:
RE(bp.count([signal]))
[23]:
('fca1c869-5d28-4ecf-b14a-e829678ae17b',)
[24]:
%pycat 20230329-141656.dat
#F 20230329-141656.dat
#E 1680117416
#D Wed Mar 29 14:16:56 2023
#C Bluesky user = prjemian host = zap
#O0
#o0
#S 1 count(detectors=['signal'], num=1)
#D Wed Mar 29 14:19:27 2023
#C Wed Mar 29 14:19:27 2023. plan_type = generator
#C Wed Mar 29 14:19:27 2023. uid = fca1c869-5d28-4ecf-b14a-e829678ae17b
#MD uid = fca1c869-5d28-4ecf-b14a-e829678ae17b
#MD detectors = ['signal']
#MD num_intervals = 0
#MD num_points = 1
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 3
#L Epoch_float Epoch signal
0.00418853759765625 0 25.26832227054246
#C Wed Mar 29 14:19:27 2023. num_events_primary = 1
#C Wed Mar 29 14:19:27 2023. exit_status = success
[28]:
specwriter.newfile("/tmp/spec_file_demo.spec")
[28]:
PosixPath('/tmp/spec_file_demo.spec')
[29]:
RE(bp.scan([signal], m1, -1, 0, 3))
[29]:
('4ea2058d-8b78-4b93-a61e-77a6178f525a',)
[30]:
%pycat /tmp/spec_file_demo.spec
#F /tmp/spec_file_demo.spec
#E 1680117763
#D Wed Mar 29 14:22:43 2023
#C Bluesky user = prjemian host = zap
#O0
#o0
#S 3 scan(detectors=['signal'], num=3, args='['m1', -1, 0]', per_step='None')
#D Wed Mar 29 14:22:50 2023
#C Wed Mar 29 14:22:50 2023. plan_type = generator
#C Wed Mar 29 14:22:50 2023. uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD detectors = ['signal']
#MD motors = ('m1',)
#MD num_intervals = 2
#MD num_points = 3
#MD plan_pattern = inner_product
#MD plan_pattern_args = {'num': 3, 'args': ["EpicsMotor(prefix='gp:m1', name='m1', settle_time=0.0, timeout=None, read_attrs=['user_readback', 'user_setpoint'], configuration_attrs=['user_offset', 'user_offset_dir', 'velocity', 'acceleration', 'motor_egu'])", -1, 0]}
#MD plan_pattern_module = bluesky.plan_patterns
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 5
#L m1 Epoch_float Epoch m1_user_setpoint signal
-1.0 1.2423996925354004 1 -1.0 24.68619058518349
-0.5 2.030499219894409 2 -0.5 24.613359273670557
0.0 2.8312039375305176 3 0.0 24.613359273670557
#C Wed Mar 29 14:22:52 2023. num_events_primary = 3
#C Wed Mar 29 14:22:52 2023. exit_status = success
[31]:
def my_plan(count_time=1):
print(f"{count_time=}")
yield from bp.count([signal])
[32]:
RE(my_plan(3.14))
count_time=3.14
#F /tmp/spec_file_demo.spec
#E 1680117763
#D Wed Mar 29 14:22:43 2023
#C Bluesky user = prjemian host = zap
#O0
#o0
#S 3 scan(detectors=['signal'], num=3, args='['m1', -1, 0]', per_step='None')
#D Wed Mar 29 14:22:50 2023
#C Wed Mar 29 14:22:50 2023. plan_type = generator
#C Wed Mar 29 14:22:50 2023. uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD detectors = ['signal']
#MD motors = ('m1',)
#MD num_intervals = 2
#MD num_points = 3
#MD plan_pattern = inner_product
#MD plan_pattern_args = {'num': 3, 'args': ["EpicsMotor(prefix='gp:m1', name='m1', settle_time=0.0, timeout=None, read_attrs=['user_readback', 'user_setpoint'], configuration_attrs=['user_offset', 'user_offset_dir', 'velocity', 'acceleration', 'motor_egu'])", -1, 0]}
#MD plan_pattern_module = bluesky.plan_patterns
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 5
#L m1 Epoch_float Epoch m1_user_setpoint signal
-1.0 1.2423996925354004 1 -1.0 24.68619058518349
-0.5 2.030499219894409 2 -0.5 24.613359273670557
0.0 2.8312039375305176 3 0.0 24.613359273670557
#C Wed Mar 29 14:22:52 2023. num_events_primary = 3
#C Wed Mar 29 14:22:52 2023. exit_status = success
#S 4 count(detectors=['signal'], num=1)
#D Wed Mar 29 14:26:44 2023
#C Wed Mar 29 14:26:44 2023. plan_type = generator
#C Wed Mar 29 14:26:44 2023. uid = a984dffc-55b1-49ca-9fe9-5843c95eac8c
#MD uid = a984dffc-55b1-49ca-9fe9-5843c95eac8c
#MD detectors = ['signal']
#MD num_intervals = 0
#MD num_points = 1
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 3
#L Epoch_float Epoch signal
0.003344297409057617 0 24.523498893720912
#C Wed Mar 29 14:26:44 2023. num_events_primary = 1
#C Wed Mar 29 14:26:44 2023. exit_status = success
[33]:
%pycat /tmp/spec_file_demo.spec
#F /tmp/spec_file_demo.spec
#E 1680117763
#D Wed Mar 29 14:22:43 2023
#C Bluesky user = prjemian host = zap
#O0
#o0
#S 3 scan(detectors=['signal'], num=3, args='['m1', -1, 0]', per_step='None')
#D Wed Mar 29 14:22:50 2023
#C Wed Mar 29 14:22:50 2023. plan_type = generator
#C Wed Mar 29 14:22:50 2023. uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD uid = 4ea2058d-8b78-4b93-a61e-77a6178f525a
#MD detectors = ['signal']
#MD motors = ('m1',)
#MD num_intervals = 2
#MD num_points = 3
#MD plan_pattern = inner_product
#MD plan_pattern_args = {'num': 3, 'args': ["EpicsMotor(prefix='gp:m1', name='m1', settle_time=0.0, timeout=None, read_attrs=['user_readback', 'user_setpoint'], configuration_attrs=['user_offset', 'user_offset_dir', 'velocity', 'acceleration', 'motor_egu'])", -1, 0]}
#MD plan_pattern_module = bluesky.plan_patterns
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 5
#L m1 Epoch_float Epoch m1_user_setpoint signal
-1.0 1.2423996925354004 1 -1.0 24.68619058518349
-0.5 2.030499219894409 2 -0.5 24.613359273670557
0.0 2.8312039375305176 3 0.0 24.613359273670557
#C Wed Mar 29 14:22:52 2023. num_events_primary = 3
#C Wed Mar 29 14:22:52 2023. exit_status = success
#S 4 count(detectors=['signal'], num=1)
#D Wed Mar 29 14:26:44 2023
#C Wed Mar 29 14:26:44 2023. plan_type = generator
#C Wed Mar 29 14:26:44 2023. uid = a984dffc-55b1-49ca-9fe9-5843c95eac8c
#MD uid = a984dffc-55b1-49ca-9fe9-5843c95eac8c
#MD detectors = ['signal']
#MD num_intervals = 0
#MD num_points = 1
#MD versions = {'ophyd': '1.7.0', 'bluesky': '1.10.0'}
#P0
#N 3
#L Epoch_float Epoch signal
0.003344297409057617 0 24.523498893720912
#C Wed Mar 29 14:26:44 2023. num_events_primary = 1
#C Wed Mar 29 14:26:44 2023. exit_status = success
[39]:
print(f"{m1.prefix} {m1.user_setpoint.pvname}")
gp:m1 gp:m1.VAL
[37]:
from apstools.utils import listdevice
listdevice(m1, show_pv=True)
[37]:
======================= ========== ======== ==========================
data name PV value timestamp
======================= ========== ======== ==========================
m1 gp:m1.RBV 0.0 2023-03-29 14:22:52.958127
m1_user_setpoint gp:m1.VAL 0.0 2023-03-29 14:22:52.160880
m1_user_offset gp:m1.OFF 0.0 2023-03-29 11:48:42.736747
m1_user_offset_dir gp:m1.DIR 0 2023-03-29 11:48:42.736747
m1_offset_freeze_switch gp:m1.FOFF 0 2023-03-29 11:48:42.736747
m1_set_use_switch gp:m1.SET 0 2023-03-29 11:48:42.736747
m1_velocity gp:m1.VELO 1.0 2023-03-29 11:48:42.736747
m1_acceleration gp:m1.ACCL 0.2 2023-03-29 11:48:42.736747
m1_motor_egu gp:m1.EGU degrees 2023-03-29 11:48:42.736747
m1_motor_is_moving gp:m1.MOVN 0 2023-03-29 14:22:52.958127
m1_motor_done_move gp:m1.DMOV 1 2023-03-29 14:22:52.958127
m1_high_limit_switch gp:m1.HLS 0 2023-03-29 11:48:42.736747
m1_low_limit_switch gp:m1.LLS 0 2023-03-29 11:48:42.736747
m1_high_limit_travel gp:m1.HLM 32000.0 2023-03-29 11:48:42.736747
m1_low_limit_travel gp:m1.LLM -32000.0 2023-03-29 11:48:42.736747
m1_direction_of_travel gp:m1.TDIR 0 2023-03-29 14:22:52.958127
m1_motor_stop gp:m1.STOP 0 2023-03-29 14:22:52.961634
m1_home_forward gp:m1.HOMF 0 2023-03-29 11:48:42.736747
m1_home_reverse gp:m1.HOMR 0 2023-03-29 11:48:42.736747
======================= ========== ======== ==========================
[43]:
m1.motor_egu.get()
[43]:
'degrees'