Changeset 56


Ignore:
Timestamp:
Apr 29, 2010 5:04:39 PM (12 years ago)
Author:
vondreel
Message:

major modification for images - not stored in project file. Now read as needed in plotting routine. Reduces .gpx file size from 10s of MB to 10s of kb.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r55 r56  
    378378        try:
    379379            if dlg.ShowModal() == wx.ID_OK:
    380                 self.imagefile = dlg.GetPath()
     380                imagefile = dlg.GetPath()
    381381                self.dirname = dlg.GetDirectory()
    382                 ext = ospath.splitext(self.imagefile)[1]
    383                 Comments = []
    384                 if ext == '.tif':
    385                     Comments,Data,Size,Image = G2IO.GetTifData(self.imagefile)
    386                 elif ext == '.img':
    387                     Comments,Data,Size,Image = G2IO.GetImgData(self.imagefile)
    388                     Image[0][0] = 0
    389                 elif ext == '.mar3450' or ext == '.mar2300':
    390                     Comments,Data,Size,Image = G2IO.GetMAR345Data(self.imagefile)
    391                 elif ext in ['.sum','.avg']:
    392                     Comments,Data,Size,Image = G2IO.GetGEsumData(self.imagefile)
     382                Comments,Data,Size,Image = G2IO.GetImageData(imagefile)
    393383                if Comments:
    394                     Id = self.PatternTree.AppendItem(parent=self.root,text='IMG '+ospath.basename(self.imagefile))
     384                    Id = self.PatternTree.AppendItem(parent=self.root,text='IMG '+ospath.basename(imagefile))
    395385                    self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Comments'),Comments)
    396386                    Imax = np.amax(Image)
     
    421411                    Data['range'] = [(Imin,Imax),[Imin,Imax]]
    422412                    self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Image Controls'),Data)
    423                     self.PatternTree.SetItemPyData(Id,[Size,Image])
     413                    self.PatternTree.SetItemPyData(Id,[Size,imagefile])
    424414                    self.PickId = Id
    425415                    self.Image = Id
  • trunk/GSASIIIO.py

    r55 r56  
    388388    return [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]
    389389   
    390 def GetGEsumData(filename):
     390def GetImageData(imagefile,imageOnly=False):
     391    ext = ospath.splitext(imagefile)[1]
     392    Comments = []
     393    if ext == '.tif':
     394        Comments,Data,Size,Image = GetTifData(imagefile)
     395    elif ext == '.img':
     396        Comments,Data,Size,Image = GetImgData(imagefile)
     397        Image[0][0] = 0
     398    elif ext == '.mar3450' or ext == '.mar2300':
     399        Comments,Data,Size,Image = GetMAR345Data(imagefile)
     400    elif ext in ['.sum','.avg']:
     401        Comments,Data,Size,Image = GetGEsumData(imagefile)
     402    if imageOnly:
     403        return Image
     404    else:
     405        return Comments,Data,Size,Image
     406
     407   
     408def GetGEsumData(filename,imageOnly=False):
    391409    import array as ar
    392410    print 'Read GE sum file: ',filename   
     
    411429        row += 1
    412430    data = {'pixelSize':(200,200),'wavelength':0.15,'distance':250.0,'center':[204.8,204.8]} 
    413     return head,data,size,image
    414431    File.close()   
     432    if imageOnly:
     433        return image
     434    else:
     435        return head,data,size,image
    415436       
    416 def GetImgData(filename):
     437def GetImgData(filename,imageOnly=False):
    417438    import struct as st
    418439    import array as ar
     
    454475        pos += 2*size
    455476    File.close()
    456     return lines[1:-2],data,size,image
     477    if imageOnly:
     478        return image
     479    else:
     480        return lines[1:-2],data,size,image
    457481       
    458 def GetMAR345Data(filename):
     482def GetMAR345Data(filename,imageOnly=False):
    459483    import array as ar
    460484    import struct as st
     
    505529    image = np.zeros(shape=(size,size),dtype=np.int32)
    506530    image = pf.pack_f(len(raw),raw,size,image)
    507     return head,data,size,image.T
    508    
    509 def GetTifData(filename):
     531    if imageOnly:
     532        return image.T
     533    else:
     534        return head,data,size,image.T
     535   
     536def GetTifData(filename,imageOnly=False):
    510537    # only works for APS Perkin-Elmer detector data files in "TIFF" format that are readable by Fit2D
    511538    import struct as st
     
    543570        pos += 4*size
    544571    data = {'pixelSize':(200,200),'wavelength':0.10,'distance':100.0,'center':[204.8,204.8]}
    545     return head,data,size,image
    546    
    547572    File.close()   
     573    if imageOnly:
     574        return image
     575    else:
     576        return head,data,size,image
     577   
    548578
    549579def ProjFileOpen(self):
  • trunk/GSASIIcomp.py

    r55 r56  
    16651665    t2 = time.time()
    16661666    print "Elapsed time:","%8.3f"%(t2-t1), "s"
    1667     G2plt.PlotTRImage(self,newPlot=True)
     1667#    G2plt.PlotTRImage(self,newPlot=True)
    16681668    print 'Form 1-D histograms for ',numAzms,' azimuthal angles'
    16691669    print 'Integration limits:',LUtth,LRazm
  • trunk/GSASIIplot.py

    r55 r56  
    88import GSASIIgrid as G2gd
    99import GSASIIcomp as G2cmp
     10import GSASIIIO as G2IO
    1011from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
    1112from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar
     
    654655       
    655656    Plot.set_title(self.PatternTree.GetItemText(self.Image)[4:])
    656     size,self.ImageZ = self.PatternTree.GetItemPyData(self.Image)
     657    size,imagefile = self.PatternTree.GetItemPyData(self.Image)
     658    self.ImageZ = G2IO.GetImageData(imagefile,True)
    657659    Data = self.PatternTree.GetItemPyData( \
    658660        G2gd.GetPatternTreeItemId(self,self.Image, 'Image Controls'))
     
    801803    Data = self.PatternTree.GetItemPyData( \
    802804        G2gd.GetPatternTreeItemId(self,self.Image, 'Image Controls'))
     805    size,imagefile = self.PatternTree.GetItemPyData(self.Image)
     806    self.ImageZ = G2IO.GetImageData(imagefile,True)
    803807    image = self.ImageZ
    804808    Iz = len(image)
Note: See TracChangeset for help on using the changeset viewer.