Changeset 4299


Ignore:
Timestamp:
Feb 13, 2020 9:56:45 AM (20 months ago)
Author:
vondreele
Message:

new spot mask algorithm - it is slow but works

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r4181 r4299  
    11881188
    11891189            t0 = time.time()
    1190             Block = image[iBeg:iFin,jBeg:jFin]
     1190            Block = image[iBeg:iFin,jBeg:jFin]          #apply image spotmask here
    11911191            tax,tay,taz,tad,tabs = Fill2ThetaAzimuthMap(Masks,TA,tam,Block)    #and apply masks
    11921192            tax = np.where(tax > LRazm[1],tax-360.,tax)                 #put azm inside limits if possible
     
    15181518    Masks['Points'] = Peaks
    15191519    return None
     1520
     1521def AutoSpotMasks2(Image,Masks,Controls,dlg=None):
     1522   
     1523    LUtth = np.array(Controls['IOtth'])
     1524    numChans = Controls['outChannels']
     1525    dtth = (LUtth[1]-LUtth[0])/numChans
     1526    esdMul = Masks['SpotMask']['esdMul']
     1527    mask = ma.make_mask_none(Image.shape)   
     1528    TA = Make2ThetaAzimuthMap(Controls,(0,Image.shape[0]),(0,Image.shape[1]))[0]    #2-theta array
     1529    TThs = np.linspace(LUtth[0],LUtth[1],numChans,False)
     1530    for it,TTh in enumerate(TThs):
     1531        band = ma.array(Image,mask=ma.getmask(ma.masked_outside(TA,TTh,TTh+dtth)))
     1532        std = ma.std(band)
     1533        anom = band.anom()/std
     1534        anom = ma.masked_greater(anom,esdMul,copy=False)
     1535        mask ^= (ma.getmask(anom)^ma.getmask(band))
     1536        if not dlg is None:
     1537            GoOn = dlg.Update(it,newmsg='Processed 2-theta rings = %d'%(it))
     1538            if not GoOn[0]:
     1539                break
     1540    Masks['SpotMask']['spotMask'] = mask
     1541    return None
  • trunk/GSASIIimgGUI.py

    r4286 r4299  
    2828import matplotlib as mpl
    2929import numpy as np
     30import numpy.ma as ma
    3031import GSASIIpath
    3132GSASIIpath.SetVersionNumber("$Revision$")
     
    16441645            Controls = copy.deepcopy(G2frame.GPXtree.GetItemPyData(
    16451646                G2gd.GetGPXtreeItemId(G2frame,G2frame.Image,'Image Controls')))
    1646             Error = G2img.AutoSpotMasks(G2frame.ImageZ,data,Controls)
     1647            nChans = Controls['outChannels']
     1648            dlg = wx.ProgressDialog("Auto spot masking","Processed 2-theta rings = ",nChans+1,
     1649                style = wx.PD_ELAPSED_TIME|wx.PD_CAN_ABORT)
     1650            Error = G2img.AutoSpotMasks2(G2frame.ImageZ,data,Controls,dlg)
    16471651            if not Error is None:
    16481652                G2frame.ErrorDialog('Auto spot search error',Error)
     
    18421846        maxSizer.Add(autoSizer)
    18431847        return maxSizer
    1844 
     1848   
     1849    def OnDelBtn(event):
     1850        data['SpotMask'] = {'esdMul':2,'spotMask':None}
     1851        wx.CallAfter(UpdateMasks,G2frame,data)
     1852               
     1853   
    18451854    G2frame.dataWindow.ClearData()
    18461855    startScroll = None
     
    18911900    if 'Frames' not in data:
    18921901        data['Frames'] = []
     1902    if 'SpotMask' not in data:
     1903        data['SpotMask'] = {'esdMul':2,'spotMask':None}
    18931904    frame = data['Frames']             #3+ x,y pairs
    18941905    Arcs = data['Arcs']                 #radius, start/end azimuth, thickness
     
    19171928    littleSizer.Add(upperThreshold,0,WACV)
    19181929    mainSizer.Add(littleSizer,0,)
     1930    spotSizer = wx.BoxSizer(wx.HORIZONTAL)
     1931    spotSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Select spot range factor (1-10): '),0,WACV)
     1932    spotSizer.Add(G2G.ValidatedTxtCtrl(G2frame.dataWindow,loc=data['SpotMask'],
     1933        key='esdMul',min=1,max=10,size=(40,25)),0,WACV)
     1934    numPix = 0
     1935    if data['SpotMask']['spotMask'] is not None:
     1936        numPix = np.count_nonzero(data['SpotMask']['spotMask'])
     1937    spotSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Number of pixels in spot mask: %d  '%numPix),0,WACV)
     1938    delbtn = wx.Button(G2frame.dataWindow,label='Clear spot mask')
     1939    delbtn.Bind(wx.EVT_BUTTON,OnDelBtn)
     1940    spotSizer.Add(delbtn,0,WACV)
     1941    mainSizer.Add(spotSizer,0,WACV)
    19191942    if len(Spots):
    19201943        lbl = wx.StaticText(parent=G2frame.dataWindow,label=' Spot masks(on plot LB drag to move, shift-LB drag to resize, RB to delete)')
  • trunk/GSASIIplot.py

    r4298 r4299  
    76747674        if newImage:
    76757675            Imin,Imax = Data['range'][1]
    7676             MA = ma.masked_greater(ma.masked_less(G2frame.ImageZ,Zlim[0]),Zlim[1])           
    7677             MaskA = ma.getmaskarray(MA)
     7676            MA = ma.masked_outside(G2frame.ImageZ,Zlim[0],Zlim[1])
     7677            MaskA = ma.getmaskarray(MA)^Masks['SpotMask']['spotMask']
     7678            MA = ma.array(MA,mask=MaskA)
    76787679            for xline in Masks.get('Xlines',[]):
    76797680                MaskA[xline,:] = True
Note: See TracChangeset for help on using the changeset viewer.