Beispiel #1
0
    def test_centroid_bias(self):
        from dials.algorithms.image.centroid import centroid_image
        from scitbx.array_family import flex
        pixels = flex.double(flex.grid(5, 5), 0)
        pixels[2, 2] = 10
        centroid = centroid_image(pixels)
        #assert abs(centroid.average_bias_estimate()[0] - 1/12.0) < 1e-7
        #assert abs(centroid.average_bias_estimate()[1] - 1/12.0) < 1e-7

        pixels = flex.double(flex.grid(5, 5), 0)
        pixels[1, 2] = 5
        pixels[2, 2] = 10
        pixels[3, 2] = 5
        pixels[2, 1] = 5
        pixels[2, 3] = 5
        centroid = centroid_image(pixels)
        assert centroid.average_bias_estimate()[0] < 1e-7
        assert centroid.average_bias_estimate()[1] < 1e-7
Beispiel #2
0
  def tst_centroid_masked_image3d(self):
    from dials.algorithms.image.centroid import centroid_image
    from scitbx import matrix

    centroid = centroid_image(self.pixels3d, self.mask3d)

    assert(abs(self.goldmasked3d - matrix.col(centroid.mean())) < self.EPS)
    assert(abs(self.goldmasked3dvar - matrix.col(centroid.variance())) < self.EPS)
    assert(abs(self.goldmasked3dubvar - matrix.col(centroid.unbiased_variance())) < self.EPS)
    print 'OK'
Beispiel #3
0
    def test_centroid_image3d(self):
        from scitbx import matrix

        from dials.algorithms.image.centroid import centroid_image

        centroid = centroid_image(self.pixels3d)

        assert abs(self.gold3d - matrix.col(centroid.mean())) < self.EPS
        assert abs(self.gold3dvar - matrix.col(centroid.variance())) < self.EPS
        assert (abs(self.gold3dubvar -
                    matrix.col(centroid.unbiased_variance())) < self.EPS)
Beispiel #4
0
  def tst_centroid_bias(self):

    from dials.algorithms.image.centroid import centroid_image
    from scitbx.array_family import flex
    pixels = flex.double(flex.grid(5,5), 0)
    pixels[2,2] = 10
    centroid = centroid_image(pixels)
    #assert abs(centroid.average_bias_estimate()[0] - 1/12.0) < 1e-7
    #assert abs(centroid.average_bias_estimate()[1] - 1/12.0) < 1e-7

    pixels = flex.double(flex.grid(5,5), 0)
    pixels[1,2] = 5
    pixels[2,2] = 10
    pixels[3,2] = 5
    pixels[2,1] = 5
    pixels[2,3] = 5
    centroid = centroid_image(pixels)
    assert centroid.average_bias_estimate()[0] < 1e-7
    assert centroid.average_bias_estimate()[1] < 1e-7

    print 'OK'
Beispiel #5
0
    def test_centroid_masked_image2d(self):
        from dials.algorithms.image.centroid import centroid_image
        from scitbx import matrix

        centroid = centroid_image(self.pixels2d, self.mask2d)

        assert (abs(self.goldmasked2d - matrix.col(centroid.mean())) <
                self.EPS)
        assert (abs(self.goldmasked2dvar - matrix.col(centroid.variance())) <
                self.EPS)
        assert (abs(self.goldmasked2dubvar -
                    matrix.col(centroid.unbiased_variance())) < self.EPS)
    def check_reference(self, reference):
        """Check the reference spots."""
        from dials.array_family import flex
        from dials.algorithms.image.centroid import centroid_image
        from math import sqrt

        # Get a load of stuff
        I_sim = reference["intensity.sim"]
        I_exp = reference["intensity.exp"]
        I_cal = reference["intensity.sum.value"]
        I_var = reference["intensity.sum.variance"]

        # Get the transformed shoeboxes
        profiles = reference["rs_shoebox"]
        n_sigma = 3
        grid_size = 4
        step_size = n_sigma / (grid_size + 0.5)
        eps = 1e-7
        for i in range(1):  # len(profiles)):
            import numpy

            data = profiles[i].data
            # dmax = flex.max(data)
            # data = 100 * data / dmax
            # p = data.as_numpy_array()
            # p = p.astype(numpy.int)
            # print p
            print(flex.sum(data), I_exp[i], I_cal[i])
            # assert(abs(flex.sum(data) - I_exp[i]) < eps)
            centroid = centroid_image(data)
            m = centroid.mean()
            v = centroid.variance()
            s1 = tuple(sqrt(vv) for vv in v)
            s2 = tuple(ss * step_size for ss in s1)
            assert all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m)
            assert all(abs(ss2 - 1.0) < 0.25 for ss2 in s2)

        # Calculate Z
        Z = (I_cal - I_exp) / flex.sqrt(I_var)
        mv = flex.mean_and_variance(Z)
        Z_mean = mv.mean()
        Z_var = mv.unweighted_sample_variance()
        print("Z: mean: %f, var: %f" % (Z_mean, Z_var))

        from matplotlib import pylab

        pylab.hist((I_cal - I_exp) / I_exp)
        pylab.show()
  def check_reference(self, reference):
    ''' Check the reference spots. '''
    from dials.array_family import flex
    from dials.algorithms.image.centroid import centroid_image
    from math import sqrt

    # Get a load of stuff
    I_sim = reference['intensity.sim']
    I_exp = reference['intensity.exp']
    I_cal = reference['intensity.prf.value']
    I_var = reference['intensity.prf.variance']

    # Get the transformed shoeboxes
    profiles = reference['rs_shoebox']
    n_sigma = 3
    n_sigma2 = 5
    grid_size = 4
    step_size = n_sigma2 / (grid_size + 0.5)
    eps = 1e-7
    for i in range(len(profiles)):
      data = profiles[i].data
      #dmax = flex.max(data)
      #data = 100 * data / dmax
      #p = data.as_numpy_array()
      #p = p.astype(numpy.int)
      #print p
      print flex.sum(data), I_exp[i], I_cal[i]
      #assert(abs(flex.sum(data) - I_exp[i]) < eps)
      centroid = centroid_image(data)
      m = centroid.mean()
      v = centroid.variance()
      s1 = tuple(sqrt(vv) for vv in v)
      s2 = tuple(ss * step_size for ss in s1)
      assert(all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m))
      assert(all(abs(ss2 - n_sigma / n_sigma2) < 0.25 for ss2 in s2))

    # Calculate Z
    Z = (I_cal - I_exp) / flex.sqrt(I_var)
    mv = flex.mean_and_variance(Z)
    Z_mean = mv.mean()
    Z_var = mv.unweighted_sample_variance()
    print "Z: mean: %f, var: %f" % (Z_mean, Z_var)

    from matplotlib import pylab
    pylab.hist((I_cal - I_exp) / I_exp)
    pylab.show()
Beispiel #8
0
    def check_profiles(self, learner):
        ''' Check the reference profiles. '''
        from dials.array_family import flex
        from dials.algorithms.image.centroid import centroid_image
        from math import sqrt

        # Get the reference locator
        locator = learner.locate()
        np = locator.size()
        assert (np == 9)
        assert (flex.sum(learner.counts()) == 10000)

        #profile = locator.profile(0)
        #pmax = flex.max(profile)
        #profile = 100 * profile / pmax
        #profile = profile.as_numpy_array()
        #import numpy
        #profile = profile.astype(numpy.int)
        #print profile

        # Check all the profiles
        eps = 1e-7
        n_sigma = 3
        n_sigma2 = 5
        grid_size = 4
        step_size = n_sigma2 / (grid_size + 0.5)
        for i in range(np):
            profile = locator.profile(i)
            assert (abs(flex.sum(profile) - 1.0) < eps)
            centroid = centroid_image(profile)
            m = centroid.mean()
            v = centroid.variance()
            s1 = tuple(sqrt(vv) for vv in v)
            s2 = tuple(ss * step_size for ss in s1)
            assert (all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m))
            assert (all(abs(ss2 - n_sigma / n_sigma2) < 0.25 for ss2 in s2))

        # Check all the profiles have good correlation coefficients
        cor = locator.correlations()
        assert (all(cor > 0.99))

        # Test passed
        print 'OK'
  def check_profiles(self, learner):
    ''' Check the reference profiles. '''
    from dials.array_family import flex
    from dials.algorithms.image.centroid import centroid_image
    from math import sqrt

    # Get the reference locator
    locator = learner.locate()
    np = locator.size()
    assert(np == 9)
    assert(flex.sum(learner.counts()) == 10000)

    #profile = locator.profile(0)
    #pmax = flex.max(profile)
    #profile = 100 * profile / pmax
    #profile = profile.as_numpy_array()
    #import numpy
    #profile = profile.astype(numpy.int)
    #print profile

    # Check all the profiles
    eps = 1e-7
    n_sigma = 3
    n_sigma2 = 5
    grid_size = 4
    step_size = n_sigma2 / (grid_size + 0.5)
    for i in range(np):
      profile = locator.profile(i)
      assert(abs(flex.sum(profile) - 1.0) < eps)
      centroid = centroid_image(profile)
      m = centroid.mean()
      v = centroid.variance()
      s1 = tuple(sqrt(vv) for vv in v)
      s2 = tuple(ss * step_size for ss in s1)
      assert(all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m))
      assert(all(abs(ss2 - n_sigma / n_sigma2) < 0.25 for ss2 in s2))

    # Check all the profiles have good correlation coefficients
    cor = locator.correlations()
    assert(all(cor > 0.99))

    # Test passed
    print 'OK'
  def check_profiles(self, learner):
    ''' Check the reference profiles. '''
    from dials.array_family import flex
    from dials.algorithms.image.centroid import centroid_image
    from math import sqrt

    # Get the reference locator
    locator = learner.locate()
    np = locator.size()
    assert(np == 9)
    cexp = [10000, 3713, 3817, 5023, 3844, 3723, 3768, 4886, 3781]
    assert(all(c1 == c2 for c1, c2 in zip(cexp, learner.counts())))

    #profile = locator.profile(0)
    #pmax = flex.max(profile)
    #profile = 100 * profile / pmax
    #profile = profile.as_numpy_array()
    #import numpy
    #profile = profile.astype(numpy.int)
    #print profile


    # Check all the profiles
    eps = 1e-7
    n_sigma = 3
    grid_size = 4
    step_size = n_sigma / (grid_size + 0.5)
    for i in range(np):
      profile = locator.profile(i)
      assert(abs(flex.sum(profile) - 1.0) < eps)
      centroid = centroid_image(profile)
      m = centroid.mean()
      v = centroid.variance()
      s1 = tuple(sqrt(vv) for vv in v)
      s2 = tuple(ss * step_size for ss in s1)
      assert(all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m))
      assert(all(abs(ss2 - 1.0) < 0.25 for ss2 in s2))

    # Test passed
    print 'OK'
    def check_profiles(self, learner):
        """Check the reference profiles."""
        from dials.array_family import flex
        from dials.algorithms.image.centroid import centroid_image
        from math import sqrt

        # Get the reference locator
        locator = learner.locate()
        np = locator.size()
        assert np == 9
        cexp = [10000, 3713, 3817, 5023, 3844, 3723, 3768, 4886, 3781]
        assert all(c1 == c2 for c1, c2 in zip(cexp, learner.counts()))

        # profile = locator.profile(0)
        # pmax = flex.max(profile)
        # profile = 100 * profile / pmax
        # profile = profile.as_numpy_array()
        # import numpy
        # profile = profile.astype(numpy.int)
        # print profile

        # Check all the profiles
        eps = 1e-7
        n_sigma = 3
        grid_size = 4
        step_size = n_sigma / (grid_size + 0.5)
        for i in range(np):
            profile = locator.profile(i)
            assert abs(flex.sum(profile) - 1.0) < eps
            centroid = centroid_image(profile)
            m = centroid.mean()
            v = centroid.variance()
            s1 = tuple(sqrt(vv) for vv in v)
            s2 = tuple(ss * step_size for ss in s1)
            assert all(abs(mm - (grid_size + 0.5)) < 0.25 for mm in m)
            assert all(abs(ss2 - 1.0) < 0.25 for ss2 in s2)

        # Test passed
        print("OK")