Esempio n. 1
0
    def make_scan(image_range,
                  exposure_times,
                  oscillation,
                  epochs,
                  batch_offset=0,
                  deg=True):
        if not isinstance(exposure_times, list):
            num_images = image_range[1] - image_range[0] + 1
            exposure_times = [exposure_times for i in range(num_images)]
        else:
            num_images = image_range[1] - image_range[0] + 1
            num_exp = len(exposure_times)
            if num_exp != num_images:
                if num_exp == 0:
                    exposure_times = [0 for i in range(num_images)]
                else:
                    exposure_times = exposure_times.extend([
                        exposure_times[-1] for i in range(num_images - num_exp)
                    ])

        epoch_list = [epochs[j] for j in sorted(epochs)]

        return Scan(
            tuple(map(int, image_range)),
            tuple(map(float, oscillation)),
            flex.double(list(map(float, exposure_times))),
            flex.double(list(map(float, epoch_list))),
            batch_offset,
            deg,
        )
Esempio n. 2
0
    def from_dict(d, t=None):
        ''' Convert the dictionary to a scan model

    Params:
        d The dictionary of parameters
        t The template dictionary to use

    Returns:
        The scan model

    '''
        from dxtbx.model import Scan
        from scitbx.array_family import flex  # import dependency

        # If None, return None
        if d == None:
            if t == None: return None
            else: return from_dict(t, None)
        elif t != None:
            d = dict(t.items() + d.items())
        if not isinstance(d['exposure_time'], list):
            d['exposure_time'] = [d['exposure_time']]

        d.setdefault('batch_offset', 0)  # backwards compatibility 20180205
        if 'valid_image_ranges' not in d:
            d['valid_image_ranges'] = {}  # backwards compatibility 20181113
        # Create the model from the dictionary
        return Scan.from_dict(d)
Esempio n. 3
0
    def from_dict(d, t=None):
        ''' Convert the dictionary to a scan model

    Params:
        d The dictionary of parameters
        t The template dictionary to use

    Returns:
        The scan model

    '''
        from dxtbx.model import Scan
        from scitbx.array_family import flex  # import dependency

        # If None, return None
        if d == None:
            if t == None: return None
            else: return from_dict(t, None)
        elif t != None:
            d = dict(t.items() + d.items())
        if not isinstance(d['exposure_time'], list):
            d['exposure_time'] = [d['exposure_time']]

        # Create the model from the dictionary
        return Scan.from_dict(d)
Esempio n. 4
0
    def from_dict(d, t=None):
        """Convert the dictionary to a scan model

        Params:
            d The dictionary of parameters
            t The template dictionary to use

        Returns:
            The scan model
        """
        if d is None and t is None:
            return None
        joint = t.copy() if t else {}
        joint.update(d)

        if not isinstance(joint["exposure_time"], list):
            joint["exposure_time"] = [joint["exposure_time"]]
        joint.setdefault("batch_offset", 0)  # backwards compatibility 20180205
        joint.setdefault("valid_image_ranges", {})  # backwards compatibility 20181113

        # Create the model from the joint dictionary
        return Scan.from_dict(joint)
Esempio n. 5
0
    def from_phil(params, reference=None):
        """
        Generate a scan model from phil parameters

        """
        if reference is None:
            if params.scan.image_range is None and params.scan.oscillation is None:
                return None
            if params.scan.image_range is None:
                raise RuntimeError("No image range set")
            if params.scan.oscillation is None:
                raise RuntimeError("No oscillation set")
            scan = Scan(params.scan.image_range, params.scan.oscillation)
        else:
            scan = reference

            if params.scan.image_range is not None:
                most_recent_image_index = (scan.get_image_range()[1] -
                                           scan.get_image_range()[0])
                scan.set_oscillation(
                    scan.get_image_oscillation(params.scan.image_range[0]))
                scan.set_image_range(params.scan.image_range)
                if (params.scan.extrapolate_scan and
                    (params.scan.image_range[1] - params.scan.image_range[0]) >
                        most_recent_image_index):
                    exposure_times = scan.get_exposure_times()
                    epochs = scan.get_epochs()
                    exposure_time = exposure_times[most_recent_image_index]
                    epoch_correction = epochs[most_recent_image_index]
                    for i in range(
                            most_recent_image_index + 1,
                            params.scan.image_range[1] -
                            params.scan.image_range[0] + 1,
                    ):
                        exposure_times[i] = exposure_time
                        epoch_correction += exposure_time
                        epochs[i] = epoch_correction
                    scan.set_epochs(epochs)
                    scan.set_exposure_times(exposure_times)
            if params.scan.oscillation is not None:
                scan.set_oscillation(params.scan.oscillation)

        if params.scan.batch_offset is not None:
            scan.set_batch_offset(params.scan.batch_offset)

        # Return the model
        return scan