示例#1
0
def scp(global_PVs, variableDict):

    log_lib.info(' ')
    log_lib.info('  *** Data transfer')

    remote_server = variableDict['RemoteAnalysisDir'].split(':')[0]
    remote_top_dir = variableDict['RemoteAnalysisDir'].split(':')[1]
    log_lib.info('      *** remote server: %s' % remote_server)
    log_lib.info('      *** remote top directory: %s' % remote_top_dir)

    fname_origin = global_PVs['HDF1_FullFileName_RBV'].get(as_string=True)
    p = pathlib.Path(fname_origin)
    fname_destination = variableDict['RemoteAnalysisDir'] + p.parts[
        -3] + '/' + p.parts[-2] + '/'
    remote_dir = remote_top_dir + p.parts[-3] + '/' + p.parts[-2] + '/'

    log_lib.info('      *** origin: %s' % fname_origin)
    log_lib.info('      *** destination: %s' % fname_destination)
    # log_lib.info('      *** remote directory: %s' % remote_dir)

    ret = check_remote_directory(remote_server, remote_dir)

    if ret == 0:
        os.system('scp -q ' + fname_origin + ' ' + fname_destination + '&')
        log_lib.info('  *** Data transfer: Done!')
        return 0
    elif ret == 2:
        iret = create_remote_directory(remote_server, remote_dir)
        if iret == 0:
            os.system('scp -q ' + fname_origin + ' ' + fname_destination + '&')
        log_lib.info('  *** Data transfer: Done!')
        return 0
    else:
        log_lib.error('  *** Quitting the copy operation')
        return -1
示例#2
0
def main():
    # create logger
    # # python 3.5+ 
    # home = str(pathlib.Path.home())
    home = os.path.expanduser("~")
    logs_home = home + '/logs/'

    # make sure logs directory exists
    if not os.path.exists(logs_home):
        os.makedirs(logs_home)

    lfname = logs_home + datetime.strftime(datetime.now(), "%Y-%m-%d_%H:%M:%S") + '.log'
    log_lib.setup_logger(lfname)

    tic =  time.time()
    aps2bm_lib.update_variable_dict(variableDict)
    aps2bm_lib.init_general_PVs(global_PVs, variableDict)
    
    try: 
        detector_sn = global_PVs['Cam1_SerialNumber'].get()
        if ((detector_sn == None) or (detector_sn == 'Unknown')):
            log_lib.info('*** The Point Grey Camera with EPICS IOC prefix %s is down' % variableDict['IOC_Prefix'])
            log_lib.info('  *** Failed!')
        else:
            log_lib.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \
                        % (variableDict['IOC_Prefix'], detector_sn))
            
            # calling global_PVs['Cam1_AcquireTime'] to replace the default 'ExposureTime' with the one set in the camera
            variableDict['ExposureTime'] = global_PVs['Cam1_AcquireTime'].get()
            # calling calc_blur_pixel() to replace the default 'SlewSpeed' 
            blur_pixel, rot_speed, scan_time = aps2bm_lib.calc_blur_pixel(global_PVs, variableDict)
            variableDict['SlewSpeed'] = rot_speed

            # moved pgInit() here from tomo_fly_scan() 
            aps2bm_lib.pgInit(global_PVs, variableDict)

            # get sample file name
            fname = global_PVs['HDF1_FileName'].get(as_string=True)
            log_lib.info('  *** Moving rotary stage to start position')
            global_PVs["Motor_SampleRot"].put(0, wait=True, timeout=600.0)
            log_lib.info('  *** Moving rotary stage to start position: Done!')
            scan_lib.dummy_tomo_fly_scan(global_PVs, variableDict, fname)
            log_lib.info(' ')
            log_lib.info('  *** Total scan time: %s minutes' % str((time.time() - tic)/60.))
            log_lib.info('  *** Data file: %s' % global_PVs['HDF1_FullFileName_RBV'].get(as_string=True))
            log_lib.info('  *** Done!')

    except  KeyError:
        log_lib.error('  *** Some PV assignment failed!')
        pass
示例#3
0
def create_remote_directory(remote_server, remote_dir):
    cmd = 'mkdir -p ' + remote_dir
    try:
        # log_lib.info('      *** sending command %s' % (cmd))
        log_lib.info('      *** creating remote directory %s' % (remote_dir))
        subprocess.check_call(['ssh', remote_server, cmd])
        log_lib.info('      *** creating remote directory %s: Done!' %
                     (remote_dir))
        return 0

    except subprocess.CalledProcessError, e:
        log_lib.error(
            '  *** Error while creating remote directory. Error code: %d' %
            (e.returncode))
        return -1
示例#4
0
def check_remote_directory(remote_server, remote_dir):
    try:
        rcmd = 'ls ' + remote_dir
        # rcmd is the command used to check if the remote directory exists
        subprocess.check_call(['ssh', remote_server, rcmd],
                              stderr=open(os.devnull, 'wb'),
                              stdout=open(os.devnull, 'wb'))
        log_lib.warning('      *** remote directory %s exists' % (remote_dir))
        return 0

    except subprocess.CalledProcessError, e:
        # log_lib.info('      *** return code = %d' % (e.returncode))
        log_lib.warning('      *** remote directory %s does not exist' %
                        (remote_dir))
        if e.returncode == 2:
            return e.returncode
        else:
            log_lib.error('  *** Unknown error code returned: %d' %
                          (e.returncode))
            return -1
示例#5
0
def main():
    # create logger
    # # python 3.5+ 
    # home = str(pathlib.Path.home())
    home = os.path.expanduser("~")
    logs_home = home + '/logs/'

    # make sure logs directory exists
    if not os.path.exists(logs_home):
        os.makedirs(logs_home)

    lfname = logs_home + datetime.strftime(datetime.now(), "%Y-%m-%d_%H:%M:%S") + '.log'
    log_lib.setup_logger(lfname)

    tic =  time.time()
    aps2bm_lib.update_variable_dict(variableDict)
    aps2bm_lib.init_general_PVs(global_PVs, variableDict)
    
    try: 
        detector_sn = global_PVs['Cam1_SerialNumber'].get()
        if ((detector_sn == None) or (detector_sn == 'Unknown')):
            log_lib.error('*** The Point Grey Camera with EPICS IOC prefix %s is down' % variableDict['IOC_Prefix'])
            log_lib.error('  *** Failed!')
        else:
            log_lib.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \
                        % (variableDict['IOC_Prefix'], detector_sn))
            
            # calling global_PVs['Cam1_AcquireTime'] to replace the default 'ExposureTime' with the one set in the camera
            variableDict['ExposureTime'] = global_PVs['Cam1_AcquireTime'].get()
            # calling calc_blur_pixel() to replace the default 'SlewSpeed' 
            blur_pixel, rot_speed, scan_time = aps2bm_lib.calc_blur_pixel(global_PVs, variableDict)
            variableDict['SlewSpeed'] = rot_speed

            # start = variableDict['SleepStart']
            # end = variableDict['SleepEnd']
            # step_size = variableDict['SleepStep']

            start = 0
            end = variableDict['SleepStep']
            step_size = 1

            # init camera
            aps2bm_lib.pgInit(global_PVs, variableDict)
            
            log_lib.info(' ')
            log_lib.info("  *** Running %d scans" % len(np.arange(start, end, step_size)))
            for i in np.arange(start, end, step_size):
                tic_01 =  time.time()
                fname = str('{:03}'.format(global_PVs['HDF1_FileNumber'].get())) + '_' + global_PVs['Sample_Name'].get(as_string=True)

                log_lib.info(' ')
                log_lib.info('  *** Start scan %d' % i)

                scan_lib.tomo_fly_scan(global_PVs, variableDict, fname)

                if ((i+1)!=end):
                    log_lib.warning('  *** Wait (s): %s ' % str(variableDict['SleepTime_s']))
                    time.sleep(variableDict['SleepTime_s']) 

                log_lib.info(' ')
                log_lib.info('  *** Data file: %s' % global_PVs['HDF1_FullFileName_RBV'].get(as_string=True))
                log_lib.info('  *** Total scan time: %s minutes' % str((time.time() - tic_01)/60.))
                log_lib.info('  *** Scan Done!')
    
                dm_lib.scp(global_PVs, variableDict)

            log_lib.info('  *** Total loop scan time: %s minutes' % str((time.time() - tic)/60.))
 
            log_lib.info('  *** Moving rotary stage to start position')
            global_PVs["Motor_SampleRot"].put(0, wait=True, timeout=600.0)
            log_lib.info('  *** Moving rotary stage to start position: Done!')

            global_PVs['Cam1_ImageMode'].put('Continuous')
 
            log_lib.info('  *** Done!')

    except  KeyError:
        log_lib.error('  *** Some PV assignment failed!')
        pass
示例#6
0
def main():
    # create logger
    # # python 3.5+
    # home = str(pathlib.Path.home())
    home = os.path.expanduser("~")
    logs_home = home + '/logs/'

    # make sure logs directory exists
    if not os.path.exists(logs_home):
        os.makedirs(logs_home)

    lfname = logs_home + datetime.strftime(datetime.now(),
                                           "%Y-%m-%d_%H:%M:%S") + '.log'
    log_lib.setup_logger(lfname)

    tic = time.time()
    aps2bm_lib.update_variable_dict(variableDict)
    aps2bm_lib.init_general_PVs(global_PVs, variableDict)

    try:
        detector_sn = global_PVs['Cam1_SerialNumber'].get()
        if ((detector_sn == None) or (detector_sn == 'Unknown')):
            log_lib.info(
                '*** The Point Grey Camera with EPICS IOC prefix %s is down' %
                variableDict['IOC_Prefix'])
            log_lib.info('  *** Failed!')
        else:
            log_lib.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \
                        % (variableDict['IOC_Prefix'], detector_sn))

            # calling global_PVs['Cam1_AcquireTime'] to replace the default 'ExposureTime' with the one set in the camera
            variableDict['ExposureTime'] = global_PVs['Cam1_AcquireTime'].get()
            # calling calc_blur_pixel() to replace the default 'SlewSpeed'
            blur_pixel, rot_speed, scan_time = aps2bm_lib.calc_blur_pixel(
                global_PVs, variableDict)
            variableDict['SlewSpeed'] = rot_speed

            start_y = variableDict['StartY']
            end_y = variableDict['EndY']
            step_size_y = variableDict['StepSizeY']

            start_x = variableDict['StartX']
            end_x = variableDict['EndX']
            step_size_x = variableDict['StepSizeX']

            # set scan stop so also ends are included
            stop_x = end_x + step_size_x
            stop_y = end_y + step_size_y

            # init camera
            aps2bm_lib.pgInit(global_PVs, variableDict)

            start = variableDict['SleepStart']
            end = variableDict['SleepEnd']
            step_size = variableDict['SleepStep']

            log_lib.info(' ')
            log_lib.info("  *** Running %d sleep scans" %
                         len(np.arange(start, end, step_size)))
            for ii in np.arange(start, end, step_size):
                tic_01 = time.time()

                log_lib.info(' ')
                log_lib.info("  *** Running %d mosaic scans" %
                             (len(np.arange(start_x, stop_x, step_size_x)) *
                              len(np.arange(start_y, stop_y, step_size_y))))
                log_lib.info(' ')
                log_lib.info('  *** Horizontal Positions (mm): %s' %
                             np.arange(start_x, stop_x, step_size_x))
                log_lib.info('  *** Vertical Positions (mm): %s' %
                             np.arange(start_y, stop_y, step_size_y))

                h = 0
                v = 0

                for i in np.arange(start_y, stop_y, step_size_y):
                    log_lib.info(' ')
                    log_lib.info(
                        '  *** The sample vertical position is at %s mm' % (i))
                    global_PVs['Motor_SampleY'].put(i, wait=True)
                    for j in np.arange(start_x, stop_x, step_size_x):
                        log_lib.info(
                            '  *** The sample horizontal position is at %s mm'
                            % (j))
                        variableDict['SampleXIn'] = j
                        fname = str('{:03}'.format(
                            global_PVs['HDF1_FileNumber'].get(
                            ))) + '_' + global_PVs['Sample_Name'].get(
                                as_string=True) + '_y' + str(v) + '_x' + str(h)
                        scan_lib.tomo_fly_scan(global_PVs, variableDict, fname)
                        h = h + 1
                        dm_lib.scp(global_PVs, variableDict)
                    log_lib.info(' ')
                    log_lib.info('  *** Total scan time: %s minutes' % str(
                        (time.time() - tic) / 60.))
                    log_lib.info('  *** Data file: %s' %
                                 global_PVs['HDF1_FullFileName_RBV'].get(
                                     as_string=True))
                    v = v + 1
                    h = 0

                log_lib.info('  *** Moving rotary stage to start position')
                global_PVs["Motor_SampleRot"].put(0, wait=True, timeout=600.0)
                log_lib.info(
                    '  *** Moving rotary stage to start position: Done!')

                if ((ii + 1) != end):
                    log_lib.warning('  *** Wait (s): %s ' %
                                    str(variableDict['SleepTime']))
                    time.sleep(variableDict['SleepTime'])

                global_PVs['Cam1_ImageMode'].put('Continuous')

                log_lib.info('  *** Done!')

    except KeyError:
        log_lib.error('  *** Some PV assignment failed!')
        pass