Changeset 3173
- Timestamp:
- Dec 5, 2017 3:23:50 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r3161 r3173 745 745 G2frame.IntgOutList.append(Id) 746 746 G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Comments'),Comments) 747 G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Limits'), [tuple(Xminmax),Xminmax])747 G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Limits'),copy.deepcopy([tuple(Xminmax),Xminmax])) 748 748 if 'PWDR' in Aname: 749 749 G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Background'),[['chebyschev',1,3,1.0,0.0,0.0], -
trunk/GSASIIimage.py
r3154 r3173 815 815 return True 816 816 817 def Make2ThetaAzimuthMap(data, masks,iLim,jLim,tamp,times): #most expensive part of integration!817 def Make2ThetaAzimuthMap(data,iLim,jLim,times): #most expensive part of integration! 818 818 'Needs a doc string' 819 819 #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 835 def MakeMaskMap(data,masks,iLim,jLim,tamp,times): 820 836 pixelSize = data['pixelSize'] 821 837 scalex = pixelSize[0]/1000. … … 840 856 tay,len(polygon),polygon,tamp)[:nI*nJ])) 841 857 if True: 842 # try:843 # import spotmask as sm844 # spots = masks['Points'].T845 # 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:849 858 for X,Y,rsq in masks['Points'].T: 850 859 tam = ma.mask_or(tam,ma.getmask(ma.masked_less((tax-X)**2+(tay-Y)**2,rsq))) 851 860 if tam.shape: tam = np.reshape(tam,(nI,nJ)) 852 861 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 858 863 859 864 def Fill2ThetaAzimuthMap(masks,TA,tam,image): … … 880 885 return tax,tay,taz,tad,tabs 881 886 882 def ImageIntegrate(image,data,masks,blkSize=128,returnN=False): 887 def 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 905 def ImageIntegrate(image,data,masks,blkSize=128,returnN=False,useTA=None): 883 906 'Integrate an image; called from OnIntegrateAll and OnIntegrate in G2imgGUI' #for q, log(q) bins need data['binType'] 884 907 import histogram2d as h2d … … 921 944 jFin = min(jBeg+blkSize,Nx) 922 945 # 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) 924 951 Block = image[iBeg:iFin,jBeg:jFin] 925 952 t0 = time.time() 926 953 tax,tay,taz,tad,tabs = Fill2ThetaAzimuthMap(Masks,TA,tam,Block) #and apply masks 927 del TA; del tam928 954 times[2] += time.time()-t0 929 955 tax = np.where(tax > LRazm[1],tax-360.,tax) #put azm inside limits if possible -
trunk/GSASIIimgGUI.py
r3172 r3173 143 143 ##### Image Controls 144 144 ################################################################################ 145 def UpdateImageControls(G2frame,data,masks,IntegrateOnly=False): 145 blkSize = 1024 #this seems to be optimal; will break in polymask if >1024 146 def UpdateImageControls(G2frame,data,masks,useTA=None,IntegrateOnly=False): 146 147 '''Shows and handles the controls on the "Image Controls" 147 148 data tree entry … … 237 238 MaxSizer.GetChildren()[5].Window.SetValue(Imin) #tricky 238 239 239 def OnIntegrate(event ):240 def OnIntegrate(event,useTA=None): 240 241 '''Integrate image in response to a menu event or from the AutoIntegrate 241 242 dialog. In the latter case, event=None. … … 243 244 ''' 244 245 CleanupMasks(masks) 245 blkSize = 1024 #this seems to be optimal; will break in polymask if >1024246 # blkSize = 128 #this seems to be optimal; will break in polymask if >1024247 246 sumImg = GetImageZ(G2frame,data) 248 247 wx.BeginBusyCursor() 249 248 try: 250 G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize )249 G2frame.Integrate = G2img.ImageIntegrate(sumImg,data,masks,blkSize,useTA=useTA) 251 250 finally: 252 251 wx.EndBusyCursor() … … 269 268 style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT) 270 269 try: 270 pId = 0 271 oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.} 271 272 for icnt,item in enumerate(items): 272 273 GoOn = dlgp.Update(icnt) … … 277 278 CId = G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Image Controls') 278 279 Data = G2frame.GPXtree.GetItemPyData(CId) 280 same = True 281 for item in ['tilt','distance','rotation','center','DetDepth','azmthOff']: 282 if Data[item] != oldData[item]: 283 same = False 284 if not same: 285 print('Use new image controls') 286 useTA = G2img.MakeUseTA(Data,blkSize) 279 287 Masks = G2frame.GPXtree.GetItemPyData( 280 288 G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Masks')) 281 289 image = GetImageZ(G2frame,Data) 282 blkSize = 128 #this seems to be optimal; will break in polymask if >1024 283 G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize) 290 G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,useTA=useTA) 284 291 del image #force cleanup 285 292 pId = G2IO.SaveIntegration(G2frame,CId,Data) 293 oldData = Data 286 294 finally: 287 295 dlgp.Destroy() 288 296 G2frame.EnablePlot = True 289 G2frame.GPXtree.SelectItem(pId) 290 G2frame.GPXtree.Expand(pId) 291 G2frame.PatternId = pId 297 if pId: 298 G2frame.GPXtree.SelectItem(pId) 299 G2frame.GPXtree.Expand(pId) 300 G2frame.PatternId = pId 292 301 finally: 293 302 dlg.Destroy() … … 1184 1193 1185 1194 if IntegrateOnly: 1186 OnIntegrate(None )1195 OnIntegrate(None,useTA=useTA) 1187 1196 return 1188 1197 … … 2715 2724 self.Pause = True 2716 2725 2717 def IntegrateImage(self,img ):2726 def IntegrateImage(self,img,useTA=None): 2718 2727 '''Integrates a single image. Ids for created PWDR entries (more than one is possible) 2719 2728 are placed in G2frame.IntgOutList … … 2741 2750 # simulate a Image Controls press, since that is where the 2742 2751 # integration is hidden 2743 UpdateImageControls(G2frame,data,masks, IntegrateOnly=True)2752 UpdateImageControls(G2frame,data,masks,useTA=useTA,IntegrateOnly=True) 2744 2753 G2frame.IntegratedList.append(img) # note this as integrated 2745 2754 # split name and control number … … 2919 2928 This is called only after the "Start" button is pressed (then its label reads "Pause"). 2920 2929 ''' 2921 def AutoIntegrateImage(imgId ):2930 def AutoIntegrateImage(imgId,useTA=None): 2922 2931 '''Integrates an image that has been read into the data tree and updates the 2923 2932 AutoInt window. … … 2936 2945 self.EnableButtons(False) 2937 2946 try: 2938 self.IntegrateImage(img )2947 self.IntegrateImage(img,useTA=useTA) 2939 2948 finally: 2940 2949 self.EnableButtons(True) … … 3022 3031 # integrate the images that have already been read in, but 3023 3032 # have not yet been processed 3033 oldData = {'tilt':0.,'distance':0.,'rotation':0.,'center':[0.,0.],'DetDepth':0.,'azmthOff':0.} 3024 3034 for img in G2gd.GetGPXtreeDataNames(G2frame,['IMG ']): 3025 3035 imgId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,img) … … 3029 3039 # skip if already integrated 3030 3040 if img in G2frame.IntegratedList: continue 3031 AutoIntegrateImage(imgId) 3032 #self.Pause |= G2frame.PauseIntegration 3033 #if self.Pause: 3034 # self.OnPause() 3035 # self.PreventReEntryTimer = False 3036 # return 3041 Data = G2frame.GPXtree.GetItemPyData( 3042 G2gd.GetGPXtreeItemId(G2frame,imgId, 'Image Controls')) 3043 same = True 3044 for item in ['tilt','distance','rotation','center','DetDepth','azmthOff']: 3045 if Data[item] != oldData[item]: 3046 same = False 3047 if not same: 3048 print('Use new image controls') 3049 self.useTA = G2img.MakeUseTA(Data,blkSize) 3050 AutoIntegrateImage(imgId,self.useTA) 3051 oldData = Data 3037 3052 if self.pdfControls: AutoComputePDF(imgId) 3038 3053 self.Pause |= G2frame.PauseIntegration … … 3046 3061 if newImage in imageFileList or self.Pause: continue # already read? 3047 3062 for imgId in G2IO.ReadImages(G2frame,newImage): 3048 AutoIntegrateImage(imgId) 3049 #self.Pause |= G2frame.PauseIntegration 3050 #if self.Pause: 3051 # self.OnPause() 3052 # self.PreventReEntryTimer = False 3053 # return 3063 AutoIntegrateImage(imgId,self.useTA) 3054 3064 if self.pdfControls: AutoComputePDF(imgId) 3055 3065 self.Pause |= G2frame.PauseIntegration -
trunk/GSASIIpwdGUI.py
r3171 r3173 1375 1375 Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,item) 1376 1376 G2frame.GPXtree.SetItemPyData( 1377 G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'),copy. copy(data))1377 G2gd.GetGPXtreeItemId(G2frame,Id,'Limits'),copy.deepcopy(data)) 1378 1378 finally: 1379 1379 dlg.Destroy()
Note: See TracChangeset
for help on using the changeset viewer.