Skip to content

Commit

Permalink
check boom
Browse files Browse the repository at this point in the history
  • Loading branch information
ravescovi committed Jun 21, 2024
1 parent 9c3d0e4 commit f1f8f74
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 393 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ select = [
# "RUF"
]
ignore = [
"F401",
"F403",
"F405",
"E501" # Line too long
]

Expand Down
27 changes: 27 additions & 0 deletions scripts/ipython_startup.ipy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
import time

# import databroker # noqa: F401
# import matplotlib.pyplot as plt # noqa: F401
# from bluesky import (
# RunEngine, # noqa: F401
# suspenders, # noqa: F401
# )
# from bluesky import plan_stubs as bps # noqa: F401
# from bluesky import plans as bp # noqa: F401
# from bluesky.callbacks.best_effort import BestEffortCallback # noqa: F401
from IPython import get_ipython

import aps_8id_bs_instrument # noqa: F401
import aps_8id_bs_instrument.initialize # noqa: F401
from aps_8id_bs_instrument.collection import * # noqa


logging.basicConfig(level=logging.WARNING)

get_ipython().run_line_magic("xmode", "Minimal")

config = aps_8id_bs_instrument.iconfig
t0 = time.monotonic()
aps_8id_bs_instrument.initialize()
print(f"Finished initalization in {time.monotonic() - t0:.2f} seconds.")
26 changes: 0 additions & 26 deletions scripts/ipython_startup.py

This file was deleted.

22 changes: 16 additions & 6 deletions scripts/reset_instrument.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env bash


SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BASE_DIR=$SCRIPT_DIR/..

echo $BASE_DIR
cd $BASE_DIR
pwd

OLD_INSTRUMENT_PREFIX=aps_8id
NEW_INSTRUMENT_PREFIX=empty

OLD_INSTRUMENT_PREFIX = aps_8id
NEW_INSTRUMENT_PREFIX = empty
OLD_INSTRUMENT_NAME=${OLD_INSTRUMENT_PREFIX}_bs_instrument
NEW_INSTRUMENT_NAME=${NEW_INSTRUMENT_PREFIX}_bs_instrument
OLD_QS_NAME=${OLD_INSTRUMENT_PREFIX}_bs_qserver
NEW_QS_NAME=${NEW_INSTRUMENT_PREFIX}_bs_qserver

OLD_INSTRUMENT_NAME = {$OLD_INSTRUMENT_PREFIX}_bs_instrument
NEW_INSTRUMENT_NAME = {$NEW_INSTRUMENT_PREFIX}_bs_instrument
OLD_QS_NAME = {$OLD_INSTRUMENT_PREFIX}_bs_qserver
NEW_QS_NAME = {$NEW_INSTRUMENT_PREFIX}_bs_qserver

##remove extra folders
rm -rf .ruff_cache
rm -rf *.egg-info
rm -rf build
rm -rf __pycache__

##reset analysis folder
rm -rf ./src/$OLD_INSTRUMENT_NAME/analysis/*
Expand All @@ -41,6 +48,9 @@ mv src/$OLD_INSTRUMENT_NAME src/$NEW_INSTRUMENT_NAME
##rename qserver
mv src/$OLD_QS_NAME src/$NEW_QS_NAME

##rename absolute calls to the new package in scripts


##rename parts inside pyproject.toml
## line 2 name
## line 3 version back to 0.0.1
Expand Down
5 changes: 1 addition & 4 deletions scripts/user/Lambda2M_Test_bps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
%run -i ./user/Lambda2M_Test_bps.py
"""

from aps_8id_bs_instrument.collection import * # Yikes! Starts the bluesky instrument!
from aps_8id_bs_instrument.collection import *
from bluesky import plan_stubs as bps
from bluesky import plans as bp

# from aps_8id_bs_instrument.devices import * # imported with collection
# from aps_8id_bs_instrument.framework import RE # imported with collection


def Rep_Acq(acq_rep=3):
"""
Expand Down
5 changes: 2 additions & 3 deletions src/aps_8id_bs_instrument/_iconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from __future__ import annotations

__all__ = [
"load_config",
"iconfig",
]
import logging
Expand All @@ -27,7 +26,7 @@
print(__file__)


def load_config():
def load_config_yaml():
"""Load iconfig.yml config files."""

CONFIG_FILE = pathlib.Path(__file__).absolute().parent / "iconfig.yml"
Expand All @@ -43,4 +42,4 @@ def load_config():
return iconfig


iconfig = load_config()
iconfig = load_config_yaml()
1 change: 1 addition & 0 deletions src/aps_8id_bs_instrument/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Analysis files"""
4 changes: 2 additions & 2 deletions src/aps_8id_bs_instrument/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
if iconfig.get("WRITE_SPEC_DATA_FILES", False):
from .spec_data_file_writer import *

del iconfig

from .scan_signal_statistics import *

del iconfig
12 changes: 6 additions & 6 deletions src/aps_8id_bs_instrument/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import os

from apstools.utils import *
from apstools.utils import * # noqa
from IPython import get_ipython

from . import iconfig
from .callbacks import *
from .devices import *
from .initialize import *
from .plans import *
from .utils.mpl import *
from .callbacks import * # noqa
from .devices import * # noqa
from .initialize import * # noqa
from .plans import * # noqa
from .utils.mpl import * # noqa
from .utils.session_logs import logger

logger.info(__file__)
Expand Down
3 changes: 3 additions & 0 deletions src/aps_8id_bs_instrument/qserver/queueserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _chop(text):


def make_kv_table(data):
'''make kv table'''
table = pyRestTable.Table()
table.labels = "key value".split()
for k, v in sorted(data.items()):
Expand All @@ -65,6 +66,8 @@ def make_kv_table(data):


def print_instrument_configuration():
'''print instrument config on table
move this to instrument utils'''
if len(iconfig) > 0:
table = make_kv_table(iconfig)
print("")
Expand Down
4 changes: 4 additions & 0 deletions src/aps_8id_bs_instrument/run_engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Run Engine Specific file"""

import logging

import databroker
Expand All @@ -16,6 +18,7 @@


def save_data(name, doc):
"""save data for databroker"""
# This is a hack around a problem with garbage collection
# Has been fixed in main, maybe released in databroker v2?
# Create the databroker callback if necessary
Expand All @@ -27,6 +30,7 @@ def save_data(name, doc):


def run_engine(connect_databroker=True, use_bec=True) -> BlueskyRunEngine:
"""Start Bluesky RunEngine"""
RE = BlueskyRunEngine()
# Add the best-effort callback
if use_bec:
Expand Down
5 changes: 4 additions & 1 deletion src/aps_8id_bs_instrument/utils/check_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ensure BlueSky is available
Helper functions to sanity check current environment
"""

import logging
Expand All @@ -24,6 +24,7 @@


def check_python_version():
"""check python version on current environment"""
req_version = tuple(iconfig.get("MINIMUM_PYTHON_VERSION", (3, 7)))
cur_version = sys.version_info
if cur_version < req_version:
Expand All @@ -38,6 +39,7 @@ def check_python_version():


def check_ophyd_version():
"""check ophyd version on current environment"""
req_version = tuple(iconfig.get("MINIMUM_BLUESKY_VERSION", (1, 8)))
cur_version = tuple(map(int, bluesky.__version__.split(".")[:2]))
if cur_version < req_version:
Expand All @@ -49,6 +51,7 @@ def check_ophyd_version():


def check_databroker_version():
"""Check databroker version on current environment"""
req_version = tuple(iconfig.get("MINIMUM_DATABROKER_VERSION", (1, 2)))
cur_version = tuple(map(int, databroker.__version__.split(".")[:2]))
if cur_version < req_version:
Expand Down
5 changes: 4 additions & 1 deletion src/aps_8id_bs_instrument/utils/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Exception specific files for Bluesky engine"""

from ophydregistry.exceptions import ( # noqa: F401
ComponentNotFound,
InvalidComponentLabel,
Expand Down Expand Up @@ -77,7 +79,8 @@ class SignalNotFound(KeyError):
...


class EmptySignalName(ValueError): ...
class EmptySignalName(ValueError):
"""The Signal name is empty."""


class InvalidTransformation(TypeError):
Expand Down
1 change: 1 addition & 0 deletions src/aps_8id_bs_instrument/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@


def metadata(RE):
"""Write metadata on the Run Engine"""
# Set up default metadata
RE.md["databroker_catalog"] = cat.name
RE.md["login_id"] = USERNAME + "@" + HOSTNAME
Expand Down
18 changes: 5 additions & 13 deletions src/aps_8id_bs_instrument/utils/mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,22 @@
"""


def isnotebook():
"""
see: https://stackoverflow.com/a/39662359/1046449
"""
def isnotebook(): # noqa D103
try:
from IPython import get_ipython
from IPython import get_ipython # noqa

_ipython = get_ipython()
if _ipython is not None:
shell = _ipython.__class__.__name__
return shell == "ZMQInteractiveShell"
return False
# return True # Jupyter notebook or qtconsole
# elif shell == 'TerminalInteractiveShell':
# return False # Terminal running IPython
# else:
# return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
return False


if isnotebook():
if isnotebook(): # noqa D103
# %matplotlib notebook
_ipython = get_ipython()
_ipython = get_ipython() # noqa F821
if _ipython is not None:
# _ipython.magic("matplotlib notebook")
_ipython.magic("matplotlib inline")
Expand Down
Loading

0 comments on commit f1f8f74

Please sign in to comment.