Ejemplo n.º 1
0
  def tst_weights(self):
    from dials.algorithms.profile_model.modeller import CircleSampler
    from math import exp, log
    from scitbx import matrix

    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 1
    sampler = CircleSampler((width, height), scan_range, nz)

    # Check the weight at the coord in 1.0
    eps = 1e-7
    for i in range(len(sampler)):
      coord = sampler.coord(i)
      weight = sampler.weight(i, 0, coord)
      assert(abs(weight - 1.0) < eps)

    r0 = sampler.r0()
    r1 = sampler.r1()
    r2 = sampler.r2()
    r = r2 / (2.0*r1)
    expected = exp(-4.0*r*r*log(2.0))
    for i in range(1, 9):
      coord = sampler.coord(i)
      weight = sampler.weight(0, 0, coord)
      assert(abs(weight - expected) < eps)

    r = r2 / (2.0*(r2 - r1))
    expected = exp(-4.0*r*r*log(2.0))
    for i in range(1, 9):
      coord = sampler.coord(0)
      weight = sampler.weight(i, 0, coord)
      assert(abs(weight - expected) < eps)

    for i in range(1, 9):
      coord1 = matrix.col(sampler.coord(0))
      coord2 = matrix.col(sampler.coord(i))
      coord = coord1 + r1 * (coord2 - coord1) / r2
      weight = sampler.weight(0, 0, coord)
      assert(abs(weight - 0.5) < eps)
      weight = sampler.weight(i, 0, coord)
      assert(abs(weight - 0.5) < eps)

    print 'OK'
Ejemplo n.º 2
0
    def tst_weights(self):
        from dials.algorithms.profile_model.modeller import CircleSampler
        from math import exp, log
        from scitbx import matrix

        width = 1000
        height = 1000
        scan_range = (2, 12)
        depth = scan_range[1] - scan_range[0]
        nz = 1
        sampler = CircleSampler((width, height), scan_range, nz)

        # Check the weight at the coord in 1.0
        eps = 1e-7
        for i in range(len(sampler)):
            coord = sampler.coord(i)
            weight = sampler.weight(i, coord)
            assert (abs(weight - 1.0) < eps)

        r0 = sampler.r0()
        r1 = sampler.r1()
        r2 = sampler.r2()
        r = r2 / (2.0 * r1)
        expected = exp(-4.0 * r * r * log(2.0))
        for i in range(1, 9):
            coord = sampler.coord(i)
            weight = sampler.weight(0, coord)
            assert (abs(weight - expected) < eps)

        r = r2 / (2.0 * (r2 - r1))
        expected = exp(-4.0 * r * r * log(2.0))
        for i in range(1, 9):
            coord = sampler.coord(0)
            weight = sampler.weight(i, coord)
            assert (abs(weight - expected) < eps)

        for i in range(1, 9):
            coord1 = matrix.col(sampler.coord(0))
            coord2 = matrix.col(sampler.coord(i))
            coord = coord1 + r1 * (coord2 - coord1) / r2
            weight = sampler.weight(0, coord)
            assert (abs(weight - 0.5) < eps)
            weight = sampler.weight(i, coord)
            assert (abs(weight - 0.5) < eps)

        print 'OK'
Ejemplo n.º 3
0
def test_weights():
    from scitbx import matrix

    from dials.algorithms.profile_model.modeller import CircleSampler

    width = 1000
    height = 1000
    scan_range = (2, 12)
    nz = 1
    sampler = CircleSampler((width, height), scan_range, nz)

    # Check the weight at the coord in 1.0
    eps = 1e-7
    for i in range(len(sampler)):
        coord = sampler.coord(i)
        weight = sampler.weight(i, 0, coord)
        assert abs(weight - 1.0) < eps

    r1 = sampler.r1()
    r2 = sampler.r2()
    r = r2 / (2.0 * r1)
    expected = math.exp(-4.0 * r * r * math.log(2.0))
    for i in range(1, 9):
        coord = sampler.coord(i)
        weight = sampler.weight(0, 0, coord)
        assert abs(weight - expected) < eps

    r = r2 / (2.0 * (r2 - r1))
    expected = math.exp(-4.0 * r * r * math.log(2.0))
    for i in range(1, 9):
        coord = sampler.coord(0)
        weight = sampler.weight(i, 0, coord)
        assert abs(weight - expected) < eps

    for i in range(1, 9):
        coord1 = matrix.col(sampler.coord(0))
        coord2 = matrix.col(sampler.coord(i))
        coord = coord1 + r1 * (coord2 - coord1) / r2
        weight = sampler.weight(0, 0, coord)
        assert abs(weight - 0.5) < eps
        weight = sampler.weight(i, 0, coord)
        assert abs(weight - 0.5) < eps
Ejemplo n.º 4
0
def compute_reference(experiments, reflections):
    from dials.algorithms.profile_model.modeller import CircleSampler
    from dials.array_family import flex
    from dials.algorithms.profile_model.gaussian_rs.transform import TransformForward
    from dials.algorithms.profile_model.gaussian_rs.transform import TransformSpec
    from dials.algorithms.profile_model.gaussian_rs import CoordinateSystem

    reflections = select_strong(reflections)
    print("Selected %d strong spots" % len(reflections))

    sampler = CircleSampler(
        experiments[0].detector[0].get_image_size(),
        experiments[0].scan.get_array_range(),
        1,
    )

    n_sigma = 4.0
    grid_size = 25
    spec = TransformSpec(
        experiments[0].beam,
        experiments[0].detector,
        experiments[0].goniometer,
        experiments[0].scan,
        experiments[0].profile.sigma_b(deg=False),
        experiments[0].profile.sigma_m(deg=False),
        n_sigma,
        grid_size,
    )

    m2 = experiments[0].goniometer.get_rotation_axis()
    s0 = experiments[0].beam.get_s0()

    reference = [
        flex.double(
            flex.grid(1 + 2 * grid_size, 1 + 2 * grid_size, 1 + 2 * grid_size))
        for i in range(len(sampler))
    ]
    count = [0] * len(sampler)

    for r in reflections:
        s1 = r["s1"]
        phi = r["xyzcal.mm"][2]
        xyz = r["xyzcal.px"]
        bbox = r["bbox"]
        panel = r["panel"]
        image = r["shoebox"].data.as_double()
        mask = r["shoebox"].mask.as_1d() == 5
        mask.reshape(image.accessor())
        cs = CoordinateSystem(m2, s0, s1, phi)

        try:
            transform = TransformForward(spec, cs, bbox, panel, image, mask)
            d = transform.profile()

            d /= flex.sum(d)

            index = sampler.nearest(0, xyz)
            indices = sampler.nearest_n(0, xyz)
            for i in indices:
                w = sampler.weight(i, 0, xyz)
                reference[i] += w * d
                count[i] += 1
        except Exception:
            pass

    for i in range(len(reference)):
        r = reference[i]
        if flex.sum(r) > 0:
            print(flex.max(r))
            g = r.accessor()
            r = r.as_1d()
            s = r > 0.02 * flex.max(r)
            r.set_selected(~s, flex.double(len(r), 0))
            r = r / flex.sum(r)
            r.reshape(g)
            reference[i] = r

    for i in range(len(reference)):
        from matplotlib import pylab

        print(count[i])
        r = reference[i]
        d = r.as_numpy_array()[11, :, :]
        pylab.imshow(d, interpolation="None")
        pylab.show()

    return reference