class TestSixCircleGammaOnArmGeometry(object): def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() def testGetName(self): assert self.geometry.name == "sixc_gamma_on_arm" def testPhysicalAnglesToInternalPosition(self): pos = [1, 2, 3, 4, 5, 6] expected = self.geometry.physical_angles_to_internal_position(pos) assert VliegPosition(*pos) == expected def testInternalPositionToPhysicalAngles(self): pos = VliegPosition(1, 2, 3, 4, 5, 6) result = self.geometry.internal_position_to_physical_angles(pos) mneq_(matrix([pos.totuple()]), matrix([result]), 4) def testSupportsModeGroup(self): assert self.geometry.supports_mode_group('fourc') assert not self.geometry.supports_mode_group('made up mode') def testGetFixedParameters(self): self.geometry.fixed_parameters # check for exceptions def isParamaterUnchangable(self): assert not self.geometry.isParamaterUnchangable('made up parameter')
class TestSixCircleGammaOnArmGeometry(unittest.TestCase): def setUp(self): self.geometry = SixCircleGammaOnArmGeometry() def testGetName(self): self.assertEqual(self.geometry.name, "sixc_gamma_on_arm") def testPhysicalAnglesToInternalPosition(self): pos = [1, 2, 3, 4, 5, 6] expected = self.geometry.physical_angles_to_internal_position(pos) self.assert_(VliegPosition(*pos) == expected) def testInternalPositionToPhysicalAngles(self): pos = VliegPosition(1, 2, 3, 4, 5, 6) result = self.geometry.internal_position_to_physical_angles(pos) mneq_(matrix([pos.totuple()]), matrix([result]), 4) def testSupportsModeGroup(self): self.assertTrue(self.geometry.supports_mode_group('fourc')) self.assertFalse(self.geometry.supports_mode_group('made up mode')) def testGetFixedParameters(self): self.geometry.fixed_parameters # check for exceptions def isParamaterUnchangable(self): self.assertFalse( self.geometry.isParamaterUnchangable('made up parameter'))
def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() self.hardware = DummyHardwareAdapter( ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) settings.hardware = self.hardware settings.geometry = self.geometry settings.ubcalc_persister = UbCalculationNonPersister() from diffcalc.dc import dcvlieg as dc reload(dc) self.dc = dc self.setSessionAndCalculation() prepareRawInput([])
def setup_method(self): names = 'a', 'd', 'g', 'o', 'c', 'phi' self.hardware = DummyHardwareAdapter(names) self.geometry = SixCircleGammaOnArmGeometry() self.transform_selector = VliegTransformSelector() self.transformer = VliegPositionTransformer(self.geometry, self.hardware, self.transform_selector) self.transform_commands = TransformCommands(self.transform_selector) diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True
def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() mock_hardware = Mock() mock_hardware.get_axes_names.return_value = ('a', 'd', 'g', 'o', 'c', 'p') self.ubcalc = UBCalculation( mock_hardware, self.geometry, UbCalculationNonPersister(), VliegUbCalcStrategy()) self.time = datetime.now()
def setup_method(self): settings.ubcalc_persister = UbCalculationNonPersister() settings.geometry = SixCircleGammaOnArmGeometry() settings.ubcalc_strategy = VliegUbCalcStrategy() settings.angles_to_hkl_function = vliegAnglesToHkl settings.Pos = VliegPosition self.t_matrix = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) self.t_hand = 1 _UBCommandsBase.setup_method(self)
def setup_method(self): self._geometry = SixCircleGammaOnArmGeometry() self.reflist = ReflectionList(self._geometry, ['a', 'd', 'g', 'o', 'c', 'p']) self.time = datetime.now() pos = Pos(0.1, 0.2, 0.3, 0.4, 0.5, 0.6) self.reflist.add_reflection(1, 2, 3, pos, 1000, "ref1", self.time) pos = Pos(0.11, 0.22, 0.33, 0.44, 0.55, 0.66) self.reflist.add_reflection(1.1, 2.2, 3.3, pos, 1100, "ref2", self.time)
def setUp(self): self.geometry = SixCircleGammaOnArmGeometry() self.hardware = DummyHardwareAdapter( ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) self.d = create_diffcalc('vlieg', self.geometry, self.hardware, True, UbCalculationNonPersister()) self.d.raiseExceptionsForAllErrors = True #self.scenarios = scenarios.sessions() self.setSessionAndCalculation() prepareRawInput([])
def setUp(self): names = 'a', 'd', 'g', 'o', 'c', 'phi' self.hardware = DummyHardwareAdapter(names) self.geometry = SixCircleGammaOnArmGeometry() self.transform_selector = VliegTransformSelector() self.transformer = VliegPositionTransformer( self.geometry, self.hardware, self.transform_selector) self.transform_commands = TransformCommands(self.transform_selector) diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True
def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() mock_hardware = Mock() mock_hardware.energyScannableMultiplierToGetKeV = 1 mock_hardware.get_axes_names.return_value = ('a', 'd', 'g', 'o', 'c', 'p') settings.hardware = mock_hardware settings.geometry = self.geometry self.ubcalc = UBCalculation(UbCalculationNonPersister(), VliegUbCalcStrategy()) self.time = datetime.now()
def setup_method(self): print "TestUBCalcWithCubic.setup_method" hardware = Mock() hardware.get_axes_names.return_value = \ ('a', 'd', 'g', 'o', 'c', 'p') self.ubcalc = UBCalculation(hardware, SixCircleGammaOnArmGeometry(), UbCalculationNonPersister(), VliegUbCalcStrategy()) self.ubcalc.start_new('xtalubcalc') self.ubcalc.set_lattice("xtal", *CUBIC) self.energy = CUBIC_EN
def setup_method(self): print "TestUBCalcWithCubic.setup_method" mock_hardware = Mock() mock_hardware.energyScannableMultiplierToGetKeV = 1 mock_hardware.get_axes_names.return_value = \ ('a', 'd', 'g', 'o', 'c', 'p') settings.hardware = mock_hardware settings.geometry = SixCircleGammaOnArmGeometry() self.ubcalc = UBCalculation(UbCalculationNonPersister(), VliegUbCalcStrategy()) self.ubcalc.start_new('xtalubcalc') self.ubcalc.set_lattice("xtal", *CUBIC) self.energy = CUBIC_EN
def setup_method(self): from diffcalc import settings settings.geometry = SixCircleGammaOnArmGeometry() dummy = 'alpha', 'delta', 'gamma', 'omega', 'chi', 'phi' settings.hardware = DummyHardwareAdapter(dummy) self.mock_ubcalc = Mock(spec=UBCalculation) self.hklcalc = VliegHklCalculator(self.mock_ubcalc, True) settings.ubcalc_persister = UbCalculationNonPersister() from diffcalc.hkl.vlieg import hkl reload(hkl) hkl.hklcalc = self.hklcalc self.hkl = hkl prepareRawInput([])
def setup_method(self): names = 'alpha', 'delta', 'gamma', 'omega', 'chi', 'phi' self.hardware = DummyHardwareAdapter(names) _geometry = SixCircleGammaOnArmGeometry() _ubcalc_persister = self._createPersister() settings.hardware = self.hardware settings.geometry = _geometry settings.ubcalc_persister = _ubcalc_persister #settings.set_engine_name('vlieg') settings.ubcalc_strategy = diffcalc.hkl.vlieg.calc.VliegUbCalcStrategy( ) settings.angles_to_hkl_function = diffcalc.hkl.vlieg.calc.vliegAnglesToHkl from diffcalc.ub import ub reload(ub) self.ub = ub #self.ub.ubcalc = ub.ubcalc prepareRawInput([]) diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True
class TestVliegPositionTransformer(unittest.TestCase): def setUp(self): names = 'a', 'd', 'g', 'o', 'c', 'phi' self.hardware = DummyHardwareAdapter(names) self.geometry = SixCircleGammaOnArmGeometry() self.transform_selector = VliegTransformSelector() self.transformer = VliegPositionTransformer( self.geometry, self.hardware, self.transform_selector) self.transform_commands = TransformCommands(self.transform_selector) diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True def map(self, pos): # @ReservedAssignment pos = self.transformer.transform(pos) angle_tuple = self.geometry.internal_position_to_physical_angles(pos) angle_tuple = self.hardware.cut_angles(angle_tuple) return angle_tuple def testMapDefaultSector(self): eq_(self.map(Pos(1, 2, 3, 4, 5, 6)), (1, 2, 3, 4, 5, 6)) eq_(self.map(Pos(-180, -179, 0, 179, 180, 359)), (-180, -179, 0, 179, 180, 359)) eq_(self.map(Pos(0, 0, 0, 0, 0, 0)), (0, 0, 0, 0, 0, 0)) eq_(self.map(Pos(-270, 270, 0, 0, 0, -90)), (90, -90, 0, 0, 0, 270)) def testMapSector1(self): self.transform_commands._sectorSelector.setSector(1) eq_(self.map(Pos(1, 2, 3, 4, 5, 6)), (1, 2, 3, 4 - 180, -5, (6 - 180) + 360)) eq_(self.map(Pos(-180, -179, 0, 179, 180, 359)), (-180, -179, 0, 179 - 180, -180, 359 - 180)) eq_(self.map(Pos(0, 0, 0, 0, 0, 0)), (0, 0, 0, 0 - 180, 0, (0 - 180) + 360)) eq_(self.map(Pos(-270, 270, 0, 0, 0, -90)), (90, -90, 0, 0 - 180, 0, 270 - 180)) def testMapAutoSector(self): self.transform_commands._sectorSelector.addAutoTransorm(1) self.hardware.set_lower_limit('c', 0) eq_(self.map(Pos(1, 2, 3, 4, -5, 6)), (1, 2, 3, 4 - 180, 5, (6 - 180) + 360)) eq_(self.map(Pos(-180, -179, 0, 179, -180, 359)), (-180, -179, 0, 179 - 180, 180, 359 - 180)) eq_(self.map(Pos(0, 0, 0, 0, -5, 0)), (0, 0, 0, 0 - 180, 5, (0 - 180) + 360)) eq_(self.map(Pos(-270, 270, 0, 0, -5, -90)), (90, -90, 0, 0 - 180, 5, 270 - 180)) def testTransform(self): # mapper self.transform_commands.transform() # should print its state self.assertRaises(TypeError, self.transform_commands.transform, 1) self.assertRaises(TypeError, self.transform_commands.transform, 'a', 1) def testTransformsOnOff(self): # transforma [on/off/auto/manual] ss = self.transform_commands._sectorSelector self.transform_commands.transforma() # should print mapper state eq_(ss.transforms, [], "test assumes transforms are off to start") self.transform_commands.transforma('on') eq_(ss.transforms, ['a']) self.transform_commands.transformb('on') eq_(ss.transforms, ['a', 'b']) self.transform_commands.transformc('off') eq_(ss.transforms, ['a', 'b']) self.transform_commands.transformb('off') eq_(ss.transforms, ['a']) def testTransformsAuto(self): ss = self.transform_commands._sectorSelector eq_(ss.autotransforms, [], "test assumes transforms are off to start") self.transform_commands.transforma('auto') eq_(ss.autotransforms, ['a']) self.transform_commands.transformb('auto') eq_(ss.autotransforms, ['a', 'b']) self.transform_commands.transformc('manual') eq_(ss.autotransforms, ['a', 'b']) self.transform_commands.transformb('manual') eq_(ss.autotransforms, ['a']) def testTransformsBadInput(self): transforma = self.transform_commands.transforma self.assertRaises(TypeError, transforma, 1) self.assertRaises(TypeError, transforma, 'not_valid') self.assertRaises(TypeError, transforma, 'auto', 1) def testSector(self): #sector [0-7] ss = self.transform_commands._sectorSelector self.transform_commands.sector() # should print mapper state eq_(ss.sector, 0, "test assumes sector is 0 to start") self.transform_commands.sector(1) eq_(ss.sector, 1) self.assertRaises(TypeError, self.transform_commands.sector, 1, 2) self.assertRaises(TypeError, self.transform_commands.sector, 'a') def testAutosectors(self): #autosector [0-7] ss = self.transform_selector self.transform_commands.autosector() # should print mapper state eq_(ss.autosectors, [], "test assumes no auto sectors to start") self.transform_commands.autosector(1) eq_(ss.autosectors, [1]) self.transform_commands.autosector(1, 2) eq_(ss.autosectors, [1, 2]) self.transform_commands.autosector(1) eq_(ss.autosectors, [1]) self.transform_commands.autosector(3) eq_(ss.autosectors, [3]) self.assertRaises( TypeError, self.transform_commands.autosector, 1, 'a') self.assertRaises( TypeError, self.transform_commands.autosector, 'a')
class TestVliegPositionTransformer(object): def setup_method(self): names = 'a', 'd', 'g', 'o', 'c', 'phi' self.hardware = DummyHardwareAdapter(names) self.geometry = SixCircleGammaOnArmGeometry() self.transform_selector = VliegTransformSelector() self.transformer = VliegPositionTransformer(self.geometry, self.hardware, self.transform_selector) self.transform_commands = TransformCommands(self.transform_selector) diffcalc.util.RAISE_EXCEPTIONS_FOR_ALL_ERRORS = True def map(self, pos): # @ReservedAssignment pos = self.transformer.transform(pos) angle_tuple = self.geometry.internal_position_to_physical_angles(pos) angle_tuple = self.hardware.cut_angles(angle_tuple) return angle_tuple def testMapDefaultSector(self): eq_(self.map(Pos(1, 2, 3, 4, 5, 6)), (1, 2, 3, 4, 5, 6)) eq_(self.map(Pos(-180, -179, 0, 179, 180, 359)), (-180, -179, 0, 179, 180, 359)) eq_(self.map(Pos(0, 0, 0, 0, 0, 0)), (0, 0, 0, 0, 0, 0)) eq_(self.map(Pos(-270, 270, 0, 0, 0, -90)), (90, -90, 0, 0, 0, 270)) def testMapSector1(self): self.transform_commands._sectorSelector.setSector(1) eq_(self.map(Pos(1, 2, 3, 4, 5, 6)), (1, 2, 3, 4 - 180, -5, (6 - 180) + 360)) eq_(self.map(Pos(-180, -179, 0, 179, 180, 359)), (-180, -179, 0, 179 - 180, -180, 359 - 180)) eq_(self.map(Pos(0, 0, 0, 0, 0, 0)), (0, 0, 0, 0 - 180, 0, (0 - 180) + 360)) eq_(self.map(Pos(-270, 270, 0, 0, 0, -90)), (90, -90, 0, 0 - 180, 0, 270 - 180)) def testMapAutoSector(self): self.transform_commands._sectorSelector.addAutoTransorm(1) self.hardware.set_lower_limit('c', 0) eq_(self.map(Pos(1, 2, 3, 4, -5, 6)), (1, 2, 3, 4 - 180, 5, (6 - 180) + 360)) eq_(self.map(Pos(-180, -179, 0, 179, -180, 359)), (-180, -179, 0, 179 - 180, 180, 359 - 180)) eq_(self.map(Pos(0, 0, 0, 0, -5, 0)), (0, 0, 0, 0 - 180, 5, (0 - 180) + 360)) eq_(self.map(Pos(-270, 270, 0, 0, -5, -90)), (90, -90, 0, 0 - 180, 5, 270 - 180)) def testTransform(self): # mapper self.transform_commands.transform() # should print its state with pytest.raises(TypeError): self.transform_commands.transform(1) with pytest.raises(TypeError): self.transform_commands.transform('a', 1) def testTransformsOnOff(self): # transforma [on/off/auto/manual] ss = self.transform_commands._sectorSelector self.transform_commands.transforma() # should print mapper state eq_(ss.transforms, [], "test assumes transforms are off to start") self.transform_commands.transforma('on') eq_(ss.transforms, ['a']) self.transform_commands.transformb('on') eq_(ss.transforms, ['a', 'b']) self.transform_commands.transformc('off') eq_(ss.transforms, ['a', 'b']) self.transform_commands.transformb('off') eq_(ss.transforms, ['a']) def testTransformsAuto(self): ss = self.transform_commands._sectorSelector eq_(ss.autotransforms, [], "test assumes transforms are off to start") self.transform_commands.transforma('auto') eq_(ss.autotransforms, ['a']) self.transform_commands.transformb('auto') eq_(ss.autotransforms, ['a', 'b']) self.transform_commands.transformc('manual') eq_(ss.autotransforms, ['a', 'b']) self.transform_commands.transformb('manual') eq_(ss.autotransforms, ['a']) def testTransformsBadInput(self): transforma = self.transform_commands.transforma with pytest.raises(TypeError): transforma(1) with pytest.raises(TypeError): transforma('not_valid') with pytest.raises(TypeError): transforma('auto', 1) def testSector(self): #sector [0-7] ss = self.transform_commands._sectorSelector self.transform_commands.sector() # should print mapper state eq_(ss.sector, 0, "test assumes sector is 0 to start") self.transform_commands.sector(1) eq_(ss.sector, 1) with pytest.raises(TypeError): self.transform_commands.sector(1, 2) with pytest.raises(TypeError): self.transform_commands.sector('a') def testAutosectors(self): #autosector [0-7] ss = self.transform_selector self.transform_commands.autosector() # should print mapper state eq_(ss.autosectors, [], "test assumes no auto sectors to start") self.transform_commands.autosector(1) eq_(ss.autosectors, [1]) self.transform_commands.autosector(1, 2) eq_(ss.autosectors, [1, 2]) self.transform_commands.autosector(1) eq_(ss.autosectors, [1]) self.transform_commands.autosector(3) eq_(ss.autosectors, [3]) with pytest.raises(TypeError): self.transform_commands.autosector(1, 'a') with pytest.raises(TypeError): self.transform_commands.autosector('a')
def setup_method(self): _UBCommandsBase.setup_method(self) settings.geometry = SixCircleGammaOnArmGeometry() settings.ubcalc_strategy = VliegUbCalcStrategy() settings.angles_to_hkl_function = vliegAnglesToHkl settings.Pos = VliegPosition
def setUp(self): self.geometry = SixCircleGammaOnArmGeometry()
class BaseTestDiffractionCalculatorWithData(object): def setSessionAndCalculation(self): raise Exception("Abstract") def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() self.hardware = DummyHardwareAdapter( ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) settings.hardware = self.hardware settings.geometry = self.geometry settings.ubcalc_persister = UbCalculationNonPersister() from diffcalc.dc import dcvlieg as dc reload(dc) self.dc = dc self.setSessionAndCalculation() prepareRawInput([]) def setDataAndReturnObject(self, sessionScenario, calculationScenario): self.sess = sessionScenario self.calc = calculationScenario return self def test_angles_to_hkl(self): with pytest.raises(DiffcalcException): self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6)) # no energy set settings.hardware.energy = 10 with pytest.raises(DiffcalcException): self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6)) # no ub calculated s = self.sess c = self.calc # setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos!) mneq_(self.dc.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix), 4, note="wrong UB matrix after calculating U") # Test each hkl/position pair for idx in range(len(c.hklList)): hkl = c.hklList[idx] pos = c.posList[idx] # 1) specifying energy explicitely ((h, k, l), params) = self.dc.angles_to_hkl(pos.totuple(), c.energy) msg = ("wrong hkl calc for TestScenario=%s, AngleTestScenario" "=%s, pos=%s):\n expected hkl=%f %f %f\n returned hkl=" "%f %f %f " % (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l)) assert [h, k, l] == pytest.approx(hkl, abs=.001) # self.assert_((abs(h - hkl[0]) < .001) & (abs(k - hkl[1]) < .001) # & (abs(l - hkl[2]) < .001), msg) # 2) specifying energy via hardware settings.hardware.energy = c.energy msg = ("wrong hkl calcualted for TestScenario=%s, " "AngleTestScenario=%s, pos=%s):\n expected hkl=%f %f %f\n" " returned hkl=%f %f %f " % (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l)) ((h, k, l), params) = self.dc.angles_to_hkl(pos.totuple()) assert [h, k, l] == pytest.approx(hkl, abs=.001) del params def test_hkl_to_angles(self): s = self.sess c = self.calc ## setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos !) mneq_(self.dc.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix), 4, note="wrong UB matrix after calculating U") ## setup calculation info self.dc.hklmode(c.modeNumber) # Set fixed parameters if c.alpha != None: self.dc.setpar('alpha', c.alpha) if c.gamma != None: self.dc.setpar('gamma', c.alpha) # Test each hkl/position pair for idx in range(len(c.hklList)): (h, k, l) = c.hklList[idx] expectedangles = \ self.geometry.internal_position_to_physical_angles(c.posList[idx]) (angles, params) = self.dc.hkl_to_angles(h, k, l, c.energy) expectedAnglesStr = ("%f " * len(expectedangles)) % expectedangles anglesString = ("%f " * len(angles)) % angles namesString = (("%s " * len(self.hardware.get_axes_names())) % self.hardware.get_axes_names()) note = ("wrong position calcualted for TestScenario=%s, " "AngleTestScenario=%s, hkl=%f %f %f:\n" " { %s }\n" " expected pos=%s\n returned pos=%s " % (s.name, c.tag, h, k, l, namesString, expectedAnglesStr, anglesString)) mneq_(matrix([list(expectedangles)]), matrix([list(angles)]), 2, note=note) del params def testSimWithHklAndSixc(self): dummyAxes = createDummyAxes( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) dummySixcScannableGroup = ScannableGroup('sixcgrp', dummyAxes) sixcdevice = DiffractometerScannableGroup( 'SixCircleGammaOnArmGeometry', self.dc, dummySixcScannableGroup) hkldevice = Hkl('hkl', sixcdevice, self.dc) with pytest.raises(TypeError): sim() with pytest.raises(TypeError): sim(hkldevice) with pytest.raises(TypeError): sim(hkldevice, 1, 2, 3) with pytest.raises(TypeError): sim('not a proper scannable', 1) with pytest.raises(TypeError): sim(hkldevice, (1, 2, 'not a number')) with pytest.raises(TypeError): sim(hkldevice, 1) with pytest.raises(ValueError): sim(hkldevice, (1, 2, 3, 4)) s = self.sess c = self.calc # setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos!) mneq_(self.dc.ubcalc.UB, (matrix(s.umatrix) * (matrix(s.bmatrix))), 4, note="wrong UB matrix after calculating U") self.hardware.energy = c.energy # Test each hkl/position pair for idx in range(len(c.hklList)): hkl = c.hklList[idx] pos = c.posList[idx].totuple() sim(sixcdevice, pos) sim(hkldevice, hkl) def testCheckub(self): ## setup session info s = self.sess self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() print "*** checkub ***" print self.dc.checkub() print "***************"
class BaseTestDiffractionCalculatorWithData(object): def setSessionAndCalculation(self): raise Exception("Abstract") def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() self.hardware = DummyHardwareAdapter( ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) settings.hardware = self.hardware settings.geometry = self.geometry settings.ubcalc_persister = UbCalculationNonPersister() from diffcalc.dc import dcvlieg as dc reload(dc) self.dc = dc self.setSessionAndCalculation() prepareRawInput([]) def setDataAndReturnObject(self, sessionScenario, calculationScenario): self.sess = sessionScenario self.calc = calculationScenario return self def test_angles_to_hkl(self): with pytest.raises(DiffcalcException): self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6)) # no energy set settings.hardware.energy = 10 with pytest.raises(DiffcalcException): self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6)) # no ub calculated s = self.sess c = self.calc # setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos!) mneq_(self.dc.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix), 4, note="wrong UB matrix after calculating U") # Test each hkl/position pair for idx in range(len(c.hklList)): hkl = c.hklList[idx] pos = c.posList[idx] # 1) specifying energy explicitely ((h, k, l), params) = self.dc.angles_to_hkl(pos.totuple(), c.energy) msg = ("wrong hkl calc for TestScenario=%s, AngleTestScenario" "=%s, pos=%s):\n expected hkl=%f %f %f\n returned hkl=" "%f %f %f " % (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l) ) assert [h, k, l] == pytest.approx(hkl, abs=.001) # self.assert_((abs(h - hkl[0]) < .001) & (abs(k - hkl[1]) < .001) # & (abs(l - hkl[2]) < .001), msg) # 2) specifying energy via hardware settings.hardware.energy = c.energy msg = ("wrong hkl calcualted for TestScenario=%s, " "AngleTestScenario=%s, pos=%s):\n expected hkl=%f %f %f\n" " returned hkl=%f %f %f " % (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l)) ((h, k, l), params) = self.dc.angles_to_hkl(pos.totuple()) assert [h, k, l] == pytest.approx(hkl, abs=.001) del params def test_hkl_to_angles(self): s = self.sess c = self.calc ## setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos !) mneq_(self.dc.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix), 4, note="wrong UB matrix after calculating U") ## setup calculation info self.dc.hklmode(c.modeNumber) # Set fixed parameters if c.alpha != None: self.dc.setpar('alpha', c.alpha) if c.gamma != None: self.dc.setpar('gamma', c.alpha) # Test each hkl/position pair for idx in range(len(c.hklList)): (h, k, l) = c.hklList[idx] expectedangles = \ self.geometry.internal_position_to_physical_angles(c.posList[idx]) (angles, params) = self.dc.hkl_to_angles(h, k, l, c.energy) expectedAnglesStr = ("%f " * len(expectedangles)) % expectedangles anglesString = ("%f " * len(angles)) % angles namesString = (("%s " * len(self.hardware.get_axes_names())) % self.hardware.get_axes_names()) note = ("wrong position calcualted for TestScenario=%s, " "AngleTestScenario=%s, hkl=%f %f %f:\n" " { %s }\n" " expected pos=%s\n returned pos=%s " % (s.name, c.tag, h, k, l, namesString, expectedAnglesStr, anglesString)) mneq_(matrix([list(expectedangles)]), matrix([list(angles)]), 2, note=note) del params def testSimWithHklAndSixc(self): dummyAxes = createDummyAxes( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) dummySixcScannableGroup = ScannableGroup('sixcgrp', dummyAxes) sixcdevice = DiffractometerScannableGroup( 'SixCircleGammaOnArmGeometry', self.dc, dummySixcScannableGroup) hkldevice = Hkl('hkl', sixcdevice, self.dc) with pytest.raises(TypeError): sim() with pytest.raises(TypeError): sim(hkldevice) with pytest.raises(TypeError): sim(hkldevice, 1, 2, 3) with pytest.raises(TypeError): sim('not a proper scannable', 1) with pytest.raises(TypeError): sim(hkldevice, (1, 2, 'not a number')) with pytest.raises(TypeError): sim(hkldevice, 1) with pytest.raises(ValueError): sim(hkldevice, (1, 2, 3, 4)) s = self.sess c = self.calc # setup session info self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() # check the ubcalculation is okay before continuing # (useful to check for typos!) mneq_(self.dc.ubcalc.UB, (matrix(s.umatrix) * (matrix(s.bmatrix))), 4, note="wrong UB matrix after calculating U") self.hardware.energy = c.energy # Test each hkl/position pair for idx in range(len(c.hklList)): hkl = c.hklList[idx] pos = c.posList[idx].totuple() sim(sixcdevice, pos) sim(hkldevice, hkl) def testCheckub(self): ## setup session info s = self.sess self.dc.newub(s.name) self.dc.setlat(s.name, *s.lattice) r = s.ref1 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) r = s.ref2 self.dc.addref( [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag) self.dc.calcub() print "*** checkub ***" print self.dc.checkub() print "***************"
def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry()