def test_deregister(): test_reg = fsa._FS_SINGLETON.handler_reg test_spec_name = str(uuid.uuid4()) fsa.register_handler(test_spec_name, SynHandlerMod) assert test_reg[test_spec_name] is SynHandlerMod fsa.deregister_handler(test_spec_name) assert test_spec_name not in test_reg
def test_register_fail(): with fsa.handler_context({'syn-mod': SynHandlerMod}): # shouldn't raise, it is a no-op as it is regiristering # the same class with the same name fsa.register_handler('syn-mod', SynHandlerMod) # should raise as it is trying to change the registered class with pytest.raises(RuntimeError): fsa.register_handler('syn-mod', SynHandlerEcho)
def register_builtin_handlers(): "Register all the handlers built in to filestore." # TODO This will blow up if any non-leaves in the class heirarchy # have non-empty specs. Make this smart later. for cls in vars(handlers).values(): if isinstance(cls, type) and issubclass(cls, HandlerBase): logger.debug("Found Handler %r for specs %r", cls, cls.specs) for spec in cls.specs: logger.debug("Registering Handler %r for spec %r", cls, spec) register_handler(spec, cls)
def setup_module(module): fs_setup() register_handler('AD_HDF5', AreaDetectorHDF5Handler) register_handler('AD_HDF5_SWMR', AreaDetectorHDF5SWMRHandler) register_handler('AD_HDF5_TS', AreaDetectorHDF5TimestampHandler) register_handler('AD_HDF5_SWMR_TS', AreaDetectorHDF5SWMRTimestampHandler)
def test_overwrite_global(): h_cache = fsa._FS_SINGLETON._handler_cache mock_base = dict(spec='syn-mod', resource_path='', resource_kwargs={'shape': (5, 7)}) res = fsa.insert_resource(**mock_base) cache_key = (str(res['id']), SynHandlerMod.__name__) with fsa.handler_context({'syn-mod': SynHandlerMod}): fsa.get_spec_handler(res['id']) assert cache_key in h_cache fsa.register_handler('syn-mod', SynHandlerEcho, overwrite=True) assert cache_key not in h_cache
self.filename = str(filename) def __call__(self, **kwargs): return load_gr_file(self.filename, **kwargs)[1] class GeneratedPDFHandler(HandlerBase): specs = {'genpdf'} | HandlerBase.specs def __init__(self, filename): self.filename = str(filename) def __call__(self, **kwargs): return np.load(self.filename) class FileLocation(HandlerBase): specs = {'fileloc'} | HandlerBase.specs def __init__(self, filename): self.filename = filename def __call__(self, **kwargs): return self.filename handlers = [ASEAtomsHandler, PDFGetX3Handler, GeneratedPDFHandler] for handler in handlers: for spec in handler.specs: register_handler(spec, handler)
# 4 -- under-responsive # 8 -- over-responsive # 16 -- noisy pixel_mask = md['pixel_mask'] pixel_mask[pixel_mask > 0] = 1 pixel_mask[pixel_mask == 0] = 2 pixel_mask[pixel_mask == 1] = 0 pixel_mask[pixel_mask == 2] = 1 md['framerate'] = 1. / md['frame_time'] # TODO Return a multi-dimensional PIMS seq return FixedEigerImages(master_path, md) deregister_handler('AD_EIGER') _HANDLER_CACHE.clear() register_handler('AD_EIGER', LazyEigerHandler) def print_attrs(name, obj): print(name) for key, val in obj.attrs.items(): print(" %s: %s" % (key, val)) ################################################### ##for image process ################################################### class Reverse_Coordinate(object): def __init__(self, indexable, mask):
from bluesky.examples import * from bluesky.broker_examples import * from bluesky.broker_callbacks import LiveImage from bluesky.tests.utils import setup_test_run_engine from matplotlib import pyplot as plt from xray_vision.backend.mpl.cross_section_2d import CrossSection import numpy as np import filestore.api as fsapi import time as ttime from filestore.handlers import NpyHandler fsapi.register_handler('npy', NpyHandler) def stepscan(det, motor): for i in np.linspace(-5, 5, 75): yield Msg('open_run') yield Msg('create') yield Msg('set', motor, i) yield Msg('trigger', det) yield Msg('read', motor) yield Msg('read', det) yield Msg('save') yield Msg('close_run') ic = LiveImage('det_2d') table_callback = LiveTable(fields=[motor.name, det_2d._name]) RE = setup_test_run_engine() RE(stepscan(det_2d, motor), subs={'event': ic, 'all': table_callback}, beamline_id='c08i')
def setup(): fs_setup() # register the dummy handler to use register_handler('syn-mod', SynHandlerMod)
class FixedAreaDetectorTiffHandler(HandlerBase): specs = {'AD_TIFF'} | HandlerBase.specs def __init__(self, fpath, template, filename, frame_per_point=1): self._path = fpath self._fpp = frame_per_point self._template = template.replace('_%6.6d', '*') self._filename = self._template % (self._path, filename) self._image_sequence = pims.ImageSequence(self._filename) def __call__(self, point_number): start = int(point_number * self._fpp) stop = int((point_number + 1) * self._fpp) if stop > len(self._image_sequence): # if asking for an image past the end, make sure we have an up # to # date list of the existing files self._image_sequence = pims.ImageSequence(self._filename) if stop > len(self._image_sequence): # if we _still_ don't have enough files, raise raise IntegrityError("Seeking Frame {0} out of {1} " " frames.".format(stop, len(self._image_sequence))) return np.asarray(list(self._image_sequence[start:stop])).squeeze() import databroker # so that built-in handlers are registered from filestore.api import deregister_handler, register_handler deregister_handler('AD_TIFF') register_handler('AD_TIFF', FixedAreaDetectorTiffHandler)
from dataportal.examples.sample_data import common import six import h5py import os.path as op import numpy as np import datetime import uuid import logging logger = logging.getLogger(__name__) noisy = common.noisy register_handler('hdf_maps', HDFM) def save_syn_data(eid, data, base_path=None): """ Save a array as hdf format to disk. Defaults to saving files in :path:`~/.fs_cache/YYYY-MM-DD.h5` Parameters ---------- eid : unicode id for file name data : ndarray The data to be saved base_path : str, optional The base-path to use for saving files. If not given
# 4 -- under-responsive # 8 -- over-responsive # 16 -- noisy pixel_mask = md["pixel_mask"] pixel_mask[pixel_mask > 0] = 1 pixel_mask[pixel_mask == 0] = 2 pixel_mask[pixel_mask == 1] = 0 pixel_mask[pixel_mask == 2] = 1 md["framerate"] = 1.0 / md["frame_time"] # TODO Return a multi-dimensional PIMS seq return FixedEigerImages(master_path, md) deregister_handler("AD_EIGER") _HANDLER_CACHE.clear() register_handler("AD_EIGER", LazyEigerHandler) def print_attrs(name, obj): print(name) for key, val in obj.attrs.items(): print(" %s: %s" % (key, val)) ################################################### ##for image process ################################################### class Reverse_Coordinate(object): def __init__(self, indexable, mask):
def __call__(self, frame=None, channel=None): # Don't read out the dataset until it is requested for the first time. self._get_dataset() return self._dataset[frame, channel - 1, :].squeeze() def get_roi(self, roi_info, frame=None, max_points=None): self._get_dataset() chan = roi_info.chan bin_low = roi_info.bin_low bin_high = roi_info.bin_high roi = np.sum(self._dataset[:, chan - 1, bin_low:bin_high], axis=1) if max_points is not None: roi = roi[:max_points] if len(roi) < max_points: roi = np.pad(roi, ((0, max_points - len(roi)), ), 'constant') if frame is not None: roi = roi[frame, :] return roi def __repr__(self): return '{0.__class__.__name__}(filename={0._filename!r})'.format(self) fs_api.register_handler(Xspress3HDF5Handler.HANDLER_NAME, Xspress3HDF5Handler)
def setup(): global conn db_disconnect() db_connect(db_name, 'localhost', 27017) register_handler('AD_HDF5', AreaDetectorHDF5Handler)
def dtype(self): return self.pixel_type @property def shape(self): return self.frame_shape class LazyEigerHandler(HandlerBase): specs = {'AD_EIGER'} | HandlerBase.specs def __init__(self, fpath, frame_per_point, mapping=None): # create pims handler self.vals_dict = EIGER_MD_DICT.copy() if mapping is not None: self.vals_dict.update(mapping) self._base_path = fpath self.fpp = frame_per_point def __call__(self, seq_id): import h5py master_path = '{}_{}_master.h5'.format(self._base_path, seq_id) md = {} print('hdf5 path = %s' % master_path) with h5py.File(master_path, 'r') as f: md = {k: f[v].value for k, v in self.vals_dict.items()} # TODO Return a multi-dimensional PIMS seq. return FixedEigerImages(master_path, md) deregister_handler('AD_EIGER') register_handler('AD_EIGER', LazyEigerHandler)
def register(): import filestore.api as fs_api fs_api.register_handler(Xspress3HDF5Handler.HANDLER_NAME, Xspress3HDF5Handler)
from bluesky.examples import * from bluesky.broker_examples import * from bluesky.broker_callbacks import LiveImage from bluesky.tests.utils import setup_test_run_engine from matplotlib import pyplot as plt from xray_vision.backend.mpl.cross_section_2d import CrossSection import numpy as np import filestore.api as fsapi import time as ttime from filestore.handlers import NpyHandler fsapi.register_handler('npy', NpyHandler) def stepscan(det, motor): for i in np.linspace(-5, 5, 75): yield Msg('open_run') yield Msg('create') yield Msg('set', motor, i) yield Msg('trigger', det) yield Msg('read', motor) yield Msg('read', det) yield Msg('save') yield Msg('close_run') ic = LiveImage('det_2d') table_callback = LiveTable(fields=[motor._name, det_2d._name]) RE = setup_test_run_engine() RE(stepscan(det_2d, motor), subs={
def register(): import filestore.api as fs_api fs_api.register_handler(TimepixHDF5Handler._handler_name, TimepixHDF5Handler, overwrite=True)