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 + 'load_' + datetime.strftime( datetime.now(), "%Y-%m-%d_%H:%M:%S") + '.log' log_lib.setup_logger(lfname) init_general_PVs(global_PVs, variableDict) try: while True: h5fname = global_PVs['HDF1_FullFileName_RBV'].get() h5fname_str = "".join([chr(item) for item in h5fname]) log_lib.info('Load: %4.4f N (%4.4f V): %s' % (global_PVs['LoadNewton'].get(), global_PVs['LoadVoltage'].get(), h5fname_str)) time.sleep(2) except KeyboardInterrupt: print('interrupted!')
def mkdir(remote_server, remote_dir): log_lib.info('Creating directory on server %s:%s' % (remote_server, remote_dir)) ret = dm_lib.check_remote_directory(remote_server, remote_dir) if ret == 2: iret = dm_lib.create_remote_directory(remote_server, remote_dir)
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() aps32id_lib.update_variable_dict(variableDict) aps32id_lib.init_general_PVs(global_PVs, variableDict) FileName = global_PVs['HDF1_FileName'].get(as_string=True) nLoops = variableDict['nLoops'] # global_PVs['HDF1_NextFile'].put(0) for iLoop in range(0, nLoops): log_lib.info(' ') log_lib.info(' *** Starting step scan #%i' % (iLoop + 1)) global_PVs['Motor_SampleRot'].put(variableDict['SampleStart_Rot'], wait=True, timeout=600.0) scan_lib.tomo_step_scan(variableDict, global_PVs, FileName) dm_lib.scp(global_PVs, variableDict) log_lib.info(' ') log_lib.info(' *** Total scan time: %.2f minutes' % ((time.time() - tic) / 60.))
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
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.info(' *** 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
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) aps32id_lib.update_variable_dict(variableDict) aps32id_lib.init_general_PVs(global_PVs, variableDict) FileName = global_PVs['TIFF1_FileName'].get(as_string=True) log_lib.info(' ') log_lib.info(' *** Starting tiff stack acq.') scan_lib.tiff_2Dscan(variableDict, global_PVs, FileName) dm_lib.scp(global_PVs, variableDict)
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
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
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
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