Python scripts¶
Bluesky data acquisition can be written as Python command programs (scripts).
This example program shows the RunEngine’s metadata. Save it to a file (perhaps
named example.py
). Be sure to make the file executable. [1]
1#!/usr/bin/env python
2from instrument.startup import RE
3
4print(f"{dict(RE.md)=!r}")
Assuming you named this file example.py
, then run it (in the environment
with your bluesky installation). Note that $
is a command prompt. You don’t
type that.
1$ example.py
2I Mon-12:05:21.749: **************************************** startup
3I Mon-12:05:21.749: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/utils/logging_setup.py
4I Mon-12:05:21.749: Log file: /home/prjemian/Documents/projects/prjemian/model_instrument/.logs/logging.log
5I Mon-12:05:21.898: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/startup.py
6I Mon-12:05:21.898: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/utils/aps_functions.py
7I Mon-12:05:22.212: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/utils/helper_functions.py
8W Mon-12:05:22.284: APS DM setup file does not exist: '/home/dm/etc/dm.setup.sh'
9I Mon-12:05:22.411: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/core/best_effort_init.py
10I Mon-12:05:23.002: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/core/catalog_init.py
11I Mon-12:05:23.404: Databroker catalog: temp
12I Mon-12:05:23.405: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/utils/controls_setup.py
13I Mon-12:05:23.479: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/utils/metadata.py
14I Mon-12:05:23.479: RunEngine metadata saved in directory: /home/prjemian/.config/Bluesky_RunEngine_md
15I Mon-12:05:23.479: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/core/run_engine_init.py
16I Mon-12:05:23.482: using ophyd control layer: 'pyepics'
17I Mon-12:05:23.541: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/callbacks/spec_data_file_writer.py
18I Mon-12:05:23.541: SPEC data file: /home/prjemian/Documents/projects/prjemian/model_instrument/20241014-120523.dat
19I Mon-12:05:23.574: /home/prjemian/Documents/projects/prjemian/model_instrument/src/instrument/tests/sim_plans.py
20dict(RE.md)={'scan_id': 70, 'instrument_name': 'Most Glorious Scientific Instrument', 'login_id': 'prjemian@arf.jemian.org', 'conda_prefix': '/home/prjemian/.conda/envs/model_instrument_env', 'versions': {'apstools': '1.7.0', 'bluesky': '1.13', 'databroker': '1.2.5', 'epics': '3.5.7', 'h5py': '3.12.1', 'intake': '0.6.4', 'matplotlib': '3.9.2', 'numpy': '1.26.4', 'ophyd': '1.9.0', 'pyRestTable': '2020.0.10', 'python': '3.12.7', 'pysumreg': '1.0.6', 'spec2nexus': '2021.2.6'}, 'databroker_catalog': 'temp', 'iconfig': {'ICONFIG_VERSION': '2.0.0', 'DATABROKER_CATALOG': 'temp', 'RUN_ENGINE': {'DEFAULT_METADATA': {'beamline_id': 'instrument', 'instrument_name': 'Most Glorious Scientific Instrument', 'proposal_id': 'commissioning', 'databroker_catalog': 'temp'}, 'USE_PROGRESS_BAR': False}, 'AREA_DETECTOR': {'ALLOW_PLUGIN_WARMUP': True, 'BLUESKY_FILES_ROOT': '/path/to/data/', 'IMAGE_DIR': 'sub/directory/path', 'HDF5_FILE_TEMPLATE': '%s%s_%6.6d.h5'}, 'SPEC_DATA_FILES': {'FILE_EXTENSION': 'dat'}, 'DM_SETUP_FILE': '/home/dm/etc/dm.setup.sh', 'OPHYD': {'TIMEOUTS': {'PV_READ': 5, 'PV_WRITE': 5, 'PV_CONNECTION': 5}}, 'XMODE_DEBUG_LEVEL': 'Minimal'}, 'proposal_id': 'commissioning', 'pid': 3865585, 'beamline_id': 'instrument'}
Note
The first line is a linux shebang [2] that tells the
linux command processor to start this script with the
default python
executable in the current environment.