예제 #1
0
def acquire(global_PVs, params):
    theta = []

    # Estimate the time needed for the flyscan
    angular_range =  params.rotation_end -  params.rotation_start
    flyscan_time_estimate = angular_range / params.slew_speed

    # log.info(' ')
    log.warning('  *** Fly Scan Time Estimate: %4.2f minutes' % (flyscan_time_estimate/60.))

    global_PVs['Cam1FrameType'].put(FrameTypeData, wait=True)
    time.sleep(2)    

    # global_PVs['Cam1AcquireTime'].put(float(params.exposure_time) )

    if (params.recursive_filter == False):
        params.recursive_filter_n_images = 1

    num_images = int(params.num_angles)  * params.recursive_filter_n_images   
    global_PVs['Cam1NumImages'].put(num_images, wait=True)


    # Set detectors
    if (params.camera_ioc_prefix == '2bmbPG3:'):   
        global_PVs['Cam1TriggerMode'].put('Overlapped', wait=True)
    elif (params.camera_ioc_prefix == '2bmbSP1:'):
        global_PVs['Cam1TriggerMode'].put('On', wait=True)

    # start acquiring
    global_PVs['Cam1Acquire'].put(DetectorAcquire)
    pv.wait_pv(global_PVs['Cam1Acquire'], 1)

    log.info(' ')
    log.info('  *** Fly Scan: Start!')
    global_PVs['FlyRun'].put(1, wait=True)
    # wait for acquire to finish 
    pv.wait_pv(global_PVs['FlyRun'], 0)

    # if the fly scan wait times out we should call done on the detector
#    if pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, flyscan_time_estimate) == False:
    if pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, 5) == False:
        global_PVs['Cam1Acquire'].put(DetectorIdle)
        #  got error here once when missing 100s of frames: pv.wait_pv( 2bmbSP1:cam1:Acquire 0 5 ) reached max timeout. Return False
    
    log.info('  *** Fly Scan: Done!')
    # Set trigger mode to internal for post dark and white
    if (params.camera_ioc_prefix == '2bmbPG3:'):   
        global_PVs['Cam1TriggerMode'].put('Internal')
    elif (params.camera_ioc_prefix == '2bmbSP1:'):
        global_PVs['Cam1TriggerMode'].put('Off', wait=True)


    theta = global_PVs['OmegaArray'].get(count=int(params.num_angles))
    if (params.recursive_filter_n_images > 1):
        theta = np.mean(theta.reshape(-1, params.recursive_filter_n_images), axis=1)
    
    return theta
예제 #2
0
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['Proc1EnableFilter'].put('Enable', wait=True)
            global_PVs['HDFArrayPort'].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['Proc1EnableFilter'].put('Disable')
            global_PVs['HDFArrayPort'].put(global_PVs['Proc1NDArrayPort'].get())
        global_PVs['HDFAutoSave'].put('Yes')
        global_PVs['HDFDeleteDriverFile'].put('No')
        global_PVs['HDFEnableCallbacks'].put('Enable')
        global_PVs['HDFBlockingCallbacks'].put('No')

        # if (params.recursive_filter == False):
        #     params.recursive_filter_n_images = 1

        totalProj = ((int(params.num_angles / params.recursive_filter_n_images)) + int(params.num_dark_fields) + \
                        int(params.num_flat_fields))

        global_PVs['HDFNumCapture'].put(totalProj)
        global_PVs['HDFFileWriteMode'].put(str(params.file_write_mode), wait=True)
        if fname is not None:
            global_PVs['HDFFileName'].put(str(fname), wait=True)
        global_PVs['HDFCapture'].put(1)
        pv.wait_pv(global_PVs['HDFCapture'], 1)
        log.info('  *** setup hdf_writer: Done!')
    else:
        log.error('Detector %s is not defined' % params.camera_ioc_prefix)
        return
예제 #3
0
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
예제 #4
0
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')
예제 #5
0
def acquire_flat(global_PVs, params):
    log.info('      *** White Fields')
   
    global_PVs['Cam1ImageMode'].put('Multiple')
    global_PVs['Cam1FrameType'].put(FrameTypeWhite)             

    if (params.camera_ioc_prefix == '2bmbPG3:'):
        global_PVs['Cam1TriggerMode'].put('Overlapped')
    elif (params.camera_ioc_prefix == '2bmbSP1:'):
        global_PVs['Cam1TriggerMode'].put('Off', wait=True)
        
    # Set detectors
    if (params.camera_ioc_prefix == '2bmbPG3:'):   
        wait_time_sec = int(params.exposure_time) + 5
        global_PVs['Cam1NumImages'].put(1)

        for i in range(int(params.num_flat_fields) * params.recursive_filter_n_images):
            global_PVs['Cam1Acquire'].put(DetectorAcquire)
            time.sleep(0.1)
            pv.wait_pv(global_PVs['Cam1Acquire'], DetectorAcquire, 2)
            time.sleep(0.1)
            global_PVs['Cam1SoftwareTrigger'].put(1, wait=True)
            time.sleep(0.1)
            pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, wait_time_sec)
            time.sleep(0.1)

    elif (params.camera_ioc_prefix == '2bmbSP1:'):
        wait_time_sec = float(params.num_flat_fields) * float(params.exposure_time) + 60.0
        global_PVs['Cam1NumImages'].put(int(params.num_flat_fields))
        global_PVs['Cam1Acquire'].put(DetectorAcquire, wait=True, timeout=5.0) # it was 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)
    
    log.info('      *** White Fields: Done!')
예제 #6
0
def init(global_PVs, params):
    if (params.camera_ioc_prefix == '2bmbPG3:'):   
        log.info('  *** init Point Grey camera')
        global_PVs['Cam1TriggerMode'].put('Internal', wait=True)    # 
        global_PVs['Cam1TriggerMode'].put('Overlapped', wait=True)  # sequence Internal / Overlapped / internal because of CCD bug!!
        global_PVs['Cam1TriggerMode'].put('Internal', wait=True)    #
        global_PVs['Proc1_Filter_Callbacks'].put( 'Every array' )
        global_PVs['Cam1ImageMode'].put('Single', wait=True)
        global_PVs['Cam1Display'].put(1)
        global_PVs['Cam1Acquire'].put(DetectorAcquire)
        pv.wait_pv(global_PVs['Cam1Acquire'], DetectorAcquire, 2)
        global_PVs['Proc1_Callbacks'].put('Disable')
        global_PVs['Proc1EnableFilter'].put('Disable')
        global_PVs['HDFArrayPort'].put('PG3')
        log.info('  *** init Point Grey camera: Done!')
    elif (params.camera_ioc_prefix == '2bmbSP1:'):   
        log.info(' ')                
        log.info('  *** init FLIR camera')
        log.info('  *** *** set detector to idle')
        global_PVs['Cam1Acquire'].put(DetectorIdle)
        pv.wait_pv(global_PVs['Cam1Acquire'], DetectorIdle, 2)
        log.info('  *** *** set detector to idle:  Done')
        # global_PVs['Proc1_Filter_Callbacks'].put( 'Every array', wait=True) # commented out to test if crash (ValueError: invalid literal for int() with base 0: 'Single') still occurs
        time.sleep(2) 
        log.info('  *** *** set trigger mode to Off')
        global_PVs['Cam1TriggerMode'].put('Off', wait=True)    # 
        log.info('  *** *** set trigger mode to Off: done')
        time.sleep(7) 
        log.info('  *** *** set image mode to single')
        global_PVs['Cam1ImageMode'].put('Single', wait=True)   # here is where it crashes with (ValueError: invalid literal for int() with base 0: 'Single') Added 7 s delay before
        log.info('  *** *** set image mode to single: done')
        log.info('  *** *** set cam display to 1')
        global_PVs['Cam1Display'].put(1)
        log.info('  *** *** set cam display to 1: done')
        log.info('  *** *** set cam acquire')
        global_PVs['Cam1Acquire'].put(DetectorAcquire)
        pv.wait_pv(global_PVs['Cam1Acquire'], DetectorAcquire, 2) 
        log.info('  *** *** set cam acquire: done')
        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) 
        log.info('  *** init FLIR camera: Done!')
예제 #7
0
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)