def fly(global_PVs, params): angular_range = params.sample_rotation_end - params.sample_rotation_start flyscan_time_estimate = angular_range / params.slew_speed log.warning(' *** Fly Scan Time Estimate: %4.2f minutes' % (flyscan_time_estimate/60.)) #Trigger fly motion to start. Don't wait for it, since it takes time. start_time = time.time() driver.motor.move(motor_end, wait=False) time.sleep(1) old_image_counter = 0 expected_framerate = driver.motor.slew_speed / delta_egu #Monitor the motion to make sure we aren't stuck. i = 0 while time.time() - start_time < 1.5 * flyscan_time_estimate: i += 1 if i % 10 == 0: log.info(' *** *** Sample rotation at angle {:f}'.format(driver.motor.readback)) time.sleep(1) if not driver.motor.moving: log.info(' *** *** Sample rotation stopped moving.') if abs(driver.motor.drive - motor_end) > 1e-2: log.error(' *** *** Sample rotation ended but not at right position!') raise ValueError else: log.info(' *** *** Stopped at correct position.') break #Make sure we're actually getting frames. current_image_counter = global_PVs['Cam1_NumImagesCounter'].get() if current_image_counter - old_image_counter < 0.2 * expected_framerate: log.error(' *** *** Not collecting frames!') raise ValueError else: old_image_counter = current_image_counter else: log.warning(' *** *** Fly motion timed out!') raise ValueError
def find_roll_and_rotation_axis_location(params): global_PVs = aps7bm.init_general_PVs(params) params.file_name = None # so we don't run the flir._setup_hdf_writer try: if not scan.check_camera_IOC(global_PVs, params): return False flir.init(global_PVs, params) flir.set(global_PVs, params) sphere_0, sphere_180 = take_sphere_0_180(global_PVs, params) cmass_0 = center_of_mass(sphere_0) cmass_180 = center_of_mass(sphere_180) params.rotation_axis_position = (cmass_180[1] + cmass_0[1]) / 2.0 log.info(' *** shift (center of mass): [%f, %f]' % ((cmass_180[0] - cmass_0[0]), (cmass_180[1] - cmass_0[1]))) params.roll = np.rad2deg( np.arctan( (cmass_180[0] - cmass_0[0]) / (cmass_180[1] - cmass_0[1]))) log.info(" *** roll:%f" % (params.roll)) config.update_sphere(params) return params.rotation_axis_position, params.roll except KeyError: log.error(' *** Some PV assignment failed!') pass
def set(global_PVs, params): '''Sets up detector and arms it for PSO pulses. ''' fname = params.file_name # Set detectors if params.camera_ioc_prefix in params.valid_camera_prefixes: log.info(' ') log.info(' *** setup Point Grey') # Make sure that we aren't acquiring now global_PVs['Cam1_Acquire'].put(DetectorIdle) aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorIdle) #Set up the XML files to determine HDF file layout attrib_file = Path.joinpath( Path(__file__).parent, 'mctDetectorAttributes1.xml') global_PVs['Cam1_AttributeFile'].put(str(attrib_file), wait=True) layout_file = Path.joinpath(Path(__file__).parent, 'mct3.xml') global_PVs['HDF1_XMLFileName'].put(str(layout_file), wait=True) global_PVs['Cam1_ArrayCallbacks'].put('Enable', wait=True) global_PVs['Cam1_AcquirePeriod'].put(float(params.exposure_time), wait=True) global_PVs['Cam1_AcquireTime'].put(float(params.exposure_time), wait=True) log.info(' *** setup Point Grey: Done!') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return if params.file_name is None: log.warning(' *** hdf_writer will not be configured') else: _setup_hdf_writer(global_PVs, params, fname)
def stop_scan(global_PVs, params): log.info(' ') log.error(' *** Stopping the scan: PLEASE WAIT') aps7bm.close_shutters(global_PVs, params) global_PVs['Motor_SampleRot'].stop() global_PVs['HDF1_Capture'].put(0) aps7bm.wait_pv(global_PVs['HDF1_Capture'], 0) pso.cleanup_PSO() flir.init(global_PVs, params) log.error(' *** Stopping scan: Done!')
def _setup_hdf_writer(global_PVs, params, fname=None): if params.camera_ioc_prefix in params.valid_camera_prefixes: # 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['Cam1_AsynPort'].get(), wait=True) global_PVs['HDF1_AutoSave'].put('Yes') global_PVs['HDF1_DeleteDriverFile'].put('No') global_PVs['HDF1_EnableCallbacks'].put('Enable', wait=True) global_PVs['HDF1_BlockingCallbacks'].put('No') totalProj = (int(params.num_projections) + int(params.num_dark_images) + int(params.num_white_images)) global_PVs['HDF1_NumCapture'].put(totalProj, wait=True) global_PVs['HDF1_ExtraDimSizeN'].put(totalProj, wait=True) 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) aps7bm.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 fly_scan(params): '''Perform potentially repeated fly scan. ''' tic = time.time() global_PVs = aps7bm.init_general_PVs(params) try: if not check_camera_IOC(global_PVs, params): return False # Set the slew speed, possibly based on blur and acquisition parameters set_slew_speed(global_PVs, params) # init camera flir.init(global_PVs, params) log.info(' ') log.info(" *** Running %d sleep scans" % params.sleep_steps) for i in np.arange(params.sleep_steps): tic_01 = time.time() # 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) log.info(' ') log.info(' *** Start scan {:d} of {:d}'.format( int(i + 1), int(params.sleep_steps))) 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.)) global_PVs['Cam1_ImageMode'].put('Continuous') log.info(' *** Done!') except KeyError: log.error(' *** Some PV assignment failed!') except Exception as ee: stop_scan(global_PVs, params) log.info(' Exception recorded: ' + str(ee))
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.info(args.file_path) log.info(args.file_name) log_fname = str(Path.joinpath(Path(args.file_path), 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))
def dummy_scan(params): tic = time.time() # aps7bm.update_variable_dict(params) global_PVs = aps7bm.init_general_PVs(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 acquire_dark(global_PVs, params): log.info(' *** Dark Fields') # Make sure that we aren't acquiring now global_PVs['Cam1_Acquire'].put(DetectorIdle) aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorIdle) global_PVs['Cam1_ImageMode'].put('Multiple', wait=True) global_PVs['Cam1_FrameType'].put(FrameTypeDark, wait=True) global_PVs['Cam1_TriggerMode'].put('Internal', wait=True) num_images = int( params.num_white_images) * params.recursive_filter_n_images global_PVs['Cam1_NumImages'].put(num_images, wait=True) wait_time = int(num_images) * params.exposure_time + 5 global_PVs['Cam1_Acquire'].put(DetectorAcquire) time.sleep(1.0) if aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorIdle, wait_time): log.info(' *** Dark Fields: Done!') else: log.error(' *** *** Timeout.') raise Exception
def find_tilt_rotation_axis(params): global_PVs = aps7bm.init_general_PVs(params) params.file_name = None # so we don't run the flir._setup_hdf_writer try: if not scan.check_camera_IOC(global_PVs, params): return False flir.init(global_PVs, params) flir.set(global_PVs, params) sphere_0, sphere_180 = take_sphere_0_180(global_PVs, params) sphere_180_flip = sphere_180[..., ::-1] #Find pixel shift between images log.info(' *** Calculating shift. This will take a minute.') shifts, error, phasediff = register_translation( sphere_0, sphere_180_flip, 10) log.info(' *** Calculated shift is ({0:6.4f}, {1:6.4f})'.format( shifts[0], shifts[1])) overall_res = float(global_PVs['PixelSizeMicrons'].get()) / float( params.lens_magnification) log.info(' *** Rotation axis off by {0:6.4} mm'.format( shifts[1] * overall_res / 2e3)) log.info(' *** Move SampleX by {0:6.4} mm'.format(shifts[1] * overall_res / 2e3)) log.info(' *** Shift in Y = {0:6.4} microns'.format(shifts[0] * overall_res)) tilt_angle = np.degrees(shifts[0] * overall_res / 25.4 / 1e3) log.info(' *** Equivalent to {0:6.4} deg'.format(tilt_angle)) #Plot the shifted image sphere_1 = np.roll(sphere_180_flip, (int(shifts[0]), int(shifts[1])), axis=(0, 1)) plt.figure(2) plt.imshow((sphere_0 - sphere_1)[abs(int(shifts[0])):, abs(int(shifts[1])):], vmin=-0.1, vmax=0.1) plt.colorbar() plt.title('Difference image after shift') plt.show() return 0, 0 except KeyError: log.error(' *** Some PV assignment failed!')
def checkclose_hdf(global_PVs, params): ''' Check if the HDF5 file has closed. Will wait for data to flush to disk. ''' buffer_queue = global_PVs['HDF1_QueueSize'].get( ) - global_PVs['HDF1_QueueFree'].get() frate = 55.0 wait_on_hdd = buffer_queue / frate + 10 log.info(' *** Buffer Queue (frames): %d ' % buffer_queue) log.info(' *** Wait HDD (s): %f' % wait_on_hdd) if aps7bm.wait_pv( global_PVs["HDF1_Capture_RBV"], 0, wait_on_hdd ) == False: # needs to wait for HDF plugin queue to dump to disk global_PVs["HDF1_Capture"].put(0) log.info(' *** File was not closed => forced to close') log.info(' *** before %d' % global_PVs["HDF1_Capture_RBV"].get()) aps7bm.wait_pv(global_PVs["HDF1_Capture_RBV"], 0, 5) log.info(' *** after %d' % global_PVs["HDF1_Capture_RBV"].get()) if (global_PVs["HDF1_Capture_RBV"].get() == 1): log.error( ' *** ERROR HDF FILE DID NOT CLOSE; add_theta will fail')
def move_sample_in(global_PVs, params): log.info(' *** Sample in') if params.sample_move_freeze: log.info(' *** *** Sample motion is frozen.') return try: #If we haven't saved original positions yet, use the current ones. try: _ = params.original_x _ = params.original_y except AttributeError: params.original_x = global_PVs['Motor_SampleX'].drive params.original_y = global_PVs['Motor_SampleY'].drive log.info(' *** Moving to (x,y) = ({0:6.4f}, {1:6.4f})'.format( params.original_x, params.original_y)) #Check the limits if not (global_PVs['Motor_SampleX'].within_limits(params.original_x) and global_PVs['Motor_SampleY'].within_limits( params.original_y)): log.error(' *** *** Sample in position past motor limits.') return global_PVs['Motor_SampleX'].move(params.original_x, wait=True, timeout=10) global_PVs['Motor_SampleY'].move(params.original_y, wait=True, timeout=10) #Check if we ever got there if (abs(global_PVs['Motor_SampleX'].readback - params.original_x) > 1e-3 or abs(global_PVs['Motor_SampleY'].readback - params.original_y) > 1e-3): log.error(' *** *** Sample in motion failed!') except Exception as ee: log.error('EXCEPTION DURING SAMPLE IN MOTION!') raise ee
def move_sample_out(global_PVs, params): log.info(' *** Sample out') if params.sample_move_freeze: log.info(' *** *** Sample motion is frozen.') return params.original_x = global_PVs['Motor_SampleX'].drive params.original_y = global_PVs['Motor_SampleY'].drive try: #Check the limits out_x = params.sample_out_x out_y = params.sample_out_y log.info(' *** Moving to (x,y) = ({0:6.4f}, {1:6.4f})'.format( out_x, out_y)) if not (global_PVs['Motor_SampleX'].within_limits(out_x) and global_PVs['Motor_SampleY'].within_limits(out_y)): log.error(' *** *** Sample out position past motor limits.') return global_PVs['Motor_SampleX'].move(out_x, wait=True, timeout=10) global_PVs['Motor_SampleY'].move(out_y, wait=True, timeout=10) #Check if we ever got there time.sleep(0.2) if (abs(global_PVs['Motor_SampleX'].readback - out_x) > 1e-3 or abs(global_PVs['Motor_SampleY'].readback - out_y) > 1e-3): log.error(' *** *** Sample out motion failed!') except Exception as ee: log.error('EXCEPTION DURING SAMPLE OUT MOTION!') global_PVs['Motor_SampleX'].move(params.original_x, wait=True, timeout=10) global_PVs['Motor_SampleY'].move(params.original_y, wait=True, timeout=10) raise ee
def wait_pv(pv, wait_val, max_timeout_sec=-1): ''' Wait on a PV to reach a value. max_timeout_sec is an optional timeout time. ''' 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_vertical(params): tic = time.time() # aps7bm.update_variable_dict(params) global_PVsx = aps7bm.init_general_PVs(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' blur_pixel, rot_speed, scan_time = 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 # init camera flir.init(global_PVs, params) log.info(' ') log.info(" *** Running %d scans" % params.sleep_steps) log.info(' ') log.info(' *** Vertical Positions (mm): %s' % np.arange(start_y, end_y, step_size_y)) for ii in np.arange(0, params.sleep_steps, 1): log.info(' ') log.info(' *** Start scan %d' % ii) for i in np.arange(start_y, end_y, step_size_y): tic_01 = time.time() # 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) log.info(' ') log.info(' *** The sample vertical position is at %s mm' % (i)) global_PVs['Motor_SampleY'].put(i, wait=True, timeout=1000.0) tomo_fly_scan(global_PVs, params) 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(' *** Moving vertical stage to start position') global_PVs['Motor_SampleY'].put(start_y, wait=True, timeout=1000.0) if ((ii + 1) != params.sleep_steps): log.warning(' *** Wait (s): %s ' % str(params.sleep_time)) time.sleep(params.sleep_time) 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(0, 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 init_general_PVs(params): '''Initialize epics PV objects. ''' global_PVs = {} log.info('Creating PV objects.') # shutter pv's global_PVs['ShutterA_Open'] = PV('7bma1:rShtrA:Open') global_PVs['ShutterA_Close'] = PV('7bma1:rShtrA:Close') global_PVs['ShutterA_Move_Status'] = PV('PB:07BM:STA_A_FES_CLSD_PL.VAL') # Experimment Info global_PVs['Sample_Name'] = PV('7bmb1:ExpInfo:SampleName') global_PVs['Sample_Description'] = PV( '7bmb1:ExpInfo:SampleDescription.VAL') global_PVs['User_Badge'] = PV('7bmb1:ExpInfo:UserBadge.VAL') global_PVs['User_Email'] = PV('7bmb1:ExpInfo:UserEmail.VAL') global_PVs['User_Institution'] = PV('7bmb1:ExpInfo:UserInstitution.VAL') global_PVs['Proposal_Number'] = PV('7bmb1:ExpInfo:ProposalNumber.VAL') global_PVs['Proposal_Title'] = PV('7bmb1:ExpInfo:ProposalTitle.VAL') global_PVs['User_Info_Update'] = PV('7bmb1:ExpInfo:UserInfoUpdate.VAL') global_PVs['Lens_Magnification'] = PV('7bmb1:ExpInfo:LensMagFloat.VAL') global_PVs['Scintillator_Type'] = PV('7bmb1:ExpInfo:ScintillatorType.VAL') global_PVs['Scintillator_Thickness'] = PV( '7bmb1:ExpInfo:ScintillatorThickness.VAL') global_PVs['Camera_IOC_Prefix'] = PV('7bmb1:ExpInfo:CameraIOCPrefix.VAL') global_PVs['PixelSizeMicrons'] = PV('7bmb1:ExpInfo:PixelSizeum.VAL') global_PVs['Filters'] = PV('7bmb1:ExpInfo:Filters.VAL') global_PVs['File_Name'] = PV('7bmb1:ExpInfo:FileName.VAL') global_PVs['Station'] = PV('7bmb1:ExpInfo:Station.VAL') global_PVs['Remote_Data_Trasfer'] = PV( '7bmb1:ExpInfo:RemoteDataTrasfer.VAL') global_PVs['Remote_Analysis_Dir'] = PV( '7bmb1:ExpInfo:RemoteAnalysisDir.VAL') global_PVs['User_Last_Name'] = PV('7bmb1:ExpInfo:UserLastName.VAL') global_PVs['Experiment_Year_Month'] = PV( '7bmb1:ExpInfo:ExperimentYearMonth.VAL') global_PVs['Use_Furnace'] = PV('7bmb1:ExpInfo:UseFurnace.VAL') global_PVs['White_Field_Motion'] = PV('7bmb1:ExpInfo:WhiteFieldMotion.VAL') global_PVs['Num_White_Images'] = PV('7bmb1:ExpInfo:NumWhiteImages.VAL') global_PVs['Bright_Exp_Time'] = PV('7bmb1:ExpInfo:BrightExposureTime.VAL') global_PVs['Sample_Detector_Distance'] = PV( '7bmb1:ExpInfo:SampleDetectorDistance.VAL') global_PVs['Sample_Out_Position_Y'] = PV( '7bmb1:ExpInfo:SampleOutPositionY.VAL') global_PVs['Sample_Out_Position_X'] = PV( '7bmb1:ExpInfo:SampleOutPositionX.VAL') global_PVs['Num_Projections'] = PV('7bmb1:ExpInfo:NumProjections.VAL') global_PVs['Sample_Rotation_Start'] = PV( '7bmb1:ExpInfo:SampleRotationStart.VAL') global_PVs['Sample_Rotation_End'] = PV( '7bmb1:ExpInfo:SampleRotationEnd.VAL') global_PVs['Sample_Rotation_Speed'] = PV( '7bmb1:ExpInfo:SampleRotationSpeed.VAL') global_PVs['Sample_Retrace_Speed'] = PV('7bmb1:ExpInfo:RetraceSpeed.VAL') global_PVs['Furnace_In_Position'] = PV( '7bmb1:ExpInfo:FurnaceInPosition.VAL') global_PVs['Furnace_Out_Position'] = PV( '7bmb1:ExpInfo:FurnaceOutPosition.VAL') global_PVs['Scan_Type'] = PV('7bmb1:ExpInfo:ScanType.VAL') global_PVs['Sleep_Time'] = PV('7bmb1:ExpInfo:SleepTime.VAL') global_PVs['Scan_Replicates'] = PV('7bmb1:ExpInfo:ScanReplicates.VAL') global_PVs['Vertical_Scan_Start'] = PV( '7bmb1:ExpInfo:VerticalScanStart.VAL') global_PVs['Vertical_Scan_End'] = PV('7bmb1:ExpInfo:VerticalScanEnd.VAL') global_PVs['Vertical_Scan_Step_Size'] = PV( '7bmb1:ExpInfo:VerticalScanStepSize.VAL') global_PVs['Horizontal_Scan_Start'] = PV( '7bmb1:ExpInfo:HorizontalScanStart.VAL') global_PVs['Horizontal_Scan_End'] = PV( '7bmb1:ExpInfo:HorizontalScanEnd.VAL') global_PVs['Horizontal_Scan_Step_Size'] = PV( '7bmb1:ExpInfo:HorizontalScanStepSize.VAL') params.station = global_PVs['Station'].get(as_string=True) log.info('Running in station {:s}.'.format(params.station)) if params.station == '7-BM-B': log.info('*** Running in station 7-BM-B:') # Set sample stack motor: global_PVs['Motor_SampleX'] = Motor('7bmb1:aero:m2') global_PVs['Motor_SampleY'] = Motor('7bmb1:aero:m1') global_PVs['Motor_SampleRot'] = Motor( '7bmb1:aero:m3') # Aerotech ABR-250 global_PVs['Motor_Focus'] = Motor('7bmb1:m38') else: log.error('*** %s is not a valid station' % params.station) # detector pv's params.valid_camera_prefixes = [ '7bm_pg1:', '7bm_pg2:', '7bm_pg3:', '7bm_pg4:' ] params.camera_ioc_prefix = global_PVs['Camera_IOC_Prefix'].get( as_string=True) if params.camera_ioc_prefix[-1] != ':': params.camera_ioc_prefix = params.camera_ioc_prefix + ':' log.info('Using camera IOC with prefix {:s}'.format( params.camera_ioc_prefix)) if params.camera_ioc_prefix in params.valid_camera_prefixes: update_pixel_size(global_PVs, params) # init Point Grey PV's # general PV's global_PVs['Cam1_SerialNumber'] = PV(params.camera_ioc_prefix + 'cam1:SerialNumber') global_PVs['Cam1_AsynPort'] = PV(params.camera_ioc_prefix + 'cam1:PortName_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_NumImagesCounter'] = PV(params.camera_ioc_prefix + 'cam1:NumImagesCounter_RBV') 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_Dtype'] = PV(params.camera_ioc_prefix + 'image1:DataType_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_ExtraDimSizeN'] = PV(params.camera_ioc_prefix + 'HDF1:ExtraDimSizeN') 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') 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 global TESTING TESTING = params.testing user_info_update(global_PVs, params) if params.update_from_PVs: update_params_from_PVs(global_PVs, params) return global_PVs
def find_resolution(params): log.info('find resolution') global_PVs = aps7bm.init_general_PVs(params) aps7bm.user_info_update(global_PVs, params) params.file_name = None # so we don't run the flir._setup_hdf_writer try: if not scan.check_camera_IOC(global_PVs, params): return False flir.init(global_PVs, params) flir.set(global_PVs, params) dark_field, white_field = flir.take_dark_and_white( global_PVs, params, True) start_position = global_PVs["Motor_SampleX"].drive log.info(' *** First image at X: %f mm' % (start_position)) log.info(' *** acquire first image') sphere_0 = flir.take_image(global_PVs, params) second_image_x_position = start_position + params.off_axis_position log.info(' *** Second image at X: %f mm' % (second_image_x_position)) global_PVs["Motor_SampleX"].move(second_image_x_position, wait=True, timeout=600.0) time.sleep(0.5) log.info(' *** acquire second image') sphere_1 = flir.take_image(global_PVs, params) log.info(' *** moving X stage back to %f mm position' % (start_position)) aps7bm.close_shutters(global_PVs, params) global_PVs["Motor_SampleX"].move(start_position, wait=True) sphere_0 = normalize(sphere_0, white_field, dark_field) sphere_1 = normalize(sphere_1, white_field, dark_field) log.info(' *** images normalized and unsharp masked') plt.imshow(sphere_0 - sphere_1) #, vmin=-4, vmax=4) plt.colorbar() plt.title('Difference image 1 - 2') #Find pixel shift between images log.info(' *** Calculating shift. This will take a minute.') shifts, error, phasediff = register_translation(sphere_0, sphere_1, 10) log.info(' *** Calculated shift is ({0:6.4f}, {1:6.4f})'.format( shifts[0], shifts[1])) total_shift = np.hypot(shifts[0], shifts[1]) log.info(' *** total shift {:6.4f} pixels'.format(total_shift)) pixel_size = float(global_PVs['PixelSizeMicrons'].get()) log.info(' *** pixel size = {:6.4f} microns'.format(pixel_size)) params.lens_magnification = abs( float(total_shift) * pixel_size / params.off_axis_position / 1e3) if params.auto_magnification: global_PVs['Lens_Magnification'].put(params.lens_magnification) #Plot the shifted image sphere_1 = np.roll(sphere_1, (int(shifts[0]), int(shifts[1])), axis=(0, 1)) plt.figure(2) plt.imshow((sphere_0 - sphere_1)[abs(int(shifts[0])):, abs(int(shifts[1])):]) plt.colorbar() plt.title('Difference image after shift') plt.show() config.update_sphere(params) return params.resolution except KeyError: log.error(' *** Some PV assignment failed!') pass