def __init__(self, role, filename, hdf5_group, beam_energy_coeff = 1.0, apply_mask=False, mask_filename=None, mask_hdf5_group=False, gain_map_correction=False, gain_map_filename=None, gain_map_hdf5_group=None): """Initializes the DarkCal correction algorithm. Args: role (str): node role ('worker' or 'master'). filename (str): name of the hdf5 5 with dark calibration. data hdf5_group (str): path of the dark calibration data within the hdf5 file. apply_mask (Optional[bool]): whether a mask should be applied (optional, if omitted no mask is applied). mask_filename (Optional[str]) : if the mask is applied, name of the hdf5 file with gain_map, otherwise ignored (optional). mask_hdf5_group (Optional[str]): if the mask is applied, internal hdf5 path of the data block containing the mask, otherwise ignored (optional). gain_map_correction (Optional[bool]): whether a gain_map should be applied (optional, if omitted no gain map is applied). gain_map_filename (Optional[str]) : if the gain map is applied, name of the hdf5 file with gain_map, otherwise ignored (optional). gain_map_hdf5_group (Optional[str]): if the gain map is applied, internal hdf5 path of the data block containing the mask, otherwise ignored (optional). """ # Initialized on worker if role == 'worker': self.beam_energy_coeff = beam_energy_coeff # load the darkcals self.darkcal = load_nparray_from_hdf5_file(filename, hdf5_group) if apply_mask: self.mask = load_nparray_from_hdf5_file(mask_filename, mask_hdf5_group) else: self.mask = True if gain_map_correction: self.gain_map = load_nparray_from_hdf5_file( gain_map_filename, gain_map_hdf5_group) self.gain_map[numpy.where(self.gain_map==0)] = 1.0 else: self.gain_map = numpy.ones((352,128,512), dtype=bool)
def __init__(self, monitor_params, rec_ip, rec_port): super(MainFrame, self).__init__() self.monitor_params = monitor_params gen_params = monitor_params['General'] p8pd_params = monitor_params['Peakfinder8PeakDetection'] self.rec_ip, self.rec_port = rec_ip, rec_port self.data = collections.deque(maxlen=20) self.data_index = 0 self.image_update_us = 250 self.zeromq_listener_thread = PyQt4.QtCore.QThread() self.zeromq_listener = ZMQListener(self.rec_ip, self.rec_port, u'ondarawdata') self.init_listening_thread() self.ring_pen = pyqtgraph.mkPen('r', width=2) self.circle_pen = pyqtgraph.mkPen('b', width=2) pix_maps = pixel_maps_from_geometry_file( monitor_params['General']['geometry_file']) self.pixelmap_radius = pix_maps[2] self.pixel_maps, self.slab_shape, self.img_shape = pixel_maps_for_image_view( gen_params['geometry_file']) self.img_to_draw = numpy.zeros(self.img_shape, dtype=numpy.float32) self.mask_to_draw = numpy.zeros(self.img_shape + (3, ), dtype=numpy.int16) self.max_num_peaks = int(p8pd_params['max_num_peaks']) self.asic_nx = int(p8pd_params['asics_nx']) self.asic_ny = int(p8pd_params['asics_ny']) self.nasics_x = int(p8pd_params['nasics_x']) self.nasics_y = int(p8pd_params['nasics_y']) self.adc_thresh = float(p8pd_params['adc_threshold']) self.minimum_snr = float(p8pd_params['minimum_snr']) self.min_pixel_count = int(p8pd_params['min_pixel_count']) self.max_pixel_count = int(p8pd_params['max_pixel_count']) self.local_bg_radius = int(p8pd_params['local_bg_radius']) self.mask_filename = p8pd_params['mask_filename'] self.mask_hdf5_path = p8pd_params['mask_hdf5_path'] self.min_res = int(p8pd_params['min_res']) self.max_res = int(p8pd_params['max_res']) self.loaded_mask = load_nparray_from_hdf5_file(self.mask_filename, self.mask_hdf5_path) self.min_num_peaks_for_hit = int( monitor_params['General']['min_num_peaks_for_hit']) self.max_num_peaks_for_hit = int( monitor_params['General']['max_num_peaks_for_hit']) self.res_mask = numpy.ones(self.slab_shape, dtype=numpy.int8) self.res_mask[numpy.where(self.pixelmap_radius < self.min_res)] = 0 self.res_mask[numpy.where(self.pixelmap_radius > self.max_res)] = 0 self.mask = self.loaded_mask * self.res_mask mask = self.loaded_mask.copy().astype(numpy.float) mask = mask * 255. / mask.max() mask = 255. - mask self.mask_to_draw[self.pixel_maps[0], self.pixel_maps[1], 1] = mask.ravel() self.mask_image_view = pyqtgraph.ImageItem() self.peak_canvas = pyqtgraph.ScatterPlotItem() self.circle_canvas = pyqtgraph.ScatterPlotItem() self.adc_threshold_label = PyQt4.QtGui.QLabel(self) self.adc_threshold_label.setText('adc_threshold') self.adc_threshold_lineedit = PyQt4.QtGui.QLineEdit(self) self.adc_threshold_lineedit.setText( str(self.monitor_params['Peakfinder8PeakDetection'] ['adc_threshold'])) self.adc_threshold_lineedit.editingFinished.connect(self.update_peaks) self.hlayout0 = PyQt4.QtGui.QHBoxLayout() self.hlayout0.addWidget(self.adc_threshold_label) self.hlayout0.addWidget(self.adc_threshold_lineedit) self.min_snr_label = PyQt4.QtGui.QLabel(self) self.min_snr_label.setText('minmum_snr') self.min_snr_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_snr_lineedit.setText( str(self.monitor_params['Peakfinder8PeakDetection'] ['minimum_snr'])) self.min_snr_lineedit.editingFinished.connect(self.update_peaks) self.hlayout1 = PyQt4.QtGui.QHBoxLayout() self.hlayout1.addWidget(self.min_snr_label) self.hlayout1.addWidget(self.min_snr_lineedit) self.min_pixel_count_label = PyQt4.QtGui.QLabel(self) self.min_pixel_count_label.setText('min_pixel_count') self.min_pixel_count_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_pixel_count_lineedit.setText( str(self.monitor_params['Peakfinder8PeakDetection'] ['min_pixel_count'])) self.min_pixel_count_lineedit.editingFinished.connect( self.update_peaks) self.hlayout2 = PyQt4.QtGui.QHBoxLayout() self.hlayout2.addWidget(self.min_pixel_count_label) self.hlayout2.addWidget(self.min_pixel_count_lineedit) self.max_pixel_count_label = PyQt4.QtGui.QLabel(self) self.max_pixel_count_label.setText('max_pixel_count') self.max_pixel_count_lineedit = PyQt4.QtGui.QLineEdit(self) self.max_pixel_count_lineedit.setText( str(self.monitor_params['Peakfinder8PeakDetection'] ['max_pixel_count'])) self.max_pixel_count_lineedit.editingFinished.connect( self.update_peaks) self.hlayout3 = PyQt4.QtGui.QHBoxLayout() self.hlayout3.addWidget(self.max_pixel_count_label) self.hlayout3.addWidget(self.max_pixel_count_lineedit) self.local_bg_radius_label = PyQt4.QtGui.QLabel(self) self.local_bg_radius_label.setText('local_bg_raidus') self.local_bg_radius_lineedit = PyQt4.QtGui.QLineEdit(self) self.local_bg_radius_lineedit.setText( str(self.monitor_params['Peakfinder8PeakDetection'] ['local_bg_radius'])) self.local_bg_radius_lineedit.editingFinished.connect( self.update_peaks) self.hlayout4 = PyQt4.QtGui.QHBoxLayout() self.hlayout4.addWidget(self.local_bg_radius_label) self.hlayout4.addWidget(self.local_bg_radius_lineedit) self.min_res_label = PyQt4.QtGui.QLabel(self) self.min_res_label.setText('min_res') self.min_res_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_res_lineedit.setText(str(self.min_res)) self.min_res_lineedit.editingFinished.connect(self.update_peaks) self.hlayout5 = PyQt4.QtGui.QHBoxLayout() self.hlayout5.addWidget(self.min_res_label) self.hlayout5.addWidget(self.min_res_lineedit) self.max_res_label = PyQt4.QtGui.QLabel(self) self.max_res_label.setText('max_res') self.max_res_lineedit = PyQt4.QtGui.QLineEdit(self) self.max_res_lineedit.setText(str(self.max_res)) self.max_res_lineedit.editingFinished.connect(self.update_peaks) self.hlayout6 = PyQt4.QtGui.QHBoxLayout() self.hlayout6.addWidget(self.max_res_label) self.hlayout6.addWidget(self.max_res_lineedit) self.param_label = PyQt4.QtGui.QLabel(self) self.param_label.setText('<b>Peakfinder Parameters:</b>') self.ui = GUI.UI.parameter_tweaker_UI.Ui_MainWindow() self.ui.setupUi(self) self.init_ui() self.setWindowTitle('OnDA Live Parameter Tweaker') self.proxy = pyqtgraph.SignalProxy( self.ui.imageView.getView().scene().sigMouseClicked, slot=self.mouse_clicked) self.update_peaks() self.draw_things() self.refresh_timer = PyQt4.QtCore.QTimer() self.init_timer() self.show()
def __init__(self, monitor_params, rec_ip, rec_port): super(MainFrame, self).__init__() self.monitor_params = monitor_params gen_params = monitor_params['General'] p8pd_params = monitor_params['Peakfinder8PeakDetection'] self.rec_ip, self.rec_port = rec_ip, rec_port self.data = collections.deque(maxlen=20) self.data_index = 0 self.image_update_us = 250 self.zeromq_listener_thread = PyQt4.QtCore.QThread() self.zeromq_listener = ZMQListener(self.rec_ip, self.rec_port, u'ondarawdata') self.init_listening_thread() self.ring_pen = pyqtgraph.mkPen('r', width=2) self.circle_pen = pyqtgraph.mkPen('b', width=2) pix_maps = pixel_maps_from_geometry_file(monitor_params['General']['geometry_file']) self.pixelmap_radius = pix_maps[2] self.pixel_maps, self.slab_shape, self.img_shape = pixel_maps_for_image_view(gen_params['geometry_file']) self.img_to_draw = numpy.zeros(self.img_shape, dtype=numpy.float32) self.mask_to_draw = numpy.zeros(self.img_shape+(3,), dtype=numpy.int16) self.max_num_peaks = int(p8pd_params['max_num_peaks']) self.asic_nx = int(p8pd_params['asics_nx']) self.asic_ny = int(p8pd_params['asics_ny']) self.nasics_x = int(p8pd_params['nasics_x']) self.nasics_y = int(p8pd_params['nasics_y']) self.adc_thresh = float(p8pd_params['adc_threshold']) self.minimum_snr = float(p8pd_params['minimum_snr']) self.min_pixel_count = int(p8pd_params['min_pixel_count']) self.max_pixel_count = int(p8pd_params['max_pixel_count']) self.local_bg_radius = int(p8pd_params['local_bg_radius']) self.mask_filename = p8pd_params['mask_filename'] self.mask_hdf5_path = p8pd_params['mask_hdf5_path'] self.min_res = int(p8pd_params['min_res']) self.max_res = int(p8pd_params['max_res']) self.loaded_mask = load_nparray_from_hdf5_file(self.mask_filename, self.mask_hdf5_path) self.min_num_peaks_for_hit = int(monitor_params['General']['min_num_peaks_for_hit']) self.max_num_peaks_for_hit = int(monitor_params['General']['max_num_peaks_for_hit']) self.res_mask = numpy.ones(self.slab_shape, dtype=numpy.int8) self.res_mask[numpy.where(self.pixelmap_radius < self.min_res)] = 0 self.res_mask[numpy.where(self.pixelmap_radius > self.max_res)] = 0 self.mask = self.loaded_mask * self.res_mask mask = self.loaded_mask.copy().astype(numpy.float) mask = mask * 255./mask.max() mask = 255. - mask self.mask_to_draw[self.pixel_maps[0], self.pixel_maps[1], 1] = mask.ravel() self.mask_image_view = pyqtgraph.ImageItem() self.peak_canvas = pyqtgraph.ScatterPlotItem() self.circle_canvas = pyqtgraph.ScatterPlotItem() self.adc_threshold_label = PyQt4.QtGui.QLabel(self) self.adc_threshold_label.setText('adc_threshold') self.adc_threshold_lineedit = PyQt4.QtGui.QLineEdit(self) self.adc_threshold_lineedit.setText(str(self.monitor_params['Peakfinder8PeakDetection']['adc_threshold'])) self.adc_threshold_lineedit.editingFinished.connect(self.update_peaks) self.hlayout0 = PyQt4.QtGui.QHBoxLayout() self.hlayout0.addWidget(self.adc_threshold_label) self.hlayout0.addWidget(self.adc_threshold_lineedit) self.min_snr_label = PyQt4.QtGui.QLabel(self) self.min_snr_label.setText('minmum_snr') self.min_snr_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_snr_lineedit.setText(str(self.monitor_params['Peakfinder8PeakDetection']['minimum_snr'])) self.min_snr_lineedit.editingFinished.connect(self.update_peaks) self.hlayout1 = PyQt4.QtGui.QHBoxLayout() self.hlayout1.addWidget(self.min_snr_label) self.hlayout1.addWidget(self.min_snr_lineedit) self.min_pixel_count_label = PyQt4.QtGui.QLabel(self) self.min_pixel_count_label.setText('min_pixel_count') self.min_pixel_count_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_pixel_count_lineedit.setText(str(self.monitor_params['Peakfinder8PeakDetection']['min_pixel_count'])) self.min_pixel_count_lineedit.editingFinished.connect(self.update_peaks) self.hlayout2 = PyQt4.QtGui.QHBoxLayout() self.hlayout2.addWidget(self.min_pixel_count_label) self.hlayout2.addWidget(self.min_pixel_count_lineedit) self.max_pixel_count_label = PyQt4.QtGui.QLabel(self) self.max_pixel_count_label.setText('max_pixel_count') self.max_pixel_count_lineedit = PyQt4.QtGui.QLineEdit(self) self.max_pixel_count_lineedit.setText(str(self.monitor_params['Peakfinder8PeakDetection']['max_pixel_count'])) self.max_pixel_count_lineedit.editingFinished.connect(self.update_peaks) self.hlayout3 = PyQt4.QtGui.QHBoxLayout() self.hlayout3.addWidget(self.max_pixel_count_label) self.hlayout3.addWidget(self.max_pixel_count_lineedit) self.local_bg_radius_label = PyQt4.QtGui.QLabel(self) self.local_bg_radius_label.setText('local_bg_raidus') self.local_bg_radius_lineedit = PyQt4.QtGui.QLineEdit(self) self.local_bg_radius_lineedit.setText(str(self.monitor_params['Peakfinder8PeakDetection']['local_bg_radius'])) self.local_bg_radius_lineedit.editingFinished.connect(self.update_peaks) self.hlayout4 = PyQt4.QtGui.QHBoxLayout() self.hlayout4.addWidget(self.local_bg_radius_label) self.hlayout4.addWidget(self.local_bg_radius_lineedit) self.min_res_label = PyQt4.QtGui.QLabel(self) self.min_res_label.setText('min_res') self.min_res_lineedit = PyQt4.QtGui.QLineEdit(self) self.min_res_lineedit.setText(str(self.min_res)) self.min_res_lineedit.editingFinished.connect(self.update_peaks) self.hlayout5 = PyQt4.QtGui.QHBoxLayout() self.hlayout5.addWidget(self.min_res_label) self.hlayout5.addWidget(self.min_res_lineedit) self.max_res_label = PyQt4.QtGui.QLabel(self) self.max_res_label.setText('max_res') self.max_res_lineedit = PyQt4.QtGui.QLineEdit(self) self.max_res_lineedit.setText(str(self.max_res)) self.max_res_lineedit.editingFinished.connect(self.update_peaks) self.hlayout6 = PyQt4.QtGui.QHBoxLayout() self.hlayout6.addWidget(self.max_res_label) self.hlayout6.addWidget(self.max_res_lineedit) self.param_label = PyQt4.QtGui.QLabel(self) self.param_label.setText('<b>Peakfinder Parameters:</b>') self.ui = GUI.UI.parameter_tweaker_UI.Ui_MainWindow() self.ui.setupUi(self) self.init_ui() self.setWindowTitle('OnDA Live Parameter Tweaker') self.proxy = pyqtgraph.SignalProxy(self.ui.imageView.getView().scene().sigMouseClicked, slot=self.mouse_clicked) self.update_peaks() self.draw_things() self.refresh_timer = PyQt4.QtCore.QTimer() self.init_timer() self.show()
def __init__(self, role, filter_length, min_filter_length, filter_step, sigma_factor, streak_elongation_min_steps_count, streak_elongation_radius_factor, streak_pixel_mask_radius, num_lines_to_check, background_region_preset, background_region_dist_from_edge, asic_nx, asic_ny, nasics_x, nasics_y, pixel_map_x, pixel_map_y, mask_filename, mask_hdf5_path): """Initializes the peakfinder Args: role (str): node role ('worker' or 'master') filter_length (int): length of the radial filter with which the image is prefiltered min_filter_length (int): Minimum amount of non-masked pixels in the radial filter with which the image is prefiltered float filter_step (float): size of the step through the radial filter sigma_factor(float): minimum number of stddev above the mean for the pixel to be part of a streak. streak_elongation_min_steps_count (int): number of steps to keep searching for a streak after it apparently ends streak_elongation_radius_factor (float): maximum distance in pixels from the center to keep searching for a streak after it apparently ends streak_pixel_mask_radius (int): Radius of the mask around the streak in pixels num_lines_to_check (int): maximum distance in pixels from the inner edge of the inner panels to searching for the beginning of a streak background_region_preset (int): preset locations of regions to be used to estimate the background level background_region_dist_from_edge (int): distance of background regions in pixels from the edge of the inner panels asic_nx (int): fs size of a detector's ASIC. asic_ny (int): ss size of a detector's ASIC. nasics_x (int): number of ASICs in the slab in the fs direction. nasics_y (int): number of ASICs in the slab in the ss direction. pixel_map_x (numpy.ndarray): pixel_map for x coordinate pixel_map_y (numpy.ndarray): pixel_map for y coordinate mask_filename (str): filename of the file containing the mask. mask_hdf5_path (str): internal hdf5 path of the data block containing the mask. """ # Initialized on worker if role == 'worker': self.mask = load_nparray_from_hdf5_file(mask_filename, mask_hdf5_path) self.background_region_mask = numpy.zeros(self.mask.shape) self.streak_detection = StreakDetectionClass( min_filter_length, filter_step, sigma_factor, streak_elongation_min_steps_count, streak_elongation_radius_factor, streak_pixel_mask_radius, num_lines_to_check, 0, background_region_preset, background_region_dist_from_edge, asic_nx, asic_ny, nasics_x, nasics_y, pixel_map_x, pixel_map_y, self.mask, self.background_region_mask)
def __init__(self, role, max_num_peaks, asic_nx, asic_ny, nasics_x, nasics_y, adc_threshold, minimum_snr, min_pixel_count, max_pixel_count, local_bg_radius, accumulated_shots, min_res, max_res, mask_filename, mask_hdf5_path, pixelmap_radius): """Initializes the peakfinder Args: role (str): node role ('worker' or 'master') max_num_peaks (int): maximum number of peaks that will be returned by the algorithm. asic_nx (int): fs size of a detector's ASIC. asic_ny (int): ss size of a detector's ASIC. nasics_x (int): number of ASICs in the slab in the fs direction. nasics_y (int): number of ASICs in the slab in the ss direction. adc_threshold (float): minimum adc threshold for peak detection. minimum_snr (float): minimum signal to noise for peak detection. min_pixel_count (int): minimum size of the peak in pixels. max_pixel_count (int): maximum size of the peak in pixels. local_bg_radius (int): radius for the estimation of the local background. accumulated_shots (int): the number of accumulated shots before the peak list is returned. min_res (int): minimum resolution for a peak to be considered (in pixels). max_res (int): minimum resolution for a peak to be considered (in pixels). mask_filename (str): filename of the file containing the mask. mask_hdf5_path (str): internal hdf5 path of the data block containing the mask. pixelmap_radius (numpy.ndarray): pixelmap in 'slab' format listing for each pixel the distance from the center of the detector (in pixels). """ self.max_num_peaks = max_num_peaks self.asic_nx = asic_nx self.asic_ny = asic_ny self.nasics_x = nasics_x self.nasics_y = nasics_y self.adc_thresh = adc_threshold self.minimum_snr = minimum_snr self.min_pixel_count = min_pixel_count self.max_pixel_count = max_pixel_count self.local_bg_radius = local_bg_radius self.pixelmap_radius = pixelmap_radius if role == 'master': self.accumulated_shots = accumulated_shots self.accumulator = ([], [], []) self.events_in_accumulator = 0 # Initialized on worker if role == 'worker': self.mask = load_nparray_from_hdf5_file(mask_filename, mask_hdf5_path) self.res_mask = numpy.ones(self.mask.shape, dtype=numpy.int8) self.res_mask[numpy.where(pixelmap_radius < min_res)] = 0 self.res_mask[numpy.where(pixelmap_radius > max_res)] = 0 self.mask *= self.res_mask
def __init__(self, role, max_num_peaks, asic_nx, asic_ny, nasics_x, nasics_y, sigma_factor_biggest_pixel, sigma_factor_peak_pixel, sigma_factor_whole_peak, minimum_sigma, minimum_peak_oversize_over_neighbours, window_radius, accumulated_shots, min_res, max_res, mask_filename, mask_hdf5_path, pixelmap_radius): """Initializes the peakfinder Args: role (str): node role ('worker' or 'master') max_num_peaks (int): maximum number of peaks that will be returned by the algorithm. asic_nx (int): fs size of a detector's ASIC. asic_ny (int): ss size of a detector's ASIC. nasics_x (int): number of ASICs in the slab in the fs direction. nasics_y (int): number of ASICs in the slab in the ss direction. sigma_factor_biggest_pixel (float): minimum number of stddev above the mean for the brightest pixel in a peak. sigma_factor_peak_pixel (float): minimum number of stddev above the mean for all pixels except the brightest. Should be equal to or lower than sigma_factor_biggest_pixel. sigma_factor_whole_peak (float): minimum number of stddev above the mean for the accumulated inensity of a peak. Should be equal to or lower than sigma_factor_biggest_pixel. minimum_sigma (float): minimum number of stddev for a pixel to be a peak candidate. minimum_peak_oversize_over_neighbours (float): minimum intensity difference between the brighest pixel in a peak and the background pixels (pixels on the border of the background windows). window_size (int): radius of the window used to estimate background. accumulated_shots (int): the number of accumulated shots before the peak list is returned. min_res (int): minimum resolution for a peak to be considered (in pixels). max_res (int): minimum resolution for a peak to be considered (in pixels). mask_filename (str): filename of the file containing the mask. mask_hdf5_path (str): internal hdf5 path of the data block containing the mask. """ self.max_num_peaks = max_num_peaks self.asic_nx = asic_nx self.asic_ny = asic_ny self.nasics_x = nasics_x self.nasics_y = nasics_y self.sigma_factor_biggest_pixel = sigma_factor_biggest_pixel self.sigma_factor_peak_pixel = sigma_factor_peak_pixel self.sigma_factor_whole_peak = sigma_factor_whole_peak self.minimum_sigma = minimum_sigma self.minimum_peak_oversize_over_neighbours = minimum_peak_oversize_over_neighbours self.window_radius = window_radius if role == 'master': self.accumulated_shots = accumulated_shots self.accumulator = ([], [], []) self.events_in_accumulator = 0 # Initialized on worker if role == 'worker': self.mask = load_nparray_from_hdf5_file(mask_filename, mask_hdf5_path) self.res_mask = numpy.ones(self.mask.shape, dtype=numpy.int8) self.res_mask[numpy.where(pixelmap_radius < min_res)] = 0 self.res_mask[numpy.where(pixelmap_radius > max_res)] = 0 self.mask *= self.res_mask