{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "e7e492f4", "metadata": {}, "source": [ "# Review of Bluesky commands\n", "\n", "From *APS Python Training for Bluesky Data Acquisition*.\n", "\n", "**Objective**\n", "\n", "In this notebook, the commands described in the [Bluesky Cheat Sheet](../howto/bluesky_cheat_sheet.md), are demonstrated using the `instrument` package.\n", "\n", "## Start the `instrument` package\n", "\n", "Our instrument package is in the `bluesky` subdirectory here so we add that to the search path before importing it." ] }, { "cell_type": "code", "execution_count": 1, "id": "5ac0bb03", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/prjemian/bluesky/instrument/_iconfig.py\n", "Activating auto-logging. Current session state plus future input saved.\n", "Filename : /home/prjemian/Documents/projects/BCDA-APS/bluesky_training/docs/source/reference/.logs/ipython_console.log\n", "Mode : rotate\n", "Output logging : True\n", "Raw input log : False\n", "Timestamping : True\n", "State : active\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "I Thu-14:38:42 - ############################################################ startup\n", "I Thu-14:38:42 - logging started\n", "I Thu-14:38:42 - logging level = 10\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/session_logs.py\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/collection.py\n", "I Thu-14:38:42 - CONDA_PREFIX = /home/prjemian/.conda/envs/bluesky_2023_2\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Exception reporting mode: Minimal\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "I Thu-14:38:42 - xmode exception level: 'Minimal'\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/mpl/notebook.py\n", "I Thu-14:38:42 - #### Bluesky Framework ####\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/framework/check_python.py\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/framework/check_bluesky.py\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/framework/initialize.py\n", "I Thu-14:38:42 - RunEngine metadata saved in directory: /home/prjemian/Bluesky_RunEngine_md\n", "I Thu-14:38:42 - using databroker catalog 'training'\n", "I Thu-14:38:42 - using ophyd control layer: pyepics\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/framework/metadata.py\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/epics_signal_config.py\n", "I Thu-14:38:42 - Using RunEngine metadata for scan_id\n", "I Thu-14:38:42 - #### Devices ####\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/devices/area_detector.py\n", "I Thu-14:38:42 - /home/prjemian/bluesky/instrument/devices/calculation_records.py\n", "I Thu-14:38:44 - /home/prjemian/bluesky/instrument/devices/fourc_diffractometer.py\n", "I Thu-14:38:44 - /home/prjemian/bluesky/instrument/devices/ioc_stats.py\n", "I Thu-14:38:44 - /home/prjemian/bluesky/instrument/devices/kohzu_monochromator.py\n", "I Thu-14:38:44 - /home/prjemian/bluesky/instrument/devices/motors.py\n", "I Thu-14:38:45 - /home/prjemian/bluesky/instrument/devices/noisy_detector.py\n", "I Thu-14:38:45 - /home/prjemian/bluesky/instrument/devices/scaler.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/shutter_simulator.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/simulated_fourc.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/simulated_kappa.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/slits.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/sixc_diffractometer.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/devices/temperature_signal.py\n", "I Thu-14:38:46 - #### Callbacks ####\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/callbacks/spec_data_file_writer.py\n", "I Thu-14:38:46 - #### Plans ####\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/plans/lup_plan.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/plans/peak_finder_example.py\n", "I Thu-14:38:46 - /home/prjemian/bluesky/instrument/utils/image_analysis.py\n", "I Thu-14:38:46 - #### Utilities ####\n", "I Thu-14:38:46 - writing to SPEC file: /home/prjemian/Documents/projects/BCDA-APS/bluesky_training/docs/source/reference/20230413-143846.dat\n", "I Thu-14:38:46 - >>>> Using default SPEC file name <<<<\n", "I Thu-14:38:46 - file will be created when bluesky ends its next scan\n", "I Thu-14:38:46 - to change SPEC file, use command: newSpecFile('title')\n", "I Thu-14:38:46 - #### Startup is complete. ####\n" ] } ], "source": [ "import pathlib, sys\n", "sys.path.append(str(pathlib.Path.home() / \"bluesky\"))\n", "from instrument.collection import *" ] }, { "attachments": {}, "cell_type": "markdown", "id": "4db0ba24", "metadata": {}, "source": [ "## List, Describe, Summary\n", "\n", "On the command line, there is an [IPython magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#built-in-magic-commands) command from the [bluesky](https://blueskyproject.io/bluesky/) package to print the current value of [labeled](https://blueskyproject.io/bluesky/magics.html?highlight=label) items: [%wa](https://blueskyproject.io/bluesky/magics.html#listing-available-motors-using-wa-post-v1-3-0)" ] }, { "cell_type": "code", "execution_count": 2, "id": "151e36f2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "area_detector\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " adsimdet adsimdet \n", "\n", "motor\n", " Positioner Value Low Limit High Limit Offset \n", " dcm_m_theta 0.0 -1000.0 1000.0 0.0 \n", " dcm_m_y 0.0 -1000.0 1000.0 0.0 \n", " dcm_m_z 0.0 -1000.0 1000.0 0.0 \n", " fourc_chi 0.0 -1000.0 1000.0 0.0 \n", " fourc_omega 0.0 -1000.0 1000.0 0.0 \n", " fourc_phi 0.0 -1000.0 1000.0 0.0 \n", " fourc_tth 0.0 -1000.0 1000.0 0.0 \n", " m1 1.0 -1000.0 1000.0 0.0 \n", " m10 0.0 -1000.0 1000.0 0.0 \n", " m11 0.0 -1000.0 1000.0 0.0 \n", " m12 0.0 -1000.0 1000.0 0.0 \n", " m13 0.0 -1000.0 1000.0 0.0 \n", " m14 0.0 -1000.0 1000.0 0.0 \n", " m15 0.0 -1000.0 1000.0 0.0 \n", " m16 0.0 -1000.0 1000.0 0.0 \n", " m2 6.0 -1000.0 1000.0 0.0 \n", " m3 0.0 -1000.0 1000.0 0.0 \n", " m4 0.0 -1000.0 1000.0 0.0 \n", " m7 0.0 -1000.0 1000.0 0.0 \n", " m8 0.0 -1000.0 1000.0 0.0 \n", " m9 0.0 -1000.0 1000.0 0.0 \n", " sixc_chi 0.0 -1000.0 1000.0 0.0 \n", " sixc_delta 0.0 -1000.0 1000.0 0.0 \n", " sixc_gamma 0.0 -1000.0 1000.0 0.0 \n", " sixc_mu 0.0 -1000.0 1000.0 0.0 \n", " sixc_omega 0.0 -1000.0 1000.0 0.0 \n", " sixc_phi 0.0 -1000.0 1000.0 0.0 \n", "\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " dcm.m_theta dcm_m_theta \n", " dcm.m_y dcm_m_y \n", " dcm.m_z dcm_m_z \n", " fourc.chi fourc_chi \n", " fourc.omega fourc_omega \n", " fourc.phi fourc_phi \n", " fourc.tth fourc_tth \n", " m1 m1 \n", " m10 m10 \n", " m11 m11 \n", " m12 m12 \n", " m13 m13 \n", " m14 m14 \n", " m15 m15 \n", " m16 m16 \n", " m2 m2 \n", " m3 m3 \n", " m4 m4 \n", " m7 m7 \n", " m8 m8 \n", " m9 m9 \n", " sixc.chi sixc_chi \n", " sixc.delta sixc_delta \n", " sixc.gamma sixc_gamma \n", " sixc.mu sixc_mu \n", " sixc.omega sixc_omega \n", " sixc.phi sixc_phi \n", "\n", "detectors\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " noisy noisy \n", " scaler1 scaler1 \n", "\n", "simulator\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " noisy noisy \n", "\n", "scalers\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " scaler1 scaler1 \n", "\n", "counter\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " I0 I0 \n", " I00 I00 \n", " I000 I000 \n", " diode scint \n", " scaler1.channels.chan01.s timebase \n", " scaler1.channels.chan02.s I0 \n", " scaler1.channels.chan04.s scint \n", " scaler1.channels.chan05.s I000 \n", " scaler1.channels.chan06.s I00 \n", " scint scint \n", " timebase timebase \n", "\n", "channel\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " I0 I0 \n", " I00 I00 \n", " I000 I000 \n", " diode scint \n", " scaler1.channels.chan01.s timebase \n", " scaler1.channels.chan02.s I0 \n", " scaler1.channels.chan04.s scint \n", " scaler1.channels.chan05.s I000 \n", " scaler1.channels.chan06.s I00 \n", " scint scint \n", " timebase timebase \n", "\n", "shutters\n", " Local variable name Ophyd name (to be recorded as metadata)\n", " shutter shutter \n", "\n" ] } ], "source": [ "%wa" ] }, { "attachments": {}, "cell_type": "markdown", "id": "f47d2f44", "metadata": {}, "source": [ "Might be a good idea to know now what ophyd symbols are available. The [apstools](https://bcda-aps.github.io/apstools/latest/) package provides a [listobjects()](https://bcda-aps.github.io/apstools/latest/api/_utils.html#apstools.utils.misc.listobjects) command that prints a table of all the known objects (in the global namespace of the session). The columns provide the ophyd name (the name you use to call this in Python), the name of the ophyd structure, the EPICS PV (if relevant), and any labels (as used in `%wa` above)." ] }, { "cell_type": "code", "execution_count": 3, "id": "d5375463", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "=========== ================================ ============== ===================\n", "name class PV (or prefix) label(s) \n", "=========== ================================ ============== ===================\n", "I0 EpicsSignalRO gp:scaler1.S2 counter channel \n", "I00 EpicsSignalRO gp:scaler1.S6 counter channel \n", "I000 EpicsSignalRO gp:scaler1.S5 counter channel \n", "adsimdet SimDetector_V34 ad: area_detector \n", "calcouts UserCalcoutDevice gp: \n", "calcs UserCalcsDevice gp: \n", "dcm MyKohzu gp: \n", "diode EpicsSignalRO gp:scaler1.S4 counter channel \n", "fourc FourCircle gp: \n", "gp_stats IocInfoDevice gp: \n", "m1 MyEpicsMotor gp:m1 motor \n", "m10 MyEpicsMotor gp:m10 motor \n", "m11 MyEpicsMotor gp:m11 motor \n", "m12 MyEpicsMotor gp:m12 motor \n", "m13 MyEpicsMotor gp:m13 motor \n", "m14 MyEpicsMotor gp:m14 motor \n", "m15 MyEpicsMotor gp:m15 motor \n", "m16 MyEpicsMotor gp:m16 motor \n", "m2 MyEpicsMotor gp:m2 motor \n", "m3 MyEpicsMotor gp:m3 motor \n", "m4 MyEpicsMotor gp:m4 motor \n", "m7 MyEpicsMotor gp:m7 motor \n", "m8 MyEpicsMotor gp:m8 motor \n", "m9 MyEpicsMotor gp:m9 motor \n", "noisy EpicsSignalRO gp:userCalc1 detectors simulator\n", "scaler1 ScalerCH gp:scaler1 detectors scalers \n", "scint EpicsSignalRO gp:scaler1.S3 counter channel \n", "shutter SimulatedApsPssShutterWithStatus shutters \n", "sim4c SimulatedE4CV \n", "simk4c SimulatedK4CV \n", "simk6c SimulatedK6C \n", "sixc SixCircle gp: \n", "slit1 Optics2Slit2D_HV gp:Slit1 \n", "temperature MyPvPositioner gp:userCalc8 \n", "timebase EpicsSignalRO gp:scaler1.S1 counter channel \n", "=========== ================================ ============== ===================" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "listobjects()" ] }, { "attachments": {}, "cell_type": "markdown", "id": "21f61edd", "metadata": {}, "source": [ "## Read\n", "\n", "We'll use the `temperature` and `m1` objects to demonstrate the various commands described in the [cheat sheet](https://bcda-aps.github.io/bluesky_training/howto/bluesky_cheat_sheet.html)\n", "\n", "command | description\n", "--- | ---\n", "`OBJECT.summary()` | more information about `OBJECT`\n", "`OBJECT.get()` | low-level command to show value of ophyd *Signal* named `OBJECT`\n", "`OBJECT.read()` | data acquisition command, includes timestamp\n", "`listdevice(OBJECT)` | table-version of `.read()`\n", "`MOTOR.position` | get readback, only for motor objects\n", "`MOTOR.user_readback.get()` | alternative to `MOTOR.position`" ] }, { "attachments": {}, "cell_type": "markdown", "id": "6f4abd20", "metadata": {}, "source": [ "### temperature" ] }, { "cell_type": "code", "execution_count": 4, "id": "239dc9ca", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "data keys (* hints)\n", "-------------------\n", "*temperature\n", " temperature_calculation\n", " temperature_description\n", " temperature_done\n", " temperature_max_change\n", " temperature_noise\n", " temperature_previous_value_pv\n", " temperature_scanning_rate\n", " temperature_setpoint\n", " temperature_tolerance\n", "\n", "read attrs\n", "----------\n", "setpoint EpicsSignal ('temperature_setpoint')\n", "readback EpicsSignal ('temperature')\n", "done Signal ('temperature_done')\n", "calculation EpicsSignal ('temperature_calculation')\n", "description EpicsSignal ('temperature_description')\n", "max_change EpicsSignal ('temperature_max_change')\n", "noise EpicsSignal ('temperature_noise')\n", "previous_value_pv EpicsSignal ('temperature_previous_value_pv')\n", "scanning_rate EpicsSignal ('temperature_scanning_rate')\n", "tolerance EpicsSignal ('temperature_tolerance')\n", "\n", "config keys\n", "-----------\n", "\n", "configuration attrs\n", "-------------------\n", "\n", "unused attrs\n", "------------\n", "report_dmov_changes Signal ('temperature_report_dmov_changes')\n", "\n" ] } ], "source": [ "temperature.summary()" ] }, { "cell_type": "code", "execution_count": 5, "id": "4eea967a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "temperature.readback.get()" ] }, { "cell_type": "code", "execution_count": 6, "id": "cfde1030", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('temperature_setpoint',\n", " {'value': 25.0, 'timestamp': 1681414726.718176}),\n", " ('temperature', {'value': 25.0, 'timestamp': 1681414726.721922}),\n", " ('temperature_done',\n", " {'value': True, 'timestamp': 1681414726.7284272}),\n", " ('temperature_calculation',\n", " {'value': 'A+max(-D,min(D,(B-A)))+C*(RNDM-0.5)',\n", " 'timestamp': 1681414726.723668}),\n", " ('temperature_description',\n", " {'value': 'temperature', 'timestamp': 1681414726.716164}),\n", " ('temperature_max_change',\n", " {'value': 2.0, 'timestamp': 1681414726.7226}),\n", " ('temperature_noise',\n", " {'value': 1.0, 'timestamp': 1681414726.721922}),\n", " ('temperature_previous_value_pv',\n", " {'value': 'gp:userCalc8.VAL', 'timestamp': 1681414726.716164}),\n", " ('temperature_scanning_rate',\n", " {'value': 5, 'timestamp': 1681414726.723668}),\n", " ('temperature_tolerance',\n", " {'value': 1.0, 'timestamp': 1681414726.723668})])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "temperature.read()" ] }, { "cell_type": "code", "execution_count": 7, "id": "4a74714a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "=============================== =================================== ==========================\n", "data name value timestamp \n", "=============================== =================================== ==========================\n", "temperature_setpoint 25.0 2023-04-13 14:38:46.718176\n", "temperature 25.0 2023-04-13 14:38:46.721922\n", "temperature_done True 2023-04-13 14:38:46.728427\n", "temperature_calculation A+max(-D,min(D,(B-A)))+C*(RNDM-0.5) 2023-04-13 14:38:46.723668\n", "temperature_description temperature 2023-04-13 14:38:46.716164\n", "temperature_max_change 2.0 2023-04-13 14:38:46.722600\n", "temperature_noise 1.0 2023-04-13 14:38:46.721922\n", "temperature_previous_value_pv gp:userCalc8.VAL 2023-04-13 14:38:46.716164\n", "temperature_scanning_rate 5 2023-04-13 14:38:46.723668\n", "temperature_tolerance 1.0 2023-04-13 14:38:46.723668\n", "temperature_report_dmov_changes False 2023-04-13 14:38:46.717620\n", "=============================== =================================== ==========================" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "listdevice(temperature)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "2787ce8f", "metadata": {}, "source": [ "### motor" ] }, { "cell_type": "code", "execution_count": 8, "id": "c0b06328", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1.position" ] }, { "cell_type": "code", "execution_count": 9, "id": "757c4b74", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1.user_readback.get()" ] }, { "attachments": {}, "cell_type": "markdown", "id": "57c0a944", "metadata": {}, "source": [ "## Move\n", "command | mode | description\n", "--- | --- | ---\n", "`%mov MOTOR value` | command line | interactive command move MOTOR to value (command line only)\n", "`%movr MOTOR value` | command line | interactive command relative move (command line only)\n", "`MOTOR.move(value)` | ophyd command | `%mov`\n", "`MOTOR.user_setpoint.put(value)` | ophyd | set motor `.VAL` field but not wait\n", "`bps.mv(MOTOR, value)` | bluesky plan | move and wait for completion\n", "`bps.mv(MOTOR.user_setpoint, value)` | bluesky plan | same\n", "`bps.mvr(MOTOR, value)` | bluesky plan | relative move" ] }, { "cell_type": "code", "execution_count": 10, "id": "edaf4ab3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "m1: 35%|█████████▎ | 0.1905/0.55 [00:00<00:00, 1.71degrees/s]\n", "m1: 70%|███████████████████ | 0.3873/0.55 [00:00<00:00, 1.83degrees/s]\n", "m1: 94%|█████████████████████████▎ | 0.5158/0.55 [00:00<00:00, 1.64degrees/s]\n", "m1: 100%|█████████████████████████████| 0.55/0.55 [00:00<00:00, 1.33degrees/s]\n", "m1 [In progress. No progress bar available.] \n", " \n" ] }, { "data": { "text/plain": [ "1.55" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%mov m1 1.55\n", "m1.position" ] }, { "cell_type": "code", "execution_count": 11, "id": "3b8ddade", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "m1: 100%|███████████████████████████▉| 0.0999/0.1 [00:00<00:00, 1.63s/degrees]\n", "m1: 100%|███████████████████████████████| 0.1/0.1 [00:00<00:00, 2.63s/degrees]\n", "m1 [In progress. No progress bar available.] \n", " \n" ] }, { "data": { "text/plain": [ "1.4500000000000002" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%movr m1 -.1\n", "m1.position" ] }, { "cell_type": "code", "execution_count": 12, "id": "7702c341", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1.move(.5)\n", "m1.position" ] }, { "cell_type": "code", "execution_count": 13, "id": "2b7dfc58", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.5, 0.0)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1.user_setpoint.put(0)\n", "m1.position, m1.user_setpoint.get()" ] }, { "cell_type": "code", "execution_count": 14, "id": "e85e0de1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "temperature: 58%|█████████████▊ | 0.396/0.687 [00:01<00:00, 2.78s/C]\n", "temperature [In progress. No progress bar available.] \n", " \n" ] } ], "source": [ "%mov temperature 26" ] }, { "cell_type": "code", "execution_count": 15, "id": "9c414584", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "m1: 81%|██████████████████████▌ | 0.1616/0.2 [00:00<00:00, 1.27degrees/s]\n", "\n", "m1: 100%|███████████████████████████████| 0.2/0.2 [00:00<00:00, 1.15s/degrees]\n", "\n", "m1 [In progress. No progress bar available.] \n", "\n", "m1 [In progress. No progress bar available.] \n", "temperature: 100%|████████████████████████████| 1.0/1.0 [00:01<00:00, 1.93s/C]\n", "m1 [In progress. No progress bar available.] \n", "temperature [In progress. No progress bar available.] \n", " \n", " \n" ] }, { "data": { "text/plain": [ "(24.23994811932555, 0.2)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%movr temperature -1 m1 .2\n", "temperature.position, m1.position" ] }, { "attachments": {}, "cell_type": "markdown", "id": "768c32d3", "metadata": {}, "source": [ "### bluesky" ] }, { "cell_type": "code", "execution_count": 16, "id": "01481477", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bps.mv(m1, 1))\n", "m1.position" ] }, { "cell_type": "code", "execution_count": 17, "id": "1ac7a550", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.1" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bps.mvr(m1, .1))\n", "m1.position" ] }, { "cell_type": "code", "execution_count": 18, "id": "cacd689e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1.1, 24.23994811932555)" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bps.mv(m1.user_setpoint, 1, temperature.setpoint, 25))\n", "m1.position, temperature.position" ] }, { "attachments": {}, "cell_type": "markdown", "id": "fda669c4", "metadata": {}, "source": [ "## Count\n", "\n", "command | description\n", "--- | ---\n", "`%ct` | count _all_ objects with label `detectors` and format output (command line only)\n", "`SCALER.trigger().wait(); SCALER.read()` | ophyd command to count SCALER\n", "`bp.count([SCALER])` | bluesky plan to count\n", "\n", "Count time setting is different for various types of detectors:\n", "\n", "detector | set count time\n", "--- | ---\n", "scaler | `SCALER.preset_time.put(COUNT_TIME_S)`\n", "area detector | `AD.cam.acquire_time.put(COUNT_TIME_S)`" ] }, { "cell_type": "code", "execution_count": 19, "id": "88387e0b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[This data will not be saved. Use the RunEngine to collect data.]\n", "noisy 34560.47582292199\n", "timebase 16000000.0\n", "I0 9.0\n", "scint 6.0\n", "I000 8.0\n", "I00 5.0\n", "roi1 7.0\n", "scaler1_time 1.6\n" ] } ], "source": [ "%ct" ] }, { "cell_type": "code", "execution_count": 20, "id": "6922146a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[This data will not be saved. Use the RunEngine to collect data.]\n", "timebase 16000000.0\n", "I0 8.0\n", "scint 4.0\n", "I000 9.0\n", "I00 9.0\n", "roi1 8.0\n", "scaler1_time 1.6\n" ] } ], "source": [ "%ct scalers" ] }, { "cell_type": "code", "execution_count": 21, "id": "b5fc90ce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('timebase',\n", " {'value': 16000000.0, 'timestamp': 1681414738.568649}),\n", " ('I0', {'value': 7.0, 'timestamp': 1681414738.568649}),\n", " ('scint', {'value': 7.0, 'timestamp': 1681414738.568649}),\n", " ('I000', {'value': 7.0, 'timestamp': 1681414738.568649}),\n", " ('I00', {'value': 7.0, 'timestamp': 1681414738.568649}),\n", " ('roi1', {'value': 5.0, 'timestamp': 1681414738.568649}),\n", " ('scaler1_time', {'value': 1.6, 'timestamp': 1681414736.984263})])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler1.trigger().wait(); scaler1.read()" ] }, { "cell_type": "code", "execution_count": 22, "id": "bd9a636f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Transient Scan ID: 935 Time: 2023-04-13 14:38:58\n", "Persistent Unique Scan ID: '8cfb6fe7-0338-42af-9288-b3c4e2c7cb63'\n", "New stream: 'label_start_motor'\n", "New stream: 'primary'\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "| seq_num | time | timebase | I0 | scint | I000 | I00 | roi1 |\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "| 1 | 14:39:00.5 | 16000000 | 8 | 9 | 8 | 8 | 9 |\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "generator count ['8cfb6fe7'] (scan num: 935)\n" ] }, { "data": { "text/plain": [ "('8cfb6fe7-0338-42af-9288-b3c4e2c7cb63',)" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RE(bp.count([scaler1]))" ] }, { "cell_type": "code", "execution_count": 23, "id": "8ce7ba10", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Transient Scan ID: 936 Time: 2023-04-13 14:39:00\n", "Persistent Unique Scan ID: '3718e73c-d07a-4591-a41d-5979c3cd1b66'\n", "New stream: 'label_start_motor'\n", "New stream: 'primary'\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "| seq_num | time | timebase | I0 | scint | I000 | I00 | roi1 |\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "| 1 | 14:39:02.5 | 16000000 | 7 | 7 | 8 | 8 | 7 |\n", "+-----------+------------+------------+------------+------------+------------+------------+------------+\n", "generator count ['3718e73c'] (scan num: 936)\n" ] }, { "data": { "text/plain": [ "('3718e73c-d07a-4591-a41d-5979c3cd1b66',)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def my_plan():\n", " yield from bp.count([scaler1])\n", "\n", "RE(my_plan())" ] } ], "metadata": { "interpreter": { "hash": "fa399ef8ed4fbc3b7fe63ebf4307839a170374bf77134d519fcb3b724ac0582b" }, "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.10.10" } }, "nbformat": 4, "nbformat_minor": 5 }