def run_server( handlers=None, prefix=None, outbound_proxy_address=glbl_dict["outbound_proxy_address"], ): """Start up the visualization server Parameters ---------- handlers : dict The map between handler specs and handler classes, defaults to the map used by the experimental databroker if possible prefix : bytes or list of bytes, optional The Publisher channels to listen to. Defaults to ``[b"an", b"raw"]`` outbound_proxy_address : str, optional The address and port of the zmq proxy. Defaults to ``glbl_dict["outbound_proxy_address"]`` """ if handlers is None: for db in ["exp_db", "an_db"]: if db in glbl_dict: handlers = glbl_dict[db].reg.handler_reg break d = RemoteDispatcher(outbound_proxy_address, prefix=prefix) install_qt_kicker(loop=d.loop) func_l = [ lambda x: if_correct_start( LiveImage( handler_reg=handlers, cmap="viridis", norm=SymLogNorm(1), limit_func=lambda x: (np.nanmin(x), np.nanmax(x)), ), x, ), lambda x: LiveWaterfall(), ] if Live3DView: func_l.append(lambda x: Live3DView() if 'tomo' in x['analysis_stage'] else None) func_l.append( lambda x: BestEffortCallback(table_enabled=False, overplot=False) ) rr = RunRouter(func_l) d.subscribe(rr) print("Starting Viz Server") d.start()
def run_server( outbound_proxy_address=glbl_dict["outbound_proxy_address"], inbound_proxy_address=glbl_dict["inbound_proxy_address"], outbound_prefix=(b"an", b"qoi"), inbound_prefix=b"tomo", _publisher=None, **kwargs, ): """Server for performing tomographic reconstructions Parameters ---------- outbound_proxy_address : str, optional The outbound ip address for the ZMQ server. Defaults to the value from the global dict inbound_proxy_address : str, optional The inbound ip address for the ZMQ server. Defaults to the value from the global dict outbound_prefix : bytes or sequence of bytes The data channels to listen to inbound_prefix : bytes The data channel to publish to kwargs : dict kwargs passed to the reconstruction, for instance ``algorithm`` could be passed in with the associated tomopy algorithm to change the reconstructgion algorithm from gridrec to something else. """ print(kwargs) db = glbl_dict["exp_db"] handler_reg = db.reg.handler_reg publisher = Publisher(inbound_proxy_address, prefix=inbound_prefix) if _publisher: publisher = _publisher rr = RunRouter( [ lambda x: tomo_callback_factory( x, publisher=publisher, handler_reg=handler_reg, **kwargs ) ] ) d = RemoteDispatcher(outbound_proxy_address, prefix=outbound_prefix) install_qt_kicker(loop=d.loop) d.subscribe(rr) print("Starting Tomography Server") d.start()
def engine(self, engine): logger.debug("Storing a new RunEngine object") # Do not allow engine to be swapped while RunEngine is active if self._engine and self._engine.state != 'idle': raise RuntimeError("Can not change the RunEngine while the " "RunEngine is running!") # Create a kicker, not worried about doing this multiple times as this # is checked by `install_qt_kicker` itself install_qt_kicker(update_rate=self.update_rate) engine.state_hook = self.on_state_change # Connect signals self._engine = engine self.engine_state_change.connect(self.label.on_state_change) self.engine_state_change.connect(self.control.on_state_change) self.control.clicked.connect(self.command) # Run callbacks manually to initialize widgets. We can not emit the # signal specifically because we can not emit signals in __init__ state = self._engine.state self.label.on_state_change(state, None) self.control.on_state_change(state, None)
def start_analysis(save=True, vis=True, **kwargs): """Start analysis pipeline [Depreciated] Parameters ---------- mask_kwargs : dict The kwargs passed to the masking see xpdtools.tools.mask_img pdf_kwargs : dict The kwargs passed to the pdf generator, see xpdtools.tools.pdf_getter fq_kwargs : dict The kwargs passed to the fq generator, see xpdtools.tools.fq_getter mask_setting : dict The setting of the mask save_template : str The template string for file saving base_folder : str The base folder for saving files """ warn(DeprecationWarning("Use the server instead")) # TODO: also start up grave vis, maybe? d = RemoteDispatcher(glbl_dict["outbound_proxy_address"]) install_qt_kicker( loop=d.loop ) # This may need to be d._loop depending on tag order = pipeline_order if save: order += save_pipeline_order if vis: order += [vis_pipeline] namespace = link( *order, raw_source=Stream(stream_name="raw source"), **kwargs ) raw_source = namespace["raw_source"] d.subscribe(lambda *x: raw_source.emit(x)) print("Starting Analysis Server") d.start()
import metadatastore.commands from bluesky.global_state import gs gs.RE.subscribe_lossless('all', metadatastore.commands.insert) from bluesky.callbacks.broker import post_run # At the end of every run, verify that files were saved and # print a confirmation message. from bluesky.callbacks.broker import verify_files_saved gs.RE.subscribe('stop', post_run(verify_files_saved)) """ # Import matplotlib and put it in interactive mode. import matplotlib.pyplot as plt plt.ion() # Make plots update live while scans run. from bluesky.utils import install_qt_kicker install_qt_kicker() # import nslsii # Register bluesky IPython magics. #from bluesky.magics import BlueskyMagics #get_ipython().register_magics(BlueskyMagics) #nslsii.configure_base(get_ipython().user_ns, 'amx') import bluesky.plans as bp from bluesky.run_engine import RunEngine from bluesky.utils import get_history RE = RunEngine(get_history()) beamline = os.environ["BEAMLINE_ID"] from databroker import Broker
mds = MDSRO(d) fs = RegistryRO(d) fs.register_handler('AD_TIFF', AreaDetectorTiffHandler) db = Broker(mds=mds, reg=fs) td = TemporaryDirectory() source = conf_main_pipeline( db, td.name, # vis=False, write_to_disk=False, # mask_setting=None ) # a = LiveImage('pe1_image') loop = zmq_asyncio.ZMQEventLoop() install_qt_kicker(loop=loop) def put_in_queue(nd): if nd[0] == 'event': nd[1]['data']['pe1_image'] = np.asarray(nd[1]['data']['pe1_image']) # if nd[0] == 'event': # db.fill_event(nd[1]) # print(nd) # source.emit(nd) a(*nd) plt.pause(.1) disp = RemoteDispatcher('127.0.0.1:5568', loop=loop) # disp.subscribe(istar(put_in_queue))
def run_server( order=order, radiogram_order=radiogram_order, db=glbl_dict["exp_db"], outbound_proxy_address=glbl_dict["outbound_proxy_address"], inbound_proxy_address=glbl_dict["inbound_proxy_address"], diffraction_dets=glbl_dict["diffraction_dets"], radiogram_dets=glbl_dict["radiogram_dets"], prefix=b"raw", inbound_prefix=b"an", zscore=False, stage_blacklist=(), _publisher=None, **kwargs, ): """Function to run the analysis server. Parameters ---------- order : list, optional The order of pipeline chunk functions to be called. Defaults to the standard order, ``xpdan.startup.analysis_server.order`` radiogram_order : list, optional The order of pipeline chunk functions to be called for radiograph analysis. Defaults to the standard order, ``xpdan.startup.analysis_server.radiogram_order`` db : databroker.Broker instance, optional The databroker to pull data from. This is used for accessing dark and background data. Defaults to the location listed in the ``xpdconf.conf.glbl_dict``. outbound_proxy_address : str, optional The location of the ZMQ proxy sending data to this server. Defaults to the location listed in the ``xpdconf.conf.glbl_dict``. inbound_proxy_address : str, optional The inbound ip address for the ZMQ server. Defaults to the value from the global dict diffraction_dets : list of str, optional The detectors used for diffraction, defaults to ``glbl_dict["diffraction_dets"]``, pulled from the config file. radiogram_dets: list of str, optional The detectors used for radiographs, defaults to ``glbl_dict["diffraction_dets"]``, pulled from the config file. prefix : bytes or list of bytes, optional Which publisher(s) to listen to for data. Defaults to ``b"raw"`` inbound_prefix : bytees The prefix for outbound data, defaults to ``b"an"`` zscore : bool, optional If True compute Z-Score, defaults to False stage_blacklist : list of str, optional Stages to not publish. Defaults to an empty tuple. Not publishing some of the large memory datasets (mask, mask_overlay, bg_corrected_img, dark_sub) could speed up data processing by cutting down on process communication times. Note that blacklisting some of these (particularly mask and dark_sub) will cause some files to not be written out by the ``save_server``. kwargs : Any Keyword arguments passed into the pipeline creation. These are used to modify the data processing. If using the default pipeline these include: - ``bg_scale=1`` The background scale factor. Defaults to 1 - ``calib_setting`` : The calibration setting, if set to ``{"setting": False}`` the user will not be prompted to perform calibration on calibration samples. This is useful for not performing calibration when re analyzing an entire experiment. - ``polarization_factor`` The polarization factor used to correct the image. Defaults to .99 - ``mask_setting`` The setting for the frequency of the mask. If set to ``{'setting': 'auto'}`` each image gets a mask generated for it, if set to ``{'setting': 'first'}`` only the first image in the series has a mask generated for it and all subsequent images in the series use that mask, if set to ``{'setting': 'none'}`` then no image is masked. Defaults to ``{'setting': 'auto'}``. - ``mask_kwargs`` The keyword arguments passed to ``xpdtools.tools.mask_img``. Defaults to ``dict(edge=30, lower_thresh=0.0, upper_thresh=None, alpha=3, auto_type="median", tmsk=None,)`` - kwargs passed to PDFgetx3. Please see the PDFgetx3 documentation: https://www.diffpy.org/doc/pdfgetx/2.0.0/options.html#pdf-parameters """ print(kwargs) db.prepare_hook = lambda x, y: copy.deepcopy(y) publisher = Publisher(inbound_proxy_address, prefix=inbound_prefix) if _publisher: publisher = _publisher if "db" not in kwargs: kwargs.update(db=db) d = RemoteDispatcher( outbound_proxy_address, # accept the raw data prefix=prefix, ) install_qt_kicker(loop=d.loop) if zscore: _order = z_score_order else: _order = order rr = RunRouter( [diffraction_router], xrd_namespace=create_analysis_pipeline( order=_order, stage_blacklist=stage_blacklist, publisher=publisher, **kwargs, ), diffraction_dets=diffraction_dets, ) rr2 = RunRouter( [radiogram_router], order=radiogram_order, radiogram_dets=radiogram_dets, publisher=publisher, **kwargs, ) d.subscribe(rr) d.subscribe(rr2) print("Starting Analysis Server") d.start()
# If this is removed, data is not saved to metadatastore. from bluesky.global_state import gs gs.RE.subscribe('all', mds.insert) # At the end of every run, verify that files were saved and # print a confirmation message. #from bluesky.callbacks.broker import verify_files_saved #gs.RE.subscribe('stop', post_run(verify_files_saved)) # Import matplotlib and put it in interactive mode. import matplotlib.pyplot as plt plt.ion() # Make plots update live while scans run. from bluesky.utils import install_qt_kicker install_qt_kicker() # Optional: set any metadata that rarely changes. # RE.md['beamline_id'] = 'YOUR_BEAMLINE_HERE' # convenience imports from ophyd.commands import * from bluesky.callbacks import * from bluesky.spec_api import * from bluesky.global_state import gs, abort, stop, resume from bluesky.plan_tools import print_summary from bluesky.callbacks.broker import LiveImage from time import sleep import numpy as np RE = gs.RE # convenience alias
print("REMOTE IS READY TO START") d.start() dispatcher_proc = multiprocessing.Process(target=make_and_start_dispatcher, daemon=True, args=(db,)) dispatcher_proc.start() ''' #time.sleep(5) # As above, give this plenty of time to start. #''' # s = conf_main_pipeline(db, glbl['tiff_base'], vis=False, write_to_disk=True, calibration_md_folder='~/xpdUser/config_base') #pt = xrun.subscribe(istar(s.emit)) #s = MainCallback(db, glbl['tiff_base'], calibration_md_folder='~/xpdUser/config_base') #pt = xrun.subscribe(s) # xrun.subscribe(lambda x, y: pprint(y)) install_qt_kicker(loop=xrun.loop) # start a beamtime PI_name = 'Billinge ' saf_num = 300000 wavelength = xpd_wavelength experimenters = [('van der Banerjee', 'S0ham', 1), ('Terban ', ' Max', 2)] try: bt = _start_beamtime(PI_name, saf_num, experimenters, wavelength=wavelength) except FileExistsError: pass # spreadsheet glbl['dk_window'] = 0.1 pytest_dir = rs_fn('xpdacq', 'tests/')
def run_server( order=order, radiogram_order=radiogram_order, db=glbl_dict["exp_db"], outbound_proxy_address=glbl_dict["outbound_proxy_address"], inbound_proxy_address=glbl_dict["inbound_proxy_address"], diffraction_dets=glbl_dict["diffraction_dets"], radiogram_dets=glbl_dict["radiogram_dets"], prefix=b"raw", zscore=False, **kwargs ): """Function to run the analysis server. Parameters ---------- order : list, optional The order of pipeline chunk functions to be called. Defaults to the standard order, ``xpdan.startup.analysis_server.order`` radiogram_order : list, optional The order of pipeline chunk functions to be called for radiograph analysis. Defaults to the standard order, ``xpdan.startup.analysis_server.radiogram_order`` db : databroker.Broker instance, optional The databroker to pull data from. This is used for accessing dark and background data. Defaults to the location listed in the ``xpdconf.conf.glbl_dict``. outbound_proxy_address : str, optional The location of the ZMQ proxy sending data to this server. Defaults to the location listed in the ``xpdconf.conf.glbl_dict``. inbound_proxy_address : str, optional The inbound ip address for the ZMQ server. Defaults to the value from the global dict diffraction_dets : list of str, optional The detectors used for diffraction, defaults to ``glbl_dict["diffraction_dets"]``, pulled from the config file. radiogram_dets: list of str, optional The detectors used for radiographs, defaults to ``glbl_dict["diffraction_dets"]``, pulled from the config file. prefix : bytes or list of bytes, optional Which publisher(s) to listen to for data. Defaults to ``b"raw"`` zscore : bool, optional If True compute Z-Score, defaults to False kwargs : Any Keyword arguments passed into the pipeline creation. These are used to modify the data processing. If using the default pipeline these include: - ``bg_scale=1`` The background scale factor. Defaults to 1 - ``calib_setting`` : The calibration setting, if set to ``{"setting": False}`` the user will not be prompted to perform calibration on calibration samples. This is useful for not performing calibration when re analyzing an entire experiment. - ``polarization_factor`` The polarization factor used to correct the image. Defaults to .99 - ``mask_setting`` The setting for the frequency of the mask. If set to ``{'setting': 'auto'}`` each image gets a mask generated for it, if set to ``{'setting': 'first'}`` only the first image in the series has a mask generated for it and all subsequent images in the series use that mask, if set to ``{'setting': 'none'}`` then no image is masked. Defaults to ``{'setting': 'auto'}``. - ``mask_kwargs`` The keyword arguments passed to ``xpdtools.tools.mask_img``. Defaults to ``dict(edge=30, lower_thresh=0.0, upper_thresh=None, alpha=3, auto_type="median", tmsk=None,)`` - kwargs passed to PDFgetx3. Please see the PDFgetx3 documentation: https://www.diffpy.org/doc/pdfgetx/2.0.0/options.html#pdf-parameters """ print(kwargs) db.prepare_hook = lambda x, y: copy.deepcopy(y) if "db" not in kwargs: kwargs.update(db=db) d = RemoteDispatcher( outbound_proxy_address, # accept the raw data prefix=prefix, ) install_qt_kicker(loop=d.loop) if zscore: rr = RunRouter( [diffraction_router], order=z_score_order, diffraction_dets=diffraction_dets, inbound_proxy_address=inbound_proxy_address, ) else: rr = RunRouter( [diffraction_router], order=order, diffraction_dets=diffraction_dets, inbound_proxy_address=inbound_proxy_address, ) rr2 = RunRouter( [radiogram_router], order=radiogram_order, radiogram_dets=radiogram_dets, inbound_proxy_address=inbound_proxy_address, ) d.subscribe(rr) d.subscribe(rr2) print("Starting Analysis Server") d.start()
def configure_base(user_ns, broker_name, *, bec=True, epics_context=True, magics=True, mpl=True, ophyd_logging=True, pbar=True): """ Perform base setup and instantiation of important objects. This factory function instantiates the following and adds them to the namespace: * ``RE`` -- a RunEngine * ``db`` -- a Broker (from "databroker"), subscribe to ``RE`` * ``bec`` -- a BestEffortCallback, subscribed to ``RE`` * ``peaks`` -- an alias for ``bec.peaks`` * ``sd`` -- a SupplementalData preprocessor, added to ``RE.preprocessors`` * ``pbar_maanger`` -- a ProgressBarManager, set as the ``RE.waiting_hook`` And it performs some low-level configuration: * creates a context in ophyd's control layer (``ophyd.setup_ophyd()``) * turns out interactive plotting (``matplotlib.pyplot.ion()``) * bridges the RunEngine and Qt event loops (``bluesky.utils.install_kicker()``) * logs ERROR-level log message from ophyd to the standard out Parameters ---------- user_ns: dict a namespace --- for example, ``get_ipython().user_ns`` broker_name : Union[str, Broker] Name of databroker configuration or a Broker instance. bec : boolean, optional True by default. Set False to skip BestEffortCallback. epics_context : boolean, optional True by default. Set False to skip ``setup_ophyd()``. magics : boolean, optional True by default. Set False to skip registration of custom IPython magics. mpl : boolean, optional True by default. Set False to skip matplotlib ``ion()`` at event-loop bridging. ophyd_logging : boolean, optional True by default. Set False to skip ERROR-level log configuration for ophyd. pbar : boolean, optional True by default. Set false to skip ProgressBarManager. Returns ------- names : list list of names added to the namespace Examples -------- Configure IPython for CHX. >>>> configure_base(get_ipython().user_ns, 'chx'); """ ns = {} # We will update user_ns with this at the end. # Test if we are in Jupyter or IPython: in_jupyter = user_ns['get_ipython']().has_trait('kernel') # Set up a RunEngine and use metadata backed by a sqlite file. from bluesky import RunEngine from bluesky.utils import get_history # if RunEngine already defined grab it # useful when users make their own custom RunEngine if 'RE' in user_ns: RE = user_ns['RE'] else: RE = RunEngine(get_history()) ns['RE'] = RE # Set up SupplementalData. # (This is a no-op until devices are added to it, # so there is no need to provide a 'skip_sd' switch.) from bluesky import SupplementalData sd = SupplementalData() RE.preprocessors.append(sd) ns['sd'] = sd if isinstance(broker_name, str): # Set up a Broker. from databroker import Broker db = Broker.named(broker_name) ns['db'] = db else: db = broker_name RE.subscribe(db.insert) if pbar and not in_jupyter: # Add a progress bar. from bluesky.utils import ProgressBarManager pbar_manager = ProgressBarManager() RE.waiting_hook = pbar_manager ns['pbar_manager'] = pbar_manager if magics: # Register bluesky IPython magics. from bluesky.magics import BlueskyMagics get_ipython().register_magics(BlueskyMagics) if bec: # Set up the BestEffortCallback. from bluesky.callbacks.best_effort import BestEffortCallback _bec = BestEffortCallback() bec = _bec RE.subscribe(_bec) if in_jupyter: _bec.disable_plots() ns['bec'] = _bec ns['peaks'] = _bec.peaks # just as alias for less typing if mpl: # Import matplotlib and put it in interactive mode. import matplotlib.pyplot as plt ns['plt'] = plt plt.ion() # Commented to allow more intelligent setting of kickers (for Jupyter and IPython): ## Make plots update live while scans run. # from bluesky.utils import install_kicker # install_kicker() # Make plots update live while scans run. if in_jupyter: from bluesky.utils import install_nb_kicker install_nb_kicker() else: from bluesky.utils import install_qt_kicker install_qt_kicker() if not ophyd_logging: # Turn on error-level logging, particularly useful for knowing when # pyepics callbacks fail. import logging import ophyd.ophydobj ch = logging.StreamHandler() ch.setLevel(logging.ERROR) ophyd.ophydobj.logger.addHandler(ch) # convenience imports # some of the * imports are for 'back-compatibility' of a sort -- we have # taught BL staff to expect LiveTable and LivePlot etc. to be in their # namespace import numpy as np ns['np'] = np import bluesky.callbacks ns['bc'] = bluesky.callbacks import_star(bluesky.callbacks, ns) import bluesky.plans ns['bp'] = bluesky.plans import_star(bluesky.plans, ns) import bluesky.plan_stubs ns['bps'] = bluesky.plan_stubs import_star(bluesky.plan_stubs, ns) # special-case the commonly-used mv / mvr and its aliases mov / movr4 ns['mv'] = bluesky.plan_stubs.mv ns['mvr'] = bluesky.plan_stubs.mvr ns['mov'] = bluesky.plan_stubs.mov ns['movr'] = bluesky.plan_stubs.movr import bluesky.preprocessors ns['bpp'] = bluesky.preprocessors import bluesky.callbacks.broker import_star(bluesky.callbacks.broker, ns) import bluesky.simulators import_star(bluesky.simulators, ns) user_ns.update(ns) return list(ns)
'timezone': tzlocal.get_localzone().zone, 'dbpath': os.path.join('/home/christopher/live_demo_data', 'filestore')} mds = MDSRO(d) fs = RegistryRO(d) fs.register_handler('AD_TIFF', AreaDetectorTiffHandler) db = Broker(mds=mds, reg=fs) td = TemporaryDirectory() source = conf_main_pipeline(db, td.name, # vis=False, write_to_disk=False, # mask_setting=None ) # a = LiveImage('pe1_image') loop = zmq_asyncio.ZMQEventLoop() install_qt_kicker(loop=loop) def put_in_queue(nd): if nd[0] == 'event': nd[1]['data']['pe1_image'] = np.asarray(nd[1]['data']['pe1_image']) # if nd[0] == 'event': # db.fill_event(nd[1]) # print(nd) # source.emit(nd) a(*nd) plt.pause(.1) disp = RemoteDispatcher('127.0.0.1:5568', loop=loop) # disp.subscribe(istar(put_in_queue)) # disp.subscribe(a)
def __init__(self, parent=None, live=False, cfg=None, dark=True): super().__init__(parent=parent) ui = self.ui #Change the stylesheet if dark: try: import qdarkstyle except ImportError: logger.error("Can not use dark theme, " "qdarkstyle package not available") else: self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # Configure debug file after all the qt logs logging.basicConfig(level=logging.DEBUG, format=('%(asctime)s ' '%(name)-12s ' '%(levelname)-8s ' '%(message)s'), datefmt='%m-%d %H:%M:%S', filename='./skywalker_debug.log', filemode='a') # Set self.sim, self.loader, self.nominal_config self.sim = not live self.config_folder = cfg self.init_config() # Load things self.config_cache = {} self.cache_config() # Load system and alignments into the combo box objects ui.image_title_combo.clear() ui.procedure_combo.clear() ui.procedure_combo.addItem('None') self.all_imager_names = [ entry['imager'] for entry in self.loader.live_systems.values() ] for imager_name in self.all_imager_names: ui.image_title_combo.addItem(imager_name) for align in self.alignments.keys(): ui.procedure_combo.addItem(align) # Pick out some initial parameters from system and alignment dicts first_system_key = list(self.alignments.values())[0][0][0] first_set = self.loader.get_subsystem(first_system_key) first_imager = first_set.get('imager', None) first_slit = first_set.get('slits', None) first_rotation = first_set.get('rotation', 0) # self.procedure and self.image_obj keep track of the gui state self.procedure = 'None' self.image_obj = first_imager # Initialize slit readback self.slit_group = ObjWidgetGroup([ ui.slit_x_width, ui.slit_y_width, ui.slit_x_setpoint, ui.slit_y_setpoint, ui.slit_circle ], [ 'xwidth.readback', 'ywidth.readback', 'xwidth.setpoint', 'ywidth.setpoint', 'xwidth.done' ], first_slit, label=ui.readback_slits_title) # Initialize mirror control self.mirror_groups = [] mirror_labels = self.get_widget_set('mirror_name') mirror_rbvs = self.get_widget_set('mirror_readback') mirror_vals = self.get_widget_set('mirror_setpos') mirror_circles = self.get_widget_set('mirror_circle') mirror_nominals = self.get_widget_set('move_nominal') for label, rbv, val, circle, nom, mirror in zip( mirror_labels, mirror_rbvs, mirror_vals, mirror_circles, mirror_nominals, self.mirrors_padded()): mirror_group = ObjWidgetGroup([rbv, val, circle, nom], [ 'pitch.user_readback', 'pitch.user_setpoint', 'pitch.motor_done_move' ], mirror, label=label) if mirror is None: mirror_group.hide() self.mirror_groups.append(mirror_group) # Initialize the goal entry fields self.goals_groups = [] goal_labels = self.get_widget_set('goal_name') goal_edits = self.get_widget_set('goal_value') slit_checks = self.get_widget_set('slit_check') for label, edit, check, img, slit in zip(goal_labels, goal_edits, slit_checks, self.imagers_padded(), self.slits_padded()): if img is None: name = None else: name = img.name validator = QDoubleValidator(0, 5000, 3) goal_group = ValueWidgetGroup(edit, label, checkbox=check, name=name, cache=self.config_cache, validator=validator) if img is None: goal_group.hide() elif slit is None: goal_group.checkbox.setEnabled(False) self.goals_groups.append(goal_group) # Initialize image and centroids. Needs goals defined first. self.image_group = ImgObjWidget(ui.image, first_imager, ui.beam_x_value, ui.beam_y_value, ui.beam_x_delta, ui.beam_y_delta, ui.image_state, ui.image_state_select, ui.readback_imager_title, self, first_rotation) ui.image.setColorMapToPreset('jet') # Initialize the settings window. first_step = Setting('first_step', 6.0) tolerance = Setting('tolerance', 5.0) averages = Setting('averages', 100) timeout = Setting('timeout', 600.0) tol_scaling = Setting('tol_scaling', 8.0) min_beam = Setting('min_beam', 1.0, required=False) min_rate = Setting('min_rate', 1.0, required=False) slit_width = Setting('slit_width', 0.2) samples = Setting('samples', 100) close_fee_att = Setting('close_fee_att', True) self.settings = SettingsGroup( parent=self, collumns=[['alignment'], ['slits', 'suspenders', 'setup']], alignment=[first_step, tolerance, averages, timeout, tol_scaling], suspenders=[min_beam, min_rate], slits=[slit_width, samples], setup=[close_fee_att]) self.settings_cache = {} self.load_settings() self.restore_settings() self.cache_settings() # Required in case nothing is loaded # Create the RunEngine that will be used in the alignments. # This gives us the ability to pause, etc. self.RE = RunEngine({}) install_qt_kicker() # Some hax to keep the state string updated # There is probably a better way to do this # This might break on some package update self.RE.state # Yes this matters old_set = RunEngine.state._memory[self.RE].set_ def new_set(state): # NOQA old_set(state) txt = " Status: " + state.capitalize() self.ui.status_label.setText(txt) RunEngine.state._memory[self.RE].set_ = new_set # Connect relevant signals and slots procedure_changed = ui.procedure_combo.currentIndexChanged[str] procedure_changed.connect(self.on_procedure_combo_changed) imager_changed = ui.image_title_combo.currentIndexChanged[str] imager_changed.connect(self.on_image_combo_changed) for goal_value in self.get_widget_set('goal_value'): goal_changed = goal_value.editingFinished goal_changed.connect(self.on_goal_changed) start_pressed = ui.start_button.clicked start_pressed.connect(self.on_start_button) pause_pressed = ui.pause_button.clicked pause_pressed.connect(self.on_pause_button) abort_pressed = ui.abort_button.clicked abort_pressed.connect(self.on_abort_button) slits_pressed = ui.slit_run_button.clicked slits_pressed.connect(self.on_slits_button) save_mirrors_pressed = ui.save_mirrors_button.clicked save_mirrors_pressed.connect(self.on_save_mirrors_button) save_goals_pressed = ui.save_goals_button.clicked save_goals_pressed.connect(self.on_save_goals_button) settings_pressed = ui.settings_button.clicked settings_pressed.connect(self.on_settings_button) for i, nominal_button in enumerate(mirror_nominals): nominal_pressed = nominal_button.clicked nominal_pressed.connect(partial(self.on_move_nominal_button, i)) self.cam_lock = RLock() # Store some info about our screen size. QApp = QCoreApplication.instance() desktop = QApp.desktop() geometry = desktop.screenGeometry() self.screen_size = (geometry.width(), geometry.height()) window_qsize = self.window().size() self.preferred_size = (window_qsize.width(), window_qsize.height()) # Setup the post-init hook post_init = PostInit(self) self.installEventFilter(post_init) post_init.post_init.connect(self.on_post_init) # Setup the on-screen logger console = self.setup_gui_logger() # Stop the run if we get closed close_dict = dict(RE=self.RE, console=console) self.destroyed.connect(partial(SkywalkerGui.on_close, close_dict)) # Put out the initialization message. init_base = 'Skywalker GUI initialized in ' if self.sim: init_str = init_base + 'sim mode.' else: init_str = init_base + 'live mode.' logger.info(init_str)
def run_server( prefix=None, outbound_proxy_address=glbl_dict["outbound_proxy_address"], inbound_proxy_address=glbl_dict["inbound_proxy_address"], _publisher=None, **kwargs ): """Start up the QOI server Parameters ---------- prefix : bytes or list of bytes, optional The Publisher channels to listen to. Defaults to ``[b"an", b"raw"]`` outbound_proxy_address : str, optional The address and port of the zmq proxy. Defaults to ``glbl_dict["outbound_proxy_address"]`` inbound_proxy_address : str, optional The inbound ip address for the ZMQ server. Defaults to the value from the global dict """ if prefix is None: prefix = [b"an", b"raw"] d = RemoteDispatcher(outbound_proxy_address, prefix=prefix) install_qt_kicker(loop=d.loop) if _publisher is None: an_with_ind_pub = Publisher(inbound_proxy_address, prefix=b"qoi") else: an_with_ind_pub = _publisher raw_source = Stream() # create amorphous pipeline amorphous_ns = link( *[amorphsivity_fem, amorphsivity_pipeline, amorphsivity_tem], source=Stream(), **kwargs ) # Combine the data outputs with the raw independent data amorphous_ns.update( to_event_stream_with_ind( move_to_first(raw_source.starmap(StripDepVar())), *[ node for node in amorphous_ns.values() if isinstance(node, SimpleToEventStream) ], publisher=an_with_ind_pub ) ) rr = RunRouter( [ lambda x: lambda *y: raw_source.emit(y) if x["analysis_stage"] == "raw" else None, lambda x: lambda *y: amorphous_ns["source"].emit(y) if x["analysis_stage"] == "pdf" else None, ] ) d.subscribe(rr) print("Starting QOI Server") d.start()
def start_analysis( mask_kwargs=None, pdf_kwargs=None, fq_kwargs=None, mask_setting=None, save_kwargs=None, # pdf_argrelmax_kwargs=None, # mean_argrelmax_kwargs=None ): """Start analysis pipeline Parameters ---------- mask_kwargs : dict The kwargs passed to the masking see xpdtools.tools.mask_img pdf_kwargs : dict The kwargs passed to the pdf generator, see xpdtools.tools.pdf_getter fq_kwargs : dict The kwargs passed to the fq generator, see xpdtools.tools.fq_getter mask_setting : dict The setting of the mask save_kwargs : dict The kwargs passed to the main formatting node (mostly the filename template) """ # if pdf_argrelmax_kwargs is None: # pdf_argrelmax_kwargs = {} # if mean_argrelmax_kwargs is None: # mean_argrelmax_kwargs = {} d = RemoteDispatcher(glbl_dict['proxy_address']) install_qt_kicker( loop=d.loop) # This may need to be d._loop depending on tag if mask_setting is None: mask_setting = {} if fq_kwargs is None: fq_kwargs = {} if pdf_kwargs is None: pdf_kwargs = {} if mask_kwargs is None: mask_kwargs = {} if save_kwargs is None: save_kwargs = {} for a, b in zip( [ mask_kwargs, pdf_kwargs, fq_kwargs, mask_setting, save_kwargs, # pdf_argrelmax_kwargs, # mean_argrelmax_kwargs ], [ _mask_kwargs, _pdf_kwargs, _fq_kwargs, _mask_setting, _save_kwargs, # _pdf_argrelmax_kwargs, # _mean_argrelmax_kwargs ]): if a: b.update(a) d.subscribe(lambda *x: raw_source.emit(x)) print('Starting Analysis Server') d.start()