Skip to content

Commit

Permalink
Cleaned up device registration and name so startup is cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
yannachen committed Mar 25, 2024
1 parent b2795d1 commit 7a62bc8
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 124 deletions.
17 changes: 10 additions & 7 deletions ipython_startup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time
import logging
import databroker # noqa: F401
import matplotlib.pyplot as plt # noqa: F401
from bluesky import RunEngine # noqa: F401
Expand All @@ -9,18 +11,19 @@

import haven # noqa: F401

logging.basicConfig(level=logging.WARNING)

# Allow best effort callback to update properly
plt.ion()

# Prepare the haven instrument
config = haven.load_config()
print(f"Initializing {config['beamline']['name']}...", end="", flush=True)
t0 = time.monotonic()
print(f"Initializing {config['beamline']['name']}…")
haven.load_instrument()
print("done")
print(f"Finished initalization in {time.monotonic() - t0:.2f} seconds.")
RE = haven.run_engine()
ion_chambers = haven.registry.findall("ion_chambers")

# Set up best effort callback for visualizing live data
plt.ion()
bec = BestEffortCallback()
RE.subscribe(bec)

# Add metadata to the run engine
RE.preprocessors.append(haven.preprocessors.inject_haven_md_wrapper)
104 changes: 0 additions & 104 deletions src/haven/iconfig_default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,117 +9,13 @@ is_connected = false
name = "Advanced Photon Source"
xray_source = "insertion device"

####################################################################
# Configuration for interacting with the beamline scheduling system
# using apsbss package
####################################################################

[bss]

prefix = "255idc:bss"
beamline = "255-ID-C"

[xray_source]

type = "undulator"
prefix = "ID255:"

[queueserver]
kafka_topic = "s255idc_queueserver"
control_host = "localhost"
control_port = "60615"
info_host = "localhost"
info_port = "60625"

[database.databroker]

catalog = "bluesky"

[database.tiled]

uri = "http://fedorov.xray.aps.anl.gov:8001/"
# uri = "http://hood.xray.aps.anl.gov:8001/"
entry_node = "25idc_microprobe"

[shutter]
prefix = "PSS:99ID"

[shutter.front_end_shutter]

hutch = "A"
# open_pv = "PSS:99ID:FES_OPEN_EPICS.VAL"
# close_pv = "PSS:99ID:FES_CLOSE_EPICS.VAL"
# status_pv = "PSS:99ID:A_BEAM_PRESENT"

[shutter.hutch_shutter]

hutch = "C"
# open_pv = "PSS:99ID:SCS_OPEN_EPICS.VAL"
# close_pv = "PSS:99ID:SCS_CLOSE_EPICS.VAL"
# status_pv = "PSS:25ID:C_BEAM_PRESENT"

[undulator]

ioc = "id_ioc"

[monochromator]

ioc = "mono_ioc"
ioc_branch = "UP" # For caQtDM macros

[ion_chamber]

[ion_chamber.scaler]
prefix = "scaler_ioc"
channels = [2]

[ion_chamber.preamp]
prefix = "preamp_ioc"

[ion_chamber.voltmeter]
prefix = "255idc:LabjackT7_" # Don't include the labjack number

[fluorescence_detector]

[dxp.vortex_me4]

prefix = "vortex_me4"
num_elements = 4

[dxp.canberra_Ge7]

prefix = "20xmap8"
num_elements = 4

[xspress.vortex_me4_xsp]

prefix = "vortex_me4_xsp"
num_elements = 4

# Motors
# ======
#
# Add a new section for each IOC (or IOC prefix) that has motors
# matching the format {prefix}:m1. The heading of the subsection
# ("VME_crate" in the example below) is a human-readable name that
# will become a label on the Ophyd Device. *num_motors* determines how
# many motors will be read. The example below will load three motors
# with PVs: "vme_crate_ioc:m1", "vme_crate_ioc:m2", and
# "vme_crate_ioc:m3".
[motor.VME_crate]
prefix = "255idVME"
num_motors = 3

# Cameras
# =======

[camera]

imagej_command = "imagej"

# [camera.sim_det]

# prefix = "25idSimDet"
# name = "sim_det"
# description = "Simulated Camera"
# device_class = "SimDetector"
89 changes: 88 additions & 1 deletion src/haven/iconfig_testing.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
[bss]

prefix = "255idc:bss"
beamline = "255-ID-C"

[xray_source]

type = "undulator"
prefix = "ID255:"

[queueserver]
kafka_topic = "s255idc_queueserver"
control_host = "localhost"
control_port = "60615"
info_host = "localhost"
info_port = "60625"

[database.tiled]

uri = "http://localhost:8337/"
entry_node = "255id_testing"

[shutter]
prefix = "PSS:99ID"

[shutter.front_end_shutter]

hutch = "A"
# open_pv = "PSS:99ID:FES_OPEN_EPICS.VAL"
# close_pv = "PSS:99ID:FES_CLOSE_EPICS.VAL"
# status_pv = "PSS:99ID:A_BEAM_PRESENT"

[shutter.hutch_shutter]

hutch = "C"
# open_pv = "PSS:99ID:SCS_OPEN_EPICS.VAL"
# close_pv = "PSS:99ID:SCS_CLOSE_EPICS.VAL"
# status_pv = "PSS:25ID:C_BEAM_PRESENT"

[undulator]

ioc = "id_ioc"

[monochromator]

ioc = "mono_ioc"
ioc_branch = "UP" # For caQtDM macros


[ion_chamber]

[ion_chamber.scaler]
prefix = "scaler_ioc"
channels = [2]

[ion_chamber.preamp]
prefix = "preamp_ioc"

[ion_chamber.voltmeter]
prefix = "255idc:LabjackT7_" # Don't include the labjack number

# Motors
# ======
#
# Add a new section for each IOC (or IOC prefix) that has motors
# matching the format {prefix}:m1. The heading of the subsection
# ("VME_crate" in the example below) is a human-readable name that
# will become a label on the Ophyd Device. *num_motors* determines how
# many motors will be read. The example below will load three motors
# with PVs: "vme_crate_ioc:m1", "vme_crate_ioc:m2", and
# "vme_crate_ioc:m3".

[motor.VME_crate]
prefix = "255idVME"
num_motors = 3

# Keys for camera definitions must begin with "cam" (e.g. "camA", "camB")
[camera.camA]
Expand Down Expand Up @@ -106,4 +176,21 @@ prefix = "255idAustin"
# Managed IOC control PVs
[iocs]
255idb = "glados:ioc255idb"
255idc = "glados:ioc255idc"
255idc = "glados:ioc255idc"

[fluorescence_detector]

[dxp.vortex_me4]

prefix = "vortex_me4"
num_elements = 4

[dxp.canberra_Ge7]

prefix = "20xmap8"
num_elements = 4

[xspress.vortex_me4_xsp]

prefix = "vortex_me4_xsp"
num_elements = 4
5 changes: 4 additions & 1 deletion src/haven/instrument/energy_positioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ async def make_energy_device(
msg = f"Could not connect to energy positioner: {name}"
log.warning(msg)
else:
registry.register(dev)
return dev


def load_energy_positioner_coros(config=None):
# Load PV's from config
if config is None:
config = load_config()
# Guard to make sure we have a mono and ID configuration
if "monochromator" not in config.keys() or "undulator" not in config.keys():
return
# Make the combined energy device
yield make_energy_device(
name="energy",
mono_suffix=Monochromator.energy.suffix,
Expand Down
2 changes: 1 addition & 1 deletion src/haven/instrument/instrument_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__all__ = ["InstrumentRegistry", "registry"]


registry = InstrumentRegistry(auto_register=False, use_typhos=True)
registry = InstrumentRegistry(auto_register=False, use_typhos=False)


# -----------------------------------------------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions src/haven/instrument/ion_chamber.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class IonChamberPreAmplifier(SRS570_PreAmplifier):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Reset the gain name, apstools converts "preamp_gain" to "preamp"
self.gain.name += "_gain"
# Subscriptions for updating the sensitivity text
self.sensitivity_value.subscribe(self.update_sensitivity_text, run=False)
self.sensitivity_unit.subscribe(self.update_sensitivity_text, run=True)
Expand All @@ -110,7 +112,7 @@ def cb_gain(self, *args, **kwargs):
Called when sensitivity changes (EPICS CA monitor event).
"""
gain = self.computed_gain()
self.gain.put(gain)
self.gain.put(gain, internal=True)
self.gain_db.put(10 * math.log10(gain), internal=True)

def computed_gain(self):
Expand Down Expand Up @@ -222,11 +224,11 @@ def _get_offset_current(
InternalSignal,
kind=Kind.config,
)
# Gain, but measured in decibels
gain_db = Cpt(InternalSignal, kind=Kind.config)
# Gain, but measured in various forms
gain = Cpt(InternalSignal, name="gainerificf", kind="normal", value=1)
gain_db = Cpt(InternalSignal, kind=Kind.config, value=0)


# @registry.register
class IonChamber(ScalerTriggered, Device, flyers.FlyerInterface):
"""An ion chamber at a spectroscopy beamline.
Expand Down Expand Up @@ -565,7 +567,6 @@ async def make_ion_chamber_device(
)
else:
log.info(f"Created ion chamber: {name} ({prefix}, {preamp_prefix})")
registry.register(ic)
return ic


Expand Down
1 change: 0 additions & 1 deletion src/haven/instrument/lerix.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ class LERIXSpectrometer(Device):
# log.warning(f"Could not connect to LERIX spectrometer: {name} ({pvs})")
# else:
# log.info(f"Created area detector: {name} ({pvs})")
# registry.register(dev)
# return dev


Expand Down
4 changes: 4 additions & 0 deletions src/haven/instrument/monochromator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def load_monochromator_coros(config=None):
# Load PV's from config
if config is None:
config = load_config()
# Guard to make sure there's at least one mono configuration
if "monochromator" not in config.keys():
return
# Load mono device from configuration
prefix = config["monochromator"]["ioc"]
yield make_device(
Monochromator, name="monochromator", labels={"monochromators"}, prefix=prefix
Expand Down
5 changes: 3 additions & 2 deletions src/haven/instrument/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ async def load_motor(prefix: str, motor_num: int, ioc_name: str = None):
log.debug(f"Resolved motor {pv} to '{name}'")

# Create the motor device
if name == f"motor {motor_num+1}":
unused_motor_names = [f"motor {motor_num+1}", ""]
if name in unused_motor_names:
# It's an unnamed motor, so skip it
log.info(f"SKipping unnamed motor {motor_num}")
log.info(f"SKipping unnamed motor {pv}")
else:
# Create a new motor object
labels = {"motors", "extra_motors", "baseline"}
Expand Down
1 change: 0 additions & 1 deletion src/haven/instrument/power_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ async def make_power_supply_device(prefix, name, ch_num):
log.warning(msg)
else:
log.info(f"Created power supply: {name}")
registry.register(dev)
return dev


Expand Down
4 changes: 4 additions & 0 deletions src/haven/instrument/shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
def load_shutter_coros(config=None):
if config is None:
config = load_config()
# Guard to make sure there's at least one shutter configuration
if "shutter" not in config.keys():
return
# Load the shutter configurations into devices
prefix = config["shutter"]["prefix"]
for name, d in config["shutter"].items():
if name == "prefix":
Expand Down
1 change: 0 additions & 1 deletion src/haven/instrument/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
log = logging.getLogger(__name__)


@registry.register
class XYStage(Device):
"""An XY stage with two motors operating in orthogonal directions.
Expand Down

0 comments on commit 7a62bc8

Please sign in to comment.