Example #1
0
    def testGetInputWithDefaultWithLists(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert (getInputWithDefault('enter a thing', (1, 2.0, 3.1))
                == (1.0, 2.0, 3.1))

        diffcalc.util.raw_input = MockRawInput('1 2.0 3.1')
        assert getInputWithDefault('enter a thing', 'default') == [1.0, 2.0, 3.1]
Example #2
0
    def testGetInputWithDefaultWithLists(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert (getInputWithDefault('enter a thing',
                                    (1, 2.0, 3.1)) == (1.0, 2.0, 3.1))

        diffcalc.util.raw_input = MockRawInput('1 2.0 3.1')
        assert getInputWithDefault('enter a thing',
                                   'default') == [1.0, 2.0, 3.1]
    def testGetInputWithDefaultWithLists(self):
        diffcalc.util.raw_input = MockRawInput('')
        self.assertEquals(getInputWithDefault('enter a thing', (1, 2.0, 3.1)),
                          (1.0, 2.0, 3.1))

        diffcalc.util.raw_input = MockRawInput('1 2.0 3.1')
        self.assertEquals(getInputWithDefault('enter a thing', 'default'),
                          [1.0, 2.0, 3.1])
Example #4
0
 def testGetInputWithDefaultWithStrings(self):
     diffcalc.util.raw_input = MockRawInput('reply')
     print">>>"
     assert getInputWithDefault('enter a thing', 'default') == 'reply'
     print">>>"
     diffcalc.util.raw_input = MockRawInput('')
     assert getInputWithDefault('enter a thing', 'default') == 'default'
     print">>>"
     diffcalc.util.raw_input = MockRawInput('1.23 1 a')
     assert getInputWithDefault('enter a thing', 'default') == '1.23 1 a'
Example #5
0
 def testGetInputWithDefaultWithStrings(self):
     diffcalc.util.raw_input = MockRawInput('reply')
     print ">>>"
     assert getInputWithDefault('enter a thing', 'default') == 'reply'
     print ">>>"
     diffcalc.util.raw_input = MockRawInput('')
     assert getInputWithDefault('enter a thing', 'default') == 'default'
     print ">>>"
     diffcalc.util.raw_input = MockRawInput('1.23 1 a')
     assert getInputWithDefault('enter a thing', 'default') == '1.23 1 a'
Example #6
0
    def testGetInputWithDefaultWithNumbers(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1) == 1.0

        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1.23) == 1.23

        diffcalc.util.raw_input = MockRawInput('1')
        assert getInputWithDefault('enter a thing', 'default') == 1.0

        diffcalc.util.raw_input = MockRawInput('1.23')
        assert getInputWithDefault('enter a thing', 'default') == 1.23
Example #7
0
    def testGetInputWithDefaultWithNumbers(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1) == 1.0

        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1.23) == 1.23

        diffcalc.util.raw_input = MockRawInput('1')
        assert getInputWithDefault('enter a thing', 'default') == 1.0

        diffcalc.util.raw_input = MockRawInput('1.23')
        assert getInputWithDefault('enter a thing', 'default') == 1.23
    def testGetInputWithDefaultWithNumbers(self):
        diffcalc.util.raw_input = MockRawInput('')
        self.assertEquals(getInputWithDefault('enter a thing', 1), 1.0)

        diffcalc.util.raw_input = MockRawInput('')
        self.assertEquals(getInputWithDefault('enter a thing', 1.23), 1.23)

        diffcalc.util.raw_input = MockRawInput('1')
        self.assertEquals(getInputWithDefault('enter a thing', 'default'), 1.0)

        diffcalc.util.raw_input = MockRawInput('1.23')
        self.assertEquals(getInputWithDefault('enter a thing', 'default'),
                          1.23)
 def testGetInputWithDefaultWithStrings(self):
     diffcalc.util.raw_input = MockRawInput('reply')
     print">>>"
     self.assertEquals(getInputWithDefault('enter a thing', 'default'),
                       'reply')
     print">>>"
     diffcalc.util.raw_input = MockRawInput('')
     self.assertEquals(getInputWithDefault('enter a thing', 'default'),
                       'default')
     print">>>"
     diffcalc.util.raw_input = MockRawInput('1.23 1 a')
     self.assertEquals(getInputWithDefault('enter a thing', 'default'),
                       '1.23 1 a')
Example #10
0
def setref2(scn, hkl):
    """setref2 scn [h k l] -- setup hkloffset scannable to scan for second reflection [hkl]"""
    
    if not isinstance(hkl, (tuple, list)):
        raise DiffcalcException("Please specify hkl values for a second reference reflection to search.")

    if not allnum(hkl):
        raise DiffcalcException("Please specify numeric values for hkl.")

    try:
        hkl_ref = scn._diffcalc._ub.ubcalc.get_reflection(0)[0]
    except IndexError:
        raise DiffcalcException("Please add one reference reflection into the reflection list.")
    pol, az, sc = scn._diffcalc._ub.ubcalc.calc_offset_for_hkl(hkl, hkl_ref)
    hkl_rot = [sc * val for val in hkl_ref]
    hkl_sc = hkl_rot[:]
    hkl_rot.extend([pol * TODEG, az * TODEG])
    hkl_sc.extend([0, 0])

    print ('\nRescaled hkl reference for second reflection : %9.4f  %.4f  %.4f' % (hkl_sc[0], hkl_sc[1], hkl_sc[2]))
    print ('         polar and azimuthal rotation angles : %9.4f  %.4f\n' % (pol * TODEG, az * TODEG))

    sim(scn, hkl_sc)
    print ('IMPORTANT: Applying subsequent polar and azimuthal rotations might fail. In this case, please manually\n'
           '           find accessible azimuthal rotation range to scan for second reference reflection.')
    reply = getInputWithDefault('Move to rescaled hkl position', 'y')
    if reply in ('y', 'Y', 'yes'):
        scn.asynchronousMoveTo(hkl_sc)
    else:
        print 'Aborting'
        return

    sim(scn, hkl_rot)
    reply = getInputWithDefault('Apply polar and azimuthal rotations', 'y')
    if reply in ('y', 'Y', 'yes'):
        scn.asynchronousMoveTo(hkl_rot)
    else:
        print 'Aborting'
        return