예제 #1
0
class TestHklWithFailingAngleCalculator(object):
    def setup_method(self):
        class BadMockAngleCalculator:
            def angles_to_hkl(self, pos):
                raise Exception("Problem in angles_to_hkl")

        dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
                                 'phi'])
        self.group = ScannableGroup('grp', dummy)
        self.SixCircleGammaOnArmGeometry = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', MockDiffcalc(6), self.group)
        self.hkl = Hkl('hkl', self.SixCircleGammaOnArmGeometry,
                       BadMockAngleCalculator())

    def testGetPosition(self):
        with pytest.raises(Exception):
            self.hkl.getPosition(None)

    def test__repr__(self):
        assert self.hkl.__repr__() == "<hkl: Problem in angles_to_hkl>"

    def test__str__(self):
        assert self.hkl.__str__() == "<hkl: Problem in angles_to_hkl>"

    def testComponentGetPosition(self):
        with pytest.raises(Exception):
            self.hkl.h.getPosition(None)

    def testComponent__repr__(self):
        raise nose.SkipTest()
        assert self.hkl.h.__repr__() == "<h: Problem in angles_to_hkl>"

    def testComponent__str__(self):
        raise nose.SkipTest()
        assert self.hkl.h.__str__() == "<h: Problem in angles_to_hkl>"
예제 #2
0
class TestHklWithFailingAngleCalculator(unittest.TestCase):
    def setUp(self):
        class BadMockAngleCalculator:
            def angles_to_hkl(self, pos):
                raise Exception("Problem in angles_to_hkl")

        dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
                                 'phi'])
        self.group = ScannableGroup('grp', dummy)
        self.SixCircleGammaOnArmGeometry = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', MockDiffcalc(6), self.group)
        self.hkl = Hkl('hkl', self.SixCircleGammaOnArmGeometry,
                       BadMockAngleCalculator())

    def testGetPosition(self):
        self.assertRaises(Exception, self.hkl.getPosition, None)

    def test__repr__(self):
        self.assertEqual(self.hkl.__repr__(), "<hkl: Problem in angles_to_hkl>")

    def test__str__(self):
        self.assertEqual(self.hkl.__str__(), "<hkl: Problem in angles_to_hkl>")

    def testComponentGetPosition(self):
        self.assertRaises(Exception, self.hkl.h.getPosition, None)

    def testComponent__repr__(self):
        raise nose.SkipTest()
        self.assertEqual(self.hkl.h.__repr__(), "<h: Problem in angles_to_hkl>")

    def testComponent__str__(self):
        raise nose.SkipTest()
        self.assertEqual(self.hkl.h.__str__(), "<h: Problem in angles_to_hkl>")
예제 #3
0
 def rawAsynchronousMoveTo(self, pos):
     self.cached_params = pos[-self.num_cached_params:]
     hkl = self.parameter_to_hkl(pos)
     if isinstance(hkl[0], (int, float)):
         Hkl.rawAsynchronousMoveTo(self, hkl)
     elif isinstance(hkl[0], (tuple, list)):
         (pos, _) = self._diffcalc.hkl_list_to_angles(hkl)
         self.diffhw.asynchronousMoveTo(pos)
예제 #4
0
    def setup_method(self):
        class BadMockAngleCalculator:
            def angles_to_hkl(self, pos):
                raise Exception("Problem in angles_to_hkl")

        dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
                                 'phi'])
        self.group = ScannableGroup('grp', dummy)
        self.SixCircleGammaOnArmGeometry = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', MockDiffcalc(6), self.group)
        self.hkl = Hkl('hkl', self.SixCircleGammaOnArmGeometry,
                       BadMockAngleCalculator())
예제 #5
0
class TestHklReturningVirtualangles(TestHkl):
    def setup_method(self):
        TestHkl.setup_method(self)
        self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module,
                       ['theta', '2theta', 'Bin', 'Bout', 'azimuth'])

    def testInit(self):
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        assert self.hkl.getPosition() == [1, 0, 1, 1, 12, 123, 1234, 12345]

    def testGetPosition(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        assert self.hkl.getPosition() == [1, 0, 1, 1, 12, 123, 1234, 12345]
        self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
 def setup_method(self):
     TestSixcBase.createDiffcalcAndScannables(self,
                                              SixCircleGammaOnArmGeometry)
     self.hklverbose = Hkl('hkl', self.sixc, self.dc,
                           ('theta', '2theta', 'Bin', 'Bout', 'azimuth'))
     settings.hardware.set_cut('phi', -180)  # cut phi at -180 to match dif
     self.orient()
예제 #7
0
class TestHklReturningVirtualangles(TestHkl):
    def setUp(self):
        TestHkl.setUp(self)
        self.hkl = Hkl('hkl', self.mockSixc, self.mockDiffcalc,
                       ['theta', '2theta', 'Bin', 'Bout', 'azimuth'])

    def testInit(self):
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.assertEqual(self.hkl.getPosition(),
                         [1, 0, 1, 1, 12, 123, 1234, 12345])

    def testGetPosition(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.assertEqual(self.hkl.getPosition(),
                         [1, 0, 1, 1, 12, 123, 1234, 12345])
        self.mockDiffcalc.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
예제 #8
0
    def __init__(self, name, inputNames, num_cached_params=0):

        from diffcalc.dc import dcyou as _dc
        Hkl.__init__(self, name, settings.axes_scannable_group, _dc, None)

        self.setName(name)
        self.setInputNames(inputNames)
        self.setOutputFormat(['%7.5f'] * len(inputNames))

        self.parameter_to_hkl = self._diffcalc.angles_to_hkl
        self.hkl_to_parameter = self._diffcalc.hkl_to_angles
        self.num_cached_params = num_cached_params
        self.cached_params = None

        self.completeInstantiation()
        self.setAutoCompletePartialMoveToTargets(True)
        self.dynamic_class_doc = 'Generic Hkl Scannable'
    def setup_method(self):
        self.en = DummyPD('en')
        dummy = createDummyAxes(['alpha', 'delta', 'omega', 'chi', 'phi'])
        group = ScannableGroup('fivecgrp', dummy)
        self.fivec = DiffractometerScannableGroup('fivec', None, group)

        settings.hardware = ScannableHardwareAdapter(self.fivec, self.en)
        settings.geometry = Fivec()
        settings.ubcalc_persister = UbCalculationNonPersister()
        from diffcalc.dc import dcvlieg as dc
        reload(dc)
        self.dc = dc

        self.fivec.diffcalc = self.dc
        self.hkl = Hkl('hkl', self.fivec, self.dc)
        self.hklverbose = Hkl('hkl', self.fivec, self.dc,
                              ('theta', '2theta', 'Bin', 'Bout', 'azimuth'))
        self.orient()
예제 #10
0
    def setUp(self):
        class BadMockAngleCalculator:
            def angles_to_hkl(self, pos):
                raise Exception("Problem in angles_to_hkl")

        dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
                                 'phi'])
        self.group = ScannableGroup('grp', dummy)
        self.SixCircleGammaOnArmGeometry = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', MockDiffcalc(6), self.group)
        self.hkl = Hkl('hkl', self.SixCircleGammaOnArmGeometry,
                       BadMockAngleCalculator())
예제 #11
0
    def swithMotors(sax, say, saz, sath, sachi, saphi, diodedelta, specm5tth):
        import __main__
        __main__.xyz_eta = ScannableGroup('xyz_eta', [sax, say, saz])  # @UndefinedVariable
        #update support for i21 non-concentric rotation motions
        __main__.sa = I21SampleStage('sa', sath, sachi, saphi,__main__.xyz_eta)  # @UndefinedVariable
        
        __main__.tp_phi = sa.tp_phi_scannable
        
        __main__.tp_lab = I21TPLab('tp_lab', __main__.sa)  # @UndefinedVariable
        __main__.tp_labx = __main__.tp_lab.tp_labx  # @UndefinedVariable
        __main__.tp_laby = __main__.tp_lab.tp_laby  # @UndefinedVariable
        __main__.tp_labz = __main__.tp_lab.tp_labz  # @UndefinedVariable
        
        ### update Wrap i21 names to get diffcalc names
        _fourc = I21DiffractometerStage('_fourc', diodedelta, __main__.sa)  # @UndefinedVariable
        __main__.delta = _fourc.delta
        __main__.eta = _fourc.eta
        __main__.chi = _fourc.chi
        __main__.phi = _fourc.phi
            #update diffcalc objects
        __main__.settings.hardware = ScannableHardwareAdapter(_fourc, __main__.en, ESMTGKeV)  # @UndefinedVariable
        __main__.settings.geometry = FourCircleI21(beamline_axes_transform=beamline_axes_transform)  # @UndefinedVariable
        __main__.settings.energy_scannable = __main__.en  # @UndefinedVariable
        __main__.settings.axes_scannable_group= _fourc
        __main__.settings.energy_scannable_multiplier_to_get_KeV = ESMTGKeV
        
        __main__.fourc=DiffractometerScannableGroup('fourc', _dc, _fourc)
        __main__.hkl = Hkl('hkl', _fourc, _dc)
        __main__.h, __main__.k, __main__.l = hkl.h, hkl.k, hkl.l

        from diffcalc.gdasupport.you import _virtual_angles
        from diffcalc.gdasupport.scannable.simulation import SimulatedCrystalCounter
        from diffcalc.gdasupport.scannable.wavelength import Wavelength
        __main__.hklverbose = Hkl('hklverbose', _fourc, _dc, _virtual_angles)
        __main__.wl = Wavelength('wl',__main__.en,ESMTGKeV)  # @UndefinedVariable
        __main__.ct = SimulatedCrystalCounter('ct', _fourc, __main__.settings.geometry,__main__.wl)  # @UndefinedVariable
        #update scannales: fourc_vessel & hkl_vessel'
        _fourc_vessel = ScannableGroup('_fourc', (delta, th, chi, phi)) #I21DiffractometerStage('_fourc_vessel', m5tth, sa)
        __main__.fourc_vessel = DiffractometerScannableGroup('fourc_vessel', _dc, _fourc_vessel)
        __main__.hkl_vessel = Hkl('hkl_vessel', _fourc_vessel, _dc)
        __main__.h_vessel, __main__.k_vessel, __main__.l_vessel = hkl_vessel.h, hkl_vessel.k, hkl_vessel.l
        
        #Update scannables: fourc_lowq & hkl_lowq'
        _fourc_lowq = ScannableGroup('_fourc', (delta, th, chi, phi)) #I21DiffractometerStage('_fourc_lowq', m5tth, sa,delta_offset=LOWQ_OFFSET_ADDED_TO_DELTA_WHEN_READING)
        __main__.fourc_lowq = DiffractometerScannableGroup('fourc_lowq', _dc, _fourc_lowq)
        __main__.hkl_lowq = Hkl('hkl_lowq', _fourc_lowq, _dc)
        __main__.h_lowq, __main__.k_lowq, __main__.l_lowq = hkl_lowq.h, hkl_lowq.k, hkl_lowq.l
        
        #Update scannables: fourc_highq & hkl_highq'
        _fourc_highq = ScannableGroup('_fourc', (delta, th, chi, phi)) #I21DiffractometerStage('_fourc_highq', m5tth, sa,delta_offset=highq_OFFSET_ADDED_TO_DELTA_WHEN_READING)
        __main__.fourc_highq = DiffractometerScannableGroup('fourc_highq', _dc, _fourc_highq)
        __main__.hkl_highq = Hkl('hkl_highq', _fourc_highq, _dc)
        __main__.h_highq, __main__.k_highq, __main__.l_highq = hkl_highq.h, hkl_highq.k, hkl_highq.l
        
        #Update scannables: fourc_diode & hkl_diode'
        _fourc_diode = ScannableGroup('_fourc', (delta, th, chi, phi)) #I21DiffractometerStage('_fourc_diode', delta, sa)
        __main__.fourc_diode = DiffractometerScannableGroup('fourc_diode', _dc, _fourc_diode)
        __main__.hkl_diode = Hkl('hkl_diode', _fourc_diode, _dc)
        __main__.h_diode, __main__.k_diode, __main__.l_diode = hkl_diode.h, hkl_diode.k, hkl_diode.l
예제 #12
0
 def simulateMoveTo(self, pos):
     lines = ['%s:' % self.name]
     hkl = self.parameter_to_hkl(pos)
     if isinstance(hkl[0], (tuple, list)):
         (angles, _) = self._diffcalc.hkl_list_to_angles(hkl)
         hkl, _ = self._diffcalc.angles_to_hkl(angles)
     #fmt_scn_params = '  '.join([' : %9.4f'] + ['%.4f'] * (len(pos) - 1))
     #lines.append('  ' + self.name + fmt_scn_params % tuple(pos))
     width = max(len(k) for k in self.inputNames)
     fmt = '  %' + str(width) + 's : % 9.4f'
     for idx, k in enumerate(self.inputNames):
         lines.append(fmt % (k, pos[idx]))
     lines.append('\n  ' + 'hkl'.rjust(width) + ' : %9.4f  %.4f  %.4f' %
                  (hkl[0], hkl[1], hkl[2]))
     res = Hkl.simulateMoveTo(self, hkl)
     lines.append(res)
     return '\n'.join(lines)
예제 #13
0
    def createDiffcalcAndScannables(self):
        self.en = DummyPD('en')
        dummy = createDummyAxes(['delta', 'omega', 'chi', 'phi'])
        scannableGroup = ScannableGroup('fourcgrp', dummy)
        self.fourc = DiffractometerScannableGroup('fourc', None,
                                                  scannableGroup)

        settings.hardware = ScannableHardwareAdapter(self.fourc, self.en)
        settings.geometry = Fourc()
        settings.ubcalc_persister = UbCalculationNonPersister()

        from diffcalc.dc import dcvlieg as dc
        reload(dc)
        self.dc = dc

        self.fourc.diffcalc = self.dc
        self.hkl = Hkl('hkl', self.fourc, self.dc)
예제 #14
0
    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)
예제 #15
0
    def createDiffcalcAndScannables(self, geometryClass):
        self.en = DummyPD('en')
        dummy = createDummyAxes(
            ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'])
        group = ScannableGroup('sixcgrp', dummy)
        self.sixc = DiffractometerScannableGroup('sixc', None, group)

        self.hardware = DummyHardwareAdapter(
            ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'))
        settings.hardware = ScannableHardwareAdapter(self.sixc, self.en)
        settings.geometry = geometryClass()
        settings.ubcalc_persister = UbCalculationNonPersister()
        from diffcalc.dc import dcvlieg as dc
        reload(dc)
        self.dc = dc

        self.sixc.diffcalc = self.dc
        self.hkl = Hkl('hkl', self.sixc, self.dc)
예제 #16
0
hardware()
### Create i21 bespoke secondary hkl devices
# Warning: this breaks the encapsulation provided by the diffcalc.dc.you public
#          interface, and may be prone to breakage in future.

print 'Creating i21 bespoke scannables:'

from diffcalc.dc import dcyou as _dc
from diffcalc.gdasupport.scannable.diffractometer import DiffractometerScannableGroup
from diffcalc.gdasupport.scannable.hkl import Hkl

print '- fourc_vessel & hkl_vessel'
_fourc_vessel = I21DiffractometerStage('_fourc_vessel', m5tth, sa, chi_offset = 90)
fourc_vessel = DiffractometerScannableGroup('fourc_vessel', _dc, _fourc_vessel)
fourc_vessel.hint_generator = _fourc_vessel.get_hints
hkl_vessel = Hkl('hkl_vessel', _fourc_vessel, _dc)
h_vessel, k_vessel, l_vessel = hkl_vessel.h, hkl_vessel.k, hkl_vessel.l

print '- fourc_lowq & hkl_lowq'
LOWQ_OFFSET_ADDED_TO_DELTA_WHEN_READING = -8
_fourc_lowq = I21DiffractometerStage(
    '_fourc_lowq', m5tth, sa, chi_offset=90,
    delta_offset=LOWQ_OFFSET_ADDED_TO_DELTA_WHEN_READING)
fourc_lowq = DiffractometerScannableGroup('fourc_lowq', _dc, _fourc_lowq)
fourc_lowq.hint_generator = _fourc_lowq.get_hints
hkl_lowq = Hkl('hkl_lowq', _fourc_lowq, _dc)
h_lowq, k_lowq, l_lowq = hkl_lowq.h, hkl_lowq.k, hkl_lowq.l

print '- fourc_highq & hkl_highq'
highq_OFFSET_ADDED_TO_DELTA_WHEN_READING = 0
_fourc_highq = I21DiffractometerStage(
예제 #17
0
 def setUp(self):
     self.mockDiffcalc = mock.Mock(spec=diffcalc_.Diffcalc)
     self.mockSixc = mock.Mock(spec=DiffractometerScannableGroup)
     self.hkl = Hkl('hkl', self.mockSixc, self.mockDiffcalc)
예제 #18
0
class TestHkl(unittest.TestCase):

    def setUp(self):
        self.mockDiffcalc = mock.Mock(spec=diffcalc_.Diffcalc)
        self.mockSixc = mock.Mock(spec=DiffractometerScannableGroup)
        self.hkl = Hkl('hkl', self.mockSixc, self.mockDiffcalc)

    def testInit(self):
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 2, 3], PARAM_DICT)
        self.assertEqual(self.hkl.getPosition(), [1, 2, 3])

    def testAsynchronousMoveTo(self):
        self.mockDiffcalc.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
                                                       None)
        self.hkl.asynchronousMoveTo([1, 0, 1])
        self.mockDiffcalc.hkl_to_angles.assert_called_with(1, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with([6, 5, 4, 3, 2, 1])

    def testGetPosition(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.assertEqual(self.hkl.getPosition(), [1, 0, 1])
        self.mockDiffcalc.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesOutsideScan(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1],
                                                       PARAM_DICT)
        self.mockDiffcalc.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)  # <- 2,0,1

        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mockDiffcalc.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
        self.mockDiffcalc.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesInScan(self):

        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        # should not be used:
        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mockDiffcalc.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])
        # atScanStart:
        self.mockDiffcalc.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
        self.mockDiffcalc.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesInScanAfterCommandFailure(self):
        # should be forgotten:
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        self.hkl.atCommandFailure()

        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mockDiffcalc.hkl_to_angles.return_value = (
                [12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mockDiffcalc.angles_to_hkl.assert_called_with(
            [6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
        self.mockDiffcalc.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1])

    def testAsynchronousMoveToWithNonesInScanAfterAtScanEnd(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mockDiffcalc.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        self.hkl.atScanEnd()

        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mockDiffcalc.hkl_to_angles.return_value = (
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mockDiffcalc.angles_to_hkl.assert_called_with(
            [6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
        self.mockDiffcalc.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1])

    def testIsBusy(self):
        self.mockSixc.isBusy.return_value = False
        self.assertFalse(self.hkl.isBusy(), False)
        self.mockSixc.isBusy.assert_called()

    def testWaitWhileBusy(self):
        self.hkl.waitWhileBusy()
        self.mockSixc.waitWhileBusy.assert_called()

    def testWhereMoveTo(self):
        # just check for exceptions
        self.mockDiffcalc.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)
        self.mockSixc.getName.return_value = 'sixc'
        self.mockSixc.getInputNames.return_value = ['alpha', 'delta', 'gamma',
                                                    'omega', 'chi', 'phi']
        print self.hkl.simulateMoveTo((1.23, 0, 0))

    def testDisp(self):
        print self.hkl.__repr__()
예제 #19
0
class ZAxisGammaOnBaseTest(TestSixcBase):

    def setup_method(self):
        TestSixcBase.createDiffcalcAndScannables(self, SixCircleGeometry)
        self.hklverbose = Hkl('hkl', self.sixc, self.dc, ('Bout'))
        self.orient()

    def orient(self):
        self.dc.newub('From DDIF')
        self.dc.setlat('cubic', 1, 1, 1)
        self.en(12.39842 / 1)
        self.dc.setu([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        self.dc.hklmode(20)  # zaxis, bisecting
        self.dc.sigtau(0, 0)

    def checkHKL(self, hkl, adgocp=None, betaout=None, nu=None):
        self.hklverbose.asynchronousMoveTo(hkl)
        aneq_(self.sixc(), list(adgocp), 3)
        aneq_(self.hklverbose(), (hkl[0], hkl[1], hkl[2], betaout), 3)

    def testHKL_001(self):
        self.checkHKL([0, 0.0000001, 1], [30, 0, 60, 90, 0, 0], betaout=30, nu=0)

    def testHKL_010(self):
        self.checkHKL([0, 1, 0], [0, 60, 0, 120, 0, 0], betaout=0, nu=0)

    def testHKL_011(self):
        self.checkHKL([0, 1, 1], [30, 54.7356, 90, 125.2644, 0, 0],
                      betaout=30, nu=-54.7356)

    def testHKL_100(self):
        self.checkHKL([1, 0, 0], [0, 60, 0, 30, 0, 0], betaout=0, nu=0)

    def testHKL_101(self):
        self.checkHKL([1, 0, 1], [30, 54.7356, 90, 35.2644, 0, 0],
                      betaout=30, nu=-54.7356)

    def testHKL_110(self):
        #TODO: Modify test to ask that in this case gamma is left unmoved
        self.checkHKL([1, 1, 0], [0, 90, 0, 90, 0, 0], betaout=0, nu=0)

    def testHKL_1_1_0001(self):
        self.checkHKL([1, 1, .0001], [0.0029, 89.9971, 90.0058, 90., 0, 0],
                      betaout=0.0029, nu=89.9971)

    def testHKL_111(self):
        self.checkHKL([1, 1, 1], [30, 54.7356, 150, 99.7356, 0, 0],
                      betaout=30, nu=54.7356)

    def testHKL_11_0_0(self):
        self.checkHKL([1.1, 0, 0], [0, 66.7340, 0., 33.3670, 0, 0],
                      betaout=0, nu=0)

    def testHKL_09_0_0(self):
        self.checkHKL([.9, 0, 0], [0, 53.4874, 0, 26.7437, 0, 0],
                      betaout=0, nu=0)

    def testHKL_07_08_08(self):
        self.checkHKL([.7, .8, .8], [23.5782, 59.9980, 76.7037, 84.2591, 0, 0],
                      betaout=23.5782, nu=-49.1014)

    def testHKL_07_08_09(self):
        self.checkHKL([.7, .8, .9], [26.7437, 58.6754, 86.6919, 85.3391, 0, 0],
                      betaout=26.7437, nu=-55.8910)

    def testHKL_07_08_1(self):
        self.checkHKL([.7, .8, 1], [30, 57.0626, 96.8659, 86.6739, 0, 0],
                      betaout=30, nu=-63.0210)
예제 #20
0
 def setup_method(self):
     TestSixcBase.createDiffcalcAndScannables(self, SixCircleGeometry)
     self.hklverbose = Hkl('hkl', self.sixc, self.dc, ('Bout'))
     self.orient()
예제 #21
0
 def setUp(self):
     TestHkl.setUp(self)
     self.hkl = Hkl('hkl', self.mockSixc, self.mockDiffcalc,
                    ['theta', '2theta', 'Bin', 'Bout', 'azimuth'])
예제 #22
0
 def setup_method(self):
     TestHkl.setup_method(self)
     self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module,
                    ['theta', '2theta', 'Bin', 'Bout', 'azimuth'])
예제 #23
0
        """
        return _scan(*args)


from diffcalc.gdasupport.scannable.sim import sim  # @UnusedImport

_scn_group = settings.axes_scannable_group
_diff_scn_name = settings.geometry.name  # @UndefinedVariable
_energy_scannable = settings.energy_scannable

# Create diffractometer scannable
_diff_scn = DiffractometerScannableGroup(_diff_scn_name, _dc, _scn_group)
globals()[_diff_scn_name] = _diff_scn

# Create hkl scannables
hkl = Hkl('hkl', _scn_group, _dc)
h = hkl.h
k = hkl.k
l = hkl.l

hkloffset = HklOffset('hkloffset', _scn_group, _dc)
h_offset = hkloffset.h
k_offset = hkloffset.k
l_offset = hkloffset.l
pol_offset = hkloffset.polar
az_offset = hkloffset.azimuthal

sr2 = Sr2('sr2', _scn_group, _dc)

qtrans = Qtrans('qtrans', _scn_group, _dc)
예제 #24
0
 def setup_method(self):
     TestFourcBase.createDiffcalcAndScannables(self)
     self.hklverbose = Hkl('hkl', self.fourc, self.dc,
                           ('theta', '2theta', 'Bin', 'Bout', 'azimuth'))
     self.orient()
예제 #25
0
class TestHkl(object):

    def setup_method(self):
        self.mock_dc_module = mock.Mock()
        self.mockSixc = mock.Mock(spec=DiffractometerScannableGroup)
        self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module)

    def testInit(self):
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 2, 3], PARAM_DICT)
        assert self.hkl.getPosition() == [1, 2, 3]

    def testAsynchronousMoveTo(self):
        self.mock_dc_module.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
                                                       None)
        self.hkl.asynchronousMoveTo([1, 0, 1])
        self.mock_dc_module.hkl_to_angles.assert_called_with(1, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with([6, 5, 4, 3, 2, 1])

    def testGetPosition(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        assert self.hkl.getPosition() == [1, 0, 1]
        self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesOutsideScan(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1],
                                                       PARAM_DICT)
        self.mock_dc_module.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)  # <- 2,0,1

        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
        self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesInScan(self):

        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        # should not be used:
        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mock_dc_module.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])
        # atScanStart:
        self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
        self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12, 5, 4, 3, 2, 1])

    def testAsynchronousMoveToWithNonesInScanAfterCommandFailure(self):
        # should be forgotten:
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        self.hkl.atCommandFailure()

        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mock_dc_module.hkl_to_angles.return_value = (
                [12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mock_dc_module.angles_to_hkl.assert_called_with(
            [6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
        self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1])

    def testAsynchronousMoveToWithNonesInScanAfterAtScanEnd(self):
        self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
        self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
        self.hkl.atScanStart()
        self.hkl.atScanEnd()

        self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
        self.mock_dc_module.hkl_to_angles.return_value = (
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
        self.hkl.asynchronousMoveTo([2, 0, None])

        self.mock_dc_module.angles_to_hkl.assert_called_with(
            [6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
        self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
        self.mockSixc.asynchronousMoveTo.assert_called_with(
            [12.1, 5.1, 4.1, 3.1, 2.1, 1.1])

    def testIsBusy(self):
        self.mockSixc.isBusy.return_value = False
        assert not self.hkl.isBusy()
        self.mockSixc.isBusy.assert_called()

    def testWaitWhileBusy(self):
        self.hkl.waitWhileBusy()
        self.mockSixc.waitWhileBusy.assert_called()

    def testWhereMoveTo(self):
        # just check for exceptions
        self.mock_dc_module.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
                                                       PARAM_DICT)
        self.mockSixc.getName.return_value = 'sixc'
        self.mockSixc.getInputNames.return_value = ['alpha', 'delta', 'gamma',
                                                    'omega', 'chi', 'phi']
        print self.hkl.simulateMoveTo((1.23, 0, 0))

    def testDisp(self):
        print self.hkl.__repr__()
예제 #26
0
 def setup_method(self):
     TestSixcBase.createDiffcalcAndScannables(self, SixCircleGeometry)
     self.hklverbose = Hkl('hkl', self.sixc, self.dc, ('Bout'))
     self.orient()
예제 #27
0
class ZAxisGammaOnBaseTest(TestSixcBase):
    def setup_method(self):
        TestSixcBase.createDiffcalcAndScannables(self, SixCircleGeometry)
        self.hklverbose = Hkl('hkl', self.sixc, self.dc, ('Bout'))
        self.orient()

    def orient(self):
        self.dc.newub('From DDIF')
        self.dc.setlat('cubic', 1, 1, 1)
        self.en(12.39842 / 1)
        self.dc.setu([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        self.dc.hklmode(20)  # zaxis, bisecting
        self.dc.sigtau(0, 0)

    def checkHKL(self, hkl, adgocp=None, betaout=None, nu=None):
        self.hklverbose.asynchronousMoveTo(hkl)
        aneq_(self.sixc(), list(adgocp), 3)
        aneq_(self.hklverbose(), (hkl[0], hkl[1], hkl[2], betaout), 3)

    def testHKL_001(self):
        self.checkHKL([0, 0.0000001, 1], [30, 0, 60, 90, 0, 0],
                      betaout=30,
                      nu=0)

    def testHKL_010(self):
        self.checkHKL([0, 1, 0], [0, 60, 0, 120, 0, 0], betaout=0, nu=0)

    def testHKL_011(self):
        self.checkHKL([0, 1, 1], [30, 54.7356, 90, 125.2644, 0, 0],
                      betaout=30,
                      nu=-54.7356)

    def testHKL_100(self):
        self.checkHKL([1, 0, 0], [0, 60, 0, 30, 0, 0], betaout=0, nu=0)

    def testHKL_101(self):
        self.checkHKL([1, 0, 1], [30, 54.7356, 90, 35.2644, 0, 0],
                      betaout=30,
                      nu=-54.7356)

    def testHKL_110(self):
        #TODO: Modify test to ask that in this case gamma is left unmoved
        self.checkHKL([1, 1, 0], [0, 90, 0, 90, 0, 0], betaout=0, nu=0)

    def testHKL_1_1_0001(self):
        self.checkHKL([1, 1, .0001], [0.0029, 89.9971, 90.0058, 90., 0, 0],
                      betaout=0.0029,
                      nu=89.9971)

    def testHKL_111(self):
        self.checkHKL([1, 1, 1], [30, 54.7356, 150, 99.7356, 0, 0],
                      betaout=30,
                      nu=54.7356)

    def testHKL_11_0_0(self):
        self.checkHKL([1.1, 0, 0], [0, 66.7340, 0., 33.3670, 0, 0],
                      betaout=0,
                      nu=0)

    def testHKL_09_0_0(self):
        self.checkHKL([.9, 0, 0], [0, 53.4874, 0, 26.7437, 0, 0],
                      betaout=0,
                      nu=0)

    def testHKL_07_08_08(self):
        self.checkHKL([.7, .8, .8], [23.5782, 59.9980, 76.7037, 84.2591, 0, 0],
                      betaout=23.5782,
                      nu=-49.1014)

    def testHKL_07_08_09(self):
        self.checkHKL([.7, .8, .9], [26.7437, 58.6754, 86.6919, 85.3391, 0, 0],
                      betaout=26.7437,
                      nu=-55.8910)

    def testHKL_07_08_1(self):
        self.checkHKL([.7, .8, 1], [30, 57.0626, 96.8659, 86.6739, 0, 0],
                      betaout=30,
                      nu=-63.0210)
예제 #28
0
 def setup_method(self):
     self.mock_dc_module = mock.Mock()
     self.mockSixc = mock.Mock(spec=DiffractometerScannableGroup)
     self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module)