Changeset 3173 for trunk/GSASIIimage.py


Ignore:
Timestamp:
Dec 5, 2017 3:23:50 PM (4 years ago)
Author:
vondreele
Message:

ensure limits on multiple powder patterns from integration are independent
Integrate All & Auto integrate now reuse x,y --> 2th,azm maps if image controls unchanged - much faster multiple integrations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r3154 r3173  
    815815    return True
    816816   
    817 def Make2ThetaAzimuthMap(data,masks,iLim,jLim,tamp,times): #most expensive part of integration!
     817def Make2ThetaAzimuthMap(data,iLim,jLim,times): #most expensive part of integration!
    818818    'Needs a doc string'
    819819    #transforms 2D image from x,y space to 2-theta,azimuth space based on detector orientation
     820    pixelSize = data['pixelSize']
     821    scalex = pixelSize[0]/1000.
     822    scaley = pixelSize[1]/1000.
     823   
     824    tay,tax = np.mgrid[iLim[0]+0.5:iLim[1]+.5,jLim[0]+.5:jLim[1]+.5]         #bin centers not corners
     825    tax = np.asfarray(tax*scalex,dtype=np.float32).flatten()
     826    tay = np.asfarray(tay*scaley,dtype=np.float32).flatten()
     827    nI = iLim[1]-iLim[0]
     828    nJ = jLim[1]-jLim[0]
     829    t0 = time.time()
     830    TA = 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
     831    times[1] += time.time()-t0
     832    TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
     833    return TA           #2-theta, azimuth & geom. corr. arrays
     834
     835def MakeMaskMap(data,masks,iLim,jLim,tamp,times):
    820836    pixelSize = data['pixelSize']
    821837    scalex = pixelSize[0]/1000.
     
    840856                tay,len(polygon),polygon,tamp)[:nI*nJ]))
    841857    if True:
    842 #    try:
    843 #        import spotmask as sm
    844 #        spots = masks['Points'].T
    845 #        if len(spots):
    846 #            tam = ma.mask_or(tam,ma.getmask(sm.spotmask(nI*nJ,tax,
    847 #                    tay,len(spots),spots,tamp)[:nI*nJ]))
    848 #    except:
    849858        for X,Y,rsq in masks['Points'].T:
    850859            tam = ma.mask_or(tam,ma.getmask(ma.masked_less((tax-X)**2+(tay-Y)**2,rsq)))
    851860    if tam.shape: tam = np.reshape(tam,(nI,nJ))
    852861    times[0] += time.time()-t0
    853     t0 = time.time()
    854     TA = 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
    855     times[1] += time.time()-t0
    856     TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
    857     return np.array(TA),tam           #2-theta, azimuth & geom. corr. arrays & position mask
     862    return tam           #position mask
    858863
    859864def Fill2ThetaAzimuthMap(masks,TA,tam,image):
     
    880885    return tax,tay,taz,tad,tabs
    881886
    882 def ImageIntegrate(image,data,masks,blkSize=128,returnN=False):
     887def MakeUseTA(data,blkSize=128):
     888    times = [0,0,0,0,0]
     889    Nx,Ny = data['size']
     890    nXBlks = (Nx-1)//blkSize+1
     891    nYBlks = (Ny-1)//blkSize+1
     892    useTA = []
     893    for iBlk in range(nYBlks):
     894        iBeg = iBlk*blkSize
     895        iFin = min(iBeg+blkSize,Ny)
     896        useTAj = []
     897        for jBlk in range(nXBlks):
     898            jBeg = jBlk*blkSize
     899            jFin = min(jBeg+blkSize,Nx)
     900            TA = Make2ThetaAzimuthMap(data,(iBeg,iFin),(jBeg,jFin),times)          #2-theta & azimuth arrays & create position mask
     901            useTAj.append(TA)
     902        useTA.append(useTAj)
     903    return useTA
     904
     905def ImageIntegrate(image,data,masks,blkSize=128,returnN=False,useTA=None):
    883906    'Integrate an image; called from OnIntegrateAll and OnIntegrate in G2imgGUI'    #for q, log(q) bins need data['binType']
    884907    import histogram2d as h2d
     
    921944            jFin = min(jBeg+blkSize,Nx)
    922945            # next is most expensive step!
    923             TA,tam = Make2ThetaAzimuthMap(data,Masks,(iBeg,iFin),(jBeg,jFin),tamp,times)           #2-theta & azimuth arrays & create position mask
     946            if useTA:
     947                TA = useTA[iBlk][jBlk]
     948            else:
     949                TA = Make2ThetaAzimuthMap(data,(iBeg,iFin),(jBeg,jFin),times)           #2-theta & azimuth arrays & create position mask
     950            tam = MakeMaskMap(data,Masks,(iBeg,iFin),(jBeg,jFin),tamp,times)
    924951            Block = image[iBeg:iFin,jBeg:jFin]
    925952            t0 = time.time()
    926953            tax,tay,taz,tad,tabs = Fill2ThetaAzimuthMap(Masks,TA,tam,Block)    #and apply masks
    927             del TA; del tam
    928954            times[2] += time.time()-t0
    929955            tax = np.where(tax > LRazm[1],tax-360.,tax)                 #put azm inside limits if possible
Note: See TracChangeset for help on using the changeset viewer.