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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Project: Fast Azimuthal Integration
# https://github.com/pyFAI/pyFAI
#
# Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"test suite for masked arrays"
__author__ = "Jérôme Kieffer"
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "GPLv3+"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "20/10/2014"
import fabio
import logging, time
import numpy
import os
import sys
import unittest
from utilstest import UtilsTest, Rwp, getLogger
logger = getLogger(__file__)
pyFAI = sys.modules["pyFAI"]
if logger.getEffectiveLevel() <= logging.INFO:
import pylab
def testExport(direct=100, centerX=900, centerY=1000, tilt=0, tpr=0, pixelX=50, pixelY=60):
a1 = pyFAI.AzimuthalIntegrator()
a2 = pyFAI.AzimuthalIntegrator()
a3 = pyFAI.AzimuthalIntegrator()
a1.setFit2D(direct, centerX, centerY, tilt, tpr, pixelX, pixelY)
# print a1
a2.setPyFAI(**a1.getPyFAI())
a3.setFit2D(**a2.getFit2D())
res = ""
for e, o in [(a1, a2), (a1, a3), (a2, a3)]:
for key in ["dist", "poni1", "poni2", "rot1", "rot2", "rot3", "pixel1", "pixel2", "splineFile"]:
refv = e.__getattribute__(key)
obtv = o.__getattribute__(key)
try:
if round(abs(float(refv) - float(obtv))) != 0:
res += "%s: %s != %s" % (key, refv, obtv)
except TypeError as error:
if refv != obtv:
res += "%s: %s != %s" % (key, refv, obtv)
return res
class TestFIT2D(unittest.TestCase):
poniFile = "1893/Pilatus1M.poni"
def setUp(self):
"""Download files"""
self.poniFile = UtilsTest.getimage(self.__class__.poniFile)
def test_simple(self):
ref = pyFAI.load(self.poniFile)
obt = pyFAI.AzimuthalIntegrator()
obt.setFit2D(**ref.getFit2D())
for key in ["dist", "poni1", "poni2", "rot1", "rot2", "rot3", "pixel1", "pixel2", "splineFile"]:
refv = ref.__getattribute__(key)
obtv = obt.__getattribute__(key)
if refv is None:
self.assertEqual(refv, obtv , "%s: %s != %s" % (key, refv, obtv))
else:
self.assertAlmostEqual(refv, obtv , 4, "%s: %s != %s" % (key, refv, obtv))
def test_export(self):
res = testExport()
self.assertFalse(res, res)
res = testExport(tilt=20)
self.assertFalse(res, res)
res = testExport(tilt=20, tpr=80)
self.assertFalse(res, res)
res = testExport(tilt=20, tpr=580)
self.assertFalse(res, res)
class TestSPD(unittest.TestCase):
poniFile = "1893/Pilatus1M.poni"
def setUp(self):
"""Download files"""
self.poniFile = UtilsTest.getimage(self.__class__.poniFile)
def test_simple(self):
ref = pyFAI.load(self.poniFile)
# ref.rot1 = 0
# ref.rot2 = 0
# ref.rot3 = 0
obt = pyFAI.AzimuthalIntegrator()
# print ref.getFit2D()
# print ref.getSPD()
obt.setSPD(**ref.getSPD())
# print obt.getSPD()
for key in ["dist", "poni1", "poni2", "rot3", "pixel1", "pixel2", "splineFile"]:
refv = ref.__getattribute__(key)
obtv = obt.__getattribute__(key)
if refv is None:
self.assertEqual(refv, obtv , "%s: %s != %s" % (key, refv, obtv))
else:
self.assertAlmostEqual(refv, obtv , 4, "%s: %s != %s" % (key, refv, obtv))
def test_suite_all_Export():
testSuite = unittest.TestSuite()
testSuite.addTest(TestFIT2D("test_simple"))
testSuite.addTest(TestFIT2D("test_export"))
testSuite.addTest(TestSPD("test_simple"))
return testSuite
if __name__ == '__main__':
mysuite = test_suite_all_Export()
runner = unittest.TextTestRunner()
if not runner.run(mysuite).wasSuccessful():
sys.exit(1)
|