Пример #1
0
    def tst_with_flat_background(self):

        from dials.algorithms.integration.fit import fit_profile
        from scitbx.array_family import flex

        # Create profile
        p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        s = flex.sum(p)
        p = p / s

        # Copy profile
        c0 = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        b = flex.double(flex.grid(9, 9, 9), 5)
        m = flex.bool(flex.grid(9, 9, 9), True)
        c = c0 + b

        # Fit
        fit = fit_profile(p, m, c, b)
        I = fit.intensity()
        V = fit.variance()

        # Test intensity is the same
        eps = 1e-7
        assert (abs(I - flex.sum(c0)) < eps)
        assert (abs(V - (flex.sum(c0) + flex.sum(b))) < eps)

        print 'OK'
Пример #2
0
    def tst_with_noisy_flat_background_partial(self):

        from dials.algorithms.integration.fit import fit_profile
        from scitbx.array_family import flex

        # Create profile
        p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        s = flex.sum(p)
        p = p / s

        # Copy profile
        c0 = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        n = flex.random_double(9 * 9 * 9)
        b = flex.double(flex.grid(9, 9, 9), 5) + n
        m = flex.bool(flex.grid(9, 9, 9), True)
        c = c0 + b

        # Get the partial profiles
        pp = p[0:5, :, :]
        mp = m[0:5, :, :]
        cp = c[0:5, :, :]
        bp = b[0:5, :, :]
        c0p = c0[0:5, :, :]

        # Fit
        fit = fit_profile(pp, mp, cp, bp)
        I = fit.intensity()
        V = fit.variance()

        # Test intensity is the same
        eps = 1e-7
        assert (abs(I - flex.sum(c0)) < eps)
        assert (abs(V - (flex.sum(c0p) + flex.sum(bp))) < eps)

        print 'OK'
Пример #3
0
    def tst_scaled_partial(self):

        from dials.algorithms.integration.fit import fit_profile
        from scitbx.array_family import flex

        # Create profile
        p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        s = flex.sum(p)
        p = p / s

        # Copy profile
        c = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        b = flex.double(flex.grid(9, 9, 9), 0)
        m = flex.bool(flex.grid(9, 9, 9), True)

        # Get the partial profiles
        pp = p[0:5, :, :]
        mp = m[0:5, :, :]
        cp = c[0:5, :, :]
        bp = b[0:5, :, :]

        # Fit
        fit = fit_profile(pp, mp, cp, bp)
        I = fit.intensity()
        V = fit.variance()

        # Test intensity is the same
        eps = 1e-7
        assert (abs(I - flex.sum(c)) < eps)
        assert (abs(V - flex.sum(cp)) < eps)

        print 'OK'
Пример #4
0
  def tst_with_no_background(self):

    from dials.algorithms.integration.fit import ProfileFitter
    from scitbx.array_family import flex
    from numpy.random import seed
    seed(0)

    # Create profile
    p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
    s = flex.sum(p)
    p = p / s

    # Copy profile
    c = add_poisson_noise(100 * p)
    b = flex.double(flex.grid(9, 9, 9), 0)
    m = flex.bool(flex.grid(9,9,9), True)

    # Fit
    fit = ProfileFitter(c, b, m, p)
    I = fit.intensity()
    V = fit.variance()
    assert fit.niter() < fit.maxiter()

    # Test intensity is the same
    eps = 1e-3
    assert(abs(I[0] - flex.sum(c)) < eps)
    assert(abs(V[0] - I[0]) < eps)

    print 'OK'
Пример #5
0
 def generate_3_profiles(self):
   from dials.array_family import flex
   p1 = gaussian((40, 9, 9), 1, (10.5, 4, 4), (2, 2, 2))
   p2 = gaussian((40, 9, 9), 1, (20.5, 4, 4), (2, 2, 2))
   p3 = gaussian((40, 9, 9), 1, (30.5, 4, 4), (2, 2, 2))
   p1 = p1 / flex.sum(p1)
   p2 = p2 / flex.sum(p2)
   p3 = p3 / flex.sum(p3)
   p1.reshape(flex.grid(1, 40, 9, 9))
   p2.reshape(flex.grid(1, 40, 9, 9))
   p3.reshape(flex.grid(1, 40, 9, 9))
   p = flex.double(flex.grid(3, 40, 9, 9))
   p[0:1,:,:,:] = p1
   p[1:2,:,:,:] = p2
   p[2:3,:,:,:] = p3
   return p
Пример #6
0
  def tst_identical_partial(self):

    from dials.algorithms.integration.fit import ProfileFitter
    from scitbx.array_family import flex
    from numpy.random import seed
    seed(0)

    # Create profile
    p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
    s = flex.sum(p)
    p = p / s

    # Copy profile
    c = p.deep_copy()
    b = flex.double(flex.grid(9, 9, 9), 0)
    m = flex.bool(flex.grid(9,9,9), True)

    # Get the partial profiles
    pp = p[0:5,:,:]
    mp = m[0:5,:,:]
    cp = c[0:5,:,:]
    bp = b[0:5,:,:]

    # Fit
    fit = ProfileFitter(cp, bp, mp, pp)
    I = fit.intensity()
    V = fit.variance()
    assert fit.niter() < fit.maxiter()

    # Test intensity is the same
    eps = 1e-7
    assert(abs(I[0] - flex.sum(p)) < eps)
    assert(abs(V[0] - flex.sum(p)) < eps)

    print 'OK'
Пример #7
0
  def tst_with_flat_background(self):

    from dials.algorithms.integration.fit import ProfileFitter
    from scitbx.array_family import flex
    from numpy.random import seed
    seed(0)

    # Create profile
    p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
    s = flex.sum(p)
    p = p / s

    # Copy profile
    c0 = add_poisson_noise(100 * p)
    b = flex.double(flex.grid(9, 9, 9), 10)
    m = flex.bool(flex.grid(9,9,9), True)
    b0 = add_poisson_noise(b)
    c = c0 + b0

    # Fit
    fit = ProfileFitter(c, b, m, p)
    I = fit.intensity()
    V = fit.variance()
    assert fit.niter() < fit.maxiter()

    Iknown = 201.67417836585147
    Vknown = 7491.6743173001205

    # Test intensity is the same
    eps = 1e-3
    assert(abs(I[0] - Iknown) < eps)
    assert(abs(V[0] - Vknown) < eps)

    print 'OK'
Пример #8
0
    def tst_identical(self):

        from dials.algorithms.integration.fit import fit_profile
        from scitbx.array_family import flex

        # Create profile
        p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
        s = flex.sum(p)
        p = p / s

        # Copy profile
        c = p.deep_copy()
        b = flex.double(flex.grid(9, 9, 9), 0)
        m = flex.bool(flex.grid(9, 9, 9), True)

        # Fit
        fit = fit_profile(p, m, c, b)
        I = fit.intensity()
        V = fit.variance()

        # Test intensity is the same
        eps = 1e-7
        assert (abs(I - flex.sum(p)) < eps)
        assert (abs(V - I) < eps)

        print 'OK'
Пример #9
0
 def generate_7_profiles(self):
   from dials.array_family import flex
   p1 = gaussian((40, 40, 40), 1, (10.5, 20.5, 20.5), (2, 2, 2))
   p2 = gaussian((40, 40, 40), 1, (20.5, 20.5, 20.5), (2, 2, 2))
   p3 = gaussian((40, 40, 40), 1, (30.5, 20.5, 20.5), (2, 2, 2))
   p4 = gaussian((40, 40, 40), 1, (20.5, 10.5, 20.5), (2, 2, 2))
   p5 = gaussian((40, 40, 40), 1, (20.5, 30.5, 20.5), (2, 2, 2))
   p6 = gaussian((40, 40, 40), 1, (20.5, 20.5, 10.5), (2, 2, 2))
   p7 = gaussian((40, 40, 40), 1, (20.5, 20.5, 30.5), (2, 2, 2))
   p1 = p1 / flex.sum(p1)
   p2 = p2 / flex.sum(p2)
   p3 = p3 / flex.sum(p3)
   p4 = p4 / flex.sum(p4)
   p5 = p5 / flex.sum(p5)
   p6 = p6 / flex.sum(p6)
   p7 = p7 / flex.sum(p7)
   p1.reshape(flex.grid(1, 40, 40, 40))
   p2.reshape(flex.grid(1, 40, 40, 40))
   p3.reshape(flex.grid(1, 40, 40, 40))
   p4.reshape(flex.grid(1, 40, 40, 40))
   p5.reshape(flex.grid(1, 40, 40, 40))
   p6.reshape(flex.grid(1, 40, 40, 40))
   p7.reshape(flex.grid(1, 40, 40, 40))
   p = flex.double(flex.grid(7, 40, 40, 40))
   p[0:1,:,:,:] = p1
   p[1:2,:,:,:] = p2
   p[2:3,:,:,:] = p3
   p[3:4,:,:,:] = p4
   p[4:5,:,:,:] = p5
   p[5:6,:,:,:] = p6
   p[6:7,:,:,:] = p7
   return p
Пример #10
0
  def generate_single_central_non_negative_profiles(self):
    from dials.array_family import flex
    rlist = flex.reflection_table(1)

    profile = gaussian(self.grid_size, 1000, (4, 4, 4), (1.5, 1.5, 1.5))

    x = 500
    y = 500
    z = 5
    xyz = flex.vec3_double(1)
    xyz[0] = (x, y, z)
    profiles = [ profile.deep_copy() ]
    rlist['xyzcal.px'] = xyz

    return rlist, profiles, profile
Пример #11
0
  def generate_identical_non_negative_profiles(self):
    from dials.array_family import flex
    from random import uniform
    rlist = flex.reflection_table(1000)

    profile = gaussian(self.grid_size, 1000, (4, 4, 4), (1.5, 1.5, 1.5))

    xyz = flex.vec3_double(1000)
    profiles = []
    for i in range(1000):
      x = uniform(0, 1000)
      y = uniform(0, 1000)
      z = uniform(0, 10)
      xyz[i] = (x, y, z)
      profiles.append(profile.deep_copy())
    rlist['xyzcal.px'] = xyz

    return rlist, profiles, profile
Пример #12
0
  def generate_systematically_offset_profiles(self):
    from dials.array_family import flex
    from random import uniform
    rlist = flex.reflection_table(1000)

    xyz = flex.vec3_double(1000)
    profiles = []
    for i in range(1000):
      x = uniform(0, 1000)
      y = uniform(0, 1000)
      z = uniform(0, 10)

      offset = -4.5  + 9 * x / 1000.0

      profile = gaussian(self.grid_size, 1000,
          (4 + offset, 4, 4), (1.5, 1.5, 1.5))
      xyz[i] = (x, y, z)
      profiles.append(profile)

    rlist['xyzcal.px'] = xyz
    return rlist, profiles
Пример #13
0
  def tst_with_flat_background_partial(self):

    from dials.algorithms.integration.fit import ProfileFitter
    from scitbx.array_family import flex
    from numpy.random import seed
    seed(0)

    # Create profile
    p = gaussian((9, 9, 9), 1, (4, 4, 4), (2, 2, 2))
    s = flex.sum(p)
    p = p / s

    # Copy profile
    c0 = add_poisson_noise(100 * p)
    b = flex.double(flex.grid(9, 9, 9), 1)
    m = flex.bool(flex.grid(9,9,9), True)
    c = c0 + add_poisson_noise(b)

    # Get the partial profiles
    pp = p[0:5,:,:]
    mp = m[0:5,:,:]
    cp = c[0:5,:,:]
    bp = b[0:5,:,:]
    c0p = c0[0:5,:,:]

    # Fit
    fit = ProfileFitter(cp, bp, mp, pp)
    I = fit.intensity()
    V = fit.variance()
    assert fit.niter() < fit.maxiter()

    Iknown = 99.06932141277105
    Vknown = 504.06932141277105

    # Test intensity is the same
    eps = 1e-7
    assert(abs(I[0] - Iknown) < eps)
    assert(abs(V[0] - Vknown) < eps)

    print 'OK'