Changeset 1392


Ignore:
Timestamp:
Jun 23, 2014 4:18:14 PM (7 years ago)
Author:
vondreele
Message:

Speedup GetTthAzmDsp? - ~40% improvement
add size item to UpdateImageData?

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIElem.py

    r1391 r1392  
    327327   
    328328def BlenResTOF(El,BLtables,wave):
    329 #    FP = np.zeros(len(wave))
     329    FP = np.zeros(len(wave))
    330330    FPP = np.zeros(len(wave))
    331331    BL = BLtables[El][1]
  • trunk/GSASIIimage.py

    r1387 r1392  
    7878    :param int Axis: 0 for rotation about x, 1 for about y, etc.
    7979    '''
    80     cs = cosd(Angle)
    81     ss = sind(Angle)
     80    cs = npcosd(Angle)
     81    ss = npsind(Angle)
    8282    M = np.array(([1.,0.,0.],[0.,cs,-ss],[0.,ss,cs]),dtype=np.float32)
    8383    return np.roll(np.roll(M,Axis,axis=0),Axis,axis=1)
     
    363363    return GetDetectorXY(dsp,azm,data)
    364364                   
    365 def GetTthAzmDsp(x,y,data):
     365def GetTthAzmDsp(x,y,data): #expensive
    366366    'Needs a doc string - checked OK for ellipses & hyperbola'
    367     wave = data['wavelength']
    368     cent = data['center']
    369367    tilt = data['tilt']
    370     dist = data['distance']/cosd(tilt)
    371     x0 = data['distance']*tand(tilt)
    372     phi = data['rotation']
    373     dep = data['DetDepth']
    374     LRazim = data['LRazimuth']
    375     azmthoff = data['azmthOff']
    376     dx = np.array(x-cent[0],dtype=np.float32)
    377     dy = np.array(y-cent[1],dtype=np.float32)
     368    dist = data['distance']/npcosd(tilt)
     369    x0 = data['distance']*nptand(tilt)
     370    dx = x-data['center'][0]
     371    dy = y-data['center'][1]
    378372    D = ((dx-x0)**2+dy**2+data['distance']**2)      #sample to pixel distance
    379     X = np.array(([dx,dy,np.zeros_like(dx)]),dtype=np.float32).T
    380     X = np.dot(X,makeMat(phi,2))
    381     Z = np.dot(X,makeMat(tilt,0)).T[2]
     373    X = np.dstack([dx,dy,np.zeros_like(dx)])
     374    M = makeMat(data['rotation'],2)
     375    N = makeMat(tilt,0)
     376    NM = np.inner(N,M)
     377    Z = np.dot(X,NM).T[2]
    382378    tth = npatand(np.sqrt(dx**2+dy**2-Z**2)/(dist-Z))
    383     dxy = peneCorr(tth,dep,tilt,npatan2d(dy,dx))
     379    dxy = peneCorr(tth,data['DetDepth'],tilt,npatan2d(dy,dx))
    384380    DX = dist-Z+dxy
    385381    DY = np.sqrt(dx**2+dy**2-Z**2)
    386382    tth = npatan2d(DY,DX)
    387     dsp = wave/(2.*npsind(tth/2.))
    388     azm = (npatan2d(dy,dx)+azmthoff+720.)%360.
     383    dsp = data['wavelength']/(2.*npsind(tth/2.))
     384    azm = (npatan2d(dy,dx)+data['azmthOff']+720.)%360.
    389385    G = D/data['distance']**2       #for geometric correction = 1/cos(2theta)^2 if tilt=0.
    390     return np.array([tth,azm,G,dsp])
     386    return tth,azm,G,dsp
    391387   
    392388def GetTth(x,y,data):
     
    398394    return GetTthAzmDsp(x,y,data)[0:2]
    399395   
    400 def GetTthAzmD(x,y,data):
    401     '''Give 2-theta, azimuth & d-spacing values for detector x,y position;
     396def GetTthAzmG(x,y,data):
     397    '''Give 2-theta, azimuth & geometric corr. values for detector x,y position;
    402398     calibration info in data
    403399    '''
     
    744740    return True
    745741   
    746 def Make2ThetaAzimuthMap(data,masks,iLim,jLim):
     742def Make2ThetaAzimuthMap(data,masks,iLim,jLim,times): #most expensive part of integration!
    747743    'Needs a doc string'
    748744    #transforms 2D image from x,y space to 2-theta,azimuth space based on detector orientation
     
    756752    nI = iLim[1]-iLim[0]
    757753    nJ = jLim[1]-jLim[0]
     754    t0 = time.time()
    758755    #make position masks here
    759756    frame = masks['Frames']
     
    776773        tamp = ma.getmask(ma.masked_less((tax-X)**2+(tay-Y)**2,(diam/2.)**2))
    777774        tam = ma.mask_or(tam,tamp)
    778     TA = np.array(GetTthAzmD(tax,tay,data))     #includes geom. corr. as dist**2/d0**2
     775    times[0] += time.time()-t0
     776    t0 = time.time()
     777    TA = np.array(GetTthAzmG(tax,tay,data))     #includes geom. corr. as dist**2/d0**2 - most expensive step
     778    times[1] += time.time()-t0
    779779    TA[1] = np.where(TA[1]<0,TA[1]+360,TA[1])
    780780    return np.array(TA),tam           #2-theta, azimuth & geom. corr. arrays & position mask
     
    830830    nYBlks = (Ny-1)/blkSize+1
    831831    Nup = nXBlks*nYBlks*3+3
    832     t0 = time.time()
     832    tbeg = time.time()
    833833    Nup = 0
    834834    if dlg:
    835835        dlg.Update(Nup)
     836    times = [0,0,0,0,0]
    836837    for iBlk in range(nYBlks):
    837838        iBeg = iBlk*blkSize
     
    839840        for jBlk in range(nXBlks):
    840841            jBeg = jBlk*blkSize
    841             jFin = min(jBeg+blkSize,Nx)               
    842             TA,tam = Make2ThetaAzimuthMap(data,masks,(iBeg,iFin),(jBeg,jFin))           #2-theta & azimuth arrays & create position mask
    843            
     842            jFin = min(jBeg+blkSize,Nx)
     843            # next is most expensive step!
     844            TA,tam = Make2ThetaAzimuthMap(data,masks,(iBeg,iFin),(jBeg,jFin),times)           #2-theta & azimuth arrays & create position mask
    844845            Nup += 1
    845846            if dlg:
    846847                dlg.Update(Nup)
    847848            Block = image[iBeg:iFin,jBeg:jFin]
     849            t0 = time.time()
    848850            tax,tay,taz,tad,tabs = Fill2ThetaAzimuthMap(masks,TA,tam,Block)    #and apply masks
     851            times[2] += time.time()-t0
    849852            Nup += 1
    850853            if dlg:
     
    862865            elif 'q' == data['binType']:
    863866                tay = 4.*np.pi*npsind(tay/2.)/data['wavelength']
     867            t0 = time.time()
    864868            if any([tax.shape[0],tay.shape[0],taz.shape[0]]):
    865869                NST,H0 = h2d.histogram2d(len(tax),tax,tay,taz*tad/tabs,
    866870                    numAzms,numChans,LRazm,lutth,Dazm,dtth,NST,H0)
     871            times[3] += time.time()-t0
    867872            Nup += 1
    868873            if dlg:
    869874                dlg.Update(Nup)
     875    t0 = time.time()
    870876    NST = np.array(NST,dtype=np.float)
    871877    H0 = np.divide(H0,NST)
     
    892898    if dlg:
    893899        dlg.Update(Nup)
    894     t1 = time.time()
     900    times[4] += time.time()-t0
     901    print 'Step times: \n apply masks  %8.3fs xy->th,azm   %8.3fs fill map     %8.3fs \
     902        \n binning      %8.3fs cleanup      %8.3fs'%(times[0],times[1],times[2],times[3],times[4])
     903    print "Elapsed time:","%8.3fs"%(time.time()-tbeg)
    895904    print 'Integration complete'
    896     print "Elapsed time:","%8.3f"%(t1-t0), "s"
    897905    return H0,H1,H2
    898906   
  • trunk/GSASIIimgGUI.py

    r1389 r1392  
    6464    mainSizer.Add(wx.StaticText(G2frame.dataDisplay,
    6565        label='Do not change anything here unless you are absolutely sure!'),0,WACV)
     66    mainSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' Image size: %d by %d'%(data['size'][0],data['size'][1])),0,WACV)
    6667    pixSize = wx.FlexGridSizer(0,4,5,5)
    67     pixLabels = [u'Pixel X-dimension (\xb5m)',u'Pixel Y-dimension (\xb5m)']
     68    pixLabels = [u' Pixel X-dimension (\xb5m)',u' Pixel Y-dimension (\xb5m)']
    6869    Indx = {}
    6970    for i,[pixLabel,pix] in enumerate(zip(pixLabels,data['pixelSize'])):
Note: See TracChangeset for help on using the changeset viewer.