Changeset 4821 for trunk


Ignore:
Timestamp:
Feb 19, 2021 2:24:19 PM (2 years ago)
Author:
toby
Message:

new peakfit mode in scripting: allow peak width terms to remain unchanged (neither refined nor calc from inst. params.); not accesible from GUI.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r4800 r4821  
    7272nxs = np.newaxis
    7373
    74 ################################################################################
    75 #### Powder utilities
    76 ################################################################################
    77 
     74#### Powder utilities ################################################################################
    7875def PhaseWtSum(G2frame,histo):
    7976    '''
     
    9592    return wtSum
    9693   
    97 ################################################################################
    98 #### GSASII pwdr & pdf calculation routines
    99 ################################################################################
    100        
     94#### GSASII pwdr & pdf calculation routines ################################################################################
    10195def Transmission(Geometry,Abs,Diam):
    10296    '''
     
    628622    return EvalLowPDF,GetCurrentVals,SetFinalVals
    629623
    630 ################################################################################       
    631 #### GSASII peak fitting routines: Finger, Cox & Jephcoat model       
    632 ################################################################################
    633 
     624#### GSASII peak fitting routines: Finger, Cox & Jephcoat model  ################################################################################
    634625def factorize(num):
    635626    ''' Provide prime number factors for integer num
     
    12791270    return G2lat.sortHKLd(HKLs,True,True,True)
    12801271
     1272peakInstPrmMode = True
     1273'''Determines the mode used for peak fitting. When peakInstPrmMode=True peak
     1274width parameters are computed from the instrument parameters (UVW,... or
     1275alpha,... etc) unless the individual parameter is refined. This allows the
     1276instrument parameters to be refined. When peakInstPrmMode=False, the instrument
     1277parameters are not used and cannot be refined.
     1278The default is peakFitMode=True.
     1279'''
     1280
     1281def setPeakInstPrmMode(normal=True):
     1282    '''Determines the mode used for peak fitting. If normal=True (default)
     1283    peak width parameters are computed from the instrument parameters
     1284    unless the individual parameter is refined. If normal=False,
     1285    peak widths are used as supplied for each peak.
     1286
     1287    Note that normal=True unless this routine is called. Also,
     1288    instrument parameters can only be refined with normal=True.
     1289
     1290    :param bool normal: setting to apply to global variable :var:`peakInstPrmMode`
     1291    '''
     1292    global peakInstPrmMode
     1293    peakInstPrmMode = normal
     1294
    12811295def getPeakProfile(dataType,parmDict,xdata,fixback,varyList,bakType):
    12821296    'Computes the profile for a powder pattern'
     
    13001314                intens = parmDict['int'+str(iPeak)]
    13011315                sigName = 'sig'+str(iPeak)
    1302                 if sigName in varyList:
     1316                if sigName in varyList or not peakInstPrmMode:
    13031317                    sig = parmDict[sigName]
    13041318                else:
     
    13061320                sig = max(sig,0.001)          #avoid neg sigma^2
    13071321                gamName = 'gam'+str(iPeak)
    1308                 if gamName in varyList:
     1322                if gamName in varyList or not peakInstPrmMode:
    13091323                    gam = parmDict[gamName]
    13101324                else:
     
    13381352                intens = parmDict['int'+str(iPeak)]
    13391353                alpName = 'alp'+str(iPeak)
    1340                 if alpName in varyList:
     1354                if alpName in varyList or not peakInstPrmMode:
    13411355                    alp = parmDict[alpName]
    13421356                else:
     
    13441358                alp = max(0.1,alp)
    13451359                betName = 'bet'+str(iPeak)
    1346                 if betName in varyList:
     1360                if betName in varyList or not peakInstPrmMode:
    13471361                    bet = parmDict[betName]
    13481362                else:
     
    13501364                bet = max(0.1,bet)
    13511365                sigName = 'sig'+str(iPeak)
    1352                 if sigName in varyList:
     1366                if sigName in varyList or not peakInstPrmMode:
    13531367                    sig = parmDict[sigName]
    13541368                else:
     
    13561370                sig = max(sig,0.001)          #avoid neg sigma^2
    13571371                gamName = 'gam'+str(iPeak)
    1358                 if gamName in varyList:
     1372                if gamName in varyList or not peakInstPrmMode:
    13591373                    gam = parmDict[gamName]
    13601374                else:
     
    13841398                intens = parmDict['int'+str(iPeak)]
    13851399                alpName = 'alp'+str(iPeak)
    1386                 if alpName in varyList:
     1400                if alpName in varyList or not peakInstPrmMode:
    13871401                    alp = parmDict[alpName]
    13881402                else:
     
    13931407                alp = max(0.1,alp)
    13941408                betName = 'bet'+str(iPeak)
    1395                 if betName in varyList:
     1409                if betName in varyList or not peakInstPrmMode:
    13961410                    bet = parmDict[betName]
    13971411                else:
     
    14021416                bet = max(0.0001,bet)
    14031417                sigName = 'sig'+str(iPeak)
    1404                 if sigName in varyList:
     1418                if sigName in varyList or not peakInstPrmMode:
    14051419                    sig = parmDict[sigName]
    14061420                else:
    14071421                    sig = G2mth.getTOFsig(parmDict,dsp)
    14081422                gamName = 'gam'+str(iPeak)
    1409                 if gamName in varyList:
     1423                if gamName in varyList or not peakInstPrmMode:
    14101424                    gam = parmDict[gamName]
    14111425                else:
     
    14671481                intens = parmDict['int'+str(iPeak)]
    14681482                sigName = 'sig'+str(iPeak)
    1469                 if sigName in varyList:
     1483                if sigName in varyList or not peakInstPrmMode:
    14701484                    sig = parmDict[sigName]
    14711485                    dsdU = dsdV = dsdW = 0
     
    14751489                sig = max(sig,0.001)          #avoid neg sigma
    14761490                gamName = 'gam'+str(iPeak)
    1477                 if gamName in varyList:
     1491                if gamName in varyList or not peakInstPrmMode:
    14781492                    gam = parmDict[gamName]
    14791493                    dgdX = dgdY = dgdZ = 0
     
    15401554                intens = parmDict['int'+str(iPeak)]
    15411555                alpName = 'alp'+str(iPeak)
    1542                 if alpName in varyList:
     1556                if alpName in varyList or not peakInstPrmMode:
    15431557                    alp = parmDict[alpName]
    15441558                    dada0 = dada1 = 0.0
     
    15481562                alp = max(0.0001,alp)
    15491563                betName = 'bet'+str(iPeak)
    1550                 if betName in varyList:
     1564                if betName in varyList or not peakInstPrmMode:
    15511565                    bet = parmDict[betName]
    15521566                    dbdb0 = dbdb1 = 0.0
     
    15561570                bet = max(0.0001,bet)
    15571571                sigName = 'sig'+str(iPeak)
    1558                 if sigName in varyList:
     1572                if sigName in varyList or not peakInstPrmMode:
    15591573                    sig = parmDict[sigName]
    15601574                    dsdU = dsdV = dsdW = 0
     
    15641578                sig = max(sig,0.001)          #avoid neg sigma
    15651579                gamName = 'gam'+str(iPeak)
    1566                 if gamName in varyList:
     1580                if gamName in varyList or not peakInstPrmMode:
    15671581                    gam = parmDict[gamName]
    15681582                    dgdX = dgdY = dgdZ = 0
     
    16251639                intens = parmDict['int'+str(iPeak)]
    16261640                alpName = 'alp'+str(iPeak)
    1627                 if alpName in varyList:
     1641                if alpName in varyList or not peakInstPrmMode:
    16281642                    alp = parmDict[alpName]
    16291643                else:
     
    16351649                        dada0 = G2mth.getTOFalphaDeriv(dsp)
    16361650                betName = 'bet'+str(iPeak)
    1637                 if betName in varyList:
     1651                if betName in varyList or not peakInstPrmMode:
    16381652                    bet = parmDict[betName]
    16391653                else:
     
    16451659                        dbdb0,dbdb1,dbdb2 = G2mth.getTOFbetaDeriv(dsp)
    16461660                sigName = 'sig'+str(iPeak)
    1647                 if sigName in varyList:
     1661                if sigName in varyList or not peakInstPrmMode:
    16481662                    sig = parmDict[sigName]
    16491663                    dsds0 = dsds1 = dsds2 = dsds3 = 0
     
    16521666                    dsds0,dsds1,dsds2,dsds3 = G2mth.getTOFsigDeriv(dsp)
    16531667                gamName = 'gam'+str(iPeak)
    1654                 if gamName in varyList:
     1668                if gamName in varyList or not peakInstPrmMode:
    16551669                    gam = parmDict[gamName]
    16561670                    dsdX = dsdY = dsdZ = 0
     
    20072021                sigName = 'sig'+str(iPeak)
    20082022                pos = parmDict['pos'+str(iPeak)]
    2009                 if sigName not in varyList:
     2023                if sigName not in varyList and peakInstPrmMode:
    20102024                    if 'T' in Inst['Type'][0]:
    20112025                        dsp = G2lat.Pos2dsp(Inst,pos)
     
    20142028                        parmDict[sigName] = G2mth.getCWsig(parmDict,pos)
    20152029                gamName = 'gam'+str(iPeak)
    2016                 if gamName not in varyList:
     2030                if gamName not in varyList and peakInstPrmMode:
    20172031                    if 'T' in Inst['Type'][0]:
    20182032                        dsp = G2lat.Pos2dsp(Inst,pos)
     
    20712085            for j in range(len(names)):
    20722086                parName = names[j]+str(i)
    2073                 if parName in varyList:
     2087                if parName in varyList or not peakInstPrmMode:
    20742088                    peak[2*j] = parmDict[parName]
    20752089                elif 'alp' in parName:
     
    21752189        varyList = bakVary+insVary+peakVary
    21762190    fullvaryList = varyList[:]
     2191    if not peakInstPrmMode:
     2192        for v in ('U','V','W','X','Y','Z','alpha','alpha-0','alpha-1',
     2193            'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q',):
     2194            if v in varyList:
     2195                raise Exception('Instrumental profile terms cannot be varied '+
     2196                                    'after setPeakInstPrmMode(False) is used')
    21772197    while True:
    21782198        begin = time.time()
     
    22952315    return YI,WYI
    22962316
    2297 ################################################################################
    2298 #### RMCutilities
    2299 ################################################################################
    2300    
     2317#### RMCutilities ################################################################################
    23012318def MakeInst(PWDdata,Name,Size,Mustrain,useSamBrd):
    23022319    inst = PWDdata['Instrument Parameters'][0]
     
    30303047    return np.array(bondAngles)
    30313048   
    3032 ################################################################################
    3033 #### Reflectometry calculations
    3034 ################################################################################
    3035 
     3049#### Reflectometry calculations ################################################################################
    30363050def REFDRefine(Profile,ProfDict,Inst,Limits,Substances,data):
    30373051    G2fil.G2Print ('fit REFD data by '+data['Minimizer']+' using %.2f%% data resolution'%(data['Resolution'][0]))
     
    34663480
    34673481   
    3468 ################################################################################
    3469 #### Stacking fault simulation codes
    3470 ################################################################################
    3471 
     3482#### Stacking fault simulation codes ################################################################################
    34723483def GetStackParms(Layers):
    34733484   
     
    38813892    G2fil.G2Print (' GETSAD time = %.2fs'%(time.time()-time0))
    38823893   
    3883 ###############################################################################
    3884 #### Maximum Entropy Method - Dysnomia
    3885 ###############################################################################
    3886    
     3894#### Maximum Entropy Method - Dysnomia ###############################################################################
    38873895def makePRFfile(data,MEMtype):
    38883896    ''' makes Dysnomia .prf control file from Dysnomia GUI controls
  • trunk/GSASIIscriptable.py

    r4783 r4821  
    42424242                        peaks['peaks'][i][j] = var
    42434243
    4244     def refine_peaks(self):
     4244    def refine_peaks(self,mode='useIP'):
    42454245        '''Causes a refinement of peak position, background and instrument parameters
     4246       
     4247        :param str mode: this determines how peak widths are determined. If
     4248          the value is 'useIP' (the default) then the width parameter values (sigma, gamma,
     4249          alpha,...) are computed from the histogram's instrument parameters. If the
     4250          value is 'hold', then peak width parameters are not overridden. In
     4251          this case, it is not possible to refine the instrument parameters
     4252          associated with the peak widths and an attempt to do so will result in
     4253          an error.
    42464254
    42474255        :returns: a list of dicts with refinement results. Element 0 has uncertainties
     
    42524260        '''
    42534261        import GSASIIpwd as G2pwd
     4262        if mode == 'useIP':
     4263            G2pwd.setPeakInstPrmMode(True)
     4264        elif mode == 'hold':
     4265            G2pwd.setPeakInstPrmMode(False)
     4266        else:
     4267            raise G2ScriptException('Error: invalid mode value in refine_peaks (allowed: "useIP" or "hold")')
    42544268        controls = self.proj.data.get('Controls',{})
    42554269        controls = controls.get('data',
Note: See TracChangeset for help on using the changeset viewer.