Changeset 4324


Ignore:
Timestamp:
Feb 21, 2020 5:48:17 AM (20 months ago)
Author:
vondreele
Message:

revised auto spot finder; set default esdMul = 3 everywhere
try dlg.Raise() for all progress bars - arg; doesn't work

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r4317 r4324  
    361361    Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[],
    362362                 'Thresholds':[(0,Imax),[0,Imax]],
    363                  'SpotMask':{'esdMul':2.,'spotMask':None}}
     363                 'SpotMask':{'esdMul':3.,'spotMask':None}}
    364364    G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Masks'),Masks)
    365365    G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Stress/Strain'),
  • trunk/GSASIIimage.py

    r4316 r4324  
    2323from scipy.optimize import leastsq
    2424import scipy.interpolate as scint
     25import scipy.special as sc
    2526import copy
    2627import GSASIIpath
     
    14601461            return None
    14611462   
    1462 def AutoSpotMasks(Image,Masks,Controls):
    1463    
    1464     G2fil.G2Print ('auto spot search')
    1465     nxy = 15
    1466     rollImage = lambda rho,roll: np.roll(np.roll(rho,roll[0],axis=0),roll[1],axis=1)
    1467     pixelSize = Controls['pixelSize']
    1468     spotMask = ma.array(Image,mask=(Image<np.mean(Image)))
    1469     indices = (-1,0,1)
    1470     rolls = np.array([[ix,iy] for ix in indices for iy in indices])
    1471     time0 = time.time()
    1472     for roll in rolls:
    1473         if np.any(roll):        #avoid [0,0]
    1474             spotMask = ma.array(spotMask,mask=(spotMask-rollImage(Image,roll)<0.),dtype=float)
    1475     mags = spotMask[spotMask.nonzero()]
    1476     indx = np.transpose(spotMask.nonzero())
    1477     size1 = mags.shape[0]
    1478     magind = [[indx[0][0],indx[0][1],mags[0]],]
    1479     for ind,mag in list(zip(indx,mags))[1:]:        #remove duplicates
    1480 #            ind[0],ind[1],I,J = ImageLocalMax(Image,nxy,ind[0],ind[1])
    1481         if (magind[-1][0]-ind[0])**2+(magind[-1][1]-ind[1])**2 > 16:
    1482             magind.append([ind[0],ind[1],Image[ind[0],ind[1]]]) 
    1483     magind = np.array(magind).T
    1484     indx = np.array(magind[0:2],dtype=np.int32)
    1485     mags = magind[2]
    1486     size2 = mags.shape[0]
    1487     G2fil.G2Print ('Initial search done: %d -->%d %.2fs'%(size1,size2,time.time()-time0))
    1488     nx,ny = Image.shape
    1489     ImMax = np.max(Image)
    1490     peaks = []
    1491     nxy2 = nxy//2
    1492     mult = 0.001
    1493     num = 1e6
    1494     while num>500:
    1495         mult += .0001           
    1496         minM = mult*np.max(mags)
    1497         num = ma.count(ma.array(mags,mask=mags<=minM))
    1498         G2fil.G2Print('try',mult,minM,num)
    1499     minM = mult*np.max(mags)
    1500     G2fil.G2Print ('Find biggest spots:',mult,num,minM)
    1501     for i,mag in enumerate(mags):
    1502         if mag > minM:
    1503             if (nxy2 < indx[0][i] < nx-nxy2-1) and (nxy2 < indx[1][i] < ny-nxy2-1):
    1504 #                    G2fil.G2Print ('try:%d %d %d %.2f'%(i,indx[0][i],indx[1][i],mags[i]))
    1505                 peak = FitImageSpots(Image,ImMax,[indx[1][i],indx[0][i]],pixelSize,nxy)
    1506                 if peak and not any(np.isnan(np.array(peak))):
    1507                     peaks.append(peak)
    1508 #                    G2fil.G2Print (' Spot found: %s'%str(peak))
    1509     peaks = G2mth.sortArray(G2mth.sortArray(peaks,1),0)
    1510     Peaks = [peaks[0],]
    1511     for peak in peaks[1:]:
    1512         if GetDsp(peak[0],peak[1],Controls) >= 1.:      #toss non-diamond low angle spots
    1513             continue
    1514         if (peak[0]-Peaks[-1][0])**2+(peak[1]-Peaks[-1][1])**2 > peak[2]*Peaks[-1][2] :
    1515             Peaks.append(peak)
    1516 #            G2fil.G2Print (' Spot found: %s'%str(peak))
    1517     G2fil.G2Print ('Spots found: %d time %.2fs'%(len(Peaks),time.time()-time0))
    1518     Masks['Points'] = Peaks
    1519     return None
    1520 
    1521 def AutoSpotMasks2(Image,Masks,Controls,numChans,dlg=None):
    1522    
     1463def AutoSpotMask(Image,Masks,Controls,numChans,dlg=None):
     1464   
     1465    frame = Masks['Frames']
     1466    tam = ma.make_mask_none(Image.shape)
     1467    if frame:
     1468        tam = ma.mask_or(tam,MakeFrameMask(Controls,frame))
    15231469    LUtth = np.array(Controls['IOtth'])
    15241470    dtth = (LUtth[1]-LUtth[0])/numChans
    15251471    esdMul = Masks['SpotMask']['esdMul']
     1472    prob = 100.*sc.erf(esdMul/np.sqrt(2.))
     1473    print(' Spots greater than %.2f of band intensity are masked'%prob)
    15261474    mask = ma.make_mask_none(Image.shape)
    15271475    band = ma.array(Image,mask=ma.nomask)
     
    15291477    TThs = np.linspace(LUtth[0],LUtth[1],numChans,False)
    15301478    for it,TTh in enumerate(TThs):
    1531         band.mask = ma.masked_outside(TA,TTh,TTh+dtth).mask
    1532         std = ma.std(band)
    1533         anom = band.anom()/std
    1534         anom = ma.masked_greater(anom,esdMul,copy=False)
     1479        band.mask = ma.masked_outside(TA,TTh,TTh+dtth).mask+tam
     1480        pcmax = np.percentile(band,prob)
     1481        mband = ma.masked_greater(band,pcmax)
     1482        mean = ma.median(mband)
     1483        std = ma.std(mband)
     1484        anom = ma.masked_greater((band-mean)/std,esdMul)
    15351485        mask ^= (anom.mask^band.mask)
    15361486        if not dlg is None:
     1487            dlg.Raise()
    15371488            GoOn = dlg.Update(it,newmsg='Processed 2-theta rings = %d'%(it))
    15381489            if not GoOn[0]:
    15391490                break
    1540     Masks['SpotMask']['spotMask'] = mask
    1541     return None
     1491    return mask
  • trunk/GSASIIimgGUI.py

    r4317 r4324  
    466466                    oldMhash = 0
    467467                    for icnt,item in enumerate(items):
     468                        dlgp.Raise()
    468469                        GoOn = dlgp.Update(icnt)
    469470                        if not GoOn[0]:
     
    16581659            x0 = G2img.GetDetectorXY(dsp0,0.0,Controls)[0]
    16591660            x1 = G2img.GetDetectorXY(dsp1,0.0,Controls)[0]   
    1660             nChans = int(1000*(x1-x0)/Controls['pixelSize'][0])
    1661             dlg = wx.ProgressDialog("Auto spot masking for %d bins"%nChans,"Processed 2-theta rings = ",nChans+1,
     1661            nChans = int(1000*(x1-x0)/Controls['pixelSize'][0])//2
     1662            dlg = wx.ProgressDialog("Auto spot masking for %d bins"%nChans,"Processed 2-theta rings = ",nChans+3,
    16621663                style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT)
    16631664            time0 = time.time()
    1664             Error = G2img.AutoSpotMasks2(G2frame.ImageZ,data,Controls,nChans,dlg)
    1665             print(' Autospot processing time: %.2f'%(time.time()-time0))
    1666             if not Error is None:
    1667                 G2frame.ErrorDialog('Auto spot search error',Error)
     1665            data['SpotMask']['spotMask'] = G2img.AutoSpotMask(G2frame.ImageZ,data,Controls,nChans,dlg)
     1666            print(' Autospot processing time: %.2f m'%((time.time()-time0)/60.))
    16681667            wx.CallAfter(UpdateMasks,G2frame,data)
    16691668            wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
     
    16721671        data['Points'] = []
    16731672        wx.CallAfter(UpdateMasks,G2frame,data)
    1674         wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)         
     1673        G2plt.PlotExposedImage(G2frame,newPlot=True,event=event)         
    16751674           
    16761675    def ToggleSpotMaskMode(event):
     
    18631862   
    18641863    def OnDelBtn(event):
    1865         data['SpotMask'] = {'esdMul':2.,'spotMask':None}
     1864        data['SpotMask'] = {'esdMul':3.,'spotMask':None}
    18661865        wx.CallAfter(UpdateMasks,G2frame,data)
    18671866               
     
    19171916        data['Frames'] = []
    19181917    if 'SpotMask' not in data:
    1919         data['SpotMask'] = {'esdMul':2.,'spotMask':None}
     1918        data['SpotMask'] = {'esdMul':3.,'spotMask':None}
    19201919    frame = data['Frames']             #3+ x,y pairs
    19211920    Arcs = data['Arcs']                 #radius, start/end azimuth, thickness
     
    19461945    spotSizer = wx.BoxSizer(wx.HORIZONTAL)
    19471946    data['SpotMask']['esdMul'] = float(data['SpotMask']['esdMul'])
    1948     spotSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Select spot range factor (1-10): '),0,WACV)
     1947    spotSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Select n*sigma spot rejection (n=1-10): '),0,WACV)
    19491948    spotSizer.Add(G2G.ValidatedTxtCtrl(G2frame.dataWindow,loc=data['SpotMask'],
    19501949        key='esdMul',min=1,max=10,size=(40,25)),0,WACV)
     
    23282327            for i,name in enumerate(names):
    23292328                print (' Sequential strain fit for '+name)
     2329                dlg.Raise()
    23302330                GoOn = dlg.Update(i,newmsg='Data set name = '+name)[0]
    23312331                if not GoOn:
     
    32043204        else:
    32053205            self.ImageMasks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[],
    3206                 'SpotMask':{'esdMul':2.,'spotMask':None},}
     3206                'SpotMask':{'esdMul':3.,'spotMask':None},}
    32073207       
    32083208    def StartLoop(self):
  • trunk/GSASIIindex.py

    r4213 r4324  
    865865            if dlg:
    866866#                GoOn,Skip = dlg.Update(100*Nc/ncMax)   #wx error doesn't work in 32 bit versions!
     867                dlg.Raise()
    867868                GoOn = dlg.Update(100*Nc/ncMax)[0]
    868869                if Skip or not GoOn:
     
    956957            while cycle < 5:
    957958                if dlg:
     959                    dlg.Raise()
    958960                    dlg.Update(0,newmsg=tries[cycle]+" cell search for "+bravaisNames[ibrav])
    959961                try:
  • trunk/GSASIImath.py

    r4295 r4324  
    30103010        sumD = np.sum(np.abs(Mat))
    30113011        R = min(100.,100.*sumD/sumObs)
     3012        pgbar.Raise()
    30123013        pgbar.Update(R,newmsg='Residual = %5.2f'%(R))
    30133014        print (' Residual: %.3f%%'%(R))
     
    31753176        rho_omit[iB[0]:iF[0],iB[1]:iF[1],iB[2]:iF[2]] = np.copy(rho1[iB[0]:iF[0],iB[1]:iF[1],iB[2]:iF[2]])
    31763177        nBlk += 1
     3178        pgbar.Raise()
    31773179        pgbar.Update(nBlk)
    31783180    mapData['rho'] = np.real(rho_omit)/cell[6]
  • trunk/GSASIIpwd.py

    r4323 r4324  
    19371937        Rwp = min(100.,np.sqrt(np.sum(M**2)/np.sum(weights*ydata**2))*100.)
    19381938        if dlg:
     1939            dlg.Raise()
    19391940            GoOn = dlg.Update(Rwp,newmsg='%s%8.3f%s'%('Peak fit Rwp =',Rwp,'%'))[0]
    19401941            if not GoOn:
  • trunk/GSASIIpwdGUI.py

    r4241 r4324  
    821821            for i,name in enumerate(names):
    822822                print (' Sequential fit for '+name)
     823                dlg.Raise()
    823824                GoOn = dlg.Update(i,newmsg='Data set name = '+name)[0]
    824825                if not GoOn:
  • trunk/GSASIIscriptable.py

    r4317 r4324  
    30083008            ImgDict['Image Controls'] = Data
    30093009            ImgDict['Masks'] = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],
    3010                                 'Frames':[],'Thresholds':[(0,Imax),[0,Imax]],
    3011                                 'SpotMask':{'esdMul':2.,'spotMask':None},
    3012                                     }
     3010                'Frames':[],'Thresholds':[(0,Imax),[0,Imax]],'SpotMask':{'esdMul':3.,'spotMask':None},}
    30133011            ImgDict['Stress/Strain']  = {'Type':'True','d-zero':[],'Sample phi':0.0,
    3014                                              'Sample z':0.0,'Sample load':0.0}
     3012                'Sample z':0.0,'Sample load':0.0}
    30153013            self.names.append([TreeName]+['Comments','Image Controls','Masks','Stress/Strain'])
    30163014            self.data[TreeName] = ImgDict
Note: See TracChangeset for help on using the changeset viewer.