Beispiel #1
0
def dark(sample, scanplan, **kwargs):
    '''on this 'scan' get dark images
    
    Arguments:
    sample - sample metadata object
    scanplan - scanplan metadata object
    **kwargs - dictionary that will be passed through to the run-engine metadata
    '''
        # print information to user since we might call dark during prun.
    scan = Scan(sample, scanplan)
    dark_uid = str(uuid.uuid4())
    dark_exposure = scan.md['sp_params']['exposure']
    if scan.sp.shutter:
        _close_shutter()
    scan.md.update({'sc_isdark':True})
    # we need a hook to search this dark frame later on
    scan.md.update({'sc_dark_uid':dark_uid})
    #_unpack_and_run(sample,scan,**kwargs)
    _unpack_and_run(scan, **kwargs)
    dark_time = time.time() # get timestamp by the end of dark_scan 
    dark_def = (dark_uid, dark_exposure, dark_time)
    #scan.md.update({'xp_isdark':False}) #reset should not be required
    if scan.sp.shutter:
        _close_shutter()
    return dark_uid
Beispiel #2
0
def SPEC_Tseries_plan(detector, motor, start, stop, steps):
    yield Msg('open_run')
    for i in np.linspace(start, stop, steps):
        yield Msg('create')
        yield Msg('set', motor, i)
        yield Msg('read', motor)
        _open_shutter()
        yield Msg('trigger', detector)
        yield Msg('read', detector)
        _close_shutter()
        yield Msg('trigger', detector)
        yield Msg('read', detector)
        yield Msg('save')
    yield Msg('close_run')
Beispiel #3
0
def setupscan(sample,scan,**kwargs):
    '''used for setup scans NOT production scans
     
    Scans run this way will get tagged with "setup_scan=True".  They
    will be saved for later retrieval but will be harder to search for
    in the database.
    Use prun() for production scans

    Arguments:
    sample - sample metadata object
    scan - scan metadata object
    **kwargs - dictionary that will be passed through to the run-engine metadata
    '''
    if scan.shutter: _open_shutter()
    scan.md.update({'xp_isprun':False})
    _unpack_and_run(sample,scan,**kwargs)
    #parms = scan.sc_params
    if scan.shutter: _close_shutter()
Beispiel #4
0
def _execute_scans(scan,
                   auto_dark,
                   subs,
                   auto_calibration,
                   light_frame=True,
                   dryrun=False,
                   **kwargs):
    '''execute this scan'

    Parameters:
    -----------
    scan : xpdAcq.beamtime.Scan object
        object carries metadata of Scanplan and Sample object

    auto_dark : bool
        option of automated dark collection. Set to true to allow collect dark automatically during scans

    subs : dict
        a dictionary of subscribes to scans

    auto_calibration : bool
        option of loading calibration parameter from SrXplanar config file. If True, the most recent calibration file in xpdUser/config_base will be loaded

    light_frame : bool
        optional. Default is True and this allows program to open shutter before _unpack_and_run()

    dryrun : bool
        optional. Default is False. If option is set to True, scan won't be executed but corresponding metadata as if executing real scans will be printed
    '''
    if auto_dark and not scan.sp._is_bs:
        auto_dark_md_dict = _auto_dark_collection(scan, subs)
        scan.md.update(auto_dark_md_dict)
    if auto_calibration:
        auto_load_calibration_dict = _auto_load_calibration_file()
        if auto_load_calibration_dict:
            scan.md.update(auto_load_calibration_dict)
    if light_frame and scan.sp.shutter:
        _open_shutter()
    _unpack_and_run(scan, dryrun, subs, **kwargs)
    # always close a shutter after scan, if shutter is in control
    if scan.sp.shutter:
        _close_shutter()
    return
Beispiel #5
0
def prun(sample, scanplan, auto_dark = glbl.auto_dark, **kwargs):
    '''on this 'sample' run this 'scanplan'
        
    Arguments:
    sample - sample metadata object
    scanplan - scanplan metadata object
    auto_dark - optional. Type auto_dark = False to suppress the automatic collection of a dark image (default = True). Strongly recommend to leave as True unless problems are encountered
    **kwargs - dictionary that will be passed through to the run-engine metadata
    '''
    scan = Scan(sample, scanplan)
    scan.md.update({'sc_isprun':True})
    light_cnt_time = scan.md['sp_params']['exposure']
    expire_time = glbl.dk_window
    # user can also specify auto_dark in argument to overwrite glbl setting
    if auto_dark:
        dark_field_uid = validate_dark(light_cnt_time, expire_time)
        if not dark_field_uid:
            print('''INFO: auto_dark didn't detect a valid dark, so is collecting a new dark frame.
See documentation at http://xpdacq.github.io for more information about controlling this behavior''')
            # create a count plan with the same light_cnt_time
            if scanplan.shutter:
                auto_dark_scanplan = ScanPlan('auto_dark_scan',
                    'ct',{'exposure':light_cnt_time})
            else:
                auto_dark_scanplan = ScanPlan('auto_dark_scan',
                    'ct',{'exposure':light_cnt_time},shutter=False)
            dark_field_uid = dark(sample, auto_dark_scanplan)
        scan.md['sp_params'].update({'dk_field_uid': dark_field_uid})
        scan.md['sp_params'].update({'dk_window':expire_time})

    try:
        (config_dict, config_name) = _load_calibration_file()
        scan.md.update({'sp_config_dict':config_dict})
        scan.md.update({'sp_config_name':config_name})
    except TypeError: # iterating on on None object causes TypeError
        print('INFO: No calibration file found in config_base. Scan will still keep going on')
    if scan.sp.shutter: 
        _open_shutter()
    #_unpack_and_run(sample,scanplan,**kwargs)
    _unpack_and_run(scan, **kwargs)
    if scan.sp.shutter: 
        _close_shutter()
Beispiel #6
0
def _execute_scans(scan, auto_dark, subs, auto_calibration,
        light_frame = True, dryrun = False, **kwargs):
    '''execute this scan'

    Parameters:
    -----------
    scan : xpdAcq.beamtime.Scan object
        object carries metadata of Scanplan and Sample object

    auto_dark : bool
        option of automated dark collection. Set to true to allow collect dark automatically during scans

    subs : dict
        a dictionary of subscribes to scans

    auto_calibration : bool
        option of loading calibration parameter from SrXplanar config file. If True, the most recent calibration file in xpdUser/config_base will be loaded

    light_frame : bool
        optional. Default is True and this allows program to open shutter before _unpack_and_run()

    dryrun : bool
        optional. Default is False. If option is set to True, scan won't be executed but corresponding metadata as if executing real scans will be printed
    '''
    if auto_dark and not scan.sp._is_bs:
        auto_dark_md_dict = _auto_dark_collection(scan, subs)
        scan.md.update(auto_dark_md_dict)
    if auto_calibration:
        auto_load_calibration_dict = _auto_load_calibration_file()
        if auto_load_calibration_dict:
            scan.md.update(auto_load_calibration_dict)
    if light_frame and scan.sp.shutter:
        _open_shutter()
    _unpack_and_run(scan, dryrun, subs, **kwargs)
    # always close a shutter after scan, if shutter is in control
    if scan.sp.shutter:
        _close_shutter()
    return