def wait_pv(pv, wait_val, max_timeout_sec=-1): # wait on a pv to be a value until max_timeout (default forever) # delay for pv to change time.sleep(.01) startTime = time.time() while (True): pv_val = pv.get() if type(pv_val) == float: if abs(pv_val - wait_val) < EPSILON: return True if (pv_val != wait_val): if max_timeout_sec > -1: curTime = time.time() diffTime = curTime - startTime if diffTime >= max_timeout_sec: log.error(' *** ERROR: DROPPED IMAGES ***') log.error( ' *** wait_pv(%s, %d, %5.2f reached max timeout. Return False' % (pv.pvname, wait_val, max_timeout_sec)) return False time.sleep(.01) else: return True
def fly_scan(params): tic = time.time() global_PVs = aps2bm.init_general_PVs(params) aps2bm.user_info_params_update_from_pv(global_PVs, params) try: detector_sn = global_PVs['Cam1_SerialNumber'].get() if ((detector_sn == None) or (detector_sn == 'Unknown')): log.info('*** The Point Grey Camera with EPICS IOC prefix %s is down' % params.camera_ioc_prefix) log.info(' *** Failed!') else: log.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \ % (params.camera_ioc_prefix, detector_sn)) # calling global_PVs['Cam1_AcquireTime'] to replace the default 'ExposureTime' with the one set in the camera params.exposure_time = global_PVs['Cam1_AcquireTime'].get() # calling calc_blur_pixel() to replace the default 'SlewSpeed' rot_speed = calc_blur_pixel(global_PVs, params) params.slew_speed = rot_speed # init camera flir.init(global_PVs, params) log.info(' ') log.info(" *** Running %d sleep scans" % params.sleep_steps) for i in np.arange(0, params.sleep_steps, 1): tic_01 = time.time() # set sample file name #fname = str('{:03}'.format(global_PVs['HDF1_FileNumber'].get())) + '_' + global_PVs['Sample_Name'].get(as_string=True) params.scan_counter = global_PVs['HDF1_FileNumber'].get() params.file_path = global_PVs['HDF1_FilePath'].get(as_string=True) params.file_name = str('{:03}'.format(global_PVs['HDF1_FileNumber'].get())) + '_' + global_PVs['Sample_Name'].get(as_string=True) log.info(' ') log.info(' *** Start scan %d/%d' % (i, (params.sleep_steps -1))) tomo_fly_scan(global_PVs, params) if ((i+1)!= params.sleep_steps): log.warning(' *** Wait (s): %s ' % str(params.sleep_time)) time.sleep(params.sleep_time) log.info(' ') log.info(' *** Data file: %s' % global_PVs['HDF1_FullFileName_RBV'].get(as_string=True)) log.info(' *** Total scan time: %s minutes' % str((time.time() - tic_01)/60.)) log.info(' *** Scan Done!') dm.scp(global_PVs, params) log.info(' *** Total loop scan time: %s minutes' % str((time.time() - tic)/60.)) log.info(' *** Moving rotary stage to start position') global_PVs["Motor_SampleRot"].put(params.sample_rotation_start, wait=True, timeout=600.0) log.info(' *** Moving rotary stage to start position: Done!') global_PVs['Cam1_ImageMode'].put('Continuous') log.info(' *** Done!') except KeyError: log.error(' *** Some PV assignment failed!') pass
def scp(global_PVs, params): log.info(' ') log.info(' *** Data transfer') remote_server = params.remote_analysis_dir.split(':')[0] remote_top_dir = params.remote_analysis_dir.split(':')[1] log.info(' *** remote server: %s' % remote_server) log.info(' *** remote top directory: %s' % remote_top_dir) fname_origin = global_PVs['HDFFullFileName_RBV'].get(as_string=True) p = pathlib.Path(fname_origin) fname_destination = params.remote_analysis_dir + p.parts[-3] + '/' + p.parts[-2] + '/' remote_dir = remote_top_dir + p.parts[-3] + '/' + p.parts[-2] + '/' log.info(' *** origin: %s' % fname_origin) log.info(' *** destination: %s' % fname_destination) # log.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.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.info(' *** Data transfer: Done!') return 0 else: log.error(' *** Quitting the copy operation') return -1
def take_image(global_PVs, params): log.info(' *** *** taking a single image') nRow = global_PVs['Cam1SizeY_RBV'].get() nCol = global_PVs['Cam1SizeX_RBV'].get() image_size = nRow * nCol global_PVs['Cam1NumImages'].put(1, wait=True) global_PVs['Cam1TriggerMode'].put('Off', wait=True) wait_time_sec = int(params.exposure_time) + 5 global_PVs['Cam1Acquire'].put(DetectorAcquire, wait=True, timeout=1000.0) time.sleep(0.1) if pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, wait_time_sec) == False: # adjust wait time global_PVs['Cam1Acquire'].put(DetectorIdle) # Get the image loaded in memory img_vect = global_PVs['Cam1Image'].get(count=image_size) img = np.reshape(img_vect,[nRow, nCol]) pixelFormat = global_PVs['Cam1PixelFormat_RBV'].get(as_string=True) if (pixelFormat == "Mono16"): pixel_f = 16 elif (pixelFormat == "Mono8"): pixel_f = 8 else: log.error(' *** *** bit %s format not supported' % pixelFormat) exit() img_uint = np.mod(img, 2**pixel_f) return img_uint
def stop_scan(global_PVs, params): log.info(' ') log.error(' *** Stopping the scan: PLEASE WAIT') global_PVs['Motor_SampleRot_Stop'].put(1) global_PVs['HDF1_Capture'].put(0) aps2bm.wait_pv(global_PVs['HDF1_Capture'], 0) flir.init(global_PVs, params) log.error(' *** Stopping scan: Done!')
def tomo_fly_scan(global_PVs, params): log.info(' ') log.info(' *** start_scan') def cleanup(signal, frame): stop_scan(global_PVs, params) sys.exit(0) signal.signal(signal.SIGINT, cleanup) # if params.has_key('StopTheScan'): # stop_scan(global_PVs, params) # return # moved to outer loop in main() # init(global_PVs, params) set_image_factor(global_PVs, params) rotation_start = params.sample_rotation_start rotation_end = params.sample_rotation_end if ((params.reverse == 'True') and ((params.scan_counter % 2) == 1)): params.sample_rotation_start = rotation_end params.sample_rotation_end = rotation_start aps2bm.set_pso(global_PVs, params) # fname = global_PVs['HDF1_FileName'].get(as_string=True) log.info(' *** File name prefix: %s' % params.file_name) flir.set(global_PVs, params) aps2bm.open_shutters(global_PVs, params) aps2bm.move_sample_in(global_PVs, params) theta = flir.acquire(global_PVs, params) if ((params.reverse == 'True') and ((params.scan_counter % 2) == 1)): params.sample_rotation_start = rotation_start params.sample_rotation_end = rotation_end theta_end = global_PVs['Motor_SampleRot_RBV'].get() if (0 < theta_end < 180.0): # print('\x1b[2;30;41m' + ' *** Rotary Stage ERROR. Theta stopped at: ***' + theta_end + '\x1b[0m') log.error(' *** Rotary Stage ERROR. Theta stopped at: %s ***' % str(theta_end)) aps2bm.move_sample_out(global_PVs, params) flir.acquire_flat(global_PVs, params) aps2bm.move_sample_in(global_PVs, params) aps2bm.close_shutters(global_PVs, params) time.sleep(2) flir.acquire_dark(global_PVs, params) flir.checkclose_hdf(global_PVs, params) flir.add_theta(global_PVs, params, theta) # update config file config.update_config(params)
def adjust(params): global_PVs = aps2bm.init_general_PVs(params) params.file_name = None # so we don't run the flir._setup_hdf_writer try: detector_sn = global_PVs['Cam1_SerialNumber'].get() if ((detector_sn == None) or (detector_sn == 'Unknown')): log.info( '*** The Point Grey Camera with EPICS IOC prefix %s is down' % params.camera_ioc_prefix) log.info(' *** Failed!') else: log.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \ % (params.camera_ioc_prefix, detector_sn)) flir.init(global_PVs, params) flir.set(global_PVs, params) dark_field, white_field = flir.take_dark_and_white( global_PVs, params) if (params.resolution == True): find_resolution(params, dark_field, white_field, angle_shift=-0.7) if (params.image_resolution == None): log.error( ' *** Detector resolution is not determined. Please run tomo adjust --resolution first!' ) exit() else: if (params.focus == True): adjust_focus(params) if (params.center == True): adjust_center(params, dark_field, white_field) if (params.roll == True): adjust_roll(params, dark_field, white_field, angle_shift=-0.7) if (params.pitch == True): adjust_pitch(params, dark_field, white_field, angle_shift=-0.7) if (params.roll == True or params.pitch == True): # align center again for higher accuracy adjust_center(params, dark_field, white_field) config.update_sphere(params) except KeyError: log.error(' *** Some PV assignment failed!') pass
def run(fname): try: # Form auto-complete for scan out = subprocess.Popen(['tomo', 'scan', '-h'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, _ = out.communicate() stdout = str(stdout) cmdscan = [] parscan = [] st = stdout.find("optional") while (1): st = stdout.find('--', st) end = min(stdout.find(' ', st), stdout.find('\\n', st)) if (st < 0): break cmdscan.append(stdout[st:end]) st = stdout.find('(default:', end) st1 = stdout.find('--', end) if (st1 > st or st1 < 0): end = stdout.find(')', st) parscan.append(stdout[st + 9:end].replace(" ", "").replace( "\\n", "")) else: parscan.append("") st = end # Create bash file fid = open(fname, 'w') fid.write( '#/usr/bin/env bash\n _tomo()\n{\n\tlocal cur prev opts\n\tCOMPREPLY=()\n\tcur="${COMP_WORDS[COMP_CWORD]}"\n\tprev="${COMP_WORDS[COMP_CWORD-1]}"\n' ) # check all tomo scan fid.write('\tif [[ ${COMP_WORDS[1]} == "scan" ]] ; then\n') fid.write('\t\topts="') fid.write(' '.join(cmdscan)) fid.write('"\n') fid.write( '\t\tCOMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )\n\tfi\n') for k in range(len(cmdscan)): fid.write('\tif [[ ${prev} == "') fid.write(cmdscan[k]) fid.write('" ]] ; then\n') fid.write('\t\topts="') fid.write(parscan[k]) fid.write('"\n') fid.write( '\t\tCOMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )\n\t\treturn 0\n\tfi\n' ) fid.write('}\n') fid.write('complete -F _tomo tomo') fid.close() except: log.error('Autocomplete file was not created')
def _setup_hdf_writer(global_PVs, params, fname=None): if (params.camera_ioc_prefix == '2bmbPG3:') or (params.camera_ioc_prefix == '2bmbSP1:'): # setup Point Grey hdf writer PV's log.info(' ') log.info(' *** setup hdf_writer') _setup_frame_type(global_PVs, params) if params.recursive_filter == True: log.info(' *** Recursive Filter Enabled') global_PVs['Proc1_Enable_Background'].put('Disable', wait=True) global_PVs['Proc1_Enable_FlatField'].put('Disable', wait=True) global_PVs['Proc1_Enable_Offset_Scale'].put('Disable', wait=True) global_PVs['Proc1_Enable_Low_Clip'].put('Disable', wait=True) global_PVs['Proc1_Enable_High_Clip'].put('Disable', wait=True) global_PVs['Proc1_Callbacks'].put('Enable', wait=True) global_PVs['Proc1_Filter_Enable'].put('Enable', wait=True) global_PVs['HDF1_ArrayPort'].put('PROC1', wait=True) global_PVs['Proc1_Filter_Type'].put(Recursive_Filter_Type, wait=True) global_PVs['Proc1_Num_Filter'].put(int( params.recursive_filter_n_images), wait=True) global_PVs['Proc1_Reset_Filter'].put(1, wait=True) global_PVs['Proc1_AutoReset_Filter'].put('Yes', wait=True) global_PVs['Proc1_Filter_Callbacks'].put('Array N only', wait=True) log.info(' *** Recursive Filter Enabled: Done!') else: global_PVs['Proc1_Filter_Enable'].put('Disable') global_PVs['HDF1_ArrayPort'].put( global_PVs['Proc1_ArrayPort'].get()) global_PVs['HDF1_AutoSave'].put('Yes') global_PVs['HDF1_DeleteDriverFile'].put('No') global_PVs['HDF1_EnableCallbacks'].put('Enable') global_PVs['HDF1_BlockingCallbacks'].put('No') # if (params.recursive_filter == False): # params.recursive_filter_n_images = 1 totalProj = ((int(params.num_projections / params.recursive_filter_n_images)) + int(params.num_dark_images) + \ int(params.num_white_images)) global_PVs['HDF1_NumCapture'].put(totalProj) global_PVs['HDF1_FileWriteMode'].put(str(params.file_write_mode), wait=True) if fname is not None: global_PVs['HDF1_FileName'].put(str(fname), wait=True) global_PVs['HDF1_Capture'].put(1) aps2bm.wait_pv(global_PVs['HDF1_Capture'], 1) log.info(' *** setup hdf_writer: Done!') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return
def create_remote_directory(remote_server, remote_dir): cmd = 'mkdir -p ' + remote_dir try: # log.info(' *** sending command %s' % (cmd)) log.info(' *** creating remote directory %s' % (remote_dir)) subprocess.check_call(['ssh', remote_server, cmd]) log.info(' *** creating remote directory %s: Done!' % (remote_dir)) return 0 except subprocess.CalledProcessError as e: log.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.warning(' *** remote directory %s exists' % (remote_dir)) return 0 except subprocess.CalledProcessError as e: # log.info(' *** return code = %d' % (e.returncode)) log.warning(' *** remote directory %s does not exist' % (remote_dir)) if e.returncode == 2: return e.returncode else: log.error(' *** Unknown error code returned: %d' % (e.returncode)) return -1
def dummy_scan(params): tic = time.time() global_PVs = aps2bm.init_general_PVs(params) aps2bm.user_info_params_update_from_pv(global_PVs, params) try: detector_sn = global_PVs['Cam1_SerialNumber'].get() if ((detector_sn == None) or (detector_sn == 'Unknown')): log.info('*** The Point Grey Camera with EPICS IOC prefix %s is down' % params.camera_ioc_prefix) log.info(' *** Failed!') else: log.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \ % (params.camera_ioc_prefix, detector_sn)) except KeyError: log.error(' *** Some PV assignment failed!') pass
def checkclose_hdf(global_PVs, params): buffer_queue = global_PVs['HDFQueueSize'].get() - global_PVs['HDFQueueFree'].get() # wait_on_hdd = 10 frate = 55.0 wait_on_hdd = buffer_queue / frate + 10 # wait_on_hdd = (global_PVs['HDFQueueSize'].get() - global_PVs['HDFQueueFree'].get()) / 55.0 + 10 log.info(' *** Buffer Queue (frames): %d ' % buffer_queue) log.info(' *** Wait HDD (s): %f' % wait_on_hdd) if pv.wait_pv(global_PVs["HDFCapture_RBV"], 0, wait_on_hdd) == False: # needs to wait for HDF plugin queue to dump to disk global_PVs["HDFCapture"].put(0) log.info(' *** File was not closed => forced to close') log.info(' *** before %d' % global_PVs["HDFCapture_RBV"].get()) pv.wait_pv(global_PVs["HDFCapture_RBV"], 0, 5) log.info(' *** after %d' % global_PVs["HDFCapture_RBV"].get()) if (global_PVs["HDFCapture_RBV"].get() == 1): log.error(' *** ERROR HDF FILE DID NOT CLOSE; add_theta will fail')
def update_config(args): # update tomo2bm.conf sections = SCAN_PARAMS write(args.config, args=args, sections=sections) # copy tomo2bm.conf to the raw data directory with a unique name (sample_name.conf) log_fname = args.file_path + os.sep + args.file_name + '.conf' try: shutil.copyfile(args.config, log_fname) log.info(' *** copied %s to %s ' % (args.config, log_fname)) except: log.error(' *** attempt to copy %s to %s failed' % (args.config, log_fname)) pass log.warning( ' *** command to repeat the scan: tomo scan --config {:s}'.format( log_fname)) if (args.dx_update): write_hdf(args, sections)
def set_pso(global_PVs, params): acclTime = 1.0 * params.slew_speed / params.accl_rot scanDelta = abs(((float(params.sample_rotation_end) - float(params.sample_rotation_start))) / ((float(params.num_projections)) * float(params.recursive_filter_n_images))) log.info(' *** *** start_pos %f' % float(params.sample_rotation_start)) log.info(' *** *** end pos %f' % float(params.sample_rotation_end)) global_PVs['Fly_StartPos'].put(float(params.sample_rotation_start), wait=True) global_PVs['Fly_EndPos'].put(float(params.sample_rotation_end), wait=True) global_PVs['Fly_SlewSpeed'].put(params.slew_speed, wait=True) global_PVs['Fly_ScanDelta'].put(scanDelta, wait=True) time.sleep(3.0) calc_num_proj = global_PVs['Fly_Calc_Projections'].get() if calc_num_proj == None: log.error( ' *** *** Error getting fly calculated number of projections!') calc_num_proj = global_PVs['Fly_Calc_Projections'].get() log.error(' *** *** Using %s instead of %s' % (calc_num_proj, params.num_projections)) if calc_num_proj != int(params.num_projections): log.warning( ' *** *** Changing number of projections from: %s to: %s' % (params.num_projections, int(calc_num_proj))) params.num_projections = int(calc_num_proj) log.info(' *** *** Number of projections: %d' % int(params.num_projections)) log.info(' *** *** Fly calc triggers: %d' % int(calc_num_proj)) global_PVs['Fly_ScanControl'].put('Standard') log.info(' ') log.info(' *** Taxi before starting capture') global_PVs['Fly_Taxi'].put(1, wait=True) wait_pv(global_PVs['Fly_Taxi'], 0) log.info(' *** Taxi before starting capture: Done!')
def init_general_PVs(global_PVs, params): # shutter pv's global_PVs['ShutterA_Open'] = PV('7bma:A_shutter:open.VAL') global_PVs['ShutterA_Close'] = PV('7bma:A_shutter:close.VAL') global_PVs['ShutterA_Move_Status'] = PV('PA:02BM:STA_A_FES_OPEN_PL') # Experimment Info global_PVs['Sample_Name'] = PV('2bmS1:ExpInfo:SampleName') global_PVs['User_Badge'] = PV('2bmS1:ExpInfo:UserBadge.VAL') global_PVs['User_Email'] = PV('2bmS1:ExpInfo:UserEmail.VAL') global_PVs['User_Institution'] = PV('2bmS1:ExpInfo:UserInstitution.VAL') global_PVs['Proposal_Number'] = PV('2bmS1:ExpInfo:ProposalNumber.VAL') global_PVs['Proposal_Title'] = PV('2bmS1:ExpInfo:ProposalTitle.VAL') global_PVs['Sample_Description'] = PV('2bmS1:ExpInfo:SampleDescription.VAL') global_PVs['User_Info_Update'] = PV('2bmS1:ExpInfo:UserInfoUpdate.VAL') global_PVs['Lens_Magnification'] = PV('2bmS1:ExpInfo:LensMagnification.VAL') global_PVs['Scintillator_Type'] = PV('2bmS1:ExpInfo:ScintillatorType.VAL') global_PVs['Filters'] = PV('2bmS1:ExpInfo:Filters.VAL') global_PVs['File_Name'] = PV('2bmS1:ExpInfo:FileName.VAL') global_PVs['Station'] = PV('2bmS1:ExpInfo:Station.VAL') global_PVs['Camera_IOC_Prefix'] = PV('2bmS1:ExpInfo:CameraIOCPrefix.VAL') global_PVs['Remote_Analysis_Dir'] = PV('2bmS1:ExpInfo:RemoteAnalysisDir.VAL') global_PVs['User_Last_Name'] = PV('2bmS1:ExpInfo:UserLastName.VAL') global_PVs['Experiment_Year_Month'] = PV('2bmS1:ExpInfo:ExperimentYearMonth.VAL') global_PVs['Use_Furnace'] = PV('2bmS1:ExpInfo:UseFurnace.VAL') global_PVs['White_Field_Motion'] = PV('2bmS1:ExpInfo:WhiteFieldMotion.VAL') global_PVs['Remote_Data_Trasfer'] = PV('2bmS1:ExpInfo:RemoteDataTrasfer.VAL') global_PVs['Scan_Type'] = PV('2bmS1:ExpInfo:ScanType.VAL') global_PVs['Num_Projections'] = PV('2bmS1:ExpInfo:NumProjections.VAL') global_PVs['Num_White_Images'] = PV('2bmS1:ExpInfo:NumWhiteImages.VAL') global_PVs['Num_Dark_Images'] = PV('2bmS1:ExpInfo:NumDarkImages.VAL') global_PVs['Scintillator_Thickness'] = PV('2bmS1:ExpInfo:ScintillatorThickness.VAL') global_PVs['Sample_Detector_Distance'] = PV('2bmS1:ExpInfo:SampleDetectorDistance.VAL') global_PVs['Sample_In_Position'] = PV('2bmS1:ExpInfo:SampleInPosition.VAL') global_PVs['Sample_Out_Position'] = PV('2bmS1:ExpInfo:SampleOutPosition.VAL') global_PVs['Sample_Rotation_Start'] = PV('2bmS1:ExpInfo:SampleRotationStart.VAL') global_PVs['Sample_Rotation_End'] = PV('2bmS1:ExpInfo:SampleRotationEnd.VAL') global_PVs['Furnace_In_Position'] = PV('2bmS1:ExpInfo:FurnaceInPosition.VAL') global_PVs['Furnace_Out_Position'] = PV('2bmS1:ExpInfo:FurnaceOutPosition.VAL') global_PVs['Sleep_Time'] = PV('2bmS1:ExpInfo:SleepTime.VAL') global_PVs['Vertical_Scan_Start'] = PV('2bmS1:ExpInfo:VerticalScanStart.VAL') global_PVs['Vertical_Scan_End'] = PV('2bmS1:ExpInfo:VerticalScanEnd.VAL') global_PVs['Vertical_Scan_Step_Size'] = PV('2bmS1:ExpInfo:VerticalScanStepSize.VAL') global_PVs['Horizontal_Scan_Start'] = PV('2bmS1:ExpInfo:HorizontalScanStart.VAL') global_PVs['Horizontal_Scan_End'] = PV('2bmS1:ExpInfo:HorizontalScanEnd.VAL') global_PVs['Horizontal_Scan_Step_Size'] = PV('2bmS1:ExpInfo:HorizontalScanStepSize.VAL') if params.station == '2-BM-A': log.info('*** Running in station A:') # Set sample stack motor pv's: global_PVs['Motor_SampleX'] = PV('2bma:m49.VAL') global_PVs['Motor_SampleX_SET'] = PV('2bma:m49.SET') global_PVs['Motor_SampleY'] = PV('2bma:m20.VAL') global_PVs['Motor_SampleRot'] = PV('2bma:m82.VAL') # Aerotech ABR-250 global_PVs['Motor_SampleRot_RBV'] = PV('2bma:m82.RBV') # Aerotech ABR-250 global_PVs['Motor_SampleRot_Cnen'] = PV('2bma:m82.CNEN') global_PVs['Motor_SampleRot_Accl'] = PV('2bma:m82.ACCL') global_PVs['Motor_SampleRot_Stop'] = PV('2bma:m82.STOP') global_PVs['Motor_SampleRot_Set'] = PV('2bma:m82.SET') global_PVs['Motor_SampleRot_Velo'] = PV('2bma:m82.VELO') global_PVs['Motor_Sample_Top_0'] = PV('2bmS1:m2.VAL') global_PVs['Motor_Sample_Top_90'] = PV('2bmS1:m1.VAL') # Set FlyScan global_PVs['Fly_ScanDelta'] = PV('2bma:PSOFly2:scanDelta') global_PVs['Fly_StartPos'] = PV('2bma:PSOFly2:startPos') global_PVs['Fly_EndPos'] = PV('2bma:PSOFly2:endPos') global_PVs['Fly_SlewSpeed'] = PV('2bma:PSOFly2:slewSpeed') global_PVs['Fly_Taxi'] = PV('2bma:PSOFly2:taxi') global_PVs['Fly_Run'] = PV('2bma:PSOFly2:fly') global_PVs['Fly_ScanControl'] = PV('2bma:PSOFly2:scanControl') global_PVs['Fly_Calc_Projections'] = PV('2bma:PSOFly2:numTriggers') global_PVs['Theta_Array'] = PV('2bma:PSOFly2:motorPos.AVAL') global_PVs['Fast_Shutter'] = PV('2bma:m23.VAL') global_PVs['Motor_Focus'] = PV('2bma:m41.VAL') global_PVs['Motor_Focus_Name'] = PV('2bma:m41.DESC') elif params.station == '2-BM-B': log.info('*** Running in station B:') # Sample stack motor pv's: global_PVs['Motor_SampleX'] = PV('2bmb:m63.VAL') global_PVs['Motor_SampleX_SET'] = PV('2bmb:m63.SET') global_PVs['Motor_SampleY'] = PV('2bmb:m57.VAL') global_PVs['Motor_SampleRot'] = PV('2bmb:m100.VAL') # Aerotech ABR-150 global_PVs['Motor_SampleRot_Accl'] = PV('2bma:m100.ACCL') global_PVs['Motor_SampleRot_Stop'] = PV('2bma:m100.STOP') global_PVs['Motor_SampleRot_Set'] = PV('2bma:m100.SET') global_PVs['Motor_SampleRot_Velo'] = PV('2bma:m100.VELO') global_PVs['Motor_Sample_Top_0'] = PV('2bmb:m76.VAL') global_PVs['Motor_Sample_Top_90'] = PV('2bmb:m77.VAL') # Set CCD stack motor PVs: global_PVs['Motor_CCD_Z'] = PV('2bmb:m31.VAL') # Set FlyScan global_PVs['Fly_ScanDelta'] = PV('2bmb:PSOFly:scanDelta') global_PVs['Fly_StartPos'] = PV('2bmb:PSOFly:startPos') global_PVs['Fly_EndPos'] = PV('2bmb:PSOFly:endPos') global_PVs['Fly_SlewSpeed'] = PV('2bmb:PSOFly:slewSpeed') global_PVs['Fly_Taxi'] = PV('2bmb:PSOFly:taxi') global_PVs['Fly_Run'] = PV('2bmb:PSOFly:fly') global_PVs['Fly_ScanControl'] = PV('2bmb:PSOFly:scanControl') global_PVs['Fly_Calc_Projections'] = PV('2bmb:PSOFly:numTriggers') global_PVs['Theta_Array'] = PV('2bmb:PSOFly:motorPos.AVAL') global_PVs['Motor_Focus'] = PV('2bmb:m78.VAL') global_PVs['Motor_Focus_Name'] = PV('2bmb:m78.DESC') else: log.error('*** %s is not a valid station' % params.station) # detector pv's if ((params.camera_ioc_prefix == '2bmbPG3:') or (params.camera_ioc_prefix == '2bmbSP1:')): # init Point Grey PV's # general PV's global_PVs['Cam1_SerialNumber'] = PV(params.camera_ioc_prefix + 'cam1:SerialNumber_RBV') global_PVs['Cam1_ImageMode'] = PV(params.camera_ioc_prefix + 'cam1:ImageMode') global_PVs['Cam1_ArrayCallbacks'] = PV(params.camera_ioc_prefix + 'cam1:ArrayCallbacks') global_PVs['Cam1_AcquirePeriod'] = PV(params.camera_ioc_prefix + 'cam1:AcquirePeriod') global_PVs['Cam1_TriggerMode'] = PV(params.camera_ioc_prefix + 'cam1:TriggerMode') global_PVs['Cam1_SoftwareTrigger'] = PV(params.camera_ioc_prefix + 'cam1:SoftwareTrigger') ### ask Mark is this is exposed in the medm screen global_PVs['Cam1_AcquireTime'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTime') global_PVs['Cam1_FrameType'] = PV(params.camera_ioc_prefix + 'cam1:FrameType') global_PVs['Cam1_NumImages'] = PV(params.camera_ioc_prefix + 'cam1:NumImages') global_PVs['Cam1_Acquire'] = PV(params.camera_ioc_prefix + 'cam1:Acquire') global_PVs['Cam1_AttributeFile'] = PV(params.camera_ioc_prefix + 'cam1:NDAttributesFile') global_PVs['Cam1_FrameTypeZRST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ZRST') global_PVs['Cam1_FrameTypeONST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ONST') global_PVs['Cam1_FrameTypeTWST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.TWST') global_PVs['Cam1_Display'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Cam1_SizeX'] = PV(params.camera_ioc_prefix + 'cam1:SizeX') global_PVs['Cam1_SizeY'] = PV(params.camera_ioc_prefix + 'cam1:SizeY') global_PVs['Cam1_SizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeX_RBV') global_PVs['Cam1_SizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeY_RBV') global_PVs['Cam1_MaxSizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeX_RBV') global_PVs['Cam1_MaxSizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeY_RBV') global_PVs['Cam1PixelFormat_RBV'] = PV(params.camera_ioc_prefix + 'cam1:PixelFormat_RBV') global_PVs['Cam1_Image'] = PV(params.camera_ioc_prefix + 'image1:ArrayData') # hdf5 writer PV's global_PVs['HDF1_AutoSave'] = PV(params.camera_ioc_prefix + 'HDF1:AutoSave') global_PVs['HDF1_DeleteDriverFile'] = PV(params.camera_ioc_prefix + 'HDF1:DeleteDriverFile') global_PVs['HDF1_EnableCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:EnableCallbacks') global_PVs['HDF1_BlockingCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:BlockingCallbacks') global_PVs['HDF1_FileWriteMode'] = PV(params.camera_ioc_prefix + 'HDF1:FileWriteMode') global_PVs['HDF1_NumCapture'] = PV(params.camera_ioc_prefix + 'HDF1:NumCapture') global_PVs['HDF1_Capture'] = PV(params.camera_ioc_prefix + 'HDF1:Capture') global_PVs['HDF1_Capture_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:Capture_RBV') global_PVs['HDF1_FilePath'] = PV(params.camera_ioc_prefix + 'HDF1:FilePath') global_PVs['HDF1_FileName'] = PV(params.camera_ioc_prefix + 'HDF1:FileName') global_PVs['HDF1_FullFileName_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:FullFileName_RBV') global_PVs['HDF1_FileTemplate'] = PV(params.camera_ioc_prefix + 'HDF1:FileTemplate') global_PVs['HDF1_ArrayPort'] = PV(params.camera_ioc_prefix + 'HDF1:NDArrayPort') global_PVs['HDF1_FileNumber'] = PV(params.camera_ioc_prefix + 'HDF1:FileNumber') global_PVs['HDF1_XMLFileName'] = PV(params.camera_ioc_prefix + 'HDF1:XMLFileName') global_PVs['HDF1_QueueSize'] = PV(params.camera_ioc_prefix + 'HDF1:QueueSize') global_PVs['HDF1_QueueFree'] = PV(params.camera_ioc_prefix + 'HDF1:QueueFree') # proc1 PV's global_PVs['Image1_Callbacks'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Proc1_Callbacks'] = PV(params.camera_ioc_prefix + 'Proc1:EnableCallbacks') global_PVs['Proc1_ArrayPort'] = PV(params.camera_ioc_prefix + 'Proc1:NDArrayPort') global_PVs['Proc1_Filter_Enable'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFilter') global_PVs['Proc1_Filter_Type'] = PV(params.camera_ioc_prefix + 'Proc1:FilterType') global_PVs['Proc1_Num_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:NumFilter') global_PVs['Proc1_Reset_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:ResetFilter') global_PVs['Proc1_AutoReset_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:AutoResetFilter') global_PVs['Proc1_Filter_Callbacks'] = PV(params.camera_ioc_prefix + 'Proc1:FilterCallbacks') global_PVs['Proc1_Enable_Background'] = PV(params.camera_ioc_prefix + 'Proc1:EnableBackground') global_PVs['Proc1_Enable_FlatField'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFlatField') global_PVs['Proc1_Enable_Offset_Scale'] = PV(params.camera_ioc_prefix + 'Proc1:EnableOffsetScale') global_PVs['Proc1_Enable_Low_Clip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableLowClip') global_PVs['Proc1_Enable_High_Clip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableHighClip') if (params.camera_ioc_prefix == '2bmbPG3:'): global_PVs['Cam1_FrameRateOnOff'] = PV(params.camera_ioc_prefix + 'cam1:FrameRateOnOff') elif (params.camera_ioc_prefix == '2bmbSP1:'): global_PVs['Cam1_AcquireTimeAuto'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTimeAuto') global_PVs['Cam1_FrameRateOnOff'] = PV(params.camera_ioc_prefix + 'cam1:FrameRateEnable') global_PVs['Cam1_TriggerSource'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSource') global_PVs['Cam1_TriggerOverlap'] = PV(params.camera_ioc_prefix + 'cam1:TriggerOverlap') global_PVs['Cam1_ExposureMode'] = PV(params.camera_ioc_prefix + 'cam1:ExposureMode') global_PVs['Cam1_TriggerSelector'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSelector') global_PVs['Cam1_TriggerActivation'] = PV(params.camera_ioc_prefix + 'cam1:TriggerActivation') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return user_info_update(global_PVs, params) return global_PVs
def set(global_PVs, params): fname = params.file_name # Set detectors if (params.camera_ioc_prefix == '2bmbPG3:'): log.info(' ') log.info(' *** setup Point Grey') # mona runf always in B with PG camera global_PVs['Cam1AttributeFile'].put('monaDetectorAttributes.xml', wait=True) global_PVs['HDFXMLFileName'].put('monaLayout.xml', wait=True) global_PVs['Cam1ImageMode'].put('Multiple') global_PVs['Cam1ArrayCallbacks'].put('Enable') #global_PVs['Image1_Callbacks'].put('Enable') global_PVs['Cam1AcquirePeriod'].put(float(params.exposure_time)) global_PVs['Cam1AcquireTime'].put(float(params.exposure_time)) # if we are using external shutter then set the exposure time global_PVs['Cam1FrameRateOnOff'].put(0) wait_time_sec = int(params.exposure_time) + 5 global_PVs['Cam1TriggerMode'].put('Overlapped', wait=True) #Ext. Standard global_PVs['Cam1NumImages'].put(1, wait=True) global_PVs['Cam1Acquire'].put(DetectorAcquire) pv.wait_pv(global_PVs['Cam1Acquire'], DetectorAcquire, 2) global_PVs['Cam1SoftwareTrigger'].put(1) pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, wait_time_sec) global_PVs['Cam1Acquire'].put(DetectorAcquire) pv.wait_pv(global_PVs['Cam1Acquire'], DetectorAcquire, 2) global_PVs['Cam1SoftwareTrigger'].put(1) pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, wait_time_sec) log.info(' *** setup Point Grey: Done!') elif (params.camera_ioc_prefix == '2bmbSP1:'): log.info(' ') log.info(' *** setup FLIR camera') if params.station == '2-BM-A': global_PVs['Cam1AttributeFile'].put('flir2bmaDetectorAttributes.xml') global_PVs['HDFXMLFileName'].put('flir2bmaLayout.xml') else: # Mona (B-station) global_PVs['Cam1AttributeFile'].put('flir2bmbDetectorAttributes.xml', wait=True) global_PVs['HDFXMLFileName'].put('flir2bmbLayout.xml', wait=True) global_PVs['Cam1Acquire'].put(DetectorIdle) pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, 2) global_PVs['Cam1TriggerMode'].put('Off', wait=True) global_PVs['Cam1TriggerSource'].put('Line2', wait=True) global_PVs['Cam1TriggerOverlap'].put('ReadOut', wait=True) global_PVs['Cam1ExposureMode'].put('Timed', wait=True) global_PVs['Cam1TriggerSelector'].put('FrameStart', wait=True) global_PVs['Cam1TriggerActivation'].put('RisingEdge', wait=True) global_PVs['Cam1ImageMode'].put('Multiple') global_PVs['Cam1ArrayCallbacks'].put('Enable') #global_PVs['Image1_Callbacks'].put('Enable') #global_PVs['Cam1AcquirePeriod'].put(float(params.exposure_time)) global_PVs['Cam1FrameRateOnOff'].put(0) global_PVs['Cam1AcquireTimeAuto'].put('Off') global_PVs['Cam1AcquireTime'].put(float(params.exposure_time)) # if we are using external shutter then set the exposure time wait_time_sec = int(params.exposure_time) + 5 global_PVs['Cam1TriggerMode'].put('On', wait=True) log.info(' *** setup FLIR camera: Done!') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return if fname is None: log.warning(' *** hdf_writer will not be configured') else: _setup_hdf_writer(global_PVs, params, fname)
def init_general_PVs(params): global_PVs = {} global_PVs['Station'] = PV('2bmS1:ExpInfo:Station.VAL') global_PVs['Camera_IOC_Prefix'] = PV('2bmS1:ExpInfo:CameraIOCPrefix.VAL') # shutter pv's global_PVs['ShutterAOpen'] = PV('2bma:A_shutter:open.VAL') global_PVs['ShutterAClose'] = PV('2bma:A_shutter:close.VAL') global_PVs['ShutterAMoveStatus'] = PV('PA:02BM:STA_A_FES_OPEN_PL') global_PVs['ShutterBOpen'] = PV('2bma:B_shutter:open.VAL') global_PVs['ShutterB_Close'] = PV('2bma:B_shutter:close.VAL') global_PVs['ShutterB_Move_Status'] = PV('PA:02BM:STA_B_SBS_OPEN_PL') # Experimment Info global_PVs['UserName'] = PV('2bmS1:ExpInfo:UserName.VAL') global_PVs['UserEmail'] = PV('2bmS1:ExpInfo:UserEmail.VAL') global_PVs['UserBadge'] = PV('2bmS1:ExpInfo:UserBadge.VAL') global_PVs['ProposalNumber'] = PV('2bmS1:ExpInfo:ProposalNumber.VAL') global_PVs['ProposalTitle'] = PV('2bmS1:ExpInfo:ProposalTitle.VAL') global_PVs['UserInstitution'] = PV('2bmS1:ExpInfo:UserInstitution.VAL') global_PVs['UserInfoUpdate'] = PV('2bmS1:ExpInfo:UserInfoUpdate.VAL') global_PVs['Time'] = PV('S:IOC:timeOfDayISO8601') global_PVs['ScintillatorType'] = PV('2bmS1:ExpInfo:ScintillatorType.VAL') global_PVs['ScintillatorThickness'] = PV( '2bmS1:ExpInfo:ScintillatorThickness.VAL') global_PVs['ImagePixelSize'] = PV('2bmS1:ExpInfo:ImagePixelSize.VAL') global_PVs['DetectorPixelSize'] = PV('2bmS1:ExpInfo:DetectorPixelSize.VAL') global_PVs['CameraObjective'] = PV('2bmS1:CameraObjective.VAL') global_PVs['CameraTubeLength'] = PV('22bmS1:ExpInfo:CameraTubeLength.VAL') # energy info global_PVs['Energy'] = PV('2bmS1:ExpInfo:Energy.VAL') global_PVs['EnergyMode'] = PV('2bmS1:ExpInfo:EnergyMode.VAL') global_PVs['Filters'] = PV('2bmS1:ExpInfo:Filters.VAL') # scan info global_PVs['RotationStart'] = PV('2bmS1:ExpInfo:RotationStart.VAL') global_PVs['RotationEnd'] = PV('2bmS1:ExpInfo:RotationEnd.VAL') global_PVs['RotationStep'] = PV('2bmS1:ExpInfo:RotationStep.VAL') global_PVs['NumAngles'] = PV('2bmS1:ExpInfo:NumAngles.VAL') global_PVs['ReturnRotation'] = PV('2bmS1:ExpInfo:ReturnRotation') global_PVs['NumFlatFields'] = PV('2bmS1:ExpInfo:NumFlatFields.VAL') global_PVs['FlatFieldMode'] = PV('2bmS1:ExpInfo:FlatFieldMode') global_PVs['FlatFieldValue'] = PV('2bmS1:ExpInfo:FlatFieldValue') global_PVs['NumDarkFields'] = PV('2bmS1:ExpInfo:NumDarkFields.VAL') global_PVs['DarkFieldMode'] = PV('2bmS1:ExpInfo:DarkFieldMode') global_PVs['DarkFieldValue'] = PV('2bmS1:ExpInfo:DarkFieldValue') global_PVs['FlatFieldAxis'] = PV('2bmS1:ExpInfo:FlatFieldAxis') global_PVs['SampleInX'] = PV('2bmS1:ExpInfo:SampleInX') global_PVs['SampleOutX'] = PV('2bmS1:ExpInfo:SampleOutX') global_PVs['SampleInY'] = PV('2bmS1:ExpInfo:SampleInY') global_PVs['SampleOutY'] = PV('2bmS1:ExpInfo:SampleOutY') global_PVs['ScanType'] = PV('2bmS1:ExpInfo:ScanType.VAL') global_PVs['SleepTime'] = PV('2bmS1:ExpInfo:SleepTime.VAL') global_PVs['VerticalScanStart'] = PV('2bmS1:ExpInfo:VerticalScanStart.VAL') global_PVs['VerticalScanEnd'] = PV('2bmS1:ExpInfo:VerticalScanEnd.VAL') global_PVs['VerticalScanStepSize'] = PV( '2bmS1:ExpInfo:VerticalScanStepSize.VAL') global_PVs['HorizontalScanStart'] = PV( '2bmS1:ExpInfo:HorizontalScanStart.VAL') global_PVs['HorizontalScanEnd'] = PV('2bmS1:ExpInfo:HorizontalScanEnd.VAL') global_PVs['HorizontalScanStepSize'] = PV( '2bmS1:ExpInfo:HorizontalScanStepSize.VAL') # sample info global_PVs['SampleName'] = PV('2bmS1:ExpInfo:SampleName') global_PVs['SampleDescription1'] = PV( '2bmS1:ExpInfo:SampleDescription1.VAL') global_PVs['SampleDescription2'] = PV( '2bmS1:ExpInfo:SampleDescription2.VAL') global_PVs['SampleDescription3'] = PV( '2bmS1:ExpInfo:SampleDescription3.VAL') # environment info global_PVs['UseFurnace'] = PV('2bmS1:ExpInfo:UseFurnace.VAL') global_PVs['FurnaceInPosition'] = PV('2bmS1:ExpInfo:FurnaceInPosition.VAL') global_PVs['FurnaceOutPosition'] = PV( '2bmS1:ExpInfo:FurnaceOutPosition.VAL') # data management info global_PVs['ExperimentYearMonth'] = PV( '2bmS1:ExpInfo:ExperimentYearMonth.VAL') global_PVs['UserLastName'] = PV('2bmS1:ExpInfo:UserLastName.VAL') global_PVs['RemoteDataTransfer'] = PV( '2bmS1:ExpInfo:RemoteDataTrasfer.VAL') global_PVs['RemoteAnalysisDir'] = PV('2bmS1:ExpInfo:RemoteAnalysisDir.VAL') if params.station == '2-BM-A': log.info('*** Running in station A:') # Set sample stack motor pv's: global_PVs['SampleX'] = PV('2bma:m49.VAL') global_PVs['SampleXSET'] = PV('2bma:m49.SET') global_PVs['SampleY'] = PV('2bma:m20.VAL') global_PVs['SampleOmega'] = PV('2bma:m82.VAL') # Aerotech ABR-250 global_PVs['SampleOmegaRBV'] = PV('2bma:m82.RBV') # Aerotech ABR-250 global_PVs['SampleOmegaCnen'] = PV('2bma:m82.CNEN') global_PVs['SampleOmegaAccl'] = PV('2bma:m82.ACCL') global_PVs['SampleOmegaStop'] = PV('2bma:m82.STOP') global_PVs['SampleOmegaSet'] = PV('2bma:m82.SET') global_PVs['SampleOmegaVelo'] = PV('2bma:m82.VELO') global_PVs['SampleXCent'] = PV('2bmS1:m2.VAL') global_PVs['SampleZCent'] = PV('2bmS1:m1.VAL') global_PVs['SamplePitch'] = PV('2bma:m50.VAL') global_PVs['SampleRoll'] = PV('2bma:m51.VAL') global_PVs['CameraDistance'] = PV('2bma:m22.VAL') # Set FlyScan global_PVs['FlyScanDelta'] = PV('2bma:PSOFly2:scanDelta') global_PVs['FlyStartPos'] = PV('2bma:PSOFly2:startPos') global_PVs['FlyEndPos'] = PV('2bma:PSOFly2:endPos') global_PVs['FlySlewSpeed'] = PV('2bma:PSOFly2:slewSpeed') global_PVs['FlyTaxi'] = PV('2bma:PSOFly2:taxi') global_PVs['FlyRun'] = PV('2bma:PSOFly2:fly') global_PVs['FlyScanControl'] = PV('2bma:PSOFly2:scanControl') global_PVs['FlyCalcProjections'] = PV('2bma:PSOFly2:numTriggers') global_PVs['OmegaArray'] = PV('2bma:PSOFly2:motorPos.AVAL') global_PVs['FastShutter'] = PV('2bma:m23.VAL') global_PVs['Focus'] = PV('2bma:m41.VAL') global_PVs['FocusName'] = PV('2bma:m41.DESC') elif params.station == '2-BM-B': log.info('*** Running in station B:') # Sample stack motor pv's: global_PVs['SampleX'] = PV('2bmb:m63.VAL') global_PVs['SampleXSET'] = PV('2bmb:m63.SET') global_PVs['SampleY'] = PV('2bmb:m57.VAL') global_PVs['SampleOmega'] = PV('2bmb:m100.VAL') # Aerotech ABR-150 global_PVs['SampleOmegaAccl'] = PV('2bma:m100.ACCL') global_PVs['SampleOmegaStop'] = PV('2bma:m100.STOP') global_PVs['SampleOmegaSet'] = PV('2bma:m100.SET') global_PVs['SampleOmegaVelo'] = PV('2bma:m100.VELO') global_PVs['SampleXCent'] = PV('2bmb:m76.VAL') global_PVs['SampleZCent'] = PV('2bmb:m77.VAL') # Set CCD stack motor PVs: global_PVs['Motor_CCD_Z'] = PV('2bmb:m31.VAL') # Set FlyScan global_PVs['FlyScanDelta'] = PV('2bmb:PSOFly:scanDelta') global_PVs['FlyStartPos'] = PV('2bmb:PSOFly:startPos') global_PVs['FlyEndPos'] = PV('2bmb:PSOFly:endPos') global_PVs['FlySlewSpeed'] = PV('2bmb:PSOFly:slewSpeed') global_PVs['FlyTaxi'] = PV('2bmb:PSOFly:taxi') global_PVs['FlyRun'] = PV('2bmb:PSOFly:fly') global_PVs['FlyScanControl'] = PV('2bmb:PSOFly:scanControl') global_PVs['FlyCalcProjections'] = PV('2bmb:PSOFly:numTriggers') global_PVs['OmegaArray'] = PV('2bmb:PSOFly:motorPos.AVAL') global_PVs['Focus'] = PV('2bmb:m78.VAL') global_PVs['FocusName'] = PV('2bmb:m78.DESC') else: log.error('*** %s is not a valid station' % params.station) # detector pv's if ((params.camera_ioc_prefix == '2bmbPG3:') or (params.camera_ioc_prefix == '2bmbSP1:')): # general PV's global_PVs['Cam1SerialNumber'] = PV(params.camera_ioc_prefix + 'cam1:SerialNumber_RBV') global_PVs['Cam1ImageMode'] = PV(params.camera_ioc_prefix + 'cam1:ImageMode') global_PVs['Cam1ArrayCallbacks'] = PV(params.camera_ioc_prefix + 'cam1:ArrayCallbacks') global_PVs['Cam1AcquirePeriod'] = PV(params.camera_ioc_prefix + 'cam1:AcquirePeriod') global_PVs['Cam1TriggerMode'] = PV(params.camera_ioc_prefix + 'cam1:TriggerMode') global_PVs['Cam1SoftwareTrigger'] = PV( params.camera_ioc_prefix + 'cam1:SoftwareTrigger' ) ### ask Mark is this is exposed in the medm screen global_PVs['Cam1AcquireTime'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTime') global_PVs['Cam1FrameType'] = PV(params.camera_ioc_prefix + 'cam1:FrameType') global_PVs['Cam1NumImages'] = PV(params.camera_ioc_prefix + 'cam1:NumImages') global_PVs['Cam1Acquire'] = PV(params.camera_ioc_prefix + 'cam1:Acquire') global_PVs['Cam1AttributeFile'] = PV(params.camera_ioc_prefix + 'cam1:NDAttributesFile') global_PVs['Cam1FrameTypeZRST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ZRST') global_PVs['Cam1FrameTypeONST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ONST') global_PVs['Cam1FrameTypeTWST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.TWST') global_PVs['Cam1Display'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Cam1SizeX'] = PV(params.camera_ioc_prefix + 'cam1:SizeX') global_PVs['Cam1SizeY'] = PV(params.camera_ioc_prefix + 'cam1:SizeY') global_PVs['Cam1SizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeX_RBV') global_PVs['Cam1SizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeY_RBV') global_PVs['Cam1MaxSizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeX_RBV') global_PVs['Cam1MaxSizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeY_RBV') global_PVs['Cam1PixelFormat_RBV'] = PV(params.camera_ioc_prefix + 'cam1:PixelFormat_RBV') global_PVs['Cam1Image'] = PV(params.camera_ioc_prefix + 'image1:ArrayData') # hdf5 writer PV's global_PVs['HDFAutoSave'] = PV(params.camera_ioc_prefix + 'HDF1:AutoSave') global_PVs['HDFDeleteDriverFile'] = PV(params.camera_ioc_prefix + 'HDF1:DeleteDriverFile') global_PVs['HDFEnableCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:EnableCallbacks') global_PVs['HDFBlockingCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:BlockingCallbacks') global_PVs['HDFFileWriteMode'] = PV(params.camera_ioc_prefix + 'HDF1:FileWriteMode') global_PVs['HDFNumCapture'] = PV(params.camera_ioc_prefix + 'HDF1:NumCapture') global_PVs['HDFCapture'] = PV(params.camera_ioc_prefix + 'HDF1:Capture') global_PVs['HDFCapture_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:Capture_RBV') global_PVs['HDFFilePath'] = PV(params.camera_ioc_prefix + 'HDF1:FilePath') global_PVs['HDFFileName'] = PV(params.camera_ioc_prefix + 'HDF1:FileName') global_PVs['HDFFullFileName_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:FullFileName_RBV') global_PVs['HDFFileTemplate'] = PV(params.camera_ioc_prefix + 'HDF1:FileTemplate') global_PVs['HDFArrayPort'] = PV(params.camera_ioc_prefix + 'HDF1:NDArrayPort') global_PVs['HDFFileNumber'] = PV(params.camera_ioc_prefix + 'HDF1:FileNumber') global_PVs['HDFXMLFileName'] = PV(params.camera_ioc_prefix + 'HDF1:XMLFileName') global_PVs['HDFQueueSize'] = PV(params.camera_ioc_prefix + 'HDF1:QueueSize') global_PVs['HDFQueueFree'] = PV(params.camera_ioc_prefix + 'HDF1:QueueFree') # proc1 PV's global_PVs['Image1EnableCallbacks'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Proc1nableCallbacks'] = PV(params.camera_ioc_prefix + 'Proc1:EnableCallbacks') global_PVs['Proc1NDArrayPort'] = PV(params.camera_ioc_prefix + 'Proc1:NDArrayPort') global_PVs['Proc1EnableFilter'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFilter') global_PVs['Proc1FilterType'] = PV(params.camera_ioc_prefix + 'Proc1:FilterType') global_PVs['Proc1Num_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:NumFilter') global_PVs['Proc1ResetFilter'] = PV(params.camera_ioc_prefix + 'Proc1:ResetFilter') global_PVs['Proc1AutoResetFilter'] = PV(params.camera_ioc_prefix + 'Proc1:AutoResetFilter') global_PVs['Proc1FilterCallbacks'] = PV(params.camera_ioc_prefix + 'Proc1:FilterCallbacks') global_PVs['Proc1EnableBackground'] = PV(params.camera_ioc_prefix + 'Proc1:EnableBackground') global_PVs['Proc1EnableFlatField'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFlatField') global_PVs['Proc1EnableOffsetScale'] = PV(params.camera_ioc_prefix + 'Proc1:EnableOffsetScale') global_PVs['Proc1EnableLowClip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableLowClip') global_PVs['Proc1EnableHighClip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableHighClip') if (params.camera_ioc_prefix == '2bmbPG3:'): global_PVs['Cam1FrameRateOnOff'] = PV(params.camera_ioc_prefix + 'cam1:FrameRateOnOff') elif (params.camera_ioc_prefix == '2bmbSP1:'): global_PVs['Cam1AcquireTimeAuto'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTimeAuto') global_PVs['Cam1FrameRateOnOff'] = PV(params.camera_ioc_prefix + 'cam1:FrameRateEnable') global_PVs['Cam1TriggerSource'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSource') global_PVs['Cam1TriggerOverlap'] = PV(params.camera_ioc_prefix + 'cam1:TriggerOverlap') global_PVs['Cam1ExposureMode'] = PV(params.camera_ioc_prefix + 'cam1:ExposureMode') global_PVs['Cam1TriggerSelector'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSelector') global_PVs['Cam1TriggerActivation'] = PV(params.camera_ioc_prefix + 'cam1:TriggerActivation') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return None return global_PVs
def move_sample_in(global_PVs, params): log.info(' *** Sample in') if not (params.sample_move_freeze): if (params.flat_field_axis == "vertical"): log.info(' *** *** Move Sample Y in at: %f' % params.sample_in_y) global_PVs['SampleY'].put(str(params.sample_in_y), wait=True, timeout=1000.0) if wait_pv(global_PVs['SampleY'], float(params.sample_in_y), 60) == False: log.error('SampleY did not move in properly') log.error(global_PVs['SampleY'].get()) else: log.info(' *** *** Move Sample X in at: %f' % params.sample_in_x) global_PVs['SampleX'].put(str(params.sample_in_x), wait=True, timeout=1000.0) if wait_pv(global_PVs['SampleX'], float(params.sample_in_x), 60) == False: log.error('SampleX did not move in properly') log.error(global_PVs['SampleX'].get()) if (params.use_furnace): log.info(' *** *** Move Furnace Y in at: %f' % params.furnace_in_position) global_PVs['Motor_FurnaceY'].put(str( params.furnace_in_position), wait=True, timeout=1000.0) if wait_pv(global_PVs['Motor_FurnaceY'], float(params.furnace_in_position), 60) == False: log.error('Motor_FurnaceY did not move in properly') log.error(global_PVs['Motor_FurnaceY'].get()) else: log.info(' *** *** Sample Stack is Frozen')
def adjust_center(params, dark_field, white_field): global_PVs = aps2bm.init_general_PVs(params) log.warning(' *** Adjusting center ***') for ang in [params.adjust_center_angle_1, params.adjust_center_angle_2]: log.warning(' *** take 3 spheres angular %f deg ***' % float(ang)) #sphere 0 log.info(' *** sphere 0') log.info(' *** *** moving rotary stage to %f deg position ***' % float(0)) global_PVs["Motor_SampleRot"].put(float(0), wait=True, timeout=600.0) log.error(' *** *** acquire sphere at %f deg position ***' % float(0)) sphere_0 = util.normalize(flir.take_image(global_PVs, params), white_field, dark_field) #sphere 1 log.info(' *** sphere 1') log.info(' *** *** moving rotary stage to %f deg position ***' % float(ang)) global_PVs["Motor_SampleRot"].put(float(ang), wait=True, timeout=600.0) log.error(' *** *** acquire sphere at %f deg position ***' % float(ang)) sphere_1 = util.normalize(flir.take_image(global_PVs, params), white_field, dark_field) #sphere 2 log.info(' *** sphere 2') log.info(' *** *** moving rotary stage to %f deg position ***' % float(2 * ang)) global_PVs["Motor_SampleRot"].put(float(2 * ang), wait=True, timeout=600.0) log.error(' *** *** acquire sphere at %f deg position ***' % float(2 * ang)) sphere_2 = util.normalize(flir.take_image(global_PVs, params), white_field, dark_field) # find shifts shift0 = register_translation(sphere_1, sphere_0, 100)[0][1] shift1 = register_translation(sphere_2, sphere_1, 100)[0][1] a = ang * np.pi / 180 # x=-(1/4) (d1+d2-2 d1 Cos[a]) Csc[a/2]^2, x = -(1 / 4) * (shift0 + shift1 - 2 * shift0 * np.cos(a)) * 1 / np.sin( a / 2)**2 # r = 1/2 Csc[a/2]^2 Csc[a] Sqrt[(d1^2+d2^2-2 d1 d2 Cos[a]) Sin[a/2]^2] r = 1 / 2 * 1 / np.sin(a / 2)**2 * 1 / np.sin(a) * np.sqrt( np.abs((shift0**2 + shift1**2 - 2 * shift0 * shift1 * np.cos(a)) * np.sin(a / 2)**2)) # g = ArcCos[((-d1-d2+2 d1 Cos[a]) Sin[a])/(2 Sqrt[(d1^2+d2^2-2 d1 d2 Cos[a]) Sin[a/2]^2])] g = np.arccos( ((-shift0 - shift1 + 2 * shift0 * np.cos(a)) * np.sin(a)) / (2 * np.sqrt( np.abs( (shift0**2 + shift1**2 - 2 * shift0 * shift1 * np.cos(a)) * np.sin(a / 2)**2)))) y = r * np.sin(g) * np.sign(shift0) # find center of mass cmass_0 = util.center_of_mass(sphere_0) log.info(' ') log.info( ' *** position of the initial sphere wrt to the rotation center (%f,%f) ***' % (x, y)) log.info(' *** center of mass for the initial sphere (%f,%f) ***' % (cmass_0[1], cmass_0[0])) log.info( ' *** moving sphere to the position of the rotation center ***') if (params.ask): if util.yes_or_no(' *** Yes or No'): move_center(params, cmass_0, x, y) check_center(params, white_field, dark_field) else: log.warning(' No motion ') exit() else: move_center(params, cmass_0, x, y) check_center(params, white_field, dark_field)
def calc_blur_pixel(global_PVs, params): """ Calculate the blur error (pixel units) due to a rotary stage fly scan motion durng the exposure. Parameters ---------- params.exposure_time: float Detector exposure time params.ccd_readout : float Detector read out time variableDict[''roiSizeX''] : int Detector X size params.sample_rotation_end : float Tomographic scan angle end params.sample_rotation_start : float Tomographic scan angle start variableDict[''Projections'] : int Numember of projections Returns ------- float Blur error in pixel. For good quality reconstruction this should be < 0.2 pixel. """ angular_range = params.sample_rotation_end - params.sample_rotation_start angular_step = angular_range/params.num_projections min_scan_time = params.num_projections * (params.exposure_time + params.ccd_readout) max_rot_speed = angular_range / min_scan_time max_blur_delta = params.exposure_time * max_rot_speed mid_detector = global_PVs['Cam1_MaxSizeX_RBV'].get() / 2.0 max_blur_pixel = mid_detector * np.sin(max_blur_delta * np.pi /180.) max_frame_rate = params.num_projections / min_scan_time rot_speed = max_rot_speed * params.rotation_slow_factor scan_time = angular_range / rot_speed blur_delta = params.exposure_time * rot_speed mid_detector = global_PVs['Cam1_MaxSizeX_RBV'].get() / 2.0 blur_pixel = mid_detector * np.sin(blur_delta * np.pi /180.) frame_rate = params.num_projections / scan_time log.info(' ') log.info(' *** Calc blur pixel') log.info(" *** *** Total # of proj: %s " % params.num_projections) log.info(" *** *** Exposure Time: %s s" % params.exposure_time) log.info(" *** *** Readout Time: %s s" % params.ccd_readout) log.info(" *** *** Angular Range: %s degrees" % angular_range) log.info(" *** *** Camera X size: %s " % global_PVs['Cam1_SizeX'].get()) log.info(' ') log.info(" *** *** *** *** Angular Step: %4.2f degrees" % angular_step) log.info(" *** *** *** *** Scan Time: %4.2f (min %4.2f) s" % (scan_time, min_scan_time)) log.info(" *** *** *** *** Rot Speed: %4.2f (max %4.2f) degrees/s" % (rot_speed, max_rot_speed)) log.info(" *** *** *** *** Rot Speed Reduced to: %4.2f %%" % (params.rotation_slow_factor *100.)) log.info(" *** *** *** *** Frame Rate: %4.2f (max %4.2f) fps" % (frame_rate, max_frame_rate)) if (blur_pixel > 1): log.error(" *** *** *** *** Blur: %4.2f (max %4.2f) pixels" % (blur_pixel, max_blur_pixel)) else: log.info(" *** *** *** *** Blur: %4.2f (max %4.2f) pixels" % (blur_pixel, max_blur_pixel)) log.info(' *** Calc blur pixel: Done!') return rot_speed
def fly_scan_mosaic(params): tic = time.time() global_PVs = aps2bm.init_general_PVs(params) aps2bm.user_info_params_update_from_pv(global_PVs, params) try: detector_sn = global_PVs['Cam1_SerialNumber'].get() if ((detector_sn == None) or (detector_sn == 'Unknown')): log.info('*** The Point Grey Camera with EPICS IOC prefix %s is down' % params.camera_ioc_prefix) log.info(' *** Failed!') else: log.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \ % (params.camera_ioc_prefix, detector_sn)) # calling global_PVs['Cam1_AcquireTime'] to replace the default 'ExposureTime' with the one set in the camera params.exposure_time = global_PVs['Cam1_AcquireTime'].get() # calling calc_blur_pixel() to replace the default 'SlewSpeed' rot_speed = calc_blur_pixel(global_PVs, params) params.slew_speed = rot_speed start_y = params.vertical_scan_start end_y = params.vertical_scan_end step_size_y = params.vertical_scan_step_size start_x = params.horizontal_scan_start end_x = params.horizontal_scan_end step_size_x = params.horizontal_scan_step_size # set scan stop so also ends are included stop_x = end_x + step_size_x stop_y = end_y + step_size_y # init camera flir.init(global_PVs, params) log.info(' ') log.info(" *** Running %d sleep scans" % params.sleep_steps) for ii in np.arange(0, params.sleep_steps, 1): tic_01 = time.time() log.info(' ') log.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.info(' ') log.info(' *** Horizontal Positions (mm): %s' % np.arange(start_x, stop_x, step_size_x)) log.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.info(' ') log.error(' *** 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.error(' *** The sample horizontal position is at %s mm' % (j)) params.sample_in_position = j params.scan_counter = global_PVs['HDF1_FileNumber'].get() # set sample file name params.file_path = global_PVs['HDF1_FilePath'].get(as_string=True) params.file_name = str('{:03}'.format(global_PVs['HDF1_FileNumber'].get())) + '_' + global_PVs['Sample_Name'].get(as_string=True) + '_y' + str(v) + '_x' + str(h) tomo_fly_scan(global_PVs, params) h = h + 1 dm.scp(global_PVs, params) log.info(' ') log.info(' *** Total scan time: %s minutes' % str((time.time() - tic)/60.)) log.info(' *** Data file: %s' % global_PVs['HDF1_FullFileName_RBV'].get(as_string=True)) v = v + 1 h = 0 log.info(' *** Moving vertical stage to start position') global_PVs['Motor_SampleY'].put(start_y, wait=True, timeout=1000.0) log.info(' *** Moving horizontal stage to start position') global_PVs['Motor_SampleX'].put(start_x, wait=True, timeout=1000.0) log.info(' *** Moving rotary stage to start position') global_PVs["Motor_SampleRot"].put(params.sample_rotation_start, wait=True, timeout=600.0) log.info(' *** Moving rotary stage to start position: Done!') if ((ii+1)!=params.sleep_steps): log.warning(' *** Wait (s): %s ' % str(params.sleep_time)) time.sleep(params.sleep_time) global_PVs['Cam1_ImageMode'].put('Continuous') log.info(' *** Done!') except KeyError: log.error(' *** Some PV assignment failed!') pass