Changeset 4903


Ignore:
Timestamp:
May 17, 2021 11:23:03 AM (2 years ago)
Author:
vondreele
Message:

fix 2 issues in HessianLSQ for SVN LinAlgErrors?
fix a typo in G2plot for SASD plot display
change GetTthAzmDsp? --> GeTthAzmDsp2 in G2plot & G2Image
comment old GetTthAzmDsp? code - fails in recent python/numpy versions; replaced by GetTthAzmDsp2
change GetTthAzmG --> GetTthAzm2 in G2image

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r4832 r4903  
    595595    return np.array([tth,azm,G,dsp])
    596596   
    597 def GetTthAzmDsp(x,y,data): #expensive
    598     '''Computes a 2theta, etc. from a detector position and calibration constants - checked
    599     OK for ellipses & hyperbola.
    600 
    601     :returns: np.array(tth,azm,G,dsp) where tth is 2theta, azm is the azimutal angle,
    602        G is ? and dsp is the d-space
    603     '''
    604    
    605     def costth(xyz):
    606         u = xyz/nl.norm(xyz,axis=-1)[:,:,nxs]
    607         return np.dot(u,np.array([0.,0.,1.]))
     597# def GetTthAzmDsp(x,y,data): #expensive
     598#     '''Computes a 2theta, etc. from a detector position and calibration constants - checked
     599#     OK for ellipses & hyperbola.
     600
     601#     :returns: np.array(tth,azm,G,dsp) where tth is 2theta, azm is the azimutal angle,
     602#        G is ? and dsp is the d-space
     603#     '''
     604   
     605#     def costth(xyz):
     606#         u = xyz/nl.norm(xyz,axis=-1)[:,:,nxs]
     607#         return np.dot(u,np.array([0.,0.,1.]))
    608608       
    609 #zero detector 2-theta: tested with tilted images - perfect integrations
    610     wave = data['wavelength']
    611     dx = x-data['center'][0]
    612     dy = y-data['center'][1]
    613     tilt = data['tilt']
    614     dist = data['distance']/npcosd(tilt)    #sample-beam intersection point
    615     T = makeMat(tilt,0)
    616     R = makeMat(data['rotation'],2)
    617     MN = np.inner(R,np.inner(R,T))
    618     dxyz0 = np.inner(np.dstack([dx,dy,np.zeros_like(dx)]),MN)    #correct for 45 deg tilt
    619     dxyz0 += np.array([0.,0.,dist])
    620     if data['DetDepth']:
    621         ctth0 = costth(dxyz0)
    622         tth0 = npacosd(ctth0)
    623         dzp = peneCorr(tth0,data['DetDepth'],dist)
    624         dxyz0[:,:,2] += dzp
    625 #non zero detector 2-theta:
    626     if data['det2theta']:       
    627         tthMat = makeMat(data['det2theta'],1)
    628         dxyz = np.inner(dxyz0,tthMat.T)
    629     else:
    630         dxyz = dxyz0
    631     ctth = costth(dxyz)
    632     tth = npacosd(ctth)
    633     dsp = wave/(2.*npsind(tth/2.))
    634     azm = (npatan2d(dxyz[:,:,1],dxyz[:,:,0])+data['azmthOff']+720.)%360.       
    635 # G-calculation       
    636     x0 = data['distance']*nptand(tilt)
    637     x0x = x0*npcosd(data['rotation'])
    638     x0y = x0*npsind(data['rotation'])
    639     distsq = data['distance']**2
    640     G = ((dx-x0x)**2+(dy-x0y)**2+distsq)/distsq       #for geometric correction = 1/cos(2theta)^2 if tilt=0.
    641     return [tth,azm,G,dsp]
     609# #zero detector 2-theta: tested with tilted images - perfect integrations
     610#     wave = data['wavelength']
     611#     dx = x-data['center'][0]
     612#     dy = y-data['center'][1]
     613#     tilt = data['tilt']
     614#     dist = data['distance']/npcosd(tilt)    #sample-beam intersection point
     615#     T = makeMat(tilt,0)
     616#     R = makeMat(data['rotation'],2)
     617#     MN = np.inner(R,np.inner(R,T))
     618#     dxyz0 = np.inner(np.dstack([dx,dy,np.zeros_like(dx)]),MN)    #correct for 45 deg tilt
     619#     dxyz0 += np.array([0.,0.,dist])
     620#     if data['DetDepth']:
     621#         ctth0 = costth(dxyz0)
     622#         tth0 = npacosd(ctth0)
     623#         dzp = peneCorr(tth0,data['DetDepth'],dist)
     624#         dxyz0[:,:,2] += dzp
     625# #non zero detector 2-theta:
     626#     if data['det2theta']:       
     627#         tthMat = makeMat(data['det2theta'],1)
     628#         dxyz = np.inner(dxyz0,tthMat.T)
     629#     else:
     630#         dxyz = dxyz0
     631#     ctth = costth(dxyz)
     632#     tth = npacosd(ctth)
     633#     dsp = wave/(2.*npsind(tth/2.))
     634#     azm = (npatan2d(dxyz[:,:,1],dxyz[:,:,0])+data['azmthOff']+720.)%360.       
     635# # G-calculation       
     636#     x0 = data['distance']*nptand(tilt)
     637#     x0x = x0*npcosd(data['rotation'])
     638#     x0y = x0*npsind(data['rotation'])
     639#     distsq = data['distance']**2
     640#     G = ((dx-x0x)**2+(dy-x0y)**2+distsq)/distsq       #for geometric correction = 1/cos(2theta)^2 if tilt=0.
     641#     return [tth,azm,G,dsp]
    642642   
    643643def GetTth(x,y,data):
    644644    'Give 2-theta value for detector x,y position; calibration info in data'
    645     return GetTthAzmDsp(x,y,data)[0]
     645    return GetTthAzmDsp2(x,y,data)[0]
    646646   
    647647def GetTthAzm(x,y,data):
    648648    'Give 2-theta, azimuth values for detector x,y position; calibration info in data'
    649     return GetTthAzmDsp(x,y,data)[0:2]
     649    return GetTthAzmDsp2(x,y,data)[0:2]
    650650   
    651651def GetTthAzmG2(x,y,data):
     
    717717def GetDsp(x,y,data):
    718718    'Give d-spacing value for detector x,y position; calibration info in data'
    719     return GetTthAzmDsp(x,y,data)[3]
     719    return GetTthAzmDsp2(x,y,data)[3]
    720720       
    721721def GetAzm(x,y,data):
    722722    'Give azimuth value for detector x,y position; calibration info in data'
    723     return GetTthAzmDsp(x,y,data)[1]
     723    return GetTthAzmDsp2(x,y,data)[1]
    724724   
    725725def meanAzm(a,b):
     
    11581158    nJ = jLim[1]-jLim[0]
    11591159    TA = np.empty((4,nI,nJ))
    1160     TA[:3] = np.array(GetTthAzmG(np.reshape(tax,(nI,nJ)),np.reshape(tay,(nI,nJ)),data))     #includes geom. corr. as dist**2/d0**2 - most expensive step
     1160    TA[:3] = np.array(GetTthAzmG2(np.reshape(tax,(nI,nJ)),np.reshape(tay,(nI,nJ)),data))     #includes geom. corr. as dist**2/d0**2 - most expensive step
    11611161    TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
    11621162    TA[3] = G2pwd.Polarization(data['PolaVal'][0],TA[0],TA[1]-90.)[0]
  • trunk/GSASIImath.py

    r4840 r4903  
    263263            Amatlam = Amat*(1.+np.eye(Amat.shape[0])*lam)
    264264            try:
     265                Nzeros = 1
    265266                Ainv,Nzeros = pinv(Amatlam,xtol)    # Moore-Penrose SVD inversion
    266267            except nl.LinAlgError:
     
    412413        psing = list(np.where(np.abs(np.diag(nl.qr(Amat)[1])) < 1.e-14)[0])
    413414        if not len(psing): # make sure at least the worst term is flagged
     415            d = np.abs(np.diag(nl.qr(Amat)[1]))       
    414416            psing = [np.argmin(d)]
    415417        Amat, indices, Yvec = dropTerms(psing, Amat, indices, Yvec)
  • trunk/GSASIIplot.py

    r4895 r4903  
    35913591                            CalcLine = Plot.plot(X,Z/ymax,colors[1],picker=False,label=incCptn('calc'))                 #Ic
    35923592                        else:
    3593                             Plot.plot(X,YB,color=colors[0],marler=pP,
     3593                            Plot.plot(X,YB,color=colors[0],marker=pP,
    35943594                                picker=True,pickradius=3.,clip_on=Clip_on,label=incCptn('obs'))
    35953595                            Plot.plot(X,ZB,colors[2],picker=False,label=incCptn('calc'))
     
    73357335                if (0 <= xpix < sizexy[0]) and (0 <= ypix < sizexy[1]):
    73367336                    Int = G2frame.ImageZ[ypix][xpix]
    7337                 tth,azm,D,dsp = G2img.GetTthAzmDsp(xpos,ypos,Data)
     7337                tth,azm,D,dsp = G2img.GetTthAzmDsp2(xpos,ypos,Data)
    73387338                Q = 2.*math.pi/dsp
    73397339                if G2frame.StrainKey:
     
    74347434                xpos = event.xdata
    74357435                ypos = event.ydata
    7436                 tth,azm,D,dsp = G2img.GetTthAzmDsp(xpos,ypos,Data)
     7436                tth,azm,D,dsp = G2img.GetTthAzmDsp2(xpos,ypos,Data)
    74377437                G2frame.calibDmin.SetValue(dsp)
    74387438            elif event.key in ['x',]:
     
    74797479                # for now ignore the movement until it moves back in
    74807480                return
    7481             tth,azm,D,dsp = G2img.GetTthAzmDsp(event.xdata,event.ydata,Data)
     7481            tth,azm,D,dsp = G2img.GetTthAzmDsp2(event.xdata,event.ydata,Data)
    74827482            itemPicked = str(G2frame.itemPicked)
    74837483            if 'Itth' in itemPicked:
     
    76137613                itemNum = G2frame.itemPicked.itemNumber
    76147614                tth,azm,thick = Masks['Arcs'][itemNum]
    7615                 tthN,azmN,D,dsp = G2img.GetTthAzmDsp(Xpos,Ypos,Data)
     7615                tthN,azmN,D,dsp = G2img.GetTthAzmDsp2(Xpos,Ypos,Data)
    76167616                if event.button == 1:
    76177617                    if pickType == 'ArcInner':
     
    79227922            if not Xpos or not Ypos or Page.toolbar.AnyActive():  #got point out of frame or zoom/pan selected
    79237923                return
    7924             tth,azm,dsp = G2img.GetTthAzmDsp(Xpos,Ypos,Data)[:3]
     7924            tth,azm,dsp = G2img.GetTthAzmDsp2(Xpos,Ypos,Data)[:3]
    79257925            itemPicked = str(G2frame.itemPicked)
    79267926            try:
Note: See TracChangeset for help on using the changeset viewer.