{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Lesson 2: motor and scan\n", "\n", "In this lesson, we'll work with a motor (for precise positioning) in [Bluesky](https://blueskyproject.io/bluesky/) and [related tools](https://blueskyproject.io/).\n", "\n", "First, we'll connect with an EPICS motor (using [ophyd](https://blueskyproject.io/ophyd/)), and then use the Bluesky software to scan the motor (with the scaler from [lesson 1](_lesson1.ipynb)).\n", "\n", "Load `ophyd` device support for the `EpicsMotor` and connect with one EPICS motor channel. We have a synApps (v6.1) XXX-style IOC with the prefix `sky:`. It has a scaler, 16 soft channel motors, and some other support we'll ignore in this lesson.\n", "\n", "**note**: This tutorial expects to find an EPICS IOC on the local network configured as a synApps [xxx](https://github.com/epics-modules/xxx) IOC with prefix `sky:`. A docker container is available to provide this IOC. See this URL for instructions: https://github.com/prjemian/epics-docker/blob/master/n3_synApps/README.md" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ophyd import EpicsMotor\n", "m1 = EpicsMotor(\"sky:m1\", name=\"m1\")\n", "m1.wait_for_connection()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show the current value fo the motor (that's the `.RBV` field, in case you were interested)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1.position" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Connect the scaler (as was done in lesson 1). Define some of the chaannel names and clear out others." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from ophyd.scaler import ScalerCH\n", "scaler = ScalerCH(\"sky:scaler1\", name=\"scaler\")\n", "scaler.wait_for_connection()\n", "\n", "# Since there are no detectors actually connected to this scaler,\n", "# we can change names at our choice. A real scaler will have\n", "# detectors connected to specific channels and we should not modify\n", "# these names without regard to how signals are physically connected.\n", "scaler.channels.chan01.chname.put(\"clock\")\n", "scaler.channels.chan02.chname.put(\"I0\")\n", "scaler.channels.chan03.chname.put(\"scint\")\n", "scaler.channels.chan04.chname.put(\"\")\n", "scaler.channels.chan05.chname.put(\"\")\n", "scaler.channels.chan06.chname.put(\"\")\n", "scaler.channels.chan07.chname.put(\"\")\n", "scaler.channels.chan08.chname.put(\"\")\n", "scaler.channels.chan09.chname.put(\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use only the channels with EPICS names, those are the *interesting* channels." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('clock', {'value': 11000000.0, 'timestamp': 1616788676.931333}),\n", " ('I0', {'value': 6.0, 'timestamp': 1616788676.931333}),\n", " ('scint', {'value': 5.0, 'timestamp': 1616788676.931333}),\n", " ('ROI1', {'value': 0.0, 'timestamp': 1616788676.931333}),\n", " ('ROI2', {'value': 0.0, 'timestamp': 1616788676.931333}),\n", " ('scaler_time', {'value': 1.1, 'timestamp': 1616788676.931333})])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler.select_channels(None)\n", "scaler.read()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a RunEngine but do not connect it with a data collection strategy. That will come in the next lessons." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from bluesky import RunEngine\n", "import bluesky.plans as bp\n", "RE = RunEngine({})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run a step scan using the motor and the scaler." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('bef2817a-22de-4780-a38f-3c64f882f99b',)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bp.scan([scaler], m1, -1, 1, 5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ah, yes. Nothing to see here since we did not setup anything to receive the *documents* from the RunEngine. Here's the basic callback from lesson 1." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import pprint\n", "def myCallback(key, doc):\n", " print()\n", " print(key, len(doc))\n", " pprint.pprint(doc)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Repeat the same scan but handle the document stream with `myCallback()`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "start 15\n", "{'detectors': ['scaler'],\n", " 'hints': {'dimensions': [(['m1'], 'primary')]},\n", " 'motors': ('m1',),\n", " 'num_intervals': 4,\n", " 'num_points': 5,\n", " 'plan_args': {'args': [\"EpicsMotor(prefix='sky:m1', name='m1', \"\n", " 'settle_time=0.0, timeout=None, '\n", " \"read_attrs=['user_readback', 'user_setpoint'], \"\n", " \"configuration_attrs=['user_offset', \"\n", " \"'user_offset_dir', 'velocity', 'acceleration', \"\n", " \"'motor_egu'])\",\n", " -1,\n", " 1],\n", " 'detectors': [\"ScalerCH(prefix='sky:scaler1', name='scaler', \"\n", " \"read_attrs=['channels', 'channels.chan01', \"\n", " \"'channels.chan01.s', 'channels.chan02', \"\n", " \"'channels.chan02.s', 'channels.chan03', \"\n", " \"'channels.chan03.s', 'channels.chan10', \"\n", " \"'channels.chan10.s', 'channels.chan11', \"\n", " \"'channels.chan11.s', 'time'], \"\n", " \"configuration_attrs=['channels', \"\n", " \"'channels.chan01', 'channels.chan01.chname', \"\n", " \"'channels.chan01.preset', \"\n", " \"'channels.chan01.gate', 'channels.chan02', \"\n", " \"'channels.chan02.chname', \"\n", " \"'channels.chan02.preset', \"\n", " \"'channels.chan02.gate', 'channels.chan03', \"\n", " \"'channels.chan03.chname', \"\n", " \"'channels.chan03.preset', \"\n", " \"'channels.chan03.gate', 'channels.chan10', \"\n", " \"'channels.chan10.chname', \"\n", " \"'channels.chan10.preset', \"\n", " \"'channels.chan10.gate', 'channels.chan11', \"\n", " \"'channels.chan11.chname', \"\n", " \"'channels.chan11.preset', \"\n", " \"'channels.chan11.gate', 'count_mode', 'delay', \"\n", " \"'auto_count_delay', 'freq', 'preset_time', \"\n", " \"'auto_count_time', 'egu'])\"],\n", " 'num': 5,\n", " 'per_step': 'None'},\n", " 'plan_name': 'scan',\n", " 'plan_pattern': 'inner_product',\n", " 'plan_pattern_args': {'args': [\"EpicsMotor(prefix='sky:m1', name='m1', \"\n", " 'settle_time=0.0, timeout=None, '\n", " \"read_attrs=['user_readback', \"\n", " \"'user_setpoint'], \"\n", " \"configuration_attrs=['user_offset', \"\n", " \"'user_offset_dir', 'velocity', \"\n", " \"'acceleration', 'motor_egu'])\",\n", " -1,\n", " 1],\n", " 'num': 5},\n", " 'plan_pattern_module': 'bluesky.plan_patterns',\n", " 'plan_type': 'generator',\n", " 'scan_id': 2,\n", " 'time': 1616788927.1139975,\n", " 'uid': '4c2e9fe2-3bed-4ae4-99e9-66f0cd006a67',\n", " 'versions': {'bluesky': '1.6.7', 'ophyd': '1.6.1'}}\n", "\n", "descriptor 8\n", "{'configuration': {'m1': {'data': {'m1_acceleration': 0.2,\n", " 'm1_motor_egu': 'degrees',\n", " 'm1_user_offset': 0.0,\n", " 'm1_user_offset_dir': 0,\n", " 'm1_velocity': 1.0},\n", " 'data_keys': OrderedDict([('m1_user_offset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': -1e+300,\n", " 'precision': 5,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.OFF',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 1e+300}),\n", " ('m1_user_offset_dir',\n", " {'dtype': 'integer',\n", " 'enum_strs': ('Pos',\n", " 'Neg'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.DIR',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('m1_velocity',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.1,\n", " 'precision': 5,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.VELO',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('m1_acceleration',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': -1e+300,\n", " 'precision': 5,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.ACCL',\n", " 'units': 'sec',\n", " 'upper_ctrl_limit': 1e+300}),\n", " ('m1_motor_egu',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.EGU',\n", " 'units': None,\n", " 'upper_ctrl_limit': None})]),\n", " 'timestamps': {'m1_acceleration': 1616788677.05184,\n", " 'm1_motor_egu': 1616788677.05184,\n", " 'm1_user_offset': 1616788677.05184,\n", " 'm1_user_offset_dir': 1616788677.05184,\n", " 'm1_velocity': 1616788677.05184}},\n", " 'scaler': {'data': {'scaler_auto_count_delay': 0.0,\n", " 'scaler_auto_count_time': 1.0,\n", " 'scaler_channels_chan01_chname': 'clock',\n", " 'scaler_channels_chan01_gate': 'Y',\n", " 'scaler_channels_chan01_preset': 10000000.0,\n", " 'scaler_channels_chan02_chname': 'I0',\n", " 'scaler_channels_chan02_gate': 'N',\n", " 'scaler_channels_chan02_preset': 0.0,\n", " 'scaler_channels_chan03_chname': 'scint',\n", " 'scaler_channels_chan03_gate': 'N',\n", " 'scaler_channels_chan03_preset': 0.0,\n", " 'scaler_channels_chan10_chname': 'ROI1',\n", " 'scaler_channels_chan10_gate': 'N',\n", " 'scaler_channels_chan10_preset': 0.0,\n", " 'scaler_channels_chan11_chname': 'ROI2',\n", " 'scaler_channels_chan11_gate': 'N',\n", " 'scaler_channels_chan11_preset': 0.0,\n", " 'scaler_count_mode': 'OneShot',\n", " 'scaler_delay': 0.0,\n", " 'scaler_egu': '',\n", " 'scaler_freq': 10000000.0,\n", " 'scaler_preset_time': 1.0},\n", " 'data_keys': OrderedDict([('scaler_channels_chan01_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.NM1',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan01_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.PR1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan01_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.G1',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan02_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.NM2',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan02_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.PR2',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan02_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.G2',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan03_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.NM3',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan03_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.PR3',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan03_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.G3',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan10_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.NM10',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan10_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.PR10',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan10_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.G10',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan11_chname',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.NM11',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_channels_chan11_preset',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.PR11',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_channels_chan11_gate',\n", " {'dtype': 'string',\n", " 'enum_strs': ('N',\n", " 'Y'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.G11',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_count_mode',\n", " {'dtype': 'string',\n", " 'enum_strs': ('OneShot',\n", " 'AutoCount'),\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.CONT',\n", " 'units': None,\n", " 'upper_ctrl_limit': None}),\n", " ('scaler_delay',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.DLY',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_auto_count_delay',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.DLY1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_freq',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.FREQ',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_preset_time',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.TP',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_auto_count_time',\n", " {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.TP1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}),\n", " ('scaler_egu',\n", " {'dtype': 'string',\n", " 'lower_ctrl_limit': None,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.EGU',\n", " 'units': None,\n", " 'upper_ctrl_limit': None})]),\n", " 'timestamps': {'scaler_auto_count_delay': 1616788930.753993,\n", " 'scaler_auto_count_time': 1616788930.753993,\n", " 'scaler_channels_chan01_chname': 1616788930.753993,\n", " 'scaler_channels_chan01_gate': 1616788930.753993,\n", " 'scaler_channels_chan01_preset': 1616788930.753993,\n", " 'scaler_channels_chan02_chname': 1616788930.753993,\n", " 'scaler_channels_chan02_gate': 1616788930.753993,\n", " 'scaler_channels_chan02_preset': 1616788930.753993,\n", " 'scaler_channels_chan03_chname': 1616788930.753993,\n", " 'scaler_channels_chan03_gate': 1616788930.753993,\n", " 'scaler_channels_chan03_preset': 1616788930.753993,\n", " 'scaler_channels_chan10_chname': 1616788930.753993,\n", " 'scaler_channels_chan10_gate': 1616788930.753993,\n", " 'scaler_channels_chan10_preset': 1616788930.753993,\n", " 'scaler_channels_chan11_chname': 1616788930.753993,\n", " 'scaler_channels_chan11_gate': 1616788930.753993,\n", " 'scaler_channels_chan11_preset': 1616788930.753993,\n", " 'scaler_count_mode': 1616788930.753993,\n", " 'scaler_delay': 1616788930.753993,\n", " 'scaler_egu': 1616788930.753993,\n", " 'scaler_freq': 1616788930.753993,\n", " 'scaler_preset_time': 1616788930.753993}}},\n", " 'data_keys': {'I0': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.S2',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'ROI1': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.S10',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'ROI2': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.S11',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'clock': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.S1',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'm1': {'dtype': 'number',\n", " 'lower_ctrl_limit': -32000.0,\n", " 'object_name': 'm1',\n", " 'precision': 5,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.RBV',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 32000.0},\n", " 'm1_user_setpoint': {'dtype': 'number',\n", " 'lower_ctrl_limit': -32000.0,\n", " 'object_name': 'm1',\n", " 'precision': 5,\n", " 'shape': [],\n", " 'source': 'PV:sky:m1.VAL',\n", " 'units': 'degrees',\n", " 'upper_ctrl_limit': 32000.0},\n", " 'scaler_time': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 3,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.T',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0},\n", " 'scint': {'dtype': 'number',\n", " 'lower_ctrl_limit': 0.0,\n", " 'object_name': 'scaler',\n", " 'precision': 0,\n", " 'shape': [],\n", " 'source': 'PV:sky:scaler1.S3',\n", " 'units': '',\n", " 'upper_ctrl_limit': 0.0}},\n", " 'hints': {'m1': {'fields': ['m1']},\n", " 'scaler': {'fields': ['clock', 'I0', 'scint', 'ROI1', 'ROI2']}},\n", " 'name': 'primary',\n", " 'object_keys': {'m1': ['m1', 'm1_user_setpoint'],\n", " 'scaler': ['clock',\n", " 'I0',\n", " 'scint',\n", " 'ROI1',\n", " 'ROI2',\n", " 'scaler_time']},\n", " 'run_start': '4c2e9fe2-3bed-4ae4-99e9-66f0cd006a67',\n", " 'time': 1616788930.7834864,\n", " 'uid': 'ce49e916-9b27-4c69-b7ba-985eb9455755'}\n", "\n", "event 7\n", "{'data': {'I0': 5.0,\n", " 'ROI1': 0.0,\n", " 'ROI2': 0.0,\n", " 'clock': 11000000.0,\n", " 'm1': -1.0,\n", " 'm1_user_setpoint': -1.0,\n", " 'scaler_time': 1.1,\n", " 'scint': 7.0},\n", " 'descriptor': 'ce49e916-9b27-4c69-b7ba-985eb9455755',\n", " 'filled': {},\n", " 'seq_num': 1,\n", " 'time': 1616788932.3618796,\n", " 'timestamps': {'I0': 1616788930.753993,\n", " 'ROI1': 1616788930.753993,\n", " 'ROI2': 1616788930.753993,\n", " 'clock': 1616788930.753993,\n", " 'm1': 1616788929.514959,\n", " 'm1_user_setpoint': 1616788927.22893,\n", " 'scaler_time': 1616788930.753993,\n", " 'scint': 1616788930.753993},\n", " 'uid': '7f4b54e7-aee5-4be1-846b-9719779461dd'}\n", "\n", "event 7\n", "{'data': {'I0': 4.0,\n", " 'ROI1': 0.0,\n", " 'ROI2': 0.0,\n", " 'clock': 11000000.0,\n", " 'm1': -0.5,\n", " 'm1_user_setpoint': -0.5,\n", " 'scaler_time': 1.1,\n", " 'scint': 5.0},\n", " 'descriptor': 'ce49e916-9b27-4c69-b7ba-985eb9455755',\n", " 'filled': {},\n", " 'seq_num': 2,\n", " 'time': 1616788934.5606568,\n", " 'timestamps': {'I0': 1616788934.557644,\n", " 'ROI1': 1616788934.557644,\n", " 'ROI2': 1616788934.557644,\n", " 'clock': 1616788934.557644,\n", " 'm1': 1616788933.318452,\n", " 'm1_user_setpoint': 1616788932.547789,\n", " 'scaler_time': 1616788934.557644,\n", " 'scint': 1616788934.557644},\n", " 'uid': '2a90c5a5-fff1-4942-928c-a9e0bd4becbb'}\n", "\n", "event 7\n", "{'data': {'I0': 4.0,\n", " 'ROI1': 0.0,\n", " 'ROI2': 0.0,\n", " 'clock': 11000000.0,\n", " 'm1': 0.0,\n", " 'm1_user_setpoint': 0.0,\n", " 'scaler_time': 1.1,\n", " 'scint': 4.0},\n", " 'descriptor': 'ce49e916-9b27-4c69-b7ba-985eb9455755',\n", " 'filled': {},\n", " 'seq_num': 3,\n", " 'time': 1616788936.666957,\n", " 'timestamps': {'I0': 1616788936.659936,\n", " 'ROI1': 1616788936.659936,\n", " 'ROI2': 1616788936.659936,\n", " 'clock': 1616788936.659936,\n", " 'm1': 1616788935.420564,\n", " 'm1_user_setpoint': 1616788934.689949,\n", " 'scaler_time': 1616788936.659936,\n", " 'scint': 1616788936.659936},\n", " 'uid': '46c7dd78-8e97-4c6b-88d8-c4863eb9fa82'}\n", "\n", "event 7\n", "{'data': {'I0': 5.0,\n", " 'ROI1': 0.0,\n", " 'ROI2': 0.0,\n", " 'clock': 11000000.0,\n", " 'm1': 0.5,\n", " 'm1_user_setpoint': 0.5,\n", " 'scaler_time': 1.1,\n", " 'scint': 4.0},\n", " 'descriptor': 'ce49e916-9b27-4c69-b7ba-985eb9455755',\n", " 'filled': {},\n", " 'seq_num': 4,\n", " 'time': 1616788938.7730787,\n", " 'timestamps': {'I0': 1616788938.764486,\n", " 'ROI1': 1616788938.764486,\n", " 'ROI2': 1616788938.764486,\n", " 'clock': 1616788938.764486,\n", " 'm1': 1616788937.522629,\n", " 'm1_user_setpoint': 1616788936.7736,\n", " 'scaler_time': 1616788938.764486,\n", " 'scint': 1616788938.764486},\n", " 'uid': '83daa851-cb42-4a48-9db7-560351b22822'}\n", "\n", "event 7\n", "{'data': {'I0': 5.0,\n", " 'ROI1': 0.0,\n", " 'ROI2': 0.0,\n", " 'clock': 11000000.0,\n", " 'm1': 1.0,\n", " 'm1_user_setpoint': 1.0,\n", " 'scaler_time': 1.1,\n", " 'scint': 3.0},\n", " 'descriptor': 'ce49e916-9b27-4c69-b7ba-985eb9455755',\n", " 'filled': {},\n", " 'seq_num': 5,\n", " 'time': 1616788940.876002,\n", " 'timestamps': {'I0': 1616788940.868264,\n", " 'ROI1': 1616788940.868264,\n", " 'ROI2': 1616788940.868264,\n", " 'clock': 1616788940.868264,\n", " 'm1': 1616788939.625246,\n", " 'm1_user_setpoint': 1616788938.91205,\n", " 'scaler_time': 1616788940.868264,\n", " 'scint': 1616788940.868264},\n", " 'uid': '117933b5-15a4-4579-808b-33084918b8ea'}\n", "\n", "stop 6\n", "{'exit_status': 'success',\n", " 'num_events': {'primary': 5},\n", " 'reason': '',\n", " 'run_start': '4c2e9fe2-3bed-4ae4-99e9-66f0cd006a67',\n", " 'time': 1616788941.0154452,\n", " 'uid': '1273fd74-9c1d-4ca0-b435-d9874394ef1c'}\n" ] }, { "data": { "text/plain": [ "('4c2e9fe2-3bed-4ae4-99e9-66f0cd006a67',)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bp.scan([scaler], m1, -1, 1, 5), myCallback)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "We'll show this code as a python program:\n", "\n", "```\n", "#!/usr/bin/env python\n", "\n", "\"lesson 2: motor\"\n", "\n", "from ophyd import EpicsMotor\n", "from ophyd.scaler import ScalerCH\n", "from bluesky import RunEngine\n", "import bluesky.plans as bp\n", "from apstools.devices import use_EPICS_scaler_channels\n", "\n", "\n", "def myCallback(key, doc):\n", " print()\n", " print(key, len(doc))\n", " pprint.pprint(doc)\n", "\n", "\n", "m1 = EpicsMotor(\"sky:m1\", name=\"m1\")\n", "m1.wait_for_connection()\n", "print(m1.position)\n", "\n", "scaler = ScalerCH(\"sky:scaler1\", name=\"scaler\")\n", "scaler.wait_for_connection()\n", "\n", "\n", "# Since there are no detectors actually connected to this scaler,\n", "# we can change names at our choice. A real scaler will have\n", "# detectors connected to specific channels and we should not modify\n", "# these names without regard to how signals are physically connected.\n", "scaler.channels.chan01.chname.put(\"clock\")\n", "scaler.channels.chan02.chname.put(\"I0\")\n", "scaler.channels.chan03.chname.put(\"scint\")\n", "scaler.channels.chan04.chname.put(\"\")\n", "scaler.channels.chan05.chname.put(\"\")\n", "scaler.channels.chan06.chname.put(\"\")\n", "scaler.channels.chan07.chname.put(\"\")\n", "scaler.channels.chan08.chname.put(\"\")\n", "scaler.channels.chan09.chname.put(\"\")\n", "\n", "\n", "scaler.match_names()\n", "use_EPICS_scaler_channels(scaler)\n", "print(scaler.read())\n", "\n", "RE = RunEngine({})\n", "\n", "RE(bp.scan([scaler], m1, -1, 1, 5))\n", "\n", "RE(bp.scan([scaler], m1, -1, 1, 5), myCallback)\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8-final" } }, "nbformat": 4, "nbformat_minor": 2 }