Changeset 2411


Ignore:
Timestamp:
Aug 8, 2016 5:09:05 PM (5 years ago)
Author:
vondreele
Message:

fix image plot rescaling problem
add ring graininess determination - can be done sequentially
some plot fixes

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r2403 r2411  
    103103
    104104[ wxID_STRSTACOPY, wxID_STRSTAFIT, wxID_STRSTASAVE, wxID_STRSTALOAD,wxID_STRSTSAMPLE,
    105     wxID_APPENDDZERO,wxID_STRSTAALLFIT,wxID_UPDATEDZERO,
    106 ] = [wx.NewId() for item in range(8)]
     105    wxID_APPENDDZERO,wxID_STRSTAALLFIT,wxID_UPDATEDZERO,wxID_STRSTAPLOT,
     106] = [wx.NewId() for item in range(9)]
    107107
    108108[ wxID_BACKCOPY,wxID_LIMITCOPY, wxID_SAMPLECOPY, wxID_SAMPLECOPYSOME, wxID_BACKFLAGCOPY, wxID_SAMPLEFLAGCOPY,
     
    18141814        self.StrStaEdit.Append(help='Fit stress/strain data',
    18151815            id=wxID_STRSTAFIT, kind=wx.ITEM_NORMAL,text='Fit stress/strain')
     1816        self.StrStaEdit.Append(help='Plot intensity distribution',
     1817            id=wxID_STRSTAPLOT, kind=wx.ITEM_NORMAL,text='Plot intensity distribution')
    18161818        self.StrStaEdit.Append(help='Update d-zero from ave d-zero',
    18171819            id=wxID_UPDATEDZERO, kind=wx.ITEM_NORMAL,text='Update d-zero')       
     
    41254127        data = G2frame.PatternTree.GetItemPyData(
    41264128            GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
    4127         G2frame.ImageZ = G2imG.GetImageZ(G2frame,data)
     4129        G2frame.ImageZ = G2imG.GetImageZ(G2frame,data,newRange=False)
    41284130        strsta = G2frame.PatternTree.GetItemPyData(item)
    4129         G2plt.PlotImage(G2frame,newPlot=True)
    41304131        G2plt.PlotStrain(G2frame,strsta,newPlot=True)
     4132        G2plt.PlotImage(G2frame,newPlot=False)
    41314133        G2imG.UpdateStressStrain(G2frame,strsta)
    41324134    elif G2frame.PatternTree.GetItemText(item) == 'PDF Controls':
  • trunk/GSASIIimage.py

    r2348 r2411  
    2121import numpy.linalg as nl
    2222import numpy.ma as ma
     23import numpy.fft as fft
     24import scipy.signal as signal
    2325import polymask as pm
    2426from scipy.optimize import leastsq
     
    216218    xpix = int(Xpix)            #get reference corner of pixel chosen
    217219    ypix = int(Ypix)
    218     if (w < xpix < sizex-w) and (w < ypix < sizey-w) and image[ypix,xpix]:
    219         Z = image[ypix-w:ypix+w,xpix-w:xpix+w]
    220         Zmax = np.argmax(Z)
    221         Zmin = np.argmin(Z)
     220    if not w:
     221        ZMax = np.sum(image[ypix-1:ypix+1,xpix-1:xpix+1])
     222        return xpix,ypix,ZMax,0.0001
     223    if (w2 < xpix < sizex-w2) and (w2 < ypix < sizey-w2) and image[ypix,xpix]:
     224        ZMax = image[ypix-w:ypix+w,xpix-w:xpix+w]
     225        Zmax = np.argmax(ZMax)
     226        ZMin = image[ypix-w2:ypix+w2,xpix-w2:xpix+w2]
     227        Zmin = np.argmin(ZMin)
    222228        xpix += Zmax%w2-w
    223229        ypix += Zmax/w2-w
    224         return xpix,ypix,np.ravel(Z)[Zmax],max(0.0001,np.ravel(Z)[Zmin])   #avoid neg/zero minimum
     230        return xpix,ypix,np.ravel(ZMax)[Zmax],max(0.0001,np.ravel(ZMin)[Zmin])   #avoid neg/zero minimum
    225231    else:
    226232        return 0,0,0,0     
     
    243249    ring = []
    244250    C = int(ellipseC())         #ring circumference
     251    azm = []
    245252    for i in range(0,C,1):      #step around ring in 1mm increments
    246253        a = 360.*i/C
     
    257264            if [X,Y,dsp] not in ring:           #no duplicates!
    258265                ring.append([X,Y,dsp])
     266                azm.append(a)
    259267    if len(ring) < 10:
    260268        ring = []
    261     return ring
     269        azm = []
     270    return ring,azm
    262271   
    263272def GetEllipse2(tth,dxy,dist,cent,tilt,phi):
     
    554563            break
    555564        ellipse = GetEllipse(dsp,data)
    556         Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(G2frame.ImageZ,mask=tam))
     565        Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(G2frame.ImageZ,mask=tam))[0]
    557566        if Ring:
    558567            if iH >= skip:
     
    623632    #setup 360 points on that ring for "good" fit
    624633    data['ellipses'].append(ellipse[:]+('g',))
    625     Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)
     634    Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    626635    if Ring:
    627636        ellipse = FitEllipse(Ring)
    628         Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)    #do again
     637        Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0]    #do again
    629638        ellipse = FitEllipse(Ring)
    630639    else:
     
    670679        tth = npatan2d(radii[0],dist)
    671680        data['wavelength'] = wave =  2.0*dsp*sind(tth/2.0)
    672     Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,G2frame.ImageZ)
     681    Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    673682    ttth = nptand(tth)
    674683    stth = npsind(tth)
     
    706715            ellipsep = GetEllipse2(tth,0.,dist,centp,tilt,phi)
    707716            print fmt%('plus ellipse :',ellipsep[0][0],ellipsep[0][1],ellipsep[1],ellipsep[2][0],ellipsep[2][1])
    708             Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ)
     717            Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    709718            parmDict = {'dist':dist,'det-X':centp[0],'det-Y':centp[1],
    710719                'tilt':tilt,'phi':phi,'wave':wave,'dep':0.0}       
     
    720729            ellipsem = GetEllipse2(tth,0.,dist,centm,-tilt,phi)
    721730            print fmt%('minus ellipse:',ellipsem[0][0],ellipsem[0][1],ellipsem[1],ellipsem[2][0],ellipsem[2][1])
    722             Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ)
     731            Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    723732            if len(Ringm) > 10:
    724733                parmDict['tilt'] *= -1
     
    760769        data['ellipses'].append(copy.deepcopy(ellipse+('g',)))
    761770        if debug:   print fmt%('predicted ellipse:',elcent[0],elcent[1],phi,radii[0],radii[1])
    762         Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)
     771        Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    763772        if Ring:
    764773            data['rings'].append(np.array(Ring))
     
    979988    scalex = 1000./pixSize[0]
    980989    scaley = 1000./pixSize[1]
    981     Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image)).T   #returns x,y,dsp for each point in ring
     990    Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image)[0]).T   #returns x,y,dsp for each point in ring
    982991    if len(Ring):
    983992        ring['ImxyObs'] = copy.copy(Ring[:2])
     
    10011010    phi = StrSta['Sample phi']
    10021011    wave = Controls['wavelength']
     1012    pixelSize = Controls['pixelSize']
     1013    scalex = 1000./pixelSize[0]
     1014    scaley = 1000./pixelSize[1]
    10031015    StaType = StrSta['Type']
    10041016    StaControls['distance'] += StrSta['Sample z']*cosd(phi)
     
    10131025            ring['Emat'] = val
    10141026            ring['Esig'] = esd
     1027            ellipse = FitEllipse(R['ImxyObs'].T)
     1028            ringxy,ringazm = makeRing(ring['Dcalc'],ellipse,0,0.,scalex,scaley,Image)
     1029            ringint = np.array([float(Image[int(y*scaley),int(x*scalex)]) for x,y in np.array(ringxy)[:,:2]])
     1030            ringint /= np.mean(ringint)
     1031            ring['Ivar'] = np.var(ringint)
     1032            print 'Variance in normalized ring intensity: %.3f'%(ring['Ivar'])
    10151033    CalcStrSta(StrSta,Controls)
     1034   
     1035def IntStrSta(Image,StrSta,Controls):
     1036    StaControls = copy.deepcopy(Controls)
     1037    pixelSize = Controls['pixelSize']
     1038    scalex = 1000./pixelSize[0]
     1039    scaley = 1000./pixelSize[1]
     1040    phi = StrSta['Sample phi']
     1041    StaControls['distance'] += StrSta['Sample z']*cosd(phi)
     1042    RingsAI = []
     1043    for ring in StrSta['d-zero']:       #get observed x,y,d points for the d-zeros
     1044        Ring,R = MakeStrStaRing(ring,Image,StaControls)
     1045        if len(Ring):
     1046            ellipse = FitEllipse(R['ImxyObs'].T)
     1047            ringxy,ringazm = makeRing(ring['Dcalc'],ellipse,0,0.,scalex,scaley,Image)
     1048            ringint = np.array([float(Image[int(y*scaley),int(x*scalex)]) for x,y in np.array(ringxy)[:,:2]])
     1049            ringint /= np.mean(ringint)
     1050            print 'variance:',ring['Dcalc'],np.var(ringint)
     1051            RingsAI.append(np.array(zip(ringazm,ringint)).T)
     1052#            GSASIIpath.IPyBreak()
     1053    return RingsAI
    10161054   
    10171055def CalcStrSta(StrSta,Controls):
  • trunk/GSASIIimgGUI.py

    r2348 r2411  
    5151################################################################################
    5252
    53 def GetImageZ(G2frame,data):
     53def GetImageZ(G2frame,data,newRange=True):
    5454    '''Gets image & applies dark, background & flat background corrections
    5555    :param wx.Frame G2frame: main GSAS-II frame
     
    100100    sumImg -= int(data.get('Flat Bkg',0))
    101101    Imax = np.max(sumImg)
    102     data['range'] = [(0,Imax),[0,Imax]]
     102    if newRange:
     103        data['range'] = [(0,Imax),[0,Imax]]
    103104    return sumImg
    104105
     
    14481449    littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Lower/Upper thresholds '),0,WACV)
    14491450    lowerThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=0,
    1450                                            min=thresh[0][0],OnLeave=Replot,typeHint=int)
     1451        min=thresh[0][0],OnLeave=Replot,typeHint=int)
    14511452    littleSizer.Add(lowerThreshold,0,WACV)
    14521453    upperThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=1,
    1453                                            max=thresh[0][1],OnLeave=Replot,typeHint=int)
     1454        max=thresh[0][1],OnLeave=Replot,typeHint=int)
    14541455    littleSizer.Add(upperThreshold,0,WACV)
    14551456    mainSizer.Add(littleSizer,0,)
     
    14711472                spotText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
    14721473                spotDiameter = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Spots[i],key=2,
    1473                                            max=100.,OnLeave=Replot,nDig=[8,2])
     1474                    max=100.,OnLeave=Replot,nDig=[8,2])
    14741475                littleSizer.Add(spotDiameter,0,WACV)
    14751476                spotDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?',
    1476                                             locationcode='Delete+Points+'+str(i),
    1477                                             handler=onDeleteMask)
     1477                    locationcode='Delete+Points+'+str(i),handler=onDeleteMask)
    14781478                littleSizer.Add(spotDelete,0,WACV)
    14791479        mainSizer.Add(littleSizer,0,)
     
    14941494                littleSizer.Add(ringText,0,WACV)
    14951495                ringThick = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Rings[i],key=1,
    1496                                            min=0.001,max=1.,OnLeave=Replot,nDig=[8,3])
     1496                    min=0.001,max=1.,OnLeave=Replot,nDig=[8,3])
    14971497                littleSizer.Add(ringThick,0,WACV)
    14981498                ringDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?',
    1499                                             locationcode='Delete+Rings+'+str(i),
    1500                                             handler=onDeleteMask)
     1499                    locationcode='Delete+Rings+'+str(i),handler=onDeleteMask)
    15011500                littleSizer.Add(ringDelete,0,WACV)
    15021501        mainSizer.Add(littleSizer,0,)
     
    15241523                littleSizer.Add(azmText,0,WACV)
    15251524                arcThick = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Arcs[i],key=2,
    1526                                            min=0.001,max=20.,OnLeave=Replot,nDig=[8,3])
     1525                    min=0.001,max=20.,OnLeave=Replot,nDig=[8,3])
    15271526                littleSizer.Add(arcThick,0,WACV)
    15281527                arcDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?',
    1529                                             locationcode='Delete+Arcs+'+str(i),
    1530                                             handler=onDeleteMask)
     1528                    locationcode='Delete+Arcs+'+str(i),handler=onDeleteMask)
    15311529                littleSizer.Add(arcDelete,0,WACV)
    15321530        mainSizer.Add(littleSizer,0,)
     
    15451543                littleSizer.Add(polyText,0,WACV)
    15461544                polyDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?',
    1547                                             locationcode='Delete+Polygons+'+str(i),
    1548                                             handler=onDeleteMask)
     1545                    locationcode='Delete+Polygons+'+str(i),handler=onDeleteMask)
    15491546                littleSizer.Add(polyDelete,0,WACV)
    15501547        mainSizer.Add(littleSizer,0,)
     
    15611558        littleSizer.Add(frameText,0,WACV)
    15621559        frameDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?',
    1563                                             locationcode='Delete+Frame',
    1564                                             handler=onDeleteFrame)
     1560            locationcode='Delete+Frame',handler=onDeleteFrame)
    15651561        littleSizer.Add(frameDelete,0,WACV)
    15661562        mainSizer.Add(littleSizer,0,)
     
    17421738        UpdateStressStrain(G2frame,data)       
    17431739   
     1740    def OnPlotStrSta(event):
     1741        Controls = G2frame.PatternTree.GetItemPyData(
     1742            G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
     1743        RingInt = G2img.IntStrSta(G2frame.ImageZ,data,Controls)
     1744        Names = ['d=%.3f'%(ring['Dcalc']) for ring in data['d-zero']]
     1745        G2plt.PlotExposedImage(G2frame,event=event)
     1746        G2frame.G2plotNB.Delete('Ring Intensities')
     1747        G2plt.PlotXY(G2frame,RingInt,labelX='Azimuth',
     1748            labelY='Intensity',newPlot=True,Title='Ring Intensities',
     1749            names=Names,lines=True)
     1750       
    17441751    def OnFitStrSta(event):
    17451752        Controls = G2frame.PatternTree.GetItemPyData(
     
    17921799                    variables += item['Emat']
    17931800                    sig += item['Esig']
    1794                     varylist = ['%d%s%s'%(i,';',Name) for Name in varyNames]
     1801                    varylist = ['%d;%s'%(i,Name) for Name in varyNames]
    17951802                    varyList += varylist
    17961803                    parmDict.update(dict(zip(varylist,item['Emat'])))
    1797                     parmDict['%d:Dcalc'%(i)] = item['Dcalc']
     1804                    parmDict['%d;Dcalc'%(i)] = item['Dcalc']
     1805                    parmDict['%d;Ivar'%(i)] = item['Ivar']
     1806                    variables.append(item['Ivar'])
     1807                    varyList.append('%d;Ivar'%(i))
     1808                    sig.append(0.)
    17981809                SeqResult[name] = {'variables':variables,'varyList':varyList,'sig':sig,'Rvals':[],
    17991810                    'covMatrix':np.eye(len(variables)),'title':name,'parmDict':parmDict}
     
    19721983    G2frame.dataFrame.Bind(wx.EVT_MENU, OnUpdateDzero, id=G2gd.wxID_UPDATEDZERO)
    19731984    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitStrSta, id=G2gd.wxID_STRSTAFIT)
     1985    G2frame.dataFrame.Bind(wx.EVT_MENU, OnPlotStrSta, id=G2gd.wxID_STRSTAPLOT)
    19741986    G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitAllStrSta, id=G2gd.wxID_STRSTAALLFIT)
    19751987    G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopyStrSta, id=G2gd.wxID_STRSTACOPY)
  • trunk/GSASIIplot.py

    r2401 r2411  
    24382438def PlotXY(G2frame,XY,XY2=None,labelX=None,labelY=None,newPlot=False,
    24392439    Title='',lines=False,names=[],names2=[]):
    2440     '''simple plot of xy data, used for diagnostic purposes
     2440    '''simple plot of xy data
    24412441    '''
    24422442    def OnKeyPress(event):
     
    24572457            #GSASIIpath.IPyBreak()
    24582458            return
    2459         wx.CallAfter(PlotXY,G2frame,XY,XY2,labelX,labelY,False,Title,False,names)
     2459        wx.CallAfter(PlotXY,G2frame,XY,XY2,labelX,labelY,False,Title,lines,names)
    24602460
    24612461    def OnMotion(event):
     
    24872487        Page.Offset = [0,0]
    24882488   
    2489     if XY2 and len(XY2) > 1:
     2489    if lines:
    24902490        Page.Choice = (' key press','l: offset left','r: offset right','d: offset down',
    24912491            'u: offset up','o: reset offset',)
     
    25132513        Ymax = max(Ymax,max(Y))
    25142514        if lines:
     2515            dX = Page.Offset[0]*(ixy+1)*Xmax/500.
     2516            dY = Page.Offset[1]*(ixy+1)*Ymax/100.
    25152517            if len(names):
    2516                 Plot.plot(X,Y,colors[ixy%6],picker=False,label=names[ixy])
     2518                Plot.plot(X+dX,Y+dY,colors[ixy%6],picker=False,label=names[ixy])
    25172519            else:
    2518                 Plot.plot(X,Y,colors[ixy%6],picker=False)
     2520                Plot.plot(X+dX,Y+dY,colors[ixy%6],picker=False)
    25192521        else:
    25202522            Plot.plot(X,Y,colors[ixy%6]+'+',picker=False)
     
    25452547           
    25462548def PlotXYZ(G2frame,XY,Z,labelX=None,labelY=None,newPlot=False,Title=''):
    2547     '''simple contour plot of xyz data, used for diagnostic purposes
     2549    '''simple contour plot of xyz data
    25482550    '''
    25492551    def OnKeyPress(event):
Note: See TracChangeset for help on using the changeset viewer.