1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#!/usr/bin/env python
# coding: utf-8
#
# Project: Azimuthal integration
# https://github.com/silx-kit/pyFAI
#
# Copyright (C) 2015-2018 European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"test suite for masked arrays"
__author__ = "Jérôme Kieffer"
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "13/01/2021"
import unittest
import logging
import fabio
from .utilstest import UtilsTest
logger = logging.getLogger(__name__)
from ..azimuthalIntegrator import AzimuthalIntegrator
from ..detectors import Pilatus1M
if logger.getEffectiveLevel() <= logging.INFO:
import pylab
from ..utils import mathutil
class TestSaxs(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
img = UtilsTest.getimage("Pilatus1M.edf")
self.data = fabio.open(img).data
self.ai = AzimuthalIntegrator(1.58323111834, 0.0334170169115, 0.0412277798782, 0.00648735642526, 0.00755810191106, 0.0, detector=Pilatus1M())
self.ai.wavelength = 1e-10
self.npt = 1000
def tearDown(self):
unittest.TestCase.tearDown(self)
self.data = self.ai = self.npt = None
def testMask(self):
ss = self.ai.mask.sum()
self.assertTrue(ss == 73533, "masked pixel = %s expected 73533" % ss)
@unittest.skipIf(UtilsTest.low_mem, "test using >100Mb")
def testNumpy(self):
method = ("no", "histogram", "python")
qref, Iref, _ = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson")
q, I, s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson", method=method)
self.assertTrue(q[0] > 0, "q[0]>0 %s" % q[0])
self.assertTrue(q[-1] < 8, "q[-1] < 8, got %s" % q[-1])
self.assertTrue(s.min() >= 0, "s.min() >= 0 got %s" % (s.min()))
self.assertTrue(s.max() < 21, "s.max() < 21 got %s" % (s.max()))
self.assertTrue(I.max() < 52000, "I.max() < 52000 got %s" % (I.max()))
self.assertTrue(I.min() >= 0, "I.min() >= 0 got %s" % (I.min()))
R = mathutil.rwp((q, I), (qref, Iref))
if R > 20:
logger.error("Numpy has R=%s", R)
if logger.getEffectiveLevel() == logging.DEBUG:
pylab.errorbar(q, I, s, label="Numpy R=%.1f" % R)
pylab.yscale("log")
self.assertTrue(R < 20, "Numpy: Measure R=%s<2" % R)
@unittest.skipIf(UtilsTest.low_mem, "skipping test using >100M")
def testCython(self):
method = ("no", "histogram", "cython")
qref, Iref, _s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson")
q, I, s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson", method=method)
self.assertTrue(q[0] > 0, "q[0]>0 %s" % q[0])
self.assertTrue(q[-1] < 8, "q[-1] < 8, got %s" % q[-1])
self.assertTrue(s.min() >= 0, "s.min() >= 0 got %s" % (s.min()))
self.assertTrue(s.max() < 21, "s.max() < 21 got %s" % (s.max()))
self.assertTrue(I.max() < 52000, "I.max() < 52000 got %s" % (I.max()))
self.assertTrue(I.min() >= 0, "I.min() >= 0 got %s" % (I.min()))
R = mathutil.rwp((q, I), (qref, Iref))
if R > 20:
logger.error("Cython has R=%s", R)
if logger.getEffectiveLevel() == logging.DEBUG:
pylab.errorbar(q, I, s, label="Cython R=%.1f" % R)
pylab.yscale("log")
self.assertTrue(R < 20, "Cython: Measure R=%s<2" % R)
def testSplitBBox(self):
method = ("bbox", "histogram", "cython")
qref, Iref, _s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson")
q, I, s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson", method=method)
self.assertTrue(q[0] > 0, "q[0]>0 %s" % q[0])
self.assertTrue(q[-1] < 8, "q[-1] < 8, got %s" % q[-1])
self.assertTrue(s.min() >= 0, "s.min() >= 0 got %s" % (s.min()))
self.assertTrue(s.max() < 21, "s.max() < 21 got %s" % (s.max()))
self.assertTrue(I.max() < 52000, "I.max() < 52000 got %s" % (I.max()))
self.assertTrue(I.min() >= 0, "I.min() >= 0 got %s" % (I.min()))
R = mathutil.rwp((q, I), (qref, Iref))
if R > 20:
logger.error("SplitPixel has R=%s", R)
if logger.getEffectiveLevel() == logging.DEBUG:
pylab.errorbar(q, I, s, label="SplitBBox R=%.1f" % R)
pylab.yscale("log")
self.assertEqual(R < 20, True, "SplitBBox: Measure R=%s<20" % R)
def testSplitPixel(self):
method = ("full", "histogram", "cython")
qref, Iref, _s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson")
q, I, s = self.ai.integrate1d_ng(self.data, self.npt, error_model="poisson", method=method)
self.assertTrue(q[0] > 0, "q[0]>0 %s" % q[0])
self.assertTrue(q[-1] < 8, "q[-1] < 8, got %s" % q[-1])
self.assertTrue(s.min() >= 0, "s.min() >= 0 got %s" % (s.min()))
self.assertTrue(s.max() < 21, "s.max() < 21 got %s" % (s.max()))
self.assertTrue(I.max() < 52000, "I.max() < 52000 got %s" % (I.max()))
self.assertTrue(I.min() >= 0, "I.min() >= 0 got %s" % (I.min()))
R = mathutil.rwp((q, I), (qref, Iref))
if R > 20:
logger.error("SplitPixel has R=%s", R)
if logger.getEffectiveLevel() == logging.DEBUG:
pylab.errorbar(q, I, s, label="SplitPixel R=%.1f" % R)
pylab.yscale("log")
self.assertEqual(R < 20, True, "SplitPixel: Measure R=%s<20" % R)
def suite():
loader = unittest.defaultTestLoader.loadTestsFromTestCase
testsuite = unittest.TestSuite()
testsuite.addTest(loader(TestSaxs))
return testsuite
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(suite())
if logger.getEffectiveLevel() == logging.DEBUG:
pylab.legend()
pylab.show()
input()
pylab.clf()
|