def __init__(self, detector, t_range, num_intervals, experiment_ids=None):

        if experiment_ids is None:
            experiment_ids = [0]

        # Set up the smoother
        smoother = GaussianSmoother(t_range, num_intervals)
        nv = smoother.num_values()

        # Factory function to provide to _init_core
        def parameter_type(value, axis, ptype, name):
            return ScanVaryingParameterSet(value, nv, axis, ptype, name)

        # Set up the initial state and parameter list
        dat = self._init_core(detector, parameter_type)

        self._d_at_t = matrix.sqr(detector[0].get_d_matrix())

        # set up the base class
        ScanVaryingModelParameterisation.__init__(
            self,
            detector,
            dat["istate"],
            dat["p_list"],
            smoother,
            experiment_ids=experiment_ids,
        )

        return
    def __init__(self, crystal, t_range, num_intervals, experiment_ids=None):
        if experiment_ids is None:
            experiment_ids = [0]

        # The state of a scan-varying unit cell parameterisation is the
        # reciprocal space orthogonalisation matrix '[B](t)', expressed as a
        # function of image number 't' in a sequential scan.

        # Other comments from CrystalUnitCellParameterisation are relevant here

        # Set up the smoother
        smoother = GaussianSmoother(t_range, num_intervals)
        nv = smoother.num_values()

        # Set up the initial state
        istate = None
        self._B_at_t = crystal.get_B()

        # Factory function to provide to _build_p_list
        def parameter_type(value, name):
            return ScanVaryingParameterSet(value, nv, name=name)

        # Build the parameter list
        p_list = self._build_p_list(crystal, parameter_type)

        # Set up the base class
        ScanVaryingModelParameterisation.__init__(
            self,
            crystal,
            istate,
            p_list,
            smoother,
            experiment_ids=experiment_ids)

        return
Example #3
0
    def __init__(self,
                 beam,
                 t_range,
                 num_intervals,
                 goniometer=None,
                 experiment_ids=None):

        if experiment_ids is None:
            experiment_ids = [0]

        # The state of a scan varying beam parameterisation is a vector
        # '[s0](t)', expressed as a function of image number 't'
        # in a sequential scan.
        #
        # The initial state is a snapshot of the beam unit direction
        # at the point of initialisation '[s0dir]', which is independent of
        # image number.
        #
        # Future states are composed by rotations around axes orthogonal to the
        # initial direction and scaling by the wavenumber.
        #
        # [s0](t) = nu(t) * [Mu2](t)[Mu1](t)[s0dir]

        # Set up the smoother
        smoother = GaussianSmoother(t_range, num_intervals)
        nv = smoother.num_values()

        # Set up the initial state
        s0 = matrix.col(beam.get_s0())
        s0dir = matrix.col(beam.get_unit_s0())
        istate = s0dir
        self._s0_at_t = s0

        # Factory function to provide to _build_p_list
        def parameter_type(value, axis, ptype, name):
            return ScanVaryingParameterSet(value, nv, axis, ptype, name)

        # Build the parameter list
        p_list = self._build_p_list(s0,
                                    goniometer,
                                    parameter_type=parameter_type)

        # Set up the base class
        ScanVaryingModelParameterisation.__init__(
            self,
            beam,
            istate,
            p_list,
            smoother,
            experiment_ids=experiment_ids)

        return
Example #4
0
def test_gaussian_smoother(plots=False):
    """Test a bare parameter set with the smoother"""

    # 7 values, all set to 1.0
    myparam = ScanVaryingParameterSet(1.0, 7)

    # Adjust a couple of the values
    myparam.value[3:4] = [2.0, 2.0]

    # Make a smoother with x_range as an 'image range', between 1 and 100.
    # This smoother needs 5 intervals (for 7 total values). The default
    # smoother uses an averaging window of 3 values
    smoother = GaussianSmoother((1, 100), 5)

    assert smoother.num_values() == 7
    assert smoother.num_samples() == 5
    assert smoother.num_average() == 3

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert smoother.positions() == [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]

    # By contrast the spacing is in units of the original, unnormalised
    # coordinate
    assert smoother.spacing() == 19.8

    # Use the single value smoother multiple times...
    smooth_at = [e for e in range(1, 101)]
    data = [smoother.value_weight(e, myparam) for e in smooth_at]
    vals, weights, sumweights = zip(*data)
    assert len(smooth_at) == len(vals)

    # ...and the multi value smoother once
    mvals, mweights, msumweights = smoother.multi_value_weight(
        smooth_at, myparam)

    # the results should be identical.
    assert (flex.double(vals) == mvals).all_eq(True)
    assert (flex.double(sumweights) == msumweights).all_eq(True)
    for v1, v2 in zip(weights, mweights.transpose().cols()):
        assert (v1.as_dense_vector() == v2.as_dense_vector()).all_eq(True)

    # make scatterplots
    if plots:
        import matplotlib.pyplot as plt

        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
    def __init__(self,
                 goniometer,
                 t_range,
                 num_intervals,
                 beam=None,
                 experiment_ids=None):

        if experiment_ids is None:
            experiment_ids = [0]

        # The state of a scan varying goniometer parameterisation is a matrix
        # '[S](t)', expressed as a function of image number 't'
        # in a sequential scan.
        #
        # The initial state is a snapshot of the setting matrix
        # at the point of initialisation '[S0]', which is independent of
        # image number.
        #
        # Future states are composed by rotations around two axes orthogonal to the
        # initial spindle axis direction.
        #
        # [S](t) = [G2](t)[G1](t)[S0]

        # Set up the smoother
        smoother = GaussianSmoother(t_range, num_intervals)
        nv = smoother.num_values()

        # Set up the initial state
        e_lab = matrix.col(goniometer.get_rotation_axis())
        istate = matrix.sqr(goniometer.get_setting_rotation())
        self._S_at_t = istate

        # Factory function to provide to _build_p_list
        def parameter_type(value, axis, ptype, name):
            return ScanVaryingParameterSet(value, nv, axis, ptype, name)

        # Build the parameter list
        p_list = self._build_p_list(e_lab, beam, parameter_type=parameter_type)

        # Set up the base class
        ScanVaryingModelParameterisation.__init__(
            self,
            goniometer,
            istate,
            p_list,
            smoother,
            experiment_ids=experiment_ids)

        return
  def __init__(self, plots = False):

    # make scatterplots
    self.do_plots = plots

    # 7 values, all set to 1.0
    self.myparam = ScanVaryingParameterSet(1.0, 7)

    # Adjust a couple of the values
    self.myparam.value[3:4] = [2.0, 2.0]

    # Make a smoother with x_range as an 'image range', between 1 and 100.
    # This smoother needs 5 intervals (for 7 total values). The default
    # smoother uses an averaging window of 3 values
    self.smoother = GaussianSmoother((1, 100), 5)
Example #7
0
    def __init__(self, phi_range_deg, deg_per_interval=5):

        n_intervals = max(
            int(abs(phi_range_deg[1] - phi_range_deg[0]) / deg_per_interval),
            1)

        # Set up the smoother
        self._smoother = GaussianSmoother(phi_range_deg, n_intervals)
        self._num_samples = self._smoother.num_values()

        # initial value of scale factors is 1
        value = 1
        self._param = ScanVaryingParameterSet(value,
                                              self._num_samples,
                                              name="IncidentBeam")
    def __init__(self, crystal, t_range, num_intervals, experiment_ids=None):
        if experiment_ids is None:
            experiment_ids = [0]

        # The state of a scan varying crystal orientation parameterisation
        # is an orientation
        # matrix '[U](t)', expressed as a function of image number 't'
        # in a sequential scan.
        #
        # The initial state is a snapshot of the crystal orientation
        # at the point of initialisation '[U0]', which is independent of
        # image number.
        #
        # Future states are composed by
        # rotations around axes of the phi-axis frame by Tait-Bryan angles.
        #
        # [U](t) = [Phi3](t)[Phi2](t)[Phi1](t)[U0]

        # Set up the smoother
        smoother = GaussianSmoother(t_range, num_intervals)
        nv = smoother.num_values()

        # Set up the initial state
        istate = matrix.sqr(crystal.get_U())
        self._U_at_t = istate

        # Factory function to provide to _build_p_list
        def parameter_type(value, axis, ptype, name):
            return ScanVaryingParameterSet(value, nv, axis, ptype, name)

        # Build the parameter list
        p_list = self._build_p_list(parameter_type)

        # Set up the base class
        ScanVaryingModelParameterisation.__init__(
            self,
            crystal,
            istate,
            p_list,
            smoother,
            experiment_ids=experiment_ids)

        return