Exemple #1
0
def quick(run, theta=None, pointdet=True, roi=[0, 0], db=[0, 0], trans='', polcorr=False, usemon=-1, outputType='pd',
          debug=False, stitch_start_overlap=10, stitch_end_overlap=12, stitch_params=[1.5, 0.02, 17],
          detector_component_name='point-detector', sample_component_name='some-surface-holder',
          correct_positions=True, tof_prefix="_"):
    '''
    Original quick parameters fetched from IDF
    '''
    run_ws = ConvertToWavelength.to_workspace(run, ws_prefix=tof_prefix)
    idf_defaults = get_defaults(run_ws, polcorr)

    i0_monitor_index = idf_defaults['I0MonitorIndex']
    multi_detector_start = idf_defaults['MultiDetectorStart']
    lambda_min = idf_defaults['LambdaMin']
    lambda_max = idf_defaults['LambdaMax']
    point_detector_start = idf_defaults['PointDetectorStart']
    point_detector_stop = idf_defaults['PointDetectorStop']
    multi_detector_start = idf_defaults['MultiDetectorStart']
    background_min = idf_defaults['MonitorBackgroundMin']
    background_max = idf_defaults['MonitorBackgroundMax']
    int_min = idf_defaults['MonitorIntegralMin']
    int_max = idf_defaults['MonitorIntegralMax']
    correction_strategy = idf_defaults['AlgoritmicCorrection']
    crho = None
    calpha = None
    cAp = None
    cPp = None
    if polcorr and (polcorr != PolarisationCorrection.NONE):
        crho = idf_defaults['crho']
        calpha = idf_defaults['calpha']
        cAp = idf_defaults['cAp']
        cPp = idf_defaults['cPp']

    return quick_explicit(run=run, i0_monitor_index=i0_monitor_index, lambda_min=lambda_min, lambda_max=lambda_max,
                          point_detector_start=point_detector_start, point_detector_stop=point_detector_stop,
                          multi_detector_start=multi_detector_start, background_min=background_min,
                          background_max=background_max,
                          int_min=int_min, int_max=int_max, theta=theta, pointdet=pointdet, roi=roi, db=db, trans=trans,
                          debug=debug, correction_strategy=correction_strategy,
                          stitch_start_overlap=stitch_start_overlap,
                          stitch_end_overlap=stitch_end_overlap, stitch_params=stitch_params, polcorr=polcorr,
                          crho=crho, calpha=calpha, cAp=cAp, cPp=cPp,
                          detector_component_name=detector_component_name, sample_component_name=sample_component_name,
                          correct_positions=correct_positions)
Exemple #2
0
def quick(run, theta=None, pointdet=True, roi=[0, 0], db=[0, 0], trans='', polcorr=False, usemon=-1, outputType='pd',
          debug=False, stitch_start_overlap=10, stitch_end_overlap=12, stitch_params=[1.5, 0.02, 17],
          detector_component_name='point-detector', sample_component_name='some-surface-holder',
          correct_positions=True, tof_prefix="_"):
    '''
    Original quick parameters fetched from IDF
    '''
    run_ws = ConvertToWavelength.to_workspace(run, ws_prefix=tof_prefix)
    idf_defaults = get_defaults(run_ws, polcorr)

    i0_monitor_index = idf_defaults['I0MonitorIndex']
    multi_detector_start = idf_defaults['MultiDetectorStart']
    lambda_min = idf_defaults['LambdaMin']
    lambda_max = idf_defaults['LambdaMax']
    point_detector_start = idf_defaults['PointDetectorStart']
    point_detector_stop = idf_defaults['PointDetectorStop']
    multi_detector_start = idf_defaults['MultiDetectorStart']
    background_min = idf_defaults['MonitorBackgroundMin']
    background_max = idf_defaults['MonitorBackgroundMax']
    int_min = idf_defaults['MonitorIntegralMin']
    int_max = idf_defaults['MonitorIntegralMax']
    correction_strategy = idf_defaults['AlgoritmicCorrection']
    crho = None
    calpha = None
    cAp = None
    cPp = None
    if polcorr and (polcorr != PolarisationCorrection.NONE):
        crho = idf_defaults['crho']
        calpha = idf_defaults['calpha']
        cAp = idf_defaults['cAp']
        cPp = idf_defaults['cPp']

    return quick_explicit(run=run, i0_monitor_index=i0_monitor_index, lambda_min=lambda_min, lambda_max=lambda_max, \
                          point_detector_start=point_detector_start, point_detector_stop=point_detector_stop, \
                          multi_detector_start=multi_detector_start, background_min=background_min,
                          background_max=background_max, \
                          int_min=int_min, int_max=int_max, theta=theta, pointdet=pointdet, roi=roi, db=db, trans=trans, \
                          debug=debug, correction_strategy=correction_strategy,
                          stitch_start_overlap=stitch_start_overlap, \
                          stitch_end_overlap=stitch_end_overlap, stitch_params=stitch_params, polcorr=polcorr,
                          crho=crho, calpha=calpha, cAp=cAp, cPp=cPp, \
                          detector_component_name=detector_component_name, sample_component_name=sample_component_name,
                          correct_positions=correct_positions)
Exemple #3
0
def make_trans_corr(transrun, stitch_start_overlap, stitch_end_overlap, stitch_params,
                    lambda_min=None, lambda_max=None, background_min=None,
                    background_max=None, int_min=None, int_max=None, detector_index_ranges=None,
                    i0_monitor_index=None):
    '''
    Make the transmission correction workspace.
    '''


    # Check to see whether all optional inputs have been provide. If not we have to get them from the IDF.
    if not all((lambda_min, lambda_max, background_min, background_max, int_min, int_max, detector_index_ranges, i0_monitor_index)):
        logger.notice("make_trans_corr: Fetching missing arguments from the IDF")
        instrument_source = transrun
        if isinstance(transrun, str):
            instrument_source = transrun.split(',')[0]
        trans_ws = ConvertToWavelength.to_workspace(instrument_source)
        idf_defaults = get_defaults(trans_ws)

        # Fetch defaults for anything not specified
        if not i0_monitor_index:
            i0_monitor_index = idf_defaults['I0MonitorIndex']
        if not lambda_min:
            lambda_min = idf_defaults['LambdaMin']
        if not lambda_max:
            lambda_max = idf_defaults['LambdaMax']
        if not detector_index_ranges:
            point_detector_start = idf_defaults['PointDetectorStart']
            point_detector_stop =  idf_defaults['PointDetectorStop']
            detector_index_ranges = (point_detector_start, point_detector_stop)
        if not background_min:
            background_min = idf_defaults['MonitorBackgroundMin']
        if not background_max:
            background_max = idf_defaults['MonitorBackgroundMax']
        if not int_min:
            int_min = idf_defaults['MonitorIntegralMin']
        if not int_max:
            int_max = idf_defaults['MonitorIntegralMax']


    transWS = None
    if isinstance(transrun, str) and (',' in transrun):
        slam = transrun.split(',')[0]
        llam = transrun.split(',')[1]
        print "Transmission runs: ", transrun

        to_lam = ConvertToWavelength(slam)
        _monitor_ws_slam, _detector_ws_slam = to_lam.convert(wavelength_min=lambda_min, wavelength_max=lambda_max, detector_workspace_indexes=detector_index_ranges, monitor_workspace_index=i0_monitor_index, correct_monitor=True, bg_min=background_min, bg_max=background_max )

        _i0p_slam = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_slam, WorkspaceToMatch=_detector_ws_slam)
        _mon_int_trans = Integration(InputWorkspace=_i0p_slam, RangeLower=int_min, RangeUpper=int_max)
        _detector_ws_slam = Divide(LHSWorkspace=_detector_ws_slam, RHSWorkspace=_mon_int_trans)

        to_lam = ConvertToWavelength(llam)
        _monitor_ws_llam, _detector_ws_llam = to_lam.convert(wavelength_min=lambda_min, wavelength_max=lambda_max, detector_workspace_indexes=detector_index_ranges, monitor_workspace_index=i0_monitor_index, correct_monitor=True, bg_min=background_min, bg_max=background_max )

        _i0p_llam = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_llam, WorkspaceToMatch=_detector_ws_llam)
        _mon_int_trans = Integration(InputWorkspace=_i0p_llam, RangeLower=int_min,RangeUpper=int_max)
        _detector_ws_llam = Divide(LHSWorkspace=_detector_ws_llam, RHSWorkspace=_mon_int_trans)

        print stitch_start_overlap, stitch_end_overlap, stitch_params
        transWS, outputScaling = Stitch1D(LHSWorkspace=_detector_ws_slam, RHSWorkspace=_detector_ws_llam, StartOverlap=stitch_start_overlap,\
                                           EndOverlap=stitch_end_overlap,  Params=stitch_params)

        transWS = RenameWorkspace(InputWorkspace=transWS, OutputWorkspace="TRANS_" + slam + "_" + llam)
    else:

        to_lam = ConvertToWavelength(transrun)
        _monitor_ws_trans, _detector_ws_trans = to_lam.convert(wavelength_min=lambda_min, wavelength_max=lambda_max, detector_workspace_indexes=detector_index_ranges, monitor_workspace_index=i0_monitor_index, correct_monitor=True, bg_min=background_min, bg_max=background_max )
        _i0p_trans = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_trans, WorkspaceToMatch=_detector_ws_trans)

        _mon_int_trans = Integration( InputWorkspace=_i0p_trans, RangeLower=int_min, RangeUpper=int_max )
        transWS = Divide( LHSWorkspace=_detector_ws_trans, RHSWorkspace=_mon_int_trans )

        transWS = RenameWorkspace(InputWorkspace=transWS, OutputWorkspace="TRANS_" + transrun)
    return transWS
def autoreduce(RBno,cycle, transRun=[], runRange=[], oldList=[], auto=0, angles=[], diagnostics=False):
    if not runRange:
        rlist = INTERsearch(RBno, cycle, diagnostics=diagnostics) 
    else:
        rlist = INTERsearch(RBno, cycle, runRange, diagnostics=diagnostics) 
    tupsort = make_tuples(rlist)
    sortedList = sort_runs(tupsort)
    
    newList = [item for item in sortedList if item not in oldList]
    
    for sample in newList:
        wq_list=[]
        overlapLow=[]
        overlapHigh=[]
        index=0
        for item in sample:
            runno = item[0]
            angle = item[1]
            runnos=string.split(runno,'+')
            runnos = [int(i) for i in runnos] # check if runs have been added together
            
            try:
                angle=float(angle)
            except ValueError:
                angle=0.0
                print "Could not determine theta! Skipping run."
                        
            if len(runRange) and not len(set(runRange) & set(runnos)):
                angle=0.0 # will be skipped below
            
            if float(angle)>0.0:
                ws = ConvertToWavelength.to_workspace(runno+'.raw', ws_prefix="")
                if not mtd.doesExist(runno+'_IvsQ'):
                    th = angle
                    #if len(transRun)>1 and index>0:
                    if len(transRun)>1:
                        if not angles:
                            angle=angle
                        else:
							try:
								angle=angles[index]
							except:
								print("Not enough angles specified.")
							#angle=angles[1]
                        try:
							transmRun=transRun[index]
							cutoff = INTERexptype()[index]
							print(cutoff,"=cutoff")
							ReflectometryReductionOneAuto(InputWorkspace=ws, FirstTransmissionRun=transmRun, WavelengthMin=cutoff, thetaIn=angle, OutputWorkspaceBinned=runno+'_IvsQ_binned', OutputWorkspace=runno+'_IvsQ', OutputWorkspaceWavelength=runno+'_IvsLam')
							wq=mtd[runno+'_IvsQ']
							th = angle
                        except:
                            print("Not enough transmission runs specified or transmission workspace doesn't exist, for run "+str(ws))
                    else:
                        if not angles:
                            angle=angle
                        #else:
                            #angle=angles[0]
                        #cutoff = INTERexptype()
                        cutoff = INTERexptype()[index]
                        print(cutoff,"=cutoff")
                        ReflectometryReductionOneAuto(InputWorkspace=ws, FirstTransmissionRun=transRun[0], thetaIn=angle, WavelengthMin=cutoff, OutputWorkspaceBinned=runno+'_IvsQ_binned', OutputWorkspace=runno+'_IvsQ', OutputWorkspaceWavelength=runno+'_IvsLam') 
                        wq=mtd[runno+'_IvsQ']
                        th = angle
                else:
                    wq=mtd[runno+'_IvsQ']
                    th=angle
                wq_list.append(runno+'_IvsQ')
                inst = wq.getInstrument()
                lmin = 1.8 #inst.getNumberParameter('LambdaMin')[0] + 1
                lmax = 15 #inst.getNumberParameter('LambdaMax')[0] - 2
                qmin = 4 * math.pi / lmax * math.sin(th * math.pi / 180)
                qmax = 4 * math.pi / lmin * math.sin(th * math.pi / 180)
                overlapLow.append(qmin)
                overlapHigh.append(qmax)
                dqq = NRCalculateSlitResolution(Workspace=wq)
            index=index+1
        if len(wq_list):
            w1 = getWorkspace(wq_list[0])
            w2 = getWorkspace(wq_list[-1])
            Qmin = min(w1.readX(0))
            Qmax = max(w2.readX(0))
            Qmax = 0.3

               
            #print Qmin, Qmax, dqq 
            #print overlapHigh
            if len(wq_list)>1:
                outputwksp = string.split(wq_list[0],sep='_')[0] + '_' + string.split(wq_list[-1],sep='_')[0][3:]
            else:
                outputwksp = string.split(wq_list[0],sep='_')[0] + '_IvsQ_binned'
                SaveAscii(InputWorkspace=outputwksp,Filename=savepath+outputwksp+'.dat',Separator='Space',ColumnHeader=False,ScientificFormat=True,WriteSpectrumID=False)      
            if not mtd.doesExist(outputwksp):
                wcomb = combineDataMulti(wq_list,outputwksp , overlapLow, overlapHigh,Qmin, Qmax, -dqq, 0, keep=True)
                SaveAscii(InputWorkspace=outputwksp,Filename=savepath+outputwksp+'.dat',Separator='Space',ColumnHeader=False,ScientificFormat=True,WriteSpectrumID=False)
            
    return sortedList
Exemple #5
0
def make_trans_corr(transrun,
                    stitch_start_overlap,
                    stitch_end_overlap,
                    stitch_params,
                    lambda_min=None,
                    lambda_max=None,
                    background_min=None,
                    background_max=None,
                    int_min=None,
                    int_max=None,
                    detector_index_ranges=None,
                    i0_monitor_index=None):
    '''
    Make the transmission correction workspace.
    '''

    # Check to see whether all optional inputs have been provide. If not we have to get them from the IDF.
    if not all((lambda_min, lambda_max, background_min, background_max,
                int_min, int_max, detector_index_ranges, i0_monitor_index)):
        logger.notice(
            "make_trans_corr: Fetching missing arguments from the IDF")
        instrument_source = transrun
        if isinstance(transrun, str):
            instrument_source = transrun.split(',')[0]
        trans_ws = ConvertToWavelength.to_workspace(instrument_source)
        idf_defaults = get_defaults(trans_ws)

        # Fetch defaults for anything not specified
        if not i0_monitor_index:
            i0_monitor_index = idf_defaults['I0MonitorIndex']
        if not lambda_min:
            lambda_min = idf_defaults['LambdaMin']
        if not lambda_max:
            lambda_max = idf_defaults['LambdaMax']
        if not detector_index_ranges:
            point_detector_start = idf_defaults['PointDetectorStart']
            point_detector_stop = idf_defaults['PointDetectorStop']
            detector_index_ranges = (point_detector_start, point_detector_stop)
        if not background_min:
            background_min = idf_defaults['MonitorBackgroundMin']
        if not background_max:
            background_max = idf_defaults['MonitorBackgroundMax']
        if not int_min:
            int_min = idf_defaults['MonitorIntegralMin']
        if not int_max:
            int_max = idf_defaults['MonitorIntegralMax']

    transWS = None
    if isinstance(transrun, str) and (',' in transrun):
        slam = transrun.split(',')[0]
        llam = transrun.split(',')[1]
        print("Transmission runs: ", transrun)

        to_lam = ConvertToWavelength(slam)
        _monitor_ws_slam, _detector_ws_slam = to_lam.convert(
            wavelength_min=lambda_min,
            wavelength_max=lambda_max,
            detector_workspace_indexes=detector_index_ranges,
            monitor_workspace_index=i0_monitor_index,
            correct_monitor=True,
            bg_min=background_min,
            bg_max=background_max)

        _i0p_slam = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_slam,
                                     WorkspaceToMatch=_detector_ws_slam)
        _mon_int_trans = Integration(InputWorkspace=_i0p_slam,
                                     RangeLower=int_min,
                                     RangeUpper=int_max)
        _detector_ws_slam = Divide(LHSWorkspace=_detector_ws_slam,
                                   RHSWorkspace=_mon_int_trans)

        to_lam = ConvertToWavelength(llam)
        _monitor_ws_llam, _detector_ws_llam = to_lam.convert(
            wavelength_min=lambda_min,
            wavelength_max=lambda_max,
            detector_workspace_indexes=detector_index_ranges,
            monitor_workspace_index=i0_monitor_index,
            correct_monitor=True,
            bg_min=background_min,
            bg_max=background_max)

        _i0p_llam = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_llam,
                                     WorkspaceToMatch=_detector_ws_llam)
        _mon_int_trans = Integration(InputWorkspace=_i0p_llam,
                                     RangeLower=int_min,
                                     RangeUpper=int_max)
        _detector_ws_llam = Divide(LHSWorkspace=_detector_ws_llam,
                                   RHSWorkspace=_mon_int_trans)

        print(stitch_start_overlap, stitch_end_overlap, stitch_params)
        transWS, _outputScaling = Stitch1D(LHSWorkspace=_detector_ws_slam,
                                           RHSWorkspace=_detector_ws_llam,
                                           StartOverlap=stitch_start_overlap,
                                           EndOverlap=stitch_end_overlap,
                                           Params=stitch_params)

        transWS = RenameWorkspace(InputWorkspace=transWS,
                                  OutputWorkspace="TRANS_" + slam + "_" + llam)
    else:

        to_lam = ConvertToWavelength(transrun)
        _monitor_ws_trans, _detector_ws_trans = to_lam.convert(
            wavelength_min=lambda_min,
            wavelength_max=lambda_max,
            detector_workspace_indexes=detector_index_ranges,
            monitor_workspace_index=i0_monitor_index,
            correct_monitor=True,
            bg_min=background_min,
            bg_max=background_max)
        _i0p_trans = RebinToWorkspace(WorkspaceToRebin=_monitor_ws_trans,
                                      WorkspaceToMatch=_detector_ws_trans)

        _mon_int_trans = Integration(InputWorkspace=_i0p_trans,
                                     RangeLower=int_min,
                                     RangeUpper=int_max)
        transWS = Divide(LHSWorkspace=_detector_ws_trans,
                         RHSWorkspace=_mon_int_trans)

        transWS = RenameWorkspace(InputWorkspace=transWS,
                                  OutputWorkspace="TRANS_" + transrun)
    return transWS