Ejemplo n.º 1
0
def test_nearest():
    from dials.algorithms.profile_model.modeller import CircleSampler
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    xc, yc = sampler.image_centre()
    r1 = sampler.r1()

    for i in range(1000):
        x = random.uniform(0, 1000)
        y = random.uniform(0, 1000)
        z = random.uniform(scan_range[0], scan_range[1])

        r = math.sqrt((x - xc)**2 + (y - yc)**2)
        if r < r1:
            index00 = 0
        else:
            t = math.atan2(y - yc, x - xc)
            ai = int(math.floor(t * 8 / (2 * math.pi) + 0.5)) % 8
            index00 = ai + 1

        index01 = int((z - scan_range[0]) * nz / depth)
        if index01 < 0:
            index01 = 0
        if index01 >= 2:
            index01 = 1

        index0 = index00 + index01 * 9
        index1 = sampler.nearest(0, (x, y, z))
        assert index0 == index1
Ejemplo n.º 2
0
  def tst_getters(self):
    from math import sqrt
    from dials.algorithms.profile_model.modeller import CircleSampler
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    image_size = sampler.image_size()
    scan_range = sampler.scan_range()
    image_centre = sampler.image_centre()
    r0 = sampler.r0()
    r1 = sampler.r1()
    r2 = sampler.r2()
    size = len(sampler)

    assert(width == image_size[0])
    assert(height == image_size[1])
    assert(width // 2 == image_centre[0])
    assert(height // 2 == image_centre[1])
    assert(r0 == min([width // 2, height // 2]))
    assert(r1 == r0 / 3.0)
    assert(r2 == r1 * sqrt(5.0))
    assert(9 * nz == size)
    print 'OK'
Ejemplo n.º 3
0
    def tst_getters(self):
        from math import sqrt
        from dials.algorithms.profile_model.modeller import CircleSampler
        width = 1000
        height = 1000
        scan_range = (2, 12)
        depth = scan_range[1] - scan_range[0]
        nz = 2
        sampler = CircleSampler((width, height), scan_range, nz)
        image_size = sampler.image_size()
        scan_range = sampler.scan_range()
        image_centre = sampler.image_centre()
        r0 = sampler.r0()
        r1 = sampler.r1()
        r2 = sampler.r2()
        size = len(sampler)

        assert (width == image_size[0])
        assert (height == image_size[1])
        assert (width // 2 == image_centre[0])
        assert (height // 2 == image_centre[1])
        assert (r0 == min([width // 2, height // 2]))
        assert (r1 == r0 / 3.0)
        assert (r2 == r1 * sqrt(5.0))
        assert (9 * nz == size)
        print 'OK'
Ejemplo n.º 4
0
  def tst_nearest_n(self):
    from math import sqrt, atan2, pi, floor
    from random import uniform
    from dials.algorithms.profile_model.modeller import CircleSampler
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    xc, yc = sampler.image_centre()
    r1 = sampler.r1()

    for i in range(1000):
      x = uniform(0, 1000)
      y = uniform(0, 1000)
      z = uniform(scan_range[0], scan_range[1])

      r = sqrt((x - xc)**2 + (y - yc)**2)
      if r < r1:
        index00 = 0
      else:
        t = atan2(y - yc, x - xc)
        ai = int(floor(t * 8 / (2 * pi) + 0.5)) % 8
        index00 = ai + 1

      index01 = int((z-scan_range[0]) * nz / depth)
      if index01 < 0:
        index01 = 0
      if index01 >= 2:
        index01 = 1

      index0 = index00 + index01 * 9
      index1 = sampler.nearest_n(0, (x, y, z))
      assert(index0 == index1[0])
      if index0 % 9 == 0:
        assert(len(index1) == 9)
        assert(all(idx == index0 + i for i, idx in enumerate(index1)))
      else:
        assert(len(index1) == 4)
        assert(index1[1] == (index0 // 9) * 9)
        if (index0 % 9) == 1:
          assert(index1[2] == index0 + 1)
          assert(index1[3] == index0 + 7)
        elif (index0 % 9) == 8:
          assert(index1[2] == index0 - 7)
          assert(index1[3] == index0 - 1)
        else:
          assert(index1[2] == index0 + 1)
          assert(index1[3] == index0 - 1)

    print 'OK'
Ejemplo n.º 5
0
    def tst_nearest_n(self):
        from math import sqrt, atan2, pi, floor
        from random import uniform
        from dials.algorithms.profile_model.modeller import CircleSampler
        width = 1000
        height = 1000
        scan_range = (2, 12)
        depth = scan_range[1] - scan_range[0]
        nz = 2
        sampler = CircleSampler((width, height), scan_range, nz)
        xc, yc = sampler.image_centre()
        r1 = sampler.r1()

        for i in range(1000):
            x = uniform(0, 1000)
            y = uniform(0, 1000)
            z = uniform(scan_range[0], scan_range[1])

            r = sqrt((x - xc)**2 + (y - yc)**2)
            if r < r1:
                index00 = 0
            else:
                t = atan2(y - yc, x - xc)
                ai = int(floor(t * 8 / (2 * pi) + 0.5)) % 8
                index00 = ai + 1

            index01 = int((z - scan_range[0]) * nz / depth)
            if index01 < 0:
                index01 = 0
            if index01 >= 2:
                index01 = 1

            index0 = index00 + index01 * 9
            index1 = sampler.nearest_n((x, y, z))
            assert (index0 == index1[0])
            if index0 % 9 == 0:
                assert (len(index1) == 9)
                assert (all(idx == index0 + i for i, idx in enumerate(index1)))
            else:
                assert (len(index1) == 4)
                assert (index1[1] == (index0 // 9) * 9)
                if (index0 % 9) == 1:
                    assert (index1[2] == index0 + 1)
                    assert (index1[3] == index0 + 7)
                elif (index0 % 9) == 8:
                    assert (index1[2] == index0 - 7)
                    assert (index1[3] == index0 - 1)
                else:
                    assert (index1[2] == index0 + 1)
                    assert (index1[3] == index0 - 1)

        print 'OK'
Ejemplo n.º 6
0
def test_nearest_n():
    from dials.algorithms.profile_model.modeller import CircleSampler

    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    xc, yc = sampler.image_centre()
    r1 = sampler.r1()

    for i in range(1000):
        x = random.uniform(0, 1000)
        y = random.uniform(0, 1000)
        z = random.uniform(scan_range[0], scan_range[1])

        r = math.sqrt((x - xc)**2 + (y - yc)**2)
        if r < r1:
            index00 = 0
        else:
            t = math.atan2(y - yc, x - xc)
            ai = int(math.floor(t * 8 / (2 * math.pi) + 0.5)) % 8
            index00 = ai + 1

        index01 = int((z - scan_range[0]) * nz / depth)
        if index01 < 0:
            index01 = 0
        if index01 >= 2:
            index01 = 1

        index0 = index00 + index01 * 9
        index1 = sampler.nearest_n(0, (x, y, z))
        assert index0 == index1[0]
        if index0 % 9 == 0:
            assert len(index1) == 9
            assert all(idx == index0 + i for i, idx in enumerate(index1))
        else:
            assert len(index1) == 4
            assert index1[1] == (index0 // 9) * 9
            if (index0 % 9) == 1:
                assert index1[2] == index0 + 1
                assert index1[3] == index0 + 7
            elif (index0 % 9) == 8:
                assert index1[2] == index0 - 7
                assert index1[3] == index0 - 1
            else:
                assert index1[2] == index0 + 1
                assert index1[3] == index0 - 1
Ejemplo n.º 7
0
def test_getters():
    from dials.algorithms.profile_model.modeller import CircleSampler

    width = 1000
    height = 1000
    scan_range = (2, 12)
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    image_size = sampler.image_size()
    image_centre = sampler.image_centre()
    r0 = sampler.r0()
    r1 = sampler.r1()
    r2 = sampler.r2()
    size = len(sampler)

    assert width == image_size[0]
    assert height == image_size[1]
    assert width // 2 == image_centre[0]
    assert height // 2 == image_centre[1]
    assert r0 == min([width // 2, height // 2])
    assert r1 == r0 / 3.0
    assert r2 == r1 * math.sqrt(5.0)
    assert 9 * nz == size
Ejemplo n.º 8
0
  def tst_nearest(self):
    from math import sqrt, atan2, pi, floor
    from random import uniform
    from dials.algorithms.profile_model.modeller import CircleSampler
    width = 1000
    height = 1000
    scan_range = (2, 12)
    depth = scan_range[1] - scan_range[0]
    nz = 2
    sampler = CircleSampler((width, height), scan_range, nz)
    xc, yc = sampler.image_centre()
    r1 = sampler.r1()

    for i in range(1000):
      x = uniform(0, 1000)
      y = uniform(0, 1000)
      z = uniform(scan_range[0], scan_range[1])

      r = sqrt((x - xc)**2 + (y - yc)**2)
      if r < r1:
        index00 = 0
      else:
        t = atan2(y - yc, x - xc)
        ai = int(floor(t * 8 / (2 * pi) + 0.5)) % 8
        index00 = ai + 1

      index01 = int((z-scan_range[0]) * nz / depth)
      if index01 < 0:
        index01 = 0
      if index01 >= 2:
        index01 = 1

      index0 = index00 + index01 * 9
      index1 = sampler.nearest(0, (x, y, z))
      assert(index0 == index1)

    print 'OK'