Skip to content

Commit

Permalink
Merge pull request #308 from spc-group/ipython_startup
Browse files Browse the repository at this point in the history
IPython startup script now adds all devices to the global namespace.
  • Loading branch information
canismarko authored Nov 20, 2024
2 parents da699d2 + e635d43 commit 00adb89
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/haven/ipython_startup.ipy
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ except NotConnected as exc:
num_devices = len(haven.beamline.registry.root_devices)
print(f"Connected to {num_devices} devices in {time.monotonic() - t0:.2f} seconds.", flush=True)

# Save references to some commonly used things in the global namespace
# Save references to all the devices in the global namespace
registry = haven.beamline.registry
try:
ion_chambers = registry.findall("ion_chambers", allow_none=True)
except ComponentNotFound as exc:
log.exception(exc)
try:
energy = registry['energy']
except ComponentNotFound as exc:
log.exception(exc)
ion_chambers = registry.findall("ion_chambers", allow_none=True)
for cpt in registry._objects_by_name.values():
# Replace spaces and other illegal characters in variable name
name = haven.sanitize_name(cpt.name)
# Add the device as a variable in module's globals
globals().setdefault(name, cpt)

# Print helpful information to the console
custom_theme = Theme(
Expand Down

0 comments on commit 00adb89

Please sign in to comment.