Changeset 4519 for trunk/GSASIImath.py


Ignore:
Timestamp:
Jul 13, 2020 1:27:06 PM (17 months ago)
Author:
vondreele
Message:

G2fpaGUI - minor cleanup
G2lattice - test on 'T' instead of 'C' so that 'B' PWDR types properly handled
G2math - add getPinkalpha, getPinkbeta % deriv routines for pink beam peak shapes

modify setPeakparams to use them

G2plot - test on 'T' instead of 'C' so that 'B' PWDR types properly handled
G2pwd - add pink beam peak shape function - same as TOF peak shape; scale sig & gam to be in centidegrees

  • add wtFactor to FitPeaks? fix bad PWDR weights for peak fitting so reduced chi2 is more appropriate

G2pwdGUI - test on 'T' instead of 'C' so that 'B' PWDR types properly handled

  • add wtFactor to DoPeakFit? to fix bad PWDR weights for peak fitting so reduced chi2 is more appropriate

G2strMath - latest in incommensurate mag str factors - no real improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r4514 r4519  
    14631463    psin = np.sin(twopi*phase)
    14641464    pcos = np.cos(twopi*phase)
    1465     MmodA = np.sum(Am[nxs,nxs,:,:,:]*pcos[:,:,:,nxs,nxs],axis=3)    #cos term
    1466     MmodB = np.sum(Bm[nxs,nxs,:,:,:]*psin[:,:,:,nxs,nxs],axis=3)    #sin term
     1465    MmodA = np.sum(Am[nxs,nxs,:,:,:]*pcos[:,:,:,nxs,nxs],axis=3)/2.    #cos term
     1466    MmodB = np.sum(Bm[nxs,nxs,:,:,:]*psin[:,:,:,nxs,nxs],axis=3)/2.    #sin term
    14671467    MmodA = np.sum(SGMT[nxs,:,nxs,:,:]*MmodA[:,:,:,nxs,:],axis=-1)*SGData['SpnFlp'][nxs,:,nxs,nxs]
    14681468    MmodB = np.sum(SGMT[nxs,:,nxs,:,:]*MmodB[:,:,:,nxs,:],axis=-1)*SGData['SpnFlp'][nxs,:,nxs,nxs]
    14691469    return MmodA,MmodB    #Ntau,Nops,Natm,Mxyz; cos & sin parts; sum matches drawn atom moments
    14701470       
    1471 def MagMod2(m,glTau,XYZ,modQ,MSSdata,SGData,SSGData):
     1471def MagMod2(m,XYZ,modQ,MSSdata,SGData,SSGData):
    14721472    '''
    14731473    this needs to make magnetic moment modulations & magnitudes as
     
    14771477    Bm = np.array(MSSdata[:3]).T[:,0,:]  #...sin pos mods
    14781478    SGMT = np.array([ops[0] for ops in SGData['SGOps']])        #not .T!!
     1479    SSGMT = np.array([ops[0] for ops in SSGData['SSGOps']])        #not .T!!
    14791480    Sinv = np.array([nl.inv(ops[0]) for ops in SSGData['SSGOps']])
    14801481    SGT = np.array([ops[1] for ops in SSGData['SSGOps']])
    14811482    if SGData['SGInv']:
    14821483        SGMT = np.vstack((SGMT,-SGMT))
     1484        SSGMT = np.vstack((SSGMT,-SSGMT))
    14831485        Sinv = np.vstack((Sinv,-Sinv))
    14841486        SGT = np.vstack((SGT,-SGT))
    14851487    SGMT = np.vstack([SGMT for cen in SGData['SGCen']])
     1488    SSGMT = np.vstack([SSGMT for cen in SGData['SGCen']])
    14861489    Sinv = np.vstack([Sinv for cen in SGData['SGCen']])
    14871490    SGT = np.vstack([SGT+cen for cen in SSGData['SSGCen']])%1.
    14881491    if SGData['SGGray']:
    14891492        SGMT = np.vstack((SGMT,SGMT))
     1493        SSGMT = np.vstack((SSGMT,SSGMT))
    14901494        Sinv = np.vstack((Sinv,Sinv))
    14911495        SGT = np.vstack((SGT,SGT+.5))%1.
    1492     mst = Sinv[:,3,:3]
    14931496    epsinv = Sinv[:,3,3]
    1494     phase = np.inner(XYZ,modQ).T+(np.inner(mst,modQ)-epsinv)[:,nxs]+glTau
    1495    
    1496     psin = np.sin(twopi*m*phase).T
    1497     pcos = np.cos(twopi*m*phase).T
    1498     MmodA = Am[nxs,nxs,:,:]*pcos[:,:,nxs,nxs]    #cos term
    1499     MmodB = Bm[nxs,nxs,:,:]*psin[:,:,nxs,nxs]    #sin term
    1500     MmodA = np.sum(SGMT[nxs,:,nxs,:,:]*MmodA[:,:,:,nxs,:],axis=-1)*SGData['SpnFlp'][nxs,:,nxs,nxs]
    1501     MmodB = np.sum(SGMT[nxs,:,nxs,:,:]*MmodB[:,:,:,nxs,:],axis=-1)*SGData['SpnFlp'][nxs,:,nxs,nxs]
    1502     return MmodA,MmodB    #Nref,Ntau,Nops,Natm,Mxyz; cos & sin parts; sum matches drawn atom moments
     1497    phi = np.inner(XYZ,modQ).T
     1498    TA = phi+(epsinv*(np.inner(modQ,SGT[:,:3])-SGT[:,3]))[:,nxs]    #Nops,Natm
     1499    phase = phi+(np.inner(modQ,SGT[:,:3])-SGT[:,3])[:,nxs]
     1500   
     1501    pcos = np.cos(-twopi*m[:,nxs,nxs]*phase[nxs,:,:])      #Nref,Nops,Natm
     1502    psin = np.sin(-twopi*m[:,nxs,nxs]*phase[nxs,:,:])
     1503    MmodA = TA[nxs,:,:,nxs]*(Am[nxs,nxs,:,:]*pcos[:,:,:,nxs]-Bm[nxs,nxs,:,:]*psin[:,:,:,nxs])/2.    #Nref,Nops,Natm,Mxyz
     1504    MmodB = TA[nxs,:,:,nxs]*(Am[nxs,nxs,:,:]*psin[:,:,:,nxs]+Bm[nxs,nxs,:,:]*pcos[:,:,:,nxs])/2.    #Nref,Nops,Natm,Mxyz
     1505    MmodA = np.sum(SGMT[nxs,:,nxs,:,:]*MmodA[:,:,:,nxs,:],axis=-1)*SGData['MagMom'][nxs,:,nxs,nxs]
     1506    MmodB = np.sum(SGMT[nxs,:,nxs,:,:]*MmodB[:,:,:,nxs,:],axis=-1)*SGData['MagMom'][nxs,:,nxs,nxs]
     1507    return MmodA,MmodB    #Nref,Nops,Natm,Mxyz; cos & sin parts
    15031508       
    15041509def Modulation(H,HP,nWaves,Fmod,Xmod,Umod,glTau,glWt):
     
    41634168    return 1./dsp
    41644169   
     4170def getPinkalpha(ins,tth):
     4171    '''get TOF peak profile alpha
     4172   
     4173    :param dict ins: instrument parameters with at least 'alpha'
     4174      as values only
     4175    :param float tth: 2-theta of peak
     4176   
     4177    :returns: flaot getPinkalpha: peak alpha
     4178   
     4179    '''
     4180    return ins['alpha-0']+ ins['alpha-1']*tand(tth/2.)
     4181   
     4182def getPinkalphaDeriv(tth):
     4183    '''get derivatives of TOF peak profile beta wrt alpha
     4184   
     4185    :param float dsp: d-spacing of peak
     4186   
     4187    :returns: float getTOFalphaDeriv: d(alp)/d(alpha-0), d(alp)/d(alpha-1)
     4188   
     4189    '''
     4190    return 1.0,tand(tth/2.)
     4191   
     4192def getPinkbeta(ins,tth):
     4193    '''get TOF peak profile beta
     4194   
     4195    :param dict ins: instrument parameters with at least 'beat-0' & 'beta-1'
     4196      as values only
     4197    :param float tth: 2-theta of peak
     4198   
     4199    :returns: float getaPinkbeta: peak beta
     4200   
     4201    '''
     4202    return ins['beta-0']+ins['beta-1']*tand(tth/2.)
     4203   
     4204def getPinkbetaDeriv(tth):
     4205    '''get derivatives of TOF peak profile beta wrt beta-0 & beta-1
     4206   
     4207    :param float dsp: d-spacing of peak
     4208   
     4209    :returns: list getTOFbetaDeriv: d(beta)/d(beta-0) & d(beta)/d(beta-1)
     4210   
     4211    '''
     4212    return 1.0,tand(tth/2.)
     4213   
    41654214def setPeakparms(Parms,Parms2,pos,mag,ifQ=False,useFit=False):
    41664215    '''set starting peak parameters for single peak fits from plot selection or auto selection
     
    41764225        for CW: [pos,0,mag,1,sig,0,gam,0]
    41774226        for TOF: [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]
     4227        for Pink: [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]
    41784228        NB: mag refinement set by default, all others off
    41794229   
     
    41834233        ind = 1
    41844234    ins = {}
    4185     if 'C' in Parms['Type'][0]:                            #CW data - TOF later in an else
    4186         for x in ['U','V','W','X','Y','Z']:
    4187             ins[x] = Parms.get(x,[0.0,0.0])[ind]
    4188         if ifQ:                              #qplot - convert back to 2-theta
    4189             pos = 2.0*asind(pos*getWave(Parms)/(4*math.pi))
    4190         sig = getCWsig(ins,pos)
    4191         gam = getCWgam(ins,pos)           
    4192         XY = [pos,0, mag,1, sig,0, gam,0]       #default refine intensity 1st
    4193     else:
     4235    if 'T' in Parms['Type'][0]:
    41944236        if ifQ:
    41954237            dsp = 2.*np.pi/pos
     
    42114253        gam = getTOFgamma(ins,dsp)
    42124254        XY = [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]
     4255    elif 'C' in Parms['Type'][0]:                            #CW data - TOF later in an else
     4256        for x in ['U','V','W','X','Y','Z']:
     4257            ins[x] = Parms.get(x,[0.0,0.0])[ind]
     4258        if ifQ:                              #qplot - convert back to 2-theta
     4259            pos = 2.0*asind(pos*getWave(Parms)/(4*math.pi))
     4260        sig = getCWsig(ins,pos)
     4261        gam = getCWgam(ins,pos)           
     4262        XY = [pos,0, mag,1, sig,0, gam,0]       #default refine intensity 1st
     4263    elif 'B' in Parms['Type'][0]:
     4264        for x in ['U','V','W','X','Y','Z','alpha-0','alpha-1','beta-0','beta-1']:
     4265            ins[x] = Parms.get(x,[0.0,0.0])[ind]
     4266        if ifQ:                              #qplot - convert back to 2-theta
     4267            pos = 2.0*asind(pos*getWave(Parms)/(4*math.pi))
     4268        alp = getPinkalpha(ins,pos)
     4269        bet = getPinkbeta(ins,pos)
     4270        sig = getCWsig(ins,pos)
     4271        gam = getCWgam(ins,pos)           
     4272        XY = [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]       #default refine intensity 1st
    42134273    return XY
    42144274   
Note: See TracChangeset for help on using the changeset viewer.