Exemple #1
0
def test_nearest():
    from dials.algorithms.profile_model.modeller import GridSampler

    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nx = 10
    ny = 10
    nz = 2
    sampler = GridSampler((width, height), scan_range, (nx, ny, nz))

    for i in range(1000):
        x = random.uniform(0, 1000)
        y = random.uniform(0, 1000)
        z = random.uniform(*scan_range)
        i = int(math.floor(x / (width / nx)))
        j = int(math.floor(y / (height / ny)))
        k = int(math.floor((z - scan_range[0]) / (depth / nz)))
        if i >= nx:
            i = nx - 1
        if j >= ny:
            j = ny - 1
        if k >= nz:
            k = nz - 1
        index0 = i + j * nx + k * nx * ny
        index1 = sampler.nearest(0, (x, y, z))
        assert index0 == index1
  def tst_nearest(self):
    from random import uniform
    from dials.algorithms.profile_model.modeller import GridSampler
    from math import floor
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nx = 10
    ny = 10
    nz = 2
    sampler = GridSampler((width, height), scan_range, (nx, ny, nz))

    for i in range(1000):
      x = uniform(0, 1000)
      y = uniform(0, 1000)
      z = uniform(*scan_range)
      i = int(floor(x / (width / nx)))
      j = int(floor(y / (height / ny)))
      k = int(floor((z-scan_range[0]) / (depth / nz)))
      if i >= nx:
        i = nx - 1
      if j >= ny:
        j = ny - 1
      if k >= nz:
        k = nz - 1
      index0 = i + j * nx + k * nx * ny
      index1 = sampler.nearest((x, y, z))
      assert(index0 == index1)

    print 'OK'
Exemple #3
0
def compute_profile(experiments, reflection, reference, N):
    from dials.array_family import flex
    from dials.algorithms.profile_model.gaussian_rs import CoordinateSystem
    from dials.algorithms.profile_model.modeller import GridSampler
    from dials_scratch.jmp.sim import compute_profile_internal
    from random import uniform

    sbox = reflection["shoebox"]
    bbox = sbox.bbox
    zs = sbox.zsize()
    ys = sbox.ysize()
    xs = sbox.xsize()

    profile = flex.double(flex.grid(zs, ys, xs))

    m2 = experiments[0].goniometer.get_rotation_axis_datum()
    s0 = experiments[0].beam.get_s0()
    s1 = reflection["s1"]
    phi = reflection["xyzcal.mm"][2]
    detector = experiments[0].detector
    scan = experiments[0].scan

    cs = CoordinateSystem(m2, s0, s1, phi)

    scan_range = scan.get_array_range()
    image_size = detector[0].get_image_size()
    grid_size = (3, 3, 40)
    assert grid_size[0] * grid_size[1] * grid_size[2] == len(reference[0])

    sampler = GridSampler(image_size, scan_range, grid_size)

    xyz = reflection["xyzcal.px"]
    index = sampler.nearest(0, xyz)

    for g in reference[0]:
        assert abs(flex.sum(g) - 1.0) < 1e-7

    grid = reference[0][index]

    sigma_d = experiments[0].profile.sigma_b(deg=False)
    sigma_m = experiments[0].profile.sigma_m(deg=False)
    delta_d = 3.0 * sigma_d
    delta_m = 3.0 * sigma_m

    profile = compute_profile_internal(grid, bbox, zs, ys, xs, N, delta_d,
                                       delta_m, detector, scan, cs)

    # from dials_scratch.jmp.viewer import show_image_stack_multi_view
    # show_image_stack_multi_view(profile.as_numpy_array(), vmax=max(profile))
    sum_p = flex.sum(profile)
    print("Partiality: %f" % sum_p)
    try:
        assert sum_p > 0, "sum_p == 0"
    except Exception as e:
        print(e)
        return None

    return profile
Exemple #4
0
def test_self_consistent():
    from dials.algorithms.profile_model.modeller import GridSampler

    width = 1000
    height = 1000
    scan_range = (2, 12)
    nx = 10
    ny = 10
    nz = 2
    sampler = GridSampler((width, height), scan_range, (nx, ny, nz))

    for i in range(len(sampler)):
        coord = sampler.coord(i)
        index = sampler.nearest(0, coord)
        assert index == i
  def tst_self_consistent(self):
    from dials.algorithms.profile_model.modeller import GridSampler
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nx = 10
    ny = 10
    nz = 2
    sampler = GridSampler((width, height), scan_range, (nx, ny, nz))

    for i in range(len(sampler)):
      coord = sampler.coord(i)
      index = sampler.nearest(coord)
      assert(index == i)

    print 'OK'