instrument.utils
¶
Add Python modules here that provide any other code not covered by callbacks, configs, core, devices, or plans.
APS utility helper functions |
|
EPICS & ophyd related setup |
|
Generic utility helper functions |
|
Load configuration files |
|
Configure logging for this session. |
|
RunEngine Metadata |
|
Storage-backed Dictionary |
APS utility helper functions¶
Detect if this host is on an APS subnet. |
|
|
APS Data Management setup |
- instrument.utils.aps_functions.aps_dm_setup(dm_setup_file)[source]¶
APS Data Management setup¶
Read the bash shell script file used by DM to setup the environment. Parse any
export
lines and add their environment variables to this session. This is done by brute force here since the APS DM environment setup requires different Python code than bluesky and the two often clash.This setup must be done before any of the DM package libraries are called.
- instrument.utils.aps_functions.host_on_aps_subnet()[source]¶
Detect if this host is on an APS subnet.
- instrument.utils.controls_setup.connect_scan_id_pv(RE, pv: str = None)[source]¶
Define a PV to use for the RunEngine’s scan_id.
- instrument.utils.controls_setup.epics_scan_id_source(_md)[source]¶
Callback function for RunEngine. Returns next scan_id to be used.
Ignore metadata dictionary passed as argument.
Get current scan_id from PV.
Apply lower limit of zero.
Increment (so that scan_id numbering starts from 1).
Set PV with new value.
Return new value.
Exception will be raised if PV is not connected when next
bps.open_run()
is called.
- instrument.utils.controls_setup.oregistry¶
Registry of all ophyd-style Devices and Signals.
- instrument.utils.controls_setup.set_control_layer(control_layer: str = 'PyEpics')[source]¶
Communications library between ophyd and EPICS Channel Access.
Choices are: PyEpics (default) or caproto.
OPHYD_CONTROL_LAYER is an application of “lessons learned.”
Only used in a couple rare cases where PyEpics code was failing. It’s defined here since it was difficult to find how to do this in the ophyd documentation.
- instrument.utils.controls_setup.set_timeouts()[source]¶
Set default timeout for all EpicsSignal connections & communications.
Generic utility helper functions¶
The Bluesky Magick functions are useful with command-lines. |
|
Detect if running in the bluesky queueserver. |
|
Matplotlib setup based on environment (Notebook or non-Notebook). |
|
Detect if running in a notebook. |
- instrument.utils.helper_functions.mpl_setup()[source]¶
Matplotlib setup based on environment (Notebook or non-Notebook).
- instrument.utils.helper_functions.register_bluesky_magics()[source]¶
The Bluesky Magick functions are useful with command-lines.
- instrument.utils.helper_functions.running_in_queueserver()[source]¶
Detect if running in the bluesky queueserver.
Load configuration files¶
Load supported configuration files, such as iconfig.yml
.
|
Load iconfig.yml (and other YAML) configuration files. |
Configuration file version too old. |
- exception instrument.utils.config_loaders.IConfigFileVersionError[source]¶
Bases:
ValueError
Configuration file version too old.
- instrument.utils.config_loaders.load_config_yaml(iconfig_yml=None) dict [source]¶
Load iconfig.yml (and other YAML) configuration files.
Parameters¶
- iconfig_yml: str
Name of the YAML file to be loaded. The name can be absolute or relative to the current working directory. Default:
INSTRUMENT/configs/iconfig.yml
Configure logging for this session.
Public
Configure logging as described in file. |
Internal
|
Reconfigure the root logger as configured by the user. |
|
Record log messages in file(s). |
|
Internal: Log IPython console session In and Out to a file. |
Internal: Set logging level for each named module. |
- instrument.utils.logging_setup._setup_console_logger(logger, cfg)[source]¶
Reconfigure the root logger as configured by the user.
We can’t apply user configurations in
configure_logging()
above because the code to read the config file triggers initialization of the logging system.
- instrument.utils.logging_setup._setup_file_logger(logger, cfg)[source]¶
Record log messages in file(s).
- instrument.utils.logging_setup._setup_ipython_logger(logger, cfg)[source]¶
Internal: Log IPython console session In and Out to a file.
See
logrotate?
int he IPython console for more information.
- instrument.utils.logging_setup._setup_module_logging(cfg)[source]¶
Internal: Set logging level for each named module.
- instrument.utils.logging_setup.addLoggingLevel(levelName, levelNum, methodName=None)[source]¶
Comprehensively adds a new logging level to the logging module and the currently configured logging class.
levelName becomes an attribute of the logging module with the value levelNum. methodName becomes a convenience method for both logging itself and the class returned by logging.getLoggerClass() (usually just logging.Logger). If methodName is not specified, levelName.lower() is used.
To avoid accidental clobberings of existing attributes, this method will raise an AttributeError if the level name is already an attribute of the logging module or if the method name is already present
Example¶
>>> addLoggingLevel('TRACE', logging.INFO - 5) >>> logging.getLogger(__name__).setLevel("TEST") >>> logging.getLogger(__name__).test('that worked') >>> logging.test('so did this') >>> logging.TEST 5
RunEngine Metadata¶
PersistentDict Directory to save RE metadata between sessions. |
|
Get PersistentDict directory for RE metadata. |
|
|
Programmatic metadata for the RunEngine. |
- instrument.utils.metadata.MD_PATH = '.re_md_dict.yml'¶
PersistentDict Directory to save RE metadata between sessions.
Storage-backed Dictionary¶
A dictionary that writes its contents to YAML file.
Replaces bluesky.utils.PersistentDict
.
Contents must be JSON serializable.
Contents stored in a single human-readable YAML file.
Sync to disk shortly after dictionary is updated.
|
Dictionary that syncs to storage. |
- class instrument.utils.stored_dict.StoredDict(file, delay=5, title=None, serializable=True)[source]¶
Bases:
MutableMapping
Dictionary that syncs to storage.
flush
()Force a write of the dictionary to disk
popitem
()Remove and return a (key, value) pair as a 2-tuple.
reload
()Read dictionary from storage.
Static methods
All support for the YAML format is implemented in the static methods.
dump
(file, contents[, title])Write dictionary to YAML file.
load
(file)Read dictionary from YAML file.
- __init__(file, delay=5, title=None, serializable=True)[source]¶
StoredDict : Dictionary that syncs to storage
PARAMETERS
- filestr or pathlib.Path
Name of file to store dictionary contents.
- delaynumber
Time delay (s) since last dictionary update to write to storage. Default: 5 seconds.
- titlestr or None
Comment to write at top of file. Default: “Written by StoredDict.”
- serializablebool
If True, validate new dictionary entries are JSON serializable.
- _abc_impl = <_abc._abc_data object>¶
- _delayed_sync_to_storage()[source]¶
Sync the metadata to storage.
Start a time-delay thread. New writes to the metadata dictionary will extend the deadline. Sync once the deadline is reached.