예제 #1
0
class test_bilinear(unittest.TestCase):
    """basic maximum search test"""
    a = numpy.arange(100) - 40.
    b = numpy.arange(100) - 60.
    ga = numpy.exp(-a * a / 4000)
    gb = numpy.exp(-b * b / 6000)
    gg = numpy.outer(ga, gb)
    b = bilinear.Bilinear(gg)
    N = 10000

    def test_max_search(self):
        """test maximum search using random points"""
        ok = 0
        for s in range(self.N):
            i, j = numpy.random.randint(100), numpy.random.randint(100)
            k, l = self.b.local_maxi((i, j), 1)
            if abs(k - 40) > 1e-4 or abs(l - 60) > 1e-4:
                logger.warning("Wrong guess maximum (%i,%i) -> (%.1f,%.1f)" %
                               (i, j, k, l))
            else:
                logger.debug("Good guess maximum (%i,%i) -> (%.1f,%.1f)" %
                             (i, j, k, l))
                ok += 1
        logger.info("Success rate: %.1f" % (100. * ok / self.N))
        self.assertEqual(ok, self.N, "Maximum is always found")
예제 #2
0
 def test_max_search_half(self):
     """test maximum search using random points: maximum is at a pixel edge"""
     a = numpy.arange(100) - 40.5
     b = numpy.arange(100) - 60.5
     ga = numpy.exp(-a * a / 4000)
     gb = numpy.exp(-b * b / 6000)
     gg = numpy.outer(ga, gb)
     b = bilinear.Bilinear(gg)
     ok = 0
     for s in range(self.N):
         i, j = numpy.random.randint(100), numpy.random.randint(100)
         k, l = b.local_maxi((i, j), 1)
         if abs(k - 40.5) > 0.5 or abs(l - 60.5) > 0.5:
             logger.warning("Wrong guess maximum (%i,%i) -> (%.1f,%.1f)" % (i, j, k, l))
         else:
             logger.debug("Good guess maximum (%i,%i) -> (%.1f,%.1f)" % (i, j, k, l))
             ok += 1
     logger.info("Success rate: %.1f" % (100.*ok / self.N))
     self.assertEqual(ok, self.N, "Maximum is always found")
예제 #3
0
#!/usr/bin/python
import numpy

a = numpy.arange(100) - 50.
g = numpy.exp(-a * a / 5000)
gg = numpy.outer(g, g)
from pyFAI import bilinear

b = bilinear.Bilinear(gg)

ok = 0
for s in range(1000):
    i, j = numpy.random.randint(100), numpy.random.randint(100)
    k, l = b.local_maxi((i, j), 1)
    if (k, l) == (i, j):
        print "same", i, j
    elif abs(k - 50) > 1e-4 or abs(l - 50) > 1e-4:
        print "error", i, j, k, l
    else:
        print "OK", i, j, k, l
        ok += 1
print "result: %.1f" % (ok / 10.)