def __init__(self, address, out_dirname, out_basename, binning=1, brightness=1.0, color_scheme=0, format='png', **kwds): """The mod_dump_bitmap class constructor stores the parameters passed from the pyana configuration file in instance variables. @param address Full data source address of the DAQ device @param out_dirname Directory portion of output image pathname @param out_basename Filename prefix of output image pathname """ #define COLOR_GRAY 0 #define COLOR_RAINBOW 1 #define COLOR_HEAT 2 #define COLOR_INVERT 3 super(mod_dump_bitmap, self).__init__(address=address, **kwds) self._basename = cspad_tbx.getOptString(out_basename) self._dirname = cspad_tbx.getOptString(out_dirname) self._binning = cspad_tbx.getOptInteger(binning) self._brightness = cspad_tbx.getOptFloat(brightness) self._color_scheme = cspad_tbx.getOptInteger(color_scheme) self._format = cspad_tbx.getOptString(format) self._ext = self._format.lower() self._logger = logging.getLogger(self.__class__.__name__) if (not os.path.isdir(self._dirname)): os.makedirs(self._dirname)
def __init__(self, address, directory, beam_x = None, beam_y = None, template = None): """ @param address Address string XXX Que?! @param directory Directory portion of the MAR image paths @param beam_x Beam center x in pixels. Uses dxtbx beam center if not specified. @param beam_y Beam center y in pixels. Uses dxtbx beam center if not specified. @param template Simple template for filtering files processed. If @param template is in the file name, the file is accepted """ self._logger = logging.getLogger(self.__class__.__name__) self._logger.setLevel(logging.INFO) # This is needed as a key for the image data. self._address = cspad_tbx.getOptString(address) self._directory = cspad_tbx.getOptString(directory) # Save the beam center and image template self._beam_x = cspad_tbx.getOptInteger(beam_x) self._beam_y = cspad_tbx.getOptInteger(beam_y) self._template = cspad_tbx.getOptString(template) # At the moment, we cannot use multiprocessing for this anyway. # This has to be an absolute path to the image. self._path = None self._mccd_name = None
def __init__(self, address, n_collate=None, n_update=120, common_mode_correction="none", wait=None, photon_counting=False, sigma_scaling=False, **kwds): """The mod_view class constructor XXX. @param address Full data source address of the DAQ device @param calib_dir Directory with calibration information @param common_mode_correction The type of common mode correction to apply @param dark_path Path to input average dark image @param dark_stddev Path to input standard deviation dark image, required if @p dark_path is given @param wait Minimum time (in seconds) to wait on the current image before moving on to the next @param n_collate Number of shots to average, or <= 0 to average all shots @param n_update Number of shots between updates """ super(mod_view, self).__init__(address=address, common_mode_correction=common_mode_correction, **kwds) self.detector = cspad_tbx.address_split(address)[0] self.nvalid = 0 self.ncollate = cspad_tbx.getOptInteger(n_collate) self.nupdate = cspad_tbx.getOptInteger(n_update) self.photon_counting = cspad_tbx.getOptBool(photon_counting) self.sigma_scaling = cspad_tbx.getOptBool(sigma_scaling) if (self.ncollate is None): self.ncollate = self.nupdate if (self.ncollate > self.nupdate): self.ncollate = self.nupdate self.logger.warning("n_collate capped to %d" % self.nupdate) linger = True # XXX Make configurable wait = cspad_tbx.getOptFloat(wait) # Create a managed FIFO queue shared between the viewer and the # current process. The current process will produce images, while # the viewer process will consume them. manager = multiprocessing.Manager() self._queue = manager.Queue() self._proc = multiprocessing.Process(target=_xray_frame_process, args=(self._queue, linger, wait)) self._proc.start() self.n_shots = 0
def __init__(self, address, n_collate = None, n_update = 120, common_mode_correction = "none", wait=None, photon_counting=False, sigma_scaling=False, **kwds): """The mod_view class constructor XXX. @param address Full data source address of the DAQ device @param calib_dir Directory with calibration information @param common_mode_correction The type of common mode correction to apply @param dark_path Path to input average dark image @param dark_stddev Path to input standard deviation dark image, required if @p dark_path is given @param wait Minimum time (in seconds) to wait on the current image before moving on to the next @param n_collate Number of shots to average, or <= 0 to average all shots @param n_update Number of shots between updates """ super(mod_view, self).__init__( address=address, common_mode_correction=common_mode_correction, **kwds) self.detector = cspad_tbx.address_split(address)[0] self.nvalid = 0 self.ncollate = cspad_tbx.getOptInteger(n_collate) self.nupdate = cspad_tbx.getOptInteger(n_update) self.photon_counting = cspad_tbx.getOptBool(photon_counting) self.sigma_scaling = cspad_tbx.getOptBool(sigma_scaling) if (self.ncollate is None): self.ncollate = self.nupdate if (self.ncollate > self.nupdate): self.ncollate = self.nupdate self.logger.warning("n_collate capped to %d" % self.nupdate) linger = True # XXX Make configurable wait = cspad_tbx.getOptFloat(wait) # Create a managed FIFO queue shared between the viewer and the # current process. The current process will produce images, while # the viewer process will consume them. manager = multiprocessing.Manager() self._queue = manager.Queue() self._proc = multiprocessing.Process( target=_xray_frame_process, args=(self._queue, linger, wait)) self._proc.start() self.n_shots = 0
def __init__(self, address, pickle_dirname=".", pickle_basename="hist", roi=None, hist_min=None, hist_max=None, n_slots=None, **kwds): """ @param address Address string XXX Que?! @param pickle_dirname Directory portion of output pickle file XXX mean, mu? @param pickle_basename Filename prefix of output pickle file image XXX mean, mu? @param calib_dir Directory with calibration information @param dark_path Path to input dark image @param dark_stddev Path to input dark standard deviation """ super(pixel_histograms, self).__init__(address=address, **kwds) self.pickle_dirname = cspad_tbx.getOptString(pickle_dirname) self.pickle_basename = cspad_tbx.getOptString(pickle_basename) self.hist_min = cspad_tbx.getOptFloat(hist_min) self.hist_max = cspad_tbx.getOptFloat(hist_max) self.n_slots = cspad_tbx.getOptInteger(n_slots) self.histograms = {} self.dimensions = None self.roi = cspad_tbx.getOptROI(roi) self.values = flex.long() self.sigma_scaling = False if self.hist_min is None: self.hist_min = -50 if self.hist_max is None: self.hist_max = 150 if self.n_slots is None: self.n_slots = 200
def __init__(self, address, target_energy, angle=0, n_collate = None, n_update = 1, threshold= 0.4, filter="False", clean="False", mode="E1", peak_ratio=0.17, common_mode_correction = "none", **kwds): """ @param address Address string XXX Que?! @param dirname Directory portion of output pickle file @param basename Filename prefix of output pickle file @param dark_path Path to input dark image @param dark_stddev Path to input dark standard deviation """ super(mod_spectra, self).__init__( address=address, common_mode_correction=common_mode_correction, **kwds ) self.threshold=cspad_tbx.getOptFloat(threshold) self.peak_ratio=cspad_tbx.getOptFloat(peak_ratio) self.angle=cspad_tbx.getOptFloat(angle) self.nv = 0 self.collate=None self.data=None self.ncollate = cspad_tbx.getOptInteger(n_collate) self.nvalid = 0 self.n_shots = 0 self.nupdate = cspad_tbx.getOptInteger(n_update) self.filter=filter self.clean=clean self.target=map(float,target_energy.split(",")) self.mode=mode self.all=[] if (self.ncollate is None): self.ncollate = self.nupdate if (self.ncollate > self.nupdate): self.ncollate = self.nupdate self.logger.warning("n_collate capped to %d" % self.nupdate)
def __init__(self, address, pickle_dirname=".", pickle_basename="hist", roi=None, hist_min=None, hist_max=None, n_slots=None, **kwds): """ @param address Address string XXX Que?! @param pickle_dirname Directory portion of output pickle file XXX mean, mu? @param pickle_basename Filename prefix of output pickle file image XXX mean, mu? @param calib_dir Directory with calibration information @param dark_path Path to input dark image @param dark_stddev Path to input dark standard deviation """ super(pixel_histograms, self).__init__( address=address, **kwds ) self.pickle_dirname = cspad_tbx.getOptString(pickle_dirname) self.pickle_basename = cspad_tbx.getOptString(pickle_basename) self.hist_min = cspad_tbx.getOptFloat(hist_min) self.hist_max = cspad_tbx.getOptFloat(hist_max) self.n_slots = cspad_tbx.getOptInteger(n_slots) self.histograms = {} self.dimensions = None self.roi = cspad_tbx.getOptROI(roi) self.values = flex.long() self.sigma_scaling = False if self.hist_min is None: self.hist_min = -50 if self.hist_max is None: self.hist_max = 150 if self.n_slots is None: self.n_slots = 200
def __init__(self, address, calib_dir=None, common_mode_correction="none", photon_threshold=None, two_photon_threshold=None, dark_path=None, dark_stddev=None, mask_path=None, gain_map_path=None, gain_map_level=None, cache_image=True, roi=None, laser_1_status=None, laser_4_status=None, laser_wait_time=None, override_beam_x=None, override_beam_y=None, bin_size=None, crop_rayonix=False, **kwds): """The common_mode_correction class constructor stores the parameters passed from the pyana configuration file in instance variables. @param address Full data source address of the DAQ device @param calib_dir Directory with calibration information @param common_mode_correction The type of common mode correction to apply @param dark_path Path to input average dark image @param dark_stddev Path to input standard deviation dark image, required if @p dark_path is given @param mask_path Path to input mask. Pixels to mask out should be set to -2 @param gain_map_path Path to input gain map. Multiplied times the image. @param gain_map_level If set, all the '1' pixels in the gain_map are set to this multiplier and all the '0' pixels in the gain_map are set to '1'. If not set, use the values in the gain_map directly @param laser_1_status 0 or 1 to indicate that the laser should be off or on respectively @param laser_4_status 0 or 1 to indicate that the laser should be off or on respectively @param laser_wait_time Length of time in milliseconds to wait after a laser change of status to begin accepting images again. (rejection of images occurs immediately after status change). @param override_beam_x override value for x coordinate of beam center in pixels @param override_beam_y override value for y coordinate of beam center in pixels @param bin_size bin size for rayonix detector used to determin pixel size @param crop_rayonix whether to crop rayonix images such that image center is the beam center """ # Cannot use the super().__init__() construct here, because # common_mode_correction refers to the argument, and not the # class. mod_event_info.__init__(self, address=address, **kwds) # The paths will be substituted in beginjob(), where evt and env # are available. self._dark_path = cspad_tbx.getOptString(dark_path) self._dark_stddev_path = cspad_tbx.getOptString(dark_stddev) self._gain_map_path = cspad_tbx.getOptString(gain_map_path) self._mask_path = cspad_tbx.getOptString(mask_path) self.gain_map_level = cspad_tbx.getOptFloat(gain_map_level) self.common_mode_correction = cspad_tbx.getOptString(common_mode_correction) self.photon_threshold = cspad_tbx.getOptFloat(photon_threshold) self.two_photon_threshold = cspad_tbx.getOptFloat(two_photon_threshold) self.cache_image = cspad_tbx.getOptBool(cache_image) self.filter_laser_1_status = cspad_tbx.getOptInteger(laser_1_status) self.filter_laser_4_status = cspad_tbx.getOptInteger(laser_4_status) if self.filter_laser_1_status is not None: self.filter_laser_1_status = bool(self.filter_laser_1_status) if self.filter_laser_4_status is not None: self.filter_laser_4_status = bool(self.filter_laser_4_status) self.filter_laser_wait_time = cspad_tbx.getOptInteger(laser_wait_time) self.override_beam_x = cspad_tbx.getOptFloat(override_beam_x) self.override_beam_y = cspad_tbx.getOptFloat(override_beam_y) self.bin_size = cspad_tbx.getOptInteger(bin_size) self.crop_rayonix = cspad_tbx.getOptBool(crop_rayonix) self.cspad_img = None # The current image - set by self.event() self.sum_common_mode = 0 self.sumsq_common_mode = 0 self.roi = cspad_tbx.getOptROI(roi) # used to ignore the signal region in chebyshev fit assert self.common_mode_correction in \ ("gaussian", "mean", "median", "mode", "none", "chebyshev") # Get and parse metrology. self.sections = None device = cspad_tbx.address_split(self.address)[2] if device == 'Andor': self.sections = [] # XXX FICTION elif device == 'Cspad': if self.address == 'XppGon-0|Cspad-0': self.sections = [] # Not used for XPP else: self.sections = calib2sections(cspad_tbx.getOptString(calib_dir)) elif device == 'Cspad2x2': # There is no metrology information for the Sc1 detector, so # make it up. The sections are rotated by 90 degrees with # respect to the "standing up" convention. self.sections = [[Section(90, (185 / 2 + 0, (2 * 194 + 3) / 2)), Section(90, (185 / 2 + 185, (2 * 194 + 3) / 2))]] elif device == 'marccd': self.sections = [] # XXX FICTION elif device == 'pnCCD': self.sections = [] # XXX FICTION elif device == 'Rayonix': self.sections = [] # XXX FICTION elif device == 'Opal1000': self.sections = [] # XXX FICTION if self.sections is None: raise RuntimeError("Failed to load metrology")
def __init__(self, address, dispatch=None, integration_dirname=None, integration_basename=None, out_dirname=None, out_basename=None, roi=None, distl_min_peaks=None, distl_flags=None, threshold=None, xtal_target=None, negate_hits=False, trial_id=None, db_logging=False, progress_logging=False, sql_buffer_size=1, db_host=None, db_name=None, db_table_name=None, db_experiment_tag=None, db_user=None, db_password=None, db_tags=None, trial=None, rungroup_id=None, db_version='v1', **kwds): """The mod_hitfind class constructor stores the parameters passed from the pyana configuration file in instance variables. All parameters, except @p address are optional, and hence need not be defined in pyana.cfg. @param address Full data source address of the DAQ device @param dispatch Function to call @param integration_dirname Directory portion of output integration file pathname @param integration_basename Filename prefix of output integration file pathname @param out_dirname Directory portion of output image pathname @param out_basename Filename prefix of output image pathname @param roi Region of interest for thresholding, on the form fast_low:fast_high,slow_low:slow_high @param threshold Minimum value in region of interest to pass """ super(mod_hitfind, self).__init__(address=address, **kwds) self.m_dispatch = cspad_tbx.getOptString(dispatch) self.m_integration_basename = cspad_tbx.getOptString( integration_basename) self.m_integration_dirname = cspad_tbx.getOptString( integration_dirname) self.m_out_basename = cspad_tbx.getOptString(out_basename) self.m_out_dirname = cspad_tbx.getOptString(out_dirname) self.m_distl_min_peaks = cspad_tbx.getOptInteger(distl_min_peaks) self.m_distl_flags = cspad_tbx.getOptStrings(distl_flags) self.m_threshold = cspad_tbx.getOptInteger(threshold) self.m_xtal_target = cspad_tbx.getOptString(xtal_target) self.m_negate_hits = cspad_tbx.getOptBool(negate_hits) self.m_trial_id = cspad_tbx.getOptInteger(trial_id) self.m_db_logging = cspad_tbx.getOptBool(db_logging) self.m_progress_logging = cspad_tbx.getOptBool(progress_logging) self.m_sql_buffer_size = cspad_tbx.getOptInteger(sql_buffer_size) self.m_db_host = cspad_tbx.getOptString(db_host) self.m_db_name = cspad_tbx.getOptString(db_name) self.m_db_table_name = cspad_tbx.getOptString(db_table_name) self.m_db_experiment_tag = cspad_tbx.getOptString(db_experiment_tag) self.m_db_user = cspad_tbx.getOptString(db_user) self.m_db_password = cspad_tbx.getOptString(db_password) self.m_db_tags = cspad_tbx.getOptString(db_tags) self.m_trial = cspad_tbx.getOptInteger(trial) self.m_rungroup_id = cspad_tbx.getOptInteger(rungroup_id) self.m_db_version = cspad_tbx.getOptString(db_version) # A ROI should not contain any ASIC boundaries, as these are # noisy. Hence circular ROI:s around the beam centre are probably # not such a grand idea. self.m_roi = cspad_tbx.getOptROI(roi) # Verify that dist_min_peaks is either "restrictive" or # "permissive", but not both. ^ is the logical xor operator if self.m_distl_min_peaks is not None: if (not (('permissive' in self.m_distl_flags) ^ ('restrictive' in self.m_distl_flags))): raise RuntimeError("""Sorry, with the distl_min_peaks option, distl_flags must be set to 'permissive' or 'restrictive'.""") if (self.m_roi is not None): raise RuntimeError("""Sorry, either specify region of interest (roi) or distl_min_peaks, but not both.""") if self.m_db_logging: self.buffered_sql_entries = [] assert self.m_sql_buffer_size >= 1 if self.m_progress_logging: if self.m_db_version == 'v1': self.buffered_progress_entries = [] assert self.m_sql_buffer_size >= 1 self.isoforms = {} elif self.m_db_version == 'v2': from xfel.ui import db_phil_str from libtbx.phil import parse extra_phil = """ input { trial = None .type = int trial_id = None .type = int rungroup = None .type = int } """ self.db_params = parse(db_phil_str + extra_phil).extract() self.db_params.experiment_tag = self.m_db_experiment_tag self.db_params.db.host = self.m_db_host self.db_params.db.name = self.m_db_name self.db_params.db.user = self.m_db_user self.db_params.db.password = self.m_db_password self.db_params.input.trial = self.m_trial self.db_params.input.rungroup = self.m_rungroup_id if self.m_db_tags is None: self.m_db_tags = ""
def __init__(self, address, dispatch = None, integration_dirname = None, integration_basename = None, out_dirname = None, out_basename = None, roi = None, distl_min_peaks = None, distl_flags = None, threshold = None, xtal_target = None, negate_hits = False, trial_id = None, db_logging = False, progress_logging = False, sql_buffer_size = 1, db_host = None, db_name = None, db_table_name = None, db_experiment_tag = None, db_user = None, db_password = None, db_tags = None, rungroup_id = None, **kwds): """The mod_hitfind class constructor stores the parameters passed from the pyana configuration file in instance variables. All parameters, except @p address are optional, and hence need not be defined in pyana.cfg. @param address Full data source address of the DAQ device @param dispatch Function to call @param integration_dirname Directory portion of output integration file pathname @param integration_basename Filename prefix of output integration file pathname @param out_dirname Directory portion of output image pathname @param out_basename Filename prefix of output image pathname @param roi Region of interest for thresholding, on the form fast_low:fast_high,slow_low:slow_high @param threshold Minimum value in region of interest to pass """ super(mod_hitfind, self).__init__(address=address, **kwds) self.m_dispatch = cspad_tbx.getOptString(dispatch) self.m_integration_basename = cspad_tbx.getOptString(integration_basename) self.m_integration_dirname = cspad_tbx.getOptString(integration_dirname) self.m_out_basename = cspad_tbx.getOptString(out_basename) self.m_out_dirname = cspad_tbx.getOptString(out_dirname) self.m_distl_min_peaks = cspad_tbx.getOptInteger(distl_min_peaks) self.m_distl_flags = cspad_tbx.getOptStrings(distl_flags) self.m_threshold = cspad_tbx.getOptInteger(threshold) self.m_xtal_target = cspad_tbx.getOptString(xtal_target) self.m_negate_hits = cspad_tbx.getOptBool(negate_hits) self.m_trial_id = cspad_tbx.getOptInteger(trial_id) self.m_db_logging = cspad_tbx.getOptBool(db_logging) self.m_progress_logging = cspad_tbx.getOptBool(progress_logging) self.m_sql_buffer_size = cspad_tbx.getOptInteger(sql_buffer_size) self.m_db_host = cspad_tbx.getOptString(db_host) self.m_db_name = cspad_tbx.getOptString(db_name) self.m_db_table_name = cspad_tbx.getOptString(db_table_name) self.m_db_experiment_tag = cspad_tbx.getOptString(db_experiment_tag) self.m_db_user = cspad_tbx.getOptString(db_user) self.m_db_password = cspad_tbx.getOptString(db_password) self.m_db_tags = cspad_tbx.getOptString(db_tags) self.m_rungroup_id = cspad_tbx.getOptInteger(rungroup_id) # A ROI should not contain any ASIC boundaries, as these are # noisy. Hence circular ROI:s around the beam centre are probably # not such a grand idea. self.m_roi = cspad_tbx.getOptROI(roi) # Verify that dist_min_peaks is either "restrictive" or # "permissive", but not both. ^ is the logical xor operator if self.m_distl_min_peaks is not None: if (not (('permissive' in self.m_distl_flags) ^ ('restrictive' in self.m_distl_flags))): raise RuntimeError("""Sorry, with the distl_min_peaks option, distl_flags must be set to 'permissive' or 'restrictive'.""") if (self.m_roi is not None): raise RuntimeError("""Sorry, either specify region of interest (roi) or distl_min_peaks, but not both.""") if self.m_db_logging: self.buffered_sql_entries = [] assert self.m_sql_buffer_size >= 1 if self.m_progress_logging: self.buffered_progress_entries = [] assert self.m_sql_buffer_size >= 1 self.isoforms = {} if self.m_db_tags is None: self.m_db_tags = ""