def take_image(global_PVs, params): log.info(' *** taking a single image') nRow = global_PVs['Cam1_SizeY_RBV'].get() nCol = global_PVs['Cam1_SizeX_RBV'].get() image_size = nRow * nCol global_PVs['Cam1_ImageMode'].put('Single', wait=True) global_PVs['Cam1_NumImages'].put(1, wait=True) global_PVs['Cam1_TriggerMode'].put('Internal', wait=True) wait_time_sec = int(params.exposure_time) + 5 global_PVs['Cam1_Acquire'].put(DetectorAcquire, wait=True, timeout=1000.0) time.sleep(0.1) if aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorIdle, wait_time_sec) == False: # adjust wait time global_PVs['Cam1_Acquire'].put(DetectorIdle) log.warning( 'The camera failed to finish acquisition. Set to done manually.') # Get the image loaded in memory img_vect = global_PVs['Cam1_Image'].get(count=image_size) if global_PVs['Cam1_Image_Dtype'].get(as_string=True) == 'UInt16': img_vect = img_vect.astype(np.uint16) img = np.reshape(img_vect, [nRow, nCol]) return img
def update_params_from_PVs(global_PVs, params): '''Update values of params to values from global_PVs. ''' log.info(' *** Updating parameters from PVs') params.num_white_images = global_PVs['Num_White_Images'].get() params.num_dark_images = global_PVs['Num_White_Images'].get() params.sleep_steps = global_PVs['Scan_Replicates'].get() params.lens_magnification = global_PVs['Lens_Magnification'].get() params.resolution = global_PVs['PixelSizeMicrons'].get() params.scintillator_type = global_PVs['Scintillator_Type'].get( as_string=True) params.scintillator_thickness = global_PVs['Scintillator_Thickness'].get() params.exposure_time = global_PVs['Cam1_AcquireTime'].get() params.bright_exposure_time = global_PVs['Bright_Exp_Time'].get() params.sample_rotation_start = global_PVs['Sample_Rotation_Start'].get() params.sample_rotation_end = global_PVs['Sample_Rotation_End'].get() params.num_projections = global_PVs['Num_Projections'].get() params.retrace_speed = global_PVs['Sample_Retrace_Speed'].get() params.vertical_scan_start = global_PVs['Vertical_Scan_Start'].get() params.vertical_scan_end = global_PVs['Vertical_Scan_End'].get() params.vertical_scan_step_size = global_PVs['Vertical_Scan_Step_Size'].get( ) params.horizontal_scan_start = global_PVs['Horizontal_Scan_Start'].get() params.horizontal_scan_end = global_PVs['Horizontal_Scan_End'].get() params.horizontal_scan_step_size = global_PVs[ 'Horizontal_Scan_Step_Size'].get() params.sample_out_x = global_PVs['Sample_Out_Position_X'].get() params.sample_out_y = global_PVs['Sample_Out_Position_Y'].get()
def center_of_mass(image): threshold_value = filters.threshold_otsu(image) log.info(" *** threshold_value: %f" % (threshold_value)) labeled_foreground = (image < threshold_value).astype(int) properties = regionprops(labeled_foreground, image) return properties[0].weighted_centroid
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 cleanup_PSO(self): '''Cleanup activities after a PSO scan. Turns off PSO and sets the speed back to default. ''' log.info('Cleaning up PSO programming and setting to retrace speed.') self.asynRec.put('PSOWINDOW %s OFF' % self.axis, wait=True) self.asynRec.put('PSOCONTROL %s OFF' % self.axis, wait=True) self.motor.put('VELO', self.default_speed, wait=True)
def take_flat(global_PVs, params): log.info(' *** acquire white') log.info(' *** *** set exp time') global_PVs['Cam1_AcquireTime'].put(params.bright_exposure_time, wait=True) output = take_image(global_PVs, params) global_PVs['Cam1_AcquireTime'].put(params.exposure_time, wait=True) return output
def update_pixel_size(global_PVs, params): '''Uses the camera model number to set the correct pixel size. ''' if params.camera_ioc_prefix in ['7bm_pg1:', '7bm_pg2:', '7bm_pg3:']: global_PVs['PixelSizeMicrons'].put(5.86, wait=True) log.info('Camera pixel size for this camera = 5.86 microns.') elif params.camera_ioc_prefix == '7bm_pg4:': global_PVs['PixelSizeMicrons'].put(3.45, wait=True) log.info('Camera pixel size for this camera = 3.45 microns.')
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 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 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 log_values(args): """Log all values set in the args namespace. Arguments are grouped according to their section and logged alphabetically using the DEBUG log level thus --verbose is required. """ args = args.__dict__ log.warning('tomo scan status start') for section, name in zip(SECTIONS, NICE_NAMES): entries = sorted((k for k in args.keys() if k.replace('_', '-') in SECTIONS[section])) # print('log_values', section, name, entries) if entries: log.info(name) for entry in entries: value = args[entry] if args[entry] is not None else "-" log.info(" {:<16} {}".format(entry, value)) log.warning('tomo scan status end')
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 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 acquire(global_PVs, params): # 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_FrameType'].put(FrameTypeData, wait=True) global_PVs['Cam1_ImageMode'].put('Multiple', wait=True) num_images = int(params.num_projections) * params.recursive_filter_n_images global_PVs['Cam1_NumImages'].put(num_images, wait=True) # Set trigger mode global_PVs['Cam1_TriggerMode'].put('Overlapped', wait=True) # start acquiring global_PVs['Cam1_Acquire'].put(DetectorAcquire) aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorAcquire) log.info(' ') log.info(' *** Fly Scan: Start!') pso.fly(global_PVs, params) # if the fly scan wait times out we should call done on the detector if aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorIdle, 5) == False: log.warning(' *** *** Camera did not finish acquisition') global_PVs['Cam1_Acquire'].put(DetectorIdle) log.info(' *** Fly Scan: Done!') # Set trigger mode to internal for post dark and white global_PVs['Cam1_TriggerMode'].put('Internal') return pso.proj_positions
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 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 init(global_PVs, params): '''Performs initialization of camera. Takes a frame to make sure we have frame data. ''' if params.camera_ioc_prefix in params.valid_camera_prefixes: log.info(' *** init Point Grey camera') global_PVs['HDF1_Capture'].put(0, wait=True) global_PVs['HDF1_EnableCallbacks'].put('Disable', wait=True) global_PVs['Cam1_TriggerMode'].put('Internal', wait=True) # global_PVs['Cam1_TriggerMode'].put( 'Overlapped', wait=True ) # sequence Internal / Overlapped / internal because of CCD bug!! global_PVs['Cam1_TriggerMode'].put('Internal', wait=True) # global_PVs['Proc1_Filter_Callbacks'].put('Every array') global_PVs['Cam1_ImageMode'].put('Single', wait=True) global_PVs['Cam1_Display'].put(1) global_PVs['Cam1_Acquire'].put(DetectorAcquire) aps7bm.wait_pv(global_PVs['Cam1_Acquire'], DetectorAcquire, 2) global_PVs['Proc1_Callbacks'].put('Disable') global_PVs['Proc1_Filter_Enable'].put('Disable') global_PVs['HDF1_ArrayPort'].put(global_PVs['Cam1_AsynPort'].get()) log.info(' *** init Point Grey camera: Done!')
def add_theta(global_PVs, params): log.info(' ') log.info(' *** add_theta') fullname = global_PVs['HDF1_FullFileName_RBV'].get(as_string=True) theta_arr = pso.proj_positions if theta_arr is None: return try: with h5py.File(fullname, mode='a') as hdf_f: hdf_f.create_dataset('/exchange/theta', data=theta_arr) log.info(' *** add_theta: Done!') except Exception as ee: traceback.print_exc(file=sys.stdout) log.info(' *** add_theta: Failed accessing: %s' % fullname) raise ee
def template_match_images(image1, image2): '''Determine shift required to make image2 match image1. ''' #Make images floats, ignoring first row (bad from camera) image1 = image1.astype(np.float64) image2 = image2.astype(np.float64) #Make template sizes and shapes row_shift = image1.shape[0] // 2 col_shift = image1.shape[1] // 2 padded_image1 = np.pad(image1, ((row_shift, row_shift), (col_shift, col_shift))) correlation_matrix = match_template(padded_image1, image2) print('Maximum correlation = {0:6.4f}'.format(np.max(correlation_matrix))) print(correlation_matrix.shape) log.info('Maximum correlation = {0:6.4f}'.format( np.max(correlation_matrix))) shift_tuple = np.unravel_index(np.argmax(correlation_matrix), correlation_matrix.shape) row_shift = shift_tuple[0] - row_shift col_shift = shift_tuple[1] - col_shift log.info('Shift of (row, column) = ({0:d}, {1:d})'.format( row_shift, col_shift)) #Now display an image showing how well the images match return row_shift, col_shift
def check_camera_IOC(global_PVs, params): 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!') return False log.info('*** The Point Grey Camera with EPICS IOC prefix %s and serial number %s is on' \ % (params.camera_ioc_prefix, detector_sn)) return True
def close_shutters(global_PVs, params): log.info(' ') log.info(' *** close_shutters') if TESTING: log.warning( ' *** testing mode - shutters are deactivated during the scans !!!!' ) else: global_PVs['ShutterA_Close'].put(1, wait=True) wait_pv(global_PVs['ShutterA_Move_Status'], ShutterA_Close_Value) log.info(' *** close_shutter A: Done!')
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 tomo_fly_scan(global_PVs, params): log.info(' ') log.info(' *** start_scan') #Set things up so Ctrl+C will cause scan to clean up. def cleanup(signal, frame): stop_scan(global_PVs, params) sys.exit(0) signal.signal(signal.SIGINT, cleanup) set_image_factor(global_PVs, params) pso.pso_init(params) pso.program_PSO() log.info(' *** *** PSO programming DONE!') log.info(' *** File name prefix: %s' % params.file_name) flir.set(global_PVs, params) move_sample_out(global_PVs, params) aps7bm.open_shutters(global_PVs, params) flir.acquire_flat(global_PVs, params) aps7bm.close_shutters(global_PVs, params) time.sleep(0.5) flir.acquire_dark(global_PVs, params) move_sample_in(global_PVs, params) aps7bm.open_shutters(global_PVs, params) theta = flir.acquire(global_PVs, params) aps7bm.close_shutters(global_PVs, params) time.sleep(0.5) flir.checkclose_hdf(global_PVs, params) flir.add_theta(global_PVs, params) # If requested, move rotation stage back to zero pso.cleanup_PSO() pso.driver.motor.move(pso.req_start, wait=False) # update config file config.update_config(params)
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 take_dark(global_PVs, params): log.info(' *** acquire dark') return take_image(global_PVs, params)
def log_info(): log.warning(' *** *** Positions for fly scan.') log.info(' *** *** *** Motor start = {0:f}'.format(req_start)) log.info(' *** *** *** Motor end = {0:f}'.format(actual_end)) log.info(' *** *** *** # Points = {0:4d}'.format(num_proj)) log.info(' *** *** *** Degrees per image = {0:f}'.format(delta_egu)) log.info(' *** *** *** Degrees per projection = {0:f}'.format(delta_egu / num_images_per_proj)) log.info(' *** *** *** Encoder counts per image = {0:d}'.format(delta_encoder_counts))
def program_PSO(): '''Cause the Aerotech driver to program its PSO. ''' log.info(' *** *** Programming motor') driver.program_PSO()
def set_default_speed(speed): log.info('Setting retrace speed on motor to {0:f} deg/s'.format(float(speed))) driver.default_speed = speed
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