コード例 #1
0
ファイル: powder.py プロジェクト: michel4j/auto-process
 def __init__(self, filename):
     self.frame = read_image(filename)
     self.nx, self.ny = self.frame.data.shape
     self.x_axis = numpy.arange(self.nx)
     self.y_axis = numpy.arange(self.ny)
     self.cx, self.cy = self.frame.header['beam_center']
     self.rot_x, self.rot_y = 0.0, 0.0
     self.mask = (self.frame.data > 0.0) & (
         self.frame.data < self.frame.header['saturated_value'])
コード例 #2
0
def get_parameters(img_file):
    """ 
    Determine parameters for the data set represented by img_fiile
    returns a dictionary of results
    
    """
    data = read_image(os.path.abspath(img_file))
    if not data.header['dataset'] or len(
            data.header['dataset']['sequence']) == 0:
        logger.error("Dataset not found")
        raise autoprocess.errors.DatasetError('Dataset not found')

    info = data.header
    info['energy'] = misc.wavelength_to_energy(info['wavelength'])
    info['first_frame'] = info['dataset']['sequence'][0]
    info['frame_count'] = info['dataset']['sequence'][-1]
    info['name'] = info['dataset']['label']
    info['file_template'] = os.path.join(info['dataset']['directory'],
                                         info['dataset']['template'])

    # Generate a list of wedges. each wedge is a tuple. The first value is the
    # first frame number and the second is the number of frames in the wedge
    wedges = summarize_list(info['dataset']['sequence'])

    # determine spot ranges from wedges
    # up to 4 degrees per wedge starting at 0 and 45 and 90
    spot_range = []
    spot_span = int(4.0 // info['delta_angle'])  # frames in 4 deg
    first_wedge = wedges[0]

    for _ang in [0.0, 45.0, 90.0]:
        _rs = first_wedge[0] + int(_ang // info['delta_angle'])
        _re = _rs + spot_span
        _exp_set = set(range(_rs, _re))
        for wedge in wedges:
            _obs_set = set(range(wedge[0], wedge[0] + wedge[1]))
            _range = (_exp_set & _obs_set)
            if len(_range) > 0:
                spot_range.append((min(_range), max(_range)))

    biggest_wedge = sorted(wedges, key=lambda x: x[1], reverse=True)[0]

    info['spot_range'] = spot_range
    info['data_range'] = info['dataset']['sequence'][0], info['dataset'][
        'sequence'][-1]
    info['background_range'] = (biggest_wedge[0], biggest_wedge[0] +
                                min(10, biggest_wedge[1]) - 1)
    info['skip_range'] = summarize_gaps(info['dataset']['sequence'])
    info['max_delphi'] = info['delta_angle'] * biggest_wedge[1]
    return info
コード例 #3
0
ファイル: imagewidget.py プロジェクト: michel4j/mxdc
    def load(self, path):
        attempts = 0
        success = False
        while not success and attempts < 10:
            path_obj = pathlib.Path(path)
            if path_obj.exists(
            ) and path_obj.stat().st_ctime < time.time() - MAX_SAVE_JITTER:
                try:
                    dataset = read_image(path)
                    self.show(dataset)
                    success = True
                except (ValueError, KeyError) as err:
                    success = False
            attempts += 1
            time.sleep(0.1)

        if not success:
            logger.info("Unable to load {}".format(path))
        return success
コード例 #4
0
ファイル: frames.py プロジェクト: michel4j/mxdc
 def load(self, path):
     self.set_state(busy=True)
     attempts = 0
     success = False
     while not success and attempts < 10:
         loadable = (os.path.exists(path)
                     and time.time() - os.path.getmtime(path) >
                     self.MAX_SAVE_JITTER)
         if loadable:
             try:
                 dataset = read_image(path)
                 if self.master:
                     self.master.process_frame(dataset)
                 success = True
             except Exception:
                 success = False
         attempts += 1
         time.sleep(1 / MAX_FILE_FREQUENCY)
     self.set_state(busy=False)
     return success
コード例 #5
0
def detect_beam_peak(filename):
    img_info = read_image(filename)
    img = img_info.image
    img_array = numpy.fromstring(img.tostring(), numpy.uint32)
    img_array.shape = img.size[1], img.size[0]

    # filter the array so that features less than 8 pixels wide are blurred out
    # assumes that beam center is at least 8 pixels wide
    arr = filters.gaussian_filter(img_array, 8)
    beam_y, beam_x = measurements.maximum_position(arr)

    # valid beam centers must be within the center 1/5 region of the detector surface
    shape = img_array.shape
    cmin = [2 * v / 5 for v in shape]
    cmax = [3 * v / 5 for v in shape]
    good = False
    if cmin[0] < beam_y < cmax[0] and cmin[1] < beam_x < cmax[1]:
        good = True

    return beam_x, beam_y, good