Changeset 2789


Ignore:
Timestamp:
Apr 18, 2017 12:47:27 PM (5 years ago)
Author:
vondreele
Message:

fix GetImageZ to correctly treat background/dark images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r2788 r2789  
    6868    if sumImg is None:
    6969        return []
    70     if not 'dark image' in data:
    71         return sumImg
    72     darkImg,darkScale = data['dark image']
    73     if darkImg:
    74         Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
    75         if Did:
    76             Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
    77             dformatName = Ddata.get('formatName','')
    78             Npix,darkfile,imagetag = G2IO.GetCheckImageFile(G2frame,Did)
    79             darkImage = G2IO.GetImageData(G2frame,darkfile,True,ImageTag=imagetag,FormatName=dformatName)
    80             if darkImg is not None:               
    81                 sumImg += np.array(darkImage*darkScale,dtype='int32')
    82     if not 'background image' in data:
    83         return sumImg
    84     backImg,backScale = data['background image']           
    85     if backImg:     #ignores any transmission effect in the background image
    86         Bid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
    87         if Bid:
    88             Npix,backfile,imagetag = G2IO.GetCheckImageFile(G2frame,Bid)
    89             Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
    90             bformatName = Bdata.get('formatName','')
    91             backImage = G2IO.GetImageData(G2frame,backfile,True,ImageTag=imagetag,FormatName=bformatName)
    92             if darkImg and backImage is not None:
    93                 Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,darkImg)
    94                 if Did:
    95                     Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
    96                     dformatName = Ddata.get('formatName','')
    97                     Npix,darkfile,imagetag = G2IO.GetCheckImageFile(G2frame,Did)
    98                     darkImage = G2IO.GetImageData(G2frame,darkfile,True,ImageTag=imagetag,FormatName=dformatName)
    99                     if darkImage is not None:
    100                         backImage += np.array(darkImage*darkScale,dtype='int32')
    101             if backImage is not None:
    102                 sumImg += np.array(backImage*backScale,dtype='int32')
     70    darkImg = False
     71    if 'dark image' in data:
     72        darkImg,darkScale = data['dark image']
     73        if darkImg:
     74            Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
     75            if Did:
     76                Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
     77                dformatName = Ddata.get('formatName','')
     78                Npix,darkfile,imagetag = G2IO.GetCheckImageFile(G2frame,Did)
     79                darkImage = G2IO.GetImageData(G2frame,darkfile,True,ImageTag=imagetag,FormatName=dformatName)
     80                if darkImg is not None:               
     81                    sumImg += np.array(darkImage*darkScale,dtype='int32')
     82    if 'background image' in data:
     83        backImg,backScale = data['background image']           
     84        if backImg:     #ignores any transmission effect in the background image
     85            Bid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
     86            if Bid:
     87                Npix,backfile,imagetag = G2IO.GetCheckImageFile(G2frame,Bid)
     88                Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
     89                bformatName = Bdata.get('formatName','')
     90                backImage = G2IO.GetImageData(G2frame,backfile,True,ImageTag=imagetag,FormatName=bformatName)
     91                if darkImg and backImage is not None:
     92                    backImage += np.array(darkImage*darkScale/backScale,dtype='int32')
     93                if backImage is not None:
     94                    sumImg += np.array(backImage*backScale,dtype='int32')
    10395    if darkImg: del darkImg         #force cleanup
    10496    if backImg: del backImg
     
    10799    if 'range' not in data or newRange:
    108100        data['range'] = [(0,Imax),[0,Imax]]
    109     return sumImg
     101    return np.asarray(sumImg,dtype='int32')
    110102
    111103def UpdateImageData(G2frame,data):
     
    989981        def OnBackImage(event):
    990982            data['background image'][0] = backImage.GetValue()
    991             G2frame.ImageZ = GetImageZ(G2frame,data)
     983            G2frame.ImageZ = GetImageZ(G2frame,data,newRange=True)
    992984            ResetThresholds()
    993985            wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
     
    995987        def OnDarkImage(event):
    996988            data['dark image'][0] = darkImage.GetValue()
    997             G2frame.ImageZ = GetImageZ(G2frame,data)
     989            G2frame.ImageZ = GetImageZ(G2frame,data,newRange=True)
    998990            ResetThresholds()
    999991            wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
     
    1007999
    10081000        def OnMult(invalid,value,tc):
    1009             G2frame.ImageZ = GetImageZ(G2frame,data)
     1001            G2frame.ImageZ = GetImageZ(G2frame,data,newRange=True)
    10101002            ResetThresholds()
    10111003            wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=tc.event)
     
    12811273        wx.CallAfter(G2plt.PlotExposedImage,G2frame)
    12821274
     1275    def newReplot(*args,**kwargs):
     1276        wx.CallAfter(G2plt.PlotExposedImage,G2frame,newPlot=True)
     1277
    12831278    def onDeleteMask(event):
    12841279        Obj = event.GetEventObject()
     
    16291624    littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Lower/Upper thresholds '),0,WACV)
    16301625    lowerThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=0,
    1631         min=thresh[0][0],OnLeave=Replot,typeHint=int)
     1626        min=thresh[0][0],OnLeave=newReplot,typeHint=int)
    16321627    littleSizer.Add(lowerThreshold,0,WACV)
    16331628    upperThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=1,
    1634         max=thresh[0][1],OnLeave=Replot,typeHint=int)
     1629        max=thresh[0][1],OnLeave=newReplot,typeHint=int)
    16351630    littleSizer.Add(upperThreshold,0,WACV)
    16361631    mainSizer.Add(littleSizer,0,)
Note: See TracChangeset for help on using the changeset viewer.