Exemplo n.º 1
0
def make_multi_panel(single_panel_detector):
  """Create a 3x3 multi-panel detector filling the same space as
  a supplied single panel detector"""

  from dials.test.algorithms.refinement.tst_multi_panel_detector_parameterisation \
      import make_panel_in_array
  from dials.test.algorithms.refinement.setup_geometry import \
      random_vector_close_to

  multi_panel_detector = Detector()
  for x in range(3):
    for y in range(3):
      new_panel = make_panel_in_array(
                      (x, y), single_panel_detector[0])
      multi_panel_detector.add_panel(new_panel)

  # apply small random shifts & rotations to each panel
  for p in multi_panel_detector:

    # perturb origin vector
    o_multiplier = random.gauss(1.0, 0.01)
    new_origin = random_vector_close_to(p.get_origin(), sd=0.1)
    new_origin *= o_multiplier

    # perturb fast direction vector
    new_dir1 = random_vector_close_to(p.get_fast_axis(), sd=0.5)

    # create vector in the plane of dir1-dir2
    dir1_dir2 = random_vector_close_to(p.get_slow_axis(), sd=0.5)

    # find normal to panel plane and thus new slow direction vector
    dn = new_dir1.cross(dir1_dir2)
    new_dir2 = dn.cross(new_dir1)

    # set panel frame
    p.set_frame(new_dir1, new_dir2, new_origin)

  return multi_panel_detector
Exemplo n.º 2
0
def make_multi_panel(single_panel_detector):
    """Create a 3x3 multi-panel detector filling the same space as
  a supplied single panel detector"""

    from dials.test.algorithms.refinement.tst_multi_panel_detector_parameterisation \
        import make_panel_in_array
    from dials.test.algorithms.refinement.setup_geometry import \
        random_vector_close_to

    multi_panel_detector = Detector()
    for x in range(3):
        for y in range(3):
            new_panel = make_panel_in_array((x, y), single_panel_detector[0])
            multi_panel_detector.add_panel(new_panel)

    # apply small random shifts & rotations to each panel
    for p in multi_panel_detector:

        # perturb origin vector
        o_multiplier = random.gauss(1.0, 0.01)
        new_origin = random_vector_close_to(p.get_origin(), sd=0.1)
        new_origin *= o_multiplier

        # perturb fast direction vector
        new_dir1 = random_vector_close_to(p.get_fast_axis(), sd=0.5)

        # create vector in the plane of dir1-dir2
        dir1_dir2 = random_vector_close_to(p.get_slow_axis(), sd=0.5)

        # find normal to panel plane and thus new slow direction vector
        dn = new_dir1.cross(dir1_dir2)
        new_dir2 = dn.cross(new_dir1)

        # set panel frame
        p.set_frame(new_dir1, new_dir2, new_origin)

    return multi_panel_detector
Exemplo n.º 3
0
    p_vals = dp.get_param_vals()
    p_vals2 = [a + b for a, b in zip(p_vals, [-10.0, 1.0, 1.0, 0.0, 0.0, 0.0])]
    dp.set_param_vals(p_vals2)
    assert dp.get_param_vals() == [90.0, 1.0, 1.0, 0.0, 0.0, 0.0]

    # 5. Tests of the calculation of derivatives

    # Now using parameterisation in mrad

    # random initial orientations with a random parameter shift at each
    attempts = 100
    failures = 0
    for i in range(attempts):

        # create random initial position
        dp = DetectorParameterisationSinglePanel(Detector(random_panel()))

        # apply a random parameter shift
        p_vals = random_param_shift(
            p_vals,
            [10, 10, 10, 1000.0 * pi / 18, 1000.0 * pi / 18, 1000.0 * pi / 18])
        dp.set_param_vals(p_vals)

        # obtain current sensor state
        # state = dp.get_state()

        # compare analytical and finite difference derivatives
        an_ds_dp = dp.get_ds_dp()
        fd_ds_dp = get_fd_gradients(dp, [1.0e-6] * 3 + [1.0e-4 * pi / 180] * 3)

        for j in range(6):
Exemplo n.º 4
0
    p_vals = dp.get_param_vals()
    p_vals2 = [a + b for a, b in zip(p_vals, [-10., 1., 1., 0., 0., 0.])]
    dp.set_param_vals(p_vals2)
    assert (dp.get_param_vals() == [90., 1., 1., 0., 0., 0.])

    # 5. Tests of the calculation of derivatives

    # Now using parameterisation in mrad

    # random initial orientations with a random parameter shift at each
    attempts = 100
    failures = 0
    for i in range(attempts):

        # create random initial position
        det = Detector(random_panel())
        dp = DetectorParameterisationSinglePanel(det)

        # apply a random parameter shift
        p_vals = dp.get_param_vals()
        p_vals = random_param_shift(
            p_vals,
            [10, 10, 10, 1000. * pi / 18, 1000. * pi / 18, 1000. * pi / 18])
        dp.set_param_vals(p_vals)

        # obtain current sensor state
        #state = dp.get_state()

        # compare analytical and finite difference derivatives.
        an_ds_dp = dp.get_ds_dp(multi_state_elt=0)
        fd_ds_dp = get_fd_gradients(dp, [1.e-6] * 3 + [1.e-4 * pi / 180] * 3)
      include scope dials.test.algorithms.refinement.geometry_phil
      include scope dials.test.algorithms.refinement.minimiser_phil
      """, process_includes=True)

  models = setup_geometry.Extract(master_phil, cmdline_args = args)

  single_panel_detector = models.detector
  mygonio = models.goniometer
  mycrystal = models.crystal
  mybeam = models.beam

  # Make a 3x3 multi panel detector filling the same space as the existing
  # single panel detector. Each panel of the multi-panel detector has pixels with
  # 1/3 the length dimensions of the single panel.

  multi_panel_detector = Detector()
  for x in range(3):
    for y in range(3):
      new_panel = make_panel_in_array((x, y), single_panel_detector[0])
      multi_panel_detector.add_panel(new_panel)

  # Build a mock scan for a 180 degree sweep
  sf = scan_factory()
  myscan = sf.make_scan(image_range = (1,1800),
                        exposure_times = 0.1,
                        oscillation = (0, 0.1),
                        epochs = range(1800),
                        deg = True)
  sweep_range = myscan.get_oscillation_range(deg=False)
  im_width = myscan.get_oscillation(deg=False)[1]
  assert sweep_range == (0., pi)