Ejemplo n.º 1
0
    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
    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=[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

    ### Set up symmetrizing object
    self._S = symmetrize_reduce_enlarge(crystal.get_space_group())
    self._S.set_orientation(orientation=crystal.get_B())
    X = self._S.forward_independent_parameters()
    dB_dp = self._S.forward_gradients()
    B = self._S.backward_orientation(independent=X).reciprocal_matrix()

    ### Set up the independent parameters, with a change of scale
    p_list = [ScanVaryingParameterSet(e * 1.e5, nv, name = "g_param_%d" % i) \
              for i, e in enumerate(X)]

    # Set up the base class
    ScanVaryingModelParameterisation.__init__(self, crystal, istate,
                                              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
Ejemplo n.º 5
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
    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)
Ejemplo n.º 8
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")
class SmootherTest(object):
    """Test a bare parameter set with the smoother"""
    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)

    def run(self):

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

        # The smoother positions depend on the number of intervals but not on
        # the x_range
        assert self.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 self.smoother.spacing() == 19.8

        # Use the single value smoother multiple times...
        smooth_at = [e for e in range(1, 101)]
        data = [self.smoother.value_weight(e, self.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 = self.smoother.multi_value_weight(
            smooth_at, self.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)

        if self.do_plots:
            try:
                import matplotlib.pyplot as plt
                plt.ion()
                plt.scatter(smooth_at, vals)
                plt.draw()
            except ImportError as e:
                print "pyplot not available", e

        print "OK"
    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
Ejemplo n.º 11
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
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  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)

  def run(self):

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

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.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 self.smoother.spacing() == 19.8

    # Use the single value smoother multiple times...
    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.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 = self.smoother.multi_value_weight(smooth_at, self.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)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"
  def __init__(self, crystal, t_range, num_intervals, 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 = crystal.get_U()

    # Set up the parameters
    phi1 = ScanVaryingParameterSet(0.0, nv,
                        matrix.col((1., 0., 0.)), 'angle (mrad)', 'Phi1')
    phi2 = ScanVaryingParameterSet(0.0, nv,
                        matrix.col((0., 1., 0.)), 'angle (mrad)', 'Phi2')
    phi3 = ScanVaryingParameterSet(0.0, nv,
                        matrix.col((0., 0., 1.)), 'angle (mrad)', 'Phi3')

    # Build the list of parameter sets in a specific, maintained order
    p_list = [phi1, phi2, phi3]

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

    return
Ejemplo n.º 14
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._set_len = self._smoother.num_values()

    # initial value of scale factors is 1
    value = 1
    self._param = ScanVaryingParameterSet(value, self._set_len,
      name = "IncidentBeam")
Ejemplo n.º 15
0
    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 = 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
  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)
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  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)

  def run(self):

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

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.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 self.smoother.spacing() == 19.8

    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
    vals = [v for v, w, sw in data]
    assert len(smooth_at) == len(vals)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  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)

  def run(self):

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

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.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 self.smoother.spacing() == 19.8

    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
    vals = [v for v, w, sw in data]
    assert len(smooth_at) == len(vals)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"
Ejemplo n.º 19
0
class IncidentBeamFactor(ScaleFactor):
  """Smoothly varying scale factor combining incident beam flux variation
  with other factors that can be modelled as a function of rotation angle"""

  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._set_len = self._smoother.num_values()

    # initial value of scale factors is 1
    value = 1
    self._param = ScanVaryingParameterSet(value, self._set_len,
      name = "IncidentBeam")

  def __len__(self):
    # There is only one parameter set, so the total number of parameters is
    # equal to the set length
    return self._set_len
Ejemplo n.º 20
0
class IncidentBeamFactor(ScaleFactor):
    """Smoothly varying scale factor combining incident beam flux variation
  with other factors that can be modelled as a function of rotation angle"""
    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 __len__(self):
        # There is only one parameter set, so the total number of parameters is
        # equal to the number of samples
        return self._num_samples