Changeset 2174


Ignore:
Timestamp:
Mar 16, 2016 1:25:24 PM (9 years ago)
Author:
vondreele
Message:

fix image integrate and integrate all with dark & background images
trap bad G2frame.PickId? (there may be more!)
fix cleanup after DIFFax crash & other stacking fault fixes

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASII.py

    r2160 r2174  
    23252325        self.oldImagefile = '' # the name of the last image file read
    23262326        self.oldImageTag = None # the name of the tag for multi-image files
    2327         self.ImageZ = []  # this contains the image plotted and used for integration
     2327        self.ImageZ = []  # this contains the image plotted
    23282328        # self.ImageZ and self.oldImagefile are set in GSASIIplot.PlotImage
    23292329        # and GSASIIIO.GetImageData
  • TabularUnified trunk/GSASIIimgGUI.py

    r2149 r2174  
    149149            style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE)
    150150        try:
    151             sumImg = G2frame.ImageZ
     151            Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)
     152            sumImg = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    152153            darkImg,darkScale = data['dark image']
     154            backImg,backScale = data['background image']           
    153155            if darkImg:
    154156                Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
     
    156158                darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    157159                sumImg += darkImage*darkScale
    158             backImg,backScale = data['background image']           
    159160            if backImg:     #ignores any transmission effect in the background image
    160161                Bid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
     
    162163                backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    163164                Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
    164                 BdarkImg,BdarkScale = Bdata['dark image']
    165                 if BdarkImg:
    166                     BDid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,BdarkImg)
    167                     Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(BDid)
    168                     BdarkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    169                     backImage += BdarkImage*BdarkScale               
     165                if darkImg:
     166                    Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,darkImg)
     167                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
     168                    darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     169                    backImage += darkImage*darkScale               
    170170                sumImg += backImage*backScale
    171171            G2frame.Integrate = G2img.ImageIntegrate(sumImg-data['Flat Bkg'],data,masks,blkSize,dlg)
    172 #            G2plt.PlotIntegration(G2frame,newPlot=True)
    173172            Id = G2IO.SaveIntegration(G2frame,G2frame.PickId,data,(event is None))
    174173            G2frame.PatternId = Id
     
    186185            while id:
    187186                name = G2frame.PatternTree.GetItemText(id)
    188 #                Names.append(name)
    189187                if 'IMG' in name:
    190188                    TextList.append([False,name,id])
     
    214212                                style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE)
    215213                            try:
    216                                 id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, name)
    217214                                Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
    218215                                image = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    219                                 backImage = []
    220                                 if Data['background image'][0]:
    221                                     backImg = Data['background image'][0]
    222                                     backScale = Data['background image'][1]
     216                                darkImg,darkScale = data['dark image']
     217                                backImg,backScale = data['background image']           
     218                                if darkImg:
     219                                    id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
     220                                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
     221                                    darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     222                                    image += darkScale*darkImage
     223                                if backImg:
    223224                                    id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
    224225                                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
    225                                     backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)*backScale
    226                                 FlatBkg = Data.get('Flat Bkg',0.0)
    227                                 try:
    228                                     Masks = G2frame.PatternTree.GetItemPyData(
    229                                         G2gd.GetPatternTreeItemId(G2frame,id, 'Masks'))
    230                                 except TypeError:       #missing Masks
    231                                     # I think the next line should be 'range'! (BHT)
    232                                     Imin,Imax = Data['Range']
    233                                     Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Frames':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
    234                                     G2frame.PatternTree.SetItemPyData(
    235                                         G2gd.GetPatternTreeItemId(G2frame,id, 'Masks'),Masks)
    236                                 CleanupMasks(Masks)
    237                                 if len(backImage):                               
    238                                     G2frame.Integrate = G2img.ImageIntegrate(image+backImage-FlatBkg,Data,Masks,blkSize,dlgp)
    239                                 else:
    240                                     G2frame.Integrate = G2img.ImageIntegrate(image-FlatBkg,Data,Masks,blkSize,dlgp)
     226                                    backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     227                                    Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,id,'Image Controls'))
     228                                    if darkImg:
     229                                        id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,darkImg)
     230                                        Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
     231                                        darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     232                                        backImage += darkImage*darkScale               
     233                                    image += backImage*backScale
     234                                image -= Data['Flat Bkg']
     235                                Masks = G2frame.PatternTree.GetItemPyData(
     236                                    G2gd.GetPatternTreeItemId(G2frame,id, 'Masks'))
     237                                G2frame.Integrate = G2img.ImageIntegrate(image,Data,Masks,blkSize,dlgp)
    241238                                pId = G2IO.SaveIntegration(G2frame,Id,Data)
    242239                            finally:
  • TabularUnified trunk/GSASIIphsGUI.py

    r2172 r2174  
    24112411            Obj = event.GetEventObject()
    24122412            data['Layers']['Laue'] = Obj.GetValue()
    2413             UpdateLayerData()
     2413            wx.CallAfter(UpdateLayerData)
    24142414       
    24152415        def OnToler(event): #used when Laue = unknown
     
    24272427                [['mmm'],8,zip([" a = "," b = "," c = "],["%.5f","%.5f","%.5f"],[True,True,True],[0,1,2,])],
    24282428                [['2/m(ab)','2/m(c)','-1','axial','unknown'],10,zip([" a = "," b = "," c = "," gamma = "],
    2429                     ["%.5f","%.5f","%.5f","%.3f"],[True,True,True,True],[0,1,2,3])]]
     2429                    ["%.5f","%.5f","%.5f","%.3f"],[True,True,True,True],[0,1,2,5])]]
    24302430               
    24312431            def OnCellRef(event):
     
    24592459                    cell[4] = cell[5] = cell[6] = 90.
    24602460                    Obj.SetValue("%.5f"%(cell[ObjId+1]))
    2461                 elif laue in ['2/m']:
     2461                elif laue in ['2/m','-1']:
    24622462                    cell[4] = cell[5] = 90.
    24632463                    if ObjId != 3:
     
    24672467                        cell[6] = value
    24682468                        Obj.SetValue("%.3f"%(cell[6]))
    2469                 else:
    2470                     cell[ObjId+1] = value
    2471                     if ObjId < 3:
    2472                         Obj.SetValue("%.5f"%(cell[1+ObjId]))
    2473                     else:
    2474                         Obj.SetValue("%.3f"%(cell[1+ObjId]))                       
    24752469                cell[7] = G2lat.calc_V(G2lat.cell2A(cell[1:7]))
    24762470                volVal.SetLabel(' Vol = %.3f'%(cell[7]))
  • TabularUnified trunk/GSASIIplot.py

    r2173 r2174  
    41474147                Plot.plot([arcxI[ind],arcxO[ind]],[arcyI[ind],arcyO[ind]],color='k',dashes=(5,5))
    41484148                   
    4149         if G2frame.PatternTree.GetItemText(G2frame.PickId) in 'Image Controls':
     4149        if G2frame.PickId and G2frame.PatternTree.GetItemText(G2frame.PickId) in 'Image Controls':
    41504150            for xring,yring in Data['ring']:
    41514151                Plot.plot(xring,yring,'r+',picker=3)
     
    58135813                TX += np.array(Trans[laySeq[il-1]][layer][1:4])
    58145814                XYZ += TX
    5815                 XYZT = XYZ.T
    5816                 XYZT[0] = XYZT[0]%1.
    5817                 XYZT[1] = XYZT[1]%1.
    5818                 XYZ = XYZT.T
    58195815            AtNames += atNames
    58205816            AtTypes += atTypes
     
    58395835                       
    58405836    cell = Layers['Cell'][1:7]
     5837    print cell
    58415838    Amat,Bmat = G2lat.cell2AB(cell)         #Amat - crystal to cartesian, Bmat - inverse
    58425839    A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
     
    60366033        for line,color in zip(uEdges,uColors):
    60376034            glColor3ubv(color)
    6038             glVertex3fv(-line[1])
     6035            glVertex3fv([0,0,0])
     6036#            glVertex3fv(-line[1])
    60396037            glVertex3fv(line[1])
    60406038        glEnd()
  • TabularUnified trunk/GSASIIpwd.py

    r2172 r2174  
    18091809    gam = Layers['Cell'][6]
    18101810    df.write('%.4f %.4f %.4f %.3f\n'%(a,b,c,gam))
     1811    laue = Layers['Laue']
     1812    if laue == '2/m(ab)':
     1813        laue = '2/m(1)'
     1814    elif laue == '2/m(c)':
     1815        laue = '2/m(2)'
    18111816    if 'unknown' in Layers['Laue']:
    1812         df.write('%s %.3f\n'%(Layers['Laue'],Layers['Toler']))
     1817        df.write('%s %.3f\n'%(laue,Layers['Toler']))
    18131818    else:   
    1814         df.write('%s\n'%(Layers['Laue']))
     1819        df.write('%s\n'%(laue))
    18151820    df.write('%d\n'%(len(Layers['Layers'])))
    18161821    if Layers['Width'][0][0] < 1. or Layers['Width'][0][1] < 1.:
     
    18531858    df.write('TRANSITIONS\n')
    18541859    for iY in range(len(Layers['Layers'])):
     1860        sumPx = 0.
    18551861        for iX in range(len(Layers['Layers'])):
    18561862            p,dx,dy,dz = Layers['Transitions'][iY][iX][:4]
    1857             df.write('%.3f %.5f %.5f %.5f\n'%(p,dx,dy,dz))       
     1863            p = round(p,3)
     1864            df.write('%.3f %.5f %.5f %.5f\n'%(p,dx,dy,dz))
     1865            sumPx += p
     1866        if sumPx != 1.0:    #this has to be picky since DIFFaX is.
     1867            print 'ERROR - Layer probabilities sum to ',sumPx,' DIFFaX will insist it = 1.0'
     1868            df.close()
     1869            os.remove('data.sfc')
     1870            os.remove('control.dif')
     1871            os.remove('GSASII-DIFFaX.dat')
     1872            return       
    18581873    df.close()   
    18591874    time0 = time.time()
    18601875    subp.call(DIFFaX)
    18611876    print 'DIFFaX time = %.2fs'%(time.time()-time0)
    1862     Xpat = np.loadtxt('GSASII-DIFFaX.spc').T
    1863     iFin = iBeg+Xpat.shape[1]
    1864     bakType,backDict,backVary = SetBackgroundParms(background)
    1865     backDict['Lam1'] = G2mth.getWave(inst)
    1866 #    GSASIIpath.IPyBreak()
    1867     profile[4][iBeg:iFin] = getBackground('',backDict,bakType,inst['Type'][0],profile[0][iBeg:iFin])[0]   
    1868     profile[3][iBeg:iFin] = Xpat[2]*scale+profile[4][iBeg:iFin]
    1869     if not np.any(profile[1]):                   #fill dummy data x,y,w,yc,yb,yd
    1870         rv = st.poisson(profile[3][iBeg:iFin])
    1871         profile[1][iBeg:iFin] = rv.rvs()
    1872         Z = np.ones_like(profile[3][iBeg:iFin])
    1873         Z[1::2] *= -1
    1874         profile[1][iBeg:iFin] = profile[3][iBeg:iFin]+np.abs(profile[1][iBeg:iFin]-profile[3][iBeg:iFin])*Z
    1875         profile[2][iBeg:iFin] = np.where(profile[1][iBeg:iFin]>0.,1./profile[1][iBeg:iFin],1.0)
    1876     profile[5][iBeg:iFin] = profile[1][iBeg:iFin]-profile[3][iBeg:iFin]
    1877 
    1878 
     1877    if os.path.exists('GSASII-DIFFaX.spc'):
     1878        Xpat = np.loadtxt('GSASII-DIFFaX.spc').T
     1879        iFin = iBeg+Xpat.shape[1]
     1880        bakType,backDict,backVary = SetBackgroundParms(background)
     1881        backDict['Lam1'] = G2mth.getWave(inst)
     1882    #    GSASIIpath.IPyBreak()
     1883        profile[4][iBeg:iFin] = getBackground('',backDict,bakType,inst['Type'][0],profile[0][iBeg:iFin])[0]   
     1884        profile[3][iBeg:iFin] = Xpat[2]*scale+profile[4][iBeg:iFin]
     1885        if not np.any(profile[1]):                   #fill dummy data x,y,w,yc,yb,yd
     1886            rv = st.poisson(profile[3][iBeg:iFin])
     1887            profile[1][iBeg:iFin] = rv.rvs()
     1888            Z = np.ones_like(profile[3][iBeg:iFin])
     1889            Z[1::2] *= -1
     1890            profile[1][iBeg:iFin] = profile[3][iBeg:iFin]+np.abs(profile[1][iBeg:iFin]-profile[3][iBeg:iFin])*Z
     1891            profile[2][iBeg:iFin] = np.where(profile[1][iBeg:iFin]>0.,1./profile[1][iBeg:iFin],1.0)
     1892        profile[5][iBeg:iFin] = profile[1][iBeg:iFin]-profile[3][iBeg:iFin]
    18791893    #cleanup files..
     1894        os.remove('GSASII-DIFFaX.spc')
    18801895    os.remove('data.sfc')
    18811896    os.remove('control.dif')
    18821897    os.remove('GSASII-DIFFaX.dat')
    1883     os.remove('GSASII-DIFFaX.spc')
    18841898   
    18851899#testing data
Note: See TracChangeset for help on using the changeset viewer.