# import numpy as np # from pyOlog.ophyd_tools import * # # Uncomment the following lines to turn on verbose messages for # # debugging. # # import logging # # ophyd.logger.setLevel(logging.DEBUG) # # logging.basicConfig(level=logging.DEBUG) import nslsii BEAMLINE_ID = 'fmx' # nslsii.configure_base(get_ipython().user_ns, BEAMLINE_ID) nslsii.configure_base(get_ipython().user_ns, BEAMLINE_ID, pbar=False) # Progress bar for scans from pathlib import Path import appdirs try: from bluesky.utils import PersistentDict except ImportError: import msgpack import msgpack_numpy import zict class PersistentDict(zict.Func): """ A MutableMapping which syncs it contents to disk.
import nslsii from ophyd import Device, Component, EpicsSignal from ophyd.signal import EpicsSignalBase from ophyd.areadetector.filestore_mixins import resource_factory import uuid import os from pathlib import Path import numpy as np from IPython import get_ipython try: del RE except NameError: pass nslsii.configure_base(get_ipython().user_ns, 'temp', epics_context=False) class Det(Device): det = Component(EpicsSignal, ':det', kind='hinted') exp = Component(EpicsSignal, ':exp', kind='config') # here there be 🐉🐉🐉🐉🐉🐉 class ArraySignal(EpicsSignalBase): def __init__(self, read_pv, **kwargs): super().__init__(read_pv, **kwargs) cl = self.cl base_pv, _ = read_pv.rsplit(':', maxsplit=1)
print(f'Loading {__file__}...') import os import nslsii nslsii.configure_base(get_ipython().user_ns, 'rsoxs') # After the above call, you will now have the following in your namespace: # # RE : RunEngine # db : databroker # sd : SupplementalData # pbar_manager : ProgressBarManager # bec : BestEffortCallback # peaks : bec.peaks # plt : matplotlib.pyplot # np : numpy # bc : bluesky.callbacks # bp : bluesky.plans # bps : bluesky.plan_stubs # mv : bluesky.plan_stubs.mv # mvr : bluesky.plan_stubs.mvr # mov : bluesky.plan_stubs.mov # movr : bluesky.plan_stubs.movr # bpp : bluesky.preprocessors # Optional: set any metadata that rarely changes. RE.md['beamline_id'] = 'SST-1 RSoXS' # Add a callback that prints scan IDs at the start of each scan. def print_scan_ids(name, start_doc):
print(f'Loading {__file__}') import nslsii nslsii.configure_base(get_ipython().user_ns, 'smi') # nslsii.configure_olog(get_ipython().user_ns, subscribe=False) #Optional: set any metadata that rarely changes. RE.md['beamline_id'] = 'SMI'
from nslsii import configure_base from IPython import get_ipython configure_base(get_ipython().user_ns, 'local', publish_documents_with_kafka=True) bec.disable_plots() # Optional: set any metadata that rarely changes. RE.md['beamline_id'] = 'TES-opt'
import nslsii from datetime import datetime # Register bluesky IPython magics. if not is_re_worker_active(): from bluesky.magics import BlueskyMagics get_ipython().register_magics(BlueskyMagics) from bluesky.preprocessors import stage_decorator, run_decorator from databroker.v0 import Broker db = Broker.named("fxi") del Broker nslsii.configure_base(get_ipython().user_ns, db, bec=True) nslsii.configure_kafka_publisher(RE, "fxi") # The following plan stubs should not be imported directly in the global namespace. # Otherwise Queue Server will not be able to load the startup files. del one_1d_step del one_nd_step del one_shot # Make new RE.md storage available in old environments. from pathlib import Path import appdirs try:
import nslsii import matplotlib as mpl from IPython.terminal.prompts import Prompts, Token class SRXPrompt(Prompts): def in_prompt_tokens(self, cli=None): return [ (Token.Prompt, "BlueSky@SRX ["), (Token.PromptNum, str(self.shell.execution_count)), (Token.Prompt, "]: "), ] ip = get_ipython() nslsii.configure_base(ip.user_ns, "srx") nslsii.configure_olog(ip.user_ns) ip.prompts = SRXPrompt(ip) # Optional: set any metadata that rarely changes. RE.md["beamline_id"] = "SRX" # Custom Matplotlib configs: mpl.rcParams["axes.grid"] = True # grid always on # Comment it out to enable BEC table: bec.disable_table() # Disable BestEffortCallback to plot ring current bec.disable_plots()
from nslsii import configure_base from IPython import get_ipython configure_base(get_ipython().user_ns, 'local') bec.disable_plots() # Optional: set any metadata that rarely changes. RE.md['beamline_id'] = 'TES-sirepo'
return False use_kafka = False os.environ['BLUESKY_KAFKA_BOOTSTRAP_SERVERS'] = 'kafka1.nsls2.bnl.gov:9092' ## the intent here is to return $HOME/.profile_collection/startup #startup_dir = os.path.split(os.path.split(os.path.split(__file__)[0])[0])[0] startup_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) uns_dict = dict() if not is_re_worker_active(): ip = get_ipython() nslsii.configure_base(ip.user_ns, 'bmm', configure_logging=True, publish_documents_to_kafka=use_kafka) ip.log.setLevel('ERROR') RE = ip.user_ns['RE'] db = ip.user_ns['db'] sd = ip.user_ns['sd'] bec = ip.user_ns['bec'] else: nslsii.configure_base(uns_dict, 'bmm', configure_logging=True, publish_documents_to_kafka=use_kafka) RE = uns_dict['RE'] db = uns_dict['db'] sd = uns_dict['sd'] bec = uns_dict['bec']
# Make ophyd listen to pyepics. import logging import nslsii import time from bluesky.utils import ts_msg_hook # See docstring for nslsii.configure_base() for more details # this command takes away much of the boilerplate for settting up a profile # (such as setting up best effort callbacks etc) nslsii.configure_base( get_ipython().user_ns, 'pdf', pbar=True, bec=True, magics=True, mpl=True, #publish_documents_to_kafka=True ) from pathlib import Path import appdirs try: from bluesky.utils import PersistentDict except ImportError: import msgpack import msgpack_numpy import zict class PersistentDict(zict.Func):
return ret2 db = CompositeBroker(mds_db1, CompositeRegistry(_fs_config_db1)) from hxntools.handlers import register as _hxn_register_handlers _hxn_register_handlers(db) del _hxn_register_handlers # do the rest of the standard configuration from IPython import get_ipython from nslsii import configure_base, configure_olog configure_base( get_ipython().user_ns, db, bec=False, ipython_logging=False, publish_documents_with_kafka=True ) # configure_olog(get_ipython().user_ns) from bluesky.callbacks.best_effort import BestEffortCallback bec = BestEffortCallback() # un import * ns = get_ipython().user_ns for m in [bp, bps, bpp]: for n in dir(m): if (not n.startswith('_') and n in ns
from nslsii import configure_base from IPython import get_ipython configure_base(get_ipython().user_ns, 'tes') # Optional: set any metadata that rarely changes. RE.md['beamline_id'] = 'TES'
import nslsii from bluesky import RunEngine nslsii.configure_base(get_ipython().user_ns, 'chx', publish_documents_with_kafka=True) from pathlib import Path import appdirs try: from bluesky.utils import PersistentDict except ImportError: import msgpack import msgpack_numpy import zict class PersistentDict(zict.Func): def __init__(self, directory): self._directory = directory self._file = zict.File(directory) super().__init__(self._dump, self._load, self._file) @property def directory(self): return self._directory def __repr__(self): return f"<{self.__class__.__name__} {dict(self)!r}>" @staticmethod
EpicsSignalBase.wait_for_connection = wait_for_connection_base EpicsSignal.wait_for_connection = wait_for_connection ############################################################################### from ophyd.signal import EpicsSignalBase # EpicsSignalBase.set_default_timeout(timeout=10, connection_timeout=10) # old style EpicsSignalBase.set_defaults(timeout=10, connection_timeout=10) # new style except ImportError: pass nslsii.configure_base(get_ipython().user_ns, 'amx', bec=True, pbar=False, publish_documents_with_kafka=True) # Disable plots via BestEffortCallback: bec.disable_plots() try: from bluesky.utils import PersistentDict runengine_metadata_dir = appdirs.user_data_dir( appname="bluesky") / Path("runengine-metadata") # PersistentDict will create the directory if it does not exist RE.md = PersistentDict(runengine_metadata_dir) except ImportError: print('Older bluesky did not have PersistentDict, moving on.')
# Make ophyd listen to pyepics. import nslsii import time from bluesky.utils import ts_msg_hook # See docstring for nslsii.configure_base() for more details # this command takes away much of the boilerplate for settting up a profile # (such as setting up best effort callbacks etc) nslsii.configure_base(get_ipython().user_ns, 'pdf', pbar=True, bec=True, magics=True, mpl=True) # disable plotting for now # bec.disable_plots() # Optional: set any metadata that rarely changes. # RE.md['beamline_id'] = 'YOUR_BEAMLINE_HERE' # At the end of every run, verify that files were saved and # print a confirmation message. #from bluesky.callbacks.broker import verify_files_saved, post_run # RE.subscribe(post_run(verify_files_saved, db), 'stop') # Uncomment the following lines to turn on verbose messages for # debugging. # import logging # ophyd.logger.setLevel(logging.DEBUG) # logging.basicConfig(level=logging.DEBUG)
print(__file__) import nslsii beamline_id = 'qas' nslsii.configure_base(get_ipython().user_ns, beamline_id, bec=False) # At the end of every run, verify that files were saved and # print a confirmation message. from bluesky.callbacks.broker import verify_files_saved # RE.subscribe(post_run(verify_files_saved), 'stop') # Optional: set any metadata that rarely changes. # these should *always* be QAS RE.md['group'] = beamline_id RE.md['beamline_id'] = beamline_id.upper() RE.md['Facility'] = 'NSLS-II' # RE.md['Mono_pulses_per_deg']= # isstools reads these # check these keys exist, if not set to default keys = ["PI", "PROPOSAL", "SAF", "year", "cycle", "proposal_id"] defaults = ["No PI", None, None, 2018, 1, None] for key, default in zip(keys, defaults): if key not in RE.md: print("Warning {} not in RE.md.".format(key)) print("Set to default : {}".format(default)) RE.md[key] = default
import nslsii ip = get_ipython() nslsii.configure_base(ip.user_ns, 'bmm', configure_logging=False) bec.disable_plots() bec.disable_baseline() import ophyd ophyd.EpicsSignal.set_default_timeout(timeout=20, connection_timeout=20) #from databroker.core import SingleRunCache from bluesky.utils import ts_msg_hook RE.msg_hook = ts_msg_hook from bluesky.callbacks.zmq import Publisher publisher = Publisher('localhost:5577') RE.subscribe(publisher)
db = Broker_New(mds, CompositeRegistry(_fs_config)) from hxntools.handlers import register as _hxn_register_handlers _hxn_register_handlers(db_new) #_hxn_register_handlers(_db_cluster) _hxn_register_handlers(db_old) del _hxn_register_handlers # do the rest of the standard configuration from IPython import get_ipython from nslsii import configure_base, configure_olog # configure_base(get_ipython().user_ns, db_new, bec=False) configure_base(get_ipython().user_ns, db, bec=False) configure_olog(get_ipython().user_ns) from bluesky.callbacks.best_effort import BestEffortCallback bec = BestEffortCallback() # un import * ns = get_ipython().user_ns for m in [bp, bps, bpp]: for n in dir(m): if (not n.startswith('_') and n in ns and getattr(ns[n], '__module__', '') == m.__name__): del ns[n] del ns from bluesky.magics import BlueskyMagics
import logging from nslsii import configure_base from IPython import get_ipython from bluesky.callbacks.zmq import Publisher import functools from ophyd.signal import EpicsSignal, EpicsSignalRO EpicsSignal.set_defaults(connection_timeout=10) EpicsSignalRO.set_defaults(connection_timeout=10) configure_base(get_ipython().user_ns, "jpls") publisher = Publisher("xf12id1-ws2:5577") RE.subscribe(publisher) # Optional: set any metadata that rarely changes. RE.md["beamline_id"] = "OPLS" # For debug mode from bluesky.utils import ts_msg_hook # RE.msg_hook = ts_msg_hook # THIS NEEDS TO MOVE UPSTREAM async def reset_user_position(msg): obj = msg.obj (val,) = msg.args old_value = obj.position obj.set_current_position(val) print(f"{obj.name} reset from {old_value:.4f} to {val:.4f}")
}, 'assets' : { 'module' : 'databroker.assets.mongo', 'class' : 'Registry', 'config' : { 'host':'xf23id-ca.cs.nsls2.local', 'port': 27017, 'database':'filestore' } }, } db = Broker.from_config(config) import nslsii nslsii.configure_base(get_ipython().user_ns, db) # make sure Best Effort Callback does not plot the baseline readings bec.noplot_streams.append('pgm_energy_monitor') ### comment this out to: ### disable the zmq servce and re-enable best effort callback plotting locally bec.disable_plots() from bluesky.callbacks.zmq import Publisher pub = Publisher('xf23id-ca:5577') RE.subscribe(pub) #####
import nslsii nslsii.configure_base(get_ipython().user_ns, 'esm')
from ophyd.signal import EpicsSignalBase # EpicsSignalBase.set_default_timeout(timeout=10, connection_timeout=10) # old style EpicsSignalBase.set_defaults(timeout=10, connection_timeout=10) # new style except ImportError: print('EpicsSignalBase does not exist in ophyd') from pathlib import Path import appdirs import nslsii from IPython import get_ipython # Base configuration # pbar=False disables progress bar (undesirable in Jupyter) # bec=False disables Best Effort Callback (seems to be causing issues) nslsii.configure_base(get_ipython().user_ns, "nyx", pbar=False, bec=True) try: from bluesky.utils import PersistentDict runengine_metadata_dir = appdirs.user_data_dir( appname="bluesky") / Path("runengine-metadata") # PersistentDict will create the directory if it does not exist RE.md = PersistentDict(runengine_metadata_dir) except ImportError: print('Older bluesky did not have PersistentDict, moving on.') RE.md["beamline_name"] = "NYX" RE.md["facility"] = "NSLS-II"
# Make ophyd listen to pyepics. import nslsii # See docstring for nslsii.configure_base() for more details # this command takes away much of the boilerplate for settting up a profile # (such as setting up best effort callbacks etc) nslsii.configure_base(get_ipython().user_ns, 'xpdd', pbar=True, bec=True, magics=True, mpl=True, epics_context=False) # IMPORTANT : This is needed to read old data # db.reg.set_root_map({'/direct/XF28ID1':'/direct/XF28ID2'}) # At the end of every run, verify that files were saved and # print a confirmation message. from bluesky.callbacks.broker import verify_files_saved, post_run # RE.subscribe(post_run(verify_files_saved, db), 'stop') # Uncomment the following lines to turn on verbose messages for # debugging. # import logging # ophyd.logger.setLevel(logging.DEBUG) # logging.basicConfig(level=logging.DEBUG) RE.md['facility'] = 'NSLS-II' RE.md['group'] = 'XPD' RE.md['beamline_id'] = '28-ID-D'
from databroker import Broker db = Broker.named('csx2') import nslsii nslsii.configure_base(get_ipython().user_ns, db) # make sure Best Effort Callback does not plot the baseline readings bec.noplot_streams.append('pgm_energy_monitor') ### comment this out to: ### disable the zmq servce and re-enable best effort callback plotting locally bec.disable_plots() from bluesky.callbacks.zmq import Publisher pub = Publisher('xf23id-ca:5577') RE.subscribe(pub) ##### # TODO not need this from epics import caget, caput from amostra.client.commands import SampleReference, ContainerReference # Optional: set any metadata that rarely changes. # convenience imports def ensure_proposal_id(md): if 'proposal_id' not in md: raise ValueError("Please run user_checkin() first")