Ejemplo n.º 1
0
def drive_s2():
    slog('drive s2 away to -50 and atrans to 0')
    sics.multiDrive({'s2': -50, 'atrans':0})
    s2.value = sics.getValue('s2').getFloatData()
    atrans.value = sics.getValue('atrans').getFloatData()
    sics.execute('s2 fixed 1')
    print 'Please check if s2 is fixed!'
Ejemplo n.º 2
0
def drive_a1_a2():
    slog('drive a2 ' + str(m2.value))
    slog('drive a1 ' + str(m1.value))
    sics.multiDrive({'a1':m1.value, 'a2':m2.value})
    a1.value = sics.getValue('a1').getFloatData()
    a2.value = sics.getValue('a2').getFloatData()
    scan_a1.value = str(math.ceil((a1.value - 1) * 1000) / 1000) + ', 0.2, 11, \'timer\', 1'
    scan_a2.value = str(math.ceil((a2.value - 2.5) * 1000) / 1000) + ', 0.5, 11, \'timer\', 1'
Ejemplo n.º 3
0
def line_up():
    slog('drive m2 ' + str(m2.value)\
         + ' s2 ' + str(s2.value)\
         + ' a1 ' + str(a1.value)\
         + ' a2 ' + str(a2.value)\
         + ' atrans ' + str(atrans.value))
    sics.multiDrive({'m2':m2.value, 's2':s2.value, \
                     'a1':a1.value, 'a2':a2.value, \
                     'atrans':atrans.value})
    print 'done'
Ejemplo n.º 4
0
def run_slit():
    slog('drive pa_left ' + str(pa_left.value)\
        + ' pa_right ' + str(pa_right.value)\
        + ' pa_top ' + str(pa_top.value)\
        + ' pa_bottom ' + str(pa_bottom.value))
    sics.multiDrive({'pa_left': pa_left.value, 
                     'pa_right': pa_right.value,
                     'pa_top': pa_top.value,
                     'pa_bottom': pa_bottom.value}
                    )
    print 'done'
Ejemplo n.º 5
0
def drive_slits():
    print 'drive slits ... '
    sics.multiDrive({'ps_right' : ps_right.value, 
                     'ps_left' : ps_left.value,
                     'ps_top' : ps_top.value, 
                     'ps_bottom' : ps_bottom.value, 
                     'pa_right' : pa_right.value, 
                     'pa_left' : pa_left.value, 
                     'pa_top' : pa_top.value,
                     'pa_bottom' : pa_bottom.value})
    print 'done'
Ejemplo n.º 6
0
def drive_a1a2_0():
    if ei_old != Ei.value :
        slog('drive Ei ' + str(Ei.value))
        sics.execute('tasub update')
        time.sleep(1)
        try:
            sics.drive('ei', Ei.value)
        except:
            pass
        time.sleep(1)
        while str(sics.getDeviceController('ei').getStatus()) == 'RUNNING':
            time.sleep(0.5) 
    slog('drive a1 0 a2 0')
    sics.multiDrive({'a1' : 0, 'a2' : 0})
Ejemplo n.º 7
0
def startScan(configModel):
    ''' setup '''

    scanVariable = configModel.scanVariable
    crystal = configModel.crystal
    mode = configModel.mode

    MainDeadTime = 1.08E-6
    TransDeadTime = 1.08E-6

    if 'Si111' in crystal:
        empLevel = 0.3
        bkgLevel = 0.277
        dOmega = 2.3E-6
        gDQv = 0.0586
        gDQh = 0

        wavelength = 4.74
        TransmissionTube = 10
        TransBackground = 0  # counts per second

    elif 'Si311' in crystal:
        empLevel = 0.34
        bkgLevel = 0.333
        dOmega = 4.6E-7
        gDQv = 0.117
        gDQh = 0

        wavelength = 2.37
        TransmissionTube = 9
        TransBackground = 0  # counts per second

    else:
        print 'selected crystal is invalid'
        return
    ''' angles '''

    scan = configModel.scan

    scan_angleMin = builtin_min(scan['angles'])
    scan_angleMax = builtin_max(scan['angles'])

    if ('m1om' in scanVariable) or ('m2om' in scanVariable):
        tolerance = 2

        approved = False
        if 'Si111' in crystal:
            if (180 - tolerance <= scan_angleMin) and (scan_angleMax <=
                                                       180 + tolerance):
                approved = True

        elif 'Si311' in crystal:
            if (0 - tolerance <= scan_angleMin) and (scan_angleMax <=
                                                     0 + tolerance):
                approved = True

        if not approved:
            print 'angle out of range'
            return
    ''' execution '''

    sics.execute('hset user/name ' + configModel.user_name)
    sics.execute('hset user/email ' + configModel.user_email)

    sics.execute('hset sample/name ' + configModel.sample_name)
    sics.execute('hset sample/description ' + configModel.sample_description)
    sics.execute('hset sample/thickness %g' % configModel.sample_thickness)

    sics.execute('hset experiment/bkgLevel %g' % bkgLevel)
    sics.execute('hset experiment/empLevel %g' % empLevel)

    sics.execute('hset instrument/detector/MainDeadTime %g' % MainDeadTime)
    sics.execute('hset instrument/detector/TransDeadTime %g' % TransDeadTime)
    sics.execute('hset instrument/detector/TransBackground %g' %
                 TransBackground)
    sics.execute('hset instrument/detector/TransmissionTube %i' %
                 TransmissionTube)

    sics.execute('hset instrument/crystal/dOmega %g' % dOmega)
    sics.execute('hset instrument/crystal/gDQv %g' % gDQv)
    sics.execute('hset instrument/crystal/gDQh %g' % gDQh)
    sics.execute('hset instrument/crystal/wavelength %g' % wavelength)
    sics.execute('hset instrument/crystal/scan_variable ' + scanVariable)

    sicsController = sics.getSicsController()

    # slits
    def getSlitValues(gap, offset, a0, b0, aOpen, bOpen):

        if gap == 'fully opened':
            return (aOpen, bOpen)

        if gap == 'fully closed':
            gap = -5.0
            offset = 0.0

        a = a0 + 0.5 * float(gap) + float(offset)
        b = b0 - 0.5 * float(gap) + float(offset)

        return (a, b)

    ss1vg = configModel.ss1vg
    ss1vo = configModel.ss1vo
    ss1hg = configModel.ss1hg
    ss1ho = configModel.ss1ho

    ss2vg = configModel.ss2vg
    ss2vo = configModel.ss2vo
    ss2hg = configModel.ss2hg
    ss2ho = configModel.ss2ho

    (ss1u, ss1d) = getSlitValues(ss1vg, ss1vo, ss1u0, ss1d0, 35.8, -38.8)
    (ss1r, ss1l) = getSlitValues(ss1hg, ss1ho, ss1r0, ss1l0, 57.0, -58.0)

    (ss2u, ss2d) = getSlitValues(ss2vg, ss2vo, ss2u0, ss2d0, 37.0, -39.5)
    (ss2r, ss2l) = getSlitValues(ss2hg, ss2ho, ss2r0, ss2l0, 35.0, -35.0)

    # apply slits
    run = {}
    run['ss1u'] = ss1u
    run['ss1d'] = ss1d
    run['ss1r'] = ss1r
    run['ss1l'] = ss1l

    run['ss2u'] = ss2u
    run['ss2d'] = ss2d
    run['ss2r'] = ss2r
    run['ss2l'] = ss2l

    sics.multiDrive(run)

    time.sleep(2)
    while not sicsController.getServerStatus().equals(
            ServerStatus.EAGER_TO_EXECUTE):
        time.sleep(0.1)
    '''
    sics.execute('run ss1u %.2f' % ss1u)
    sics.execute('run ss1d %.2f' % ss1d)
    sics.execute('run ss1r %.2f' % ss1r)
    sics.execute('run ss1l %.2f' % ss1l)
    
    sics.execute('run ss2u %.2f' % ss2u)
    sics.execute('run ss2d %.2f' % ss2d)
    sics.execute('run ss2r %.2f' % ss2r)
    sics.execute('run ss2l %.2f' % ss2l)
    '''

    # load sample positions
    sam_positions = str(configModel.sam_position)

    if (len(sam_positions) == 0) or (sam_positions == 'fixed'):
        samz_list = [None]
    else:
        samz_list = []

        pos2samz = {}
        pos2samz['1'] = 33.5
        pos2samz['2'] = 178.5
        pos2samz['3'] = 323.5
        pos2samz['4'] = 468.5
        pos2samz['5'] = 613.5

        pos2samz['1 top'] = 17.4
        pos2samz['1 bottom'] = 77.7
        pos2samz['2 top'] = 163.5
        pos2samz['2 bottom'] = 223.1
        pos2samz['3 top'] = 308.0
        pos2samz['3 bottom'] = 368.1
        pos2samz['4 top'] = 454.1
        pos2samz['4 bottom'] = 513.6
        pos2samz['5 top'] = 598.2
        pos2samz['5 bottom'] = 658.0

        samz_list.append(pos2samz[sam_positions])
        '''
        for range in filter(None, sam_positions.split(',')):
            rangeItems = range.split('-')
            if ('' in rangeItems) or (len(rangeItems) < 1) or (len(rangeItems) > 2):
                raise Exception('format in "Sample Position" is incorrect')
            
            if len(rangeItems) == 1:
                samz_list.append(pos2samz[int(rangeItems[0])])
            else:
                for i in xrange(int(rangeItems[0]), int(rangeItems[1])+1):
                    samz_list.append(pos2samz[i])
                    
        if len(samz_list) == 0:
            samz_list = [0.0]
            
        '''

    for samz in samz_list:

        sics.execute('histmem stop')
        time.sleep(3)
        sics.execute('histmem mode time')

        if samz is not None:
            print 'run samz %.2f' % samz
            sics.execute('run samz %.2f' % samz)
            # sics.execute('prun samz 2' % samz) !!!
            time.sleep(1)
            while not sicsController.getServerStatus().equals(
                    ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.1)

        sics.execute('newfile HISTOGRAM_XYT')
        #sics.execute('autosave 60') # 60 seconds
        time.sleep(1)

        # start/stop hmm
        if mode == 'count_roi':
            sics.execute('histmem preset %i' % 1)
            time.sleep(1)
            sics.execute('histmem start')
            time.sleep(5)
            while not sicsController.getServerStatus().equals(
                    ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.1)
            sics.execute('histmem stop')

        print 'frames:', len(scan['angles'])
        for frame_index in xrange(len(scan['angles'])):
            angle = scan['angles'][frame_index]
            preset = scan['presets'][frame_index]
            maxTime = scan['maxTimes'][frame_index]

            print 'run %s %.6f' % (scanVariable, angle)
            sics.execute('run %s %.6f' % (scanVariable, angle))
            time.sleep(10)
            while not sicsController.getServerStatus().equals(
                    ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.1)
            print 'run done'

            time.sleep(1)
            print 'histmem start'
            while True:
                if mode == 'count_roi':
                    sics.execute('histmem preset %i' % maxTime)
                else:
                    sics.execute('histmem preset %i' % preset)

                time.sleep(5)
                sics.execute('histmem start')
                time.sleep(5)

                if mode == 'count_roi':
                    print 'count_roi'

                    time.sleep(configModel.min_time)

                    count_roi = 0
                    while not sicsController.getServerStatus().equals(
                            ServerStatus.EAGER_TO_EXECUTE):
                        try:
                            count_roi = int(
                                sicsext.runCommand(
                                    'hmm configure num_events_filled_to_count_roi'
                                ))
                            print count_roi

                            if count_roi > preset:
                                print count_roi
                                print 'reached desired count_roi'
                                sics.execute('histmem pause')
                                time.sleep(1)
                                break
                        except:
                            pass

                        time.sleep(0.5)

                    break

                else:
                    while not sicsController.getServerStatus().equals(
                            ServerStatus.EAGER_TO_EXECUTE):
                        time.sleep(0.1)

                    valid = False
                    for i in xrange(10):
                        time.sleep(1)
                        detector_time = sics.getValue(
                            '/instrument/detector/time').getFloatData()

                        valid = (detector_time >= preset - 1) or (
                            detector_time >= preset * 0.90)
                        if valid:
                            break

                    print 'detector_time:', detector_time

                    if valid:
                        break
                    else:
                        print 'scan was invalid and needs to be repeated'

            #sics.execute('histmem stop')
            sics.execute('save %i' % frame_index)
            frame_index += 1
            print 'histmem done'

        sics.execute('newfile clear')
        #sics.execute('autosave 0') # disable autosave

        # Get output filename
        filenameController = sicsController.findDeviceController(
            'datafilename')
        savedFilename = filenameController.getValue().getStringData()
        print 'saved:', savedFilename

    print 'done'
    print
Ejemplo n.º 8
0
def drive_a1a2_0():
    slog('drive a1 0 a2 0 atrans 19')
    sics.multiDrive({'a1' : 0, 'a2' : 0, 'atrans' : 19})