Changeset 85


Ignore:
Timestamp:
Jun 11, 2010 1:37:21 PM (12 years ago)
Author:
vondreel
Message:

threshold masks operational
add index peak list load/reload menu & remove delete key method
plotting of threshold masks
remove "U" in image open command; implement reading of MAR CCD tif images

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r82 r85  
    370370        dlg = wx.FileDialog(self, 'Choose image files', '.', '',\
    371371        'MAR345 (*.mar3450;*.mar2300)|*.mar3450;*.mar2300|ADSC Image (*.img)\
    372         |*.img|Perkin-Elmer TIF (*.tif)|*.tif|GE Image sum (*.sum)\
     372        |*.img|Detector tif (*.tif;*.tiff)|*.tif;*.tiff|GE Image sum (*.sum)\
    373373        |*.sum|GE Image avg (*.avg)|*.avg|All files (*.*)|*.*',wx.OPEN | wx.MULTIPLE)
    374374        if self.dirname:
     
    415415                        Data['range'] = [(Imin,Imax),[Imin,Imax]]
    416416                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Image Controls'),Data)
    417                         Masks = {'Points':[],'Rings':[],'Arcs':[],'Polygons':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
     417                        Masks = {'Spots':[],'Rings':[],'Arcs':[],'Polygons':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
    418418                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Masks'),Masks)
    419419                        self.PatternTree.SetItemPyData(Id,[Size,imagefile])
     
    482482            mainSizer.Add((10,10),1)
    483483            dataGridSizer = wx.FlexGridSizer(rows=len(data),cols=1,hgap=2,vgap=2)
    484             for id,item in enumerate(self.data[:-1]):
     484            for id,item in enumerate(self.data):
    485485                ckbox = wx.CheckBox(panel,id,item[1])
    486486                ckbox.Bind(wx.EVT_CHECKBOX,self.OnCopyChange)                   
     
    732732                                imSize = size
    733733                                newImage = newImage+scale*image
     734                            del(image)
    734735                    newImage = np.asfarray(newImage,dtype=np.float32)                       
    735736                    print 'result dtype',newImage.dtype                               
     
    754755                            newimagefile = dlg.GetPath()
    755756                            G2IO.PutG2Image(newimagefile,newImage)
     757                            Imax = np.amax(newImage)
     758                            Imin = np.amin(newImage)
    756759                            newImage = []
    757760                            self.PatternTree.SetItemPyData(Id,[imSize,newimagefile])
    758761                            self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Comments'),Comments)
     762                        del(newImage)
    759763                        if self.imageDefault:
    760764                            Data = copy.copy(self.imageDefault)
     
    766770                            Data['ellipses'] = []
    767771                            Data['calibrant'] = ''
     772                            Data['range'] = [(Imin,Imax),[Imin,Imax]]
    768773                            self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Image Controls'),Data)                                           
    769774                            self.PatternTree.SelectItem(Id)
    770775                            self.PatternTree.Expand(Id)
    771                         self.PickId = Id
    772                         self.Image = Id
     776                        Masks = {'Spots':[],'Rings':[],'Arcs':[],'Polygons':[],'Thresholds':[(Imin,Imax),[Imin,Imax]]}
     777                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Masks'),Masks)
     778                        self.PickId = G2gd.GetPatternTreeItemId(self,self.root,outname)
     779                        self.Image = self.PickId
    773780            finally:
    774781                dlg.Destroy()
  • trunk/GSASIIIO.py

    r75 r85  
    544544    import struct as st
    545545    import array as ar
    546     if not imageOnly:
    547         print 'Read APS PE-detector tiff file: ',filename
    548     File = open(filename,'Ur')
     546    File = open(filename,'rb')
    549547    dataType = 5
    550548    try:
     
    561559    tag = File.read(3)
    562560    if tag != 'II*':
    563         lines = ['not a APS PE-detector tiff file',]
     561        lines = ['not a detector tiff file',]
    564562        return lines,0,0
    565     size = st.unpack('<i',File.read(4))[0]
     563    size,Ityp = st.unpack('<ii',File.read(8))
     564    if Ityp == 0:
     565        tifType = 'Pilatus'
     566        pixy = (172,172)
     567        pos = 4096
     568        if not imageOnly:
     569            print 'Read Pilatus tiff file: ',filename
     570    elif Ityp == 1:
     571        tifType = 'PE'
     572        pixy = (200,200)
     573        pos = 8
     574        if not imageOnly:
     575            print 'Read APS PE-detector tiff file: ',filename
     576    elif Ityp == 3328:
     577        tifType = 'MAR'
     578        pixy = (79,79)
     579        pos = 4096
     580        if not imageOnly:
     581            print 'Read MAR CCD tiff file: ',filename
     582    else:
     583        lines = 'unknown tif type'
     584        return lines,0,0
    566585    image = np.zeros(shape=(size,size),dtype=np.int32)
    567586    row = 0
    568     pos = 8
    569587    while row < size:
    570588        File.seek(pos)
    571         if dataType == 5:
    572             line = ar.array('f',File.read(4*size))
    573         else:
    574             line = ar.array('l',File.read(4*size))
     589        if 'PE' in tifType:
     590            if dataType == 5:
     591                line = ar.array('f',File.read(4*size))
     592            else:
     593                line = ar.array('l',File.read(4*size))
     594            pos += 4*size
     595        elif 'MAR' in tifType:
     596            line = ar.array('H',File.read(2*size))
     597            pos += 2*size
    575598        image[row] = np.asarray(line)
    576599        row += 1
    577         pos += 4*size
    578     data = {'pixelSize':(200,200),'wavelength':0.10,'distance':100.0,'center':[204.8,204.8]}
     600    data = {'pixelSize':pixy,'wavelength':0.10,'distance':100.0,'center':[204.8,204.8]}
    579601    File.close()   
    580602    if imageOnly:
  • trunk/GSASIIgrid.py

    r84 r85  
    2323] = [wx.NewId() for _init_coll_INST_Items in range(1)]
    2424
     25[ wxID_INDXRELOAD,
     26] = [wx.NewId() for _init_coll_IndPeaks_Items in range(1)]
     27
    2528[ wxID_UNDO,wxID_PEAKFIT,wxID_AUTOPEAKFIT,
    2629] = [wx.NewId() for _init_coll_PEAK_Items in range(3)]
     
    3538    def _init_coll_AtomsMenu(self,parent):
    3639        parent.Append(menu=self.AtomEdit, title='Add atom')
     40
     41    def _init_coll_IndPeaksMenu(self,parent):
     42        parent.Append(menu=self.IndPeaksEdit,title='Index Peaks Operations')
    3743                   
    3844    def _init_coll_ImageMenu(self,parent):
     
    5561        parent.Append(id=wxID_ATOMSEDITINSERT, kind=wx.ITEM_NORMAL,text='Insert empty atom',
    5662            help='Double left click on atom row to Insert before')
     63           
     64    def _init_coll_IndPeaks_Items(self,parent):
     65        parent.Append(help='Load/Reload index peaks from peak list',id=wxID_INDXRELOAD,
     66            kind=wx.ITEM_NORMAL,text='Load/Reload')
    5767           
    5868    def _init_coll_Image_Items(self,parent):
     
    102112        self.InstMenu = wx.MenuBar()
    103113        self.PeakMenu = wx.MenuBar()
     114        self.IndPeaksMenu = wx.MenuBar()
    104115        self.IndexMenu = wx.MenuBar()
    105116        self.AtomEdit = wx.Menu(title='')
     
    108119        self.InstEdit = wx.Menu(title='')
    109120        self.PeakEdit = wx.Menu(title='')
     121        self.IndPeaksEdit = wx.Menu(title='')
    110122        self.IndexEdit = wx.Menu(title='')
    111123        self._init_coll_AtomsMenu(self.AtomsMenu)
     
    119131        self._init_coll_PeakMenu(self.PeakMenu)
    120132        self._init_coll_Peak_Items(self.PeakEdit)
     133        self._init_coll_IndPeaksMenu(self.IndPeaksMenu)
     134        self._init_coll_IndPeaks_Items(self.IndPeaksEdit)
    121135        self._init_coll_IndexMenu(self.IndexMenu)
    122136        self._init_coll_Index_Items(self.IndexEdit)
     
    488502        self.PickId = item
    489503        self.Image = self.PatternTree.GetItemParent(item)
    490         data = self.PatternTree.GetItemPyData(item)
    491         G2imG.UpdateImageControls(self,data)
     504        masks = self.PatternTree.GetItemPyData(
     505            GetPatternTreeItemId(self,self.Image, 'Masks'))
     506        data = self.PatternTree.GetItemPyData(item)
     507        G2imG.UpdateImageControls(self,data,masks)
    492508        G2plt.PlotImage(self)
    493509    elif self.PatternTree.GetItemText(item) == 'Masks':
  • trunk/GSASIIimage.py

    r81 r85  
    309309        return True
    310310       
    311     Bravais,cell = calFile.Calibrants[data['calibrant']]
     311    Bravais,cell,skip = calFile.Calibrants[data['calibrant']]
    312312    A = G2lat.cell2A(cell)
    313313    wave = data['wavelength']
     
    315315    pixLimit = data['pixLimit']
    316316    elcent,phi,radii = ellipse
    317     HKL = G2lat.GenHBravais(0.5,Bravais,A)
     317    HKL = G2lat.GenHBravais(0.5,Bravais,A)[skip:]
    318318    dsp = HKL[0][3]
    319319    tth = 2.0*asind(wave/(2.*dsp))
     
    444444    return GetTthAzm(tay,tax,data)           #2-theta & azimuth arrays
    445445
    446 def Fill2ThetaAzimuthMap(data,TA,image):
     446def Fill2ThetaAzimuthMap(masks,TA,image):
    447447    import numpy.ma as ma
    448     LUtth = data['IOtth']
    449     if data['fullIntegrate']:
    450         LRazm = [-180,180]
    451     else:
    452         LRazm = data['LRazimuth']
     448    Zlim = masks['Thresholds'][1]
    453449    imageN = len(image)
    454450    TA = np.reshape(TA,(2,imageN,imageN))
    455451    TA = np.dstack((ma.getdata(TA[1]),ma.getdata(TA[0])))    #azimuth, 2-theta
    456452    tax,tay = np.dsplit(TA,2)    #azimuth, 2-theta
    457     tax = ma.masked_outside(tax.flatten(),LRazm[0],LRazm[1])
    458     tay = ma.masked_outside(tay.flatten(),LUtth[0],LUtth[1])
    459     tam = ma.getmask(tax)+ma.getmask(tay)
    460     taz = ma.masked_where(tam,image.flatten())
    461     return tax,tay,taz,tam
     453    taz = ma.masked_greater(ma.masked_less(image,Zlim[0]),Zlim[1]).flatten()
     454    tam = ma.getmask(taz)
     455    tax = ma.compressed(ma.array(tax.flatten(),mask=tam))
     456    tay = ma.compressed(ma.array(tay.flatten(),mask=tam))
     457    taz = ma.compressed(taz)
     458    del(tam)
     459    return tax,tay,taz
    462460   
    463461def Bin2ThetaAzimuthMap(data,tax,tay,taz):
     
    474472    return NST,HST
    475473
    476 def ImageIntegrate(self,data):
     474def ImageIntegrate(self,data,masks):
    477475    dlg = wx.ProgressDialog("Elapsed time","2D image integration",5,
    478476        style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE)
     
    486484        dlg.Update(1)
    487485        print 'Fill map with 2-theta/azimuth values'
    488         tax,tay,taz,tam = Fill2ThetaAzimuthMap(data,TA,self.ImageZ)
     486        tax,tay,taz = Fill2ThetaAzimuthMap(masks,TA,self.ImageZ)
    489487        del TA
    490488        dlg.Update(2)
  • trunk/GSASIIplot.py

    r82 r85  
    288288                LimitId = G2gd.GetPatternTreeItemId(self,self.PatternId, 'Limits')
    289289                data = self.PatternTree.GetItemPyData(LimitId)
    290                 print 'limits',xpos
     290#                print 'limits',xpos
    291291                data[1][lineNo] = xpos
    292292                self.PatternTree.SetItemPyData(LimitId,data)
     
    296296                PeakId = G2gd.GetPatternTreeItemId(self,self.PatternId, 'Peak List')
    297297                data = self.PatternTree.GetItemPyData(PeakId)
    298                 print 'peaks',xpos
     298#                print 'peaks',xpos
    299299                data[lineNo-2][0] = xpos
    300300                self.PatternTree.SetItemPyData(PeakId,data)
     
    563563def PlotImage(self,newPlot=False):
    564564    from matplotlib.patches import Ellipse,Arc
     565    import numpy.ma as ma
    565566
    566567    def OnImMotion(event):
     
    593594                xpix = xpos*scalex
    594595                ypix = ypos*scaley
     596                Int = 0
    595597                if (0 <= xpix <= size) and (0 <= ypix <= size):
    596                     Page.canvas.SetToolTipString('%6d'%(self.ImageZ[ypix][xpix]))
     598                    Int = self.ImageZ[ypix][xpix]
     599#                    Page.canvas.SetToolTipString('%4x'%((ypix*2048+xpix)*2+4096))
    597600                tth,azm,dsp = G2img.GetTthAzmDsp(xpos,ypos,Data)
    598601                Q = 2.*math.pi/dsp
    599602                self.G2plotNB.status.SetFields(\
    600                     ['Detector 2-th =%9.2fdeg, dsp =%9.3fA, Q = %6.3fA-1, azm = %7.2fdeg'%(tth,dsp,Q,azm),''])
     603                    ['Detector 2-th =%9.2fdeg, dsp =%9.3fA, Q = %6.3fA-1, azm = %7.2fdeg, I = %6d'%(tth,dsp,Q,azm,Int),''])
    601604
    602605    def OnImPlotKeyPress(event):
     
    706709    Data = self.PatternTree.GetItemPyData(
    707710        G2gd.GetPatternTreeItemId(self,self.Image, 'Image Controls'))
    708     try:
    709         Masks = self.PatternTree.GetItemPyData(
    710             G2gd.GetPatternTreeItemId(self,self.Image, 'Masks'))
    711     except TypeError:       #missing Masks
    712         Masks = {}
     711    Masks = self.PatternTree.GetItemPyData(
     712        G2gd.GetPatternTreeItemId(self,self.Image, 'Masks'))
    713713    imScale = 1
    714714    if len(self.ImageZ) > 1024:
     
    727727    Plot.set_ylabel('Image y-axis, mm',fontsize=12)
    728728    #need "applyMask" routine here
    729     A = G2img.ImageCompress(self.ImageZ,imScale)
     729    Zlim = Masks['Thresholds'][1]
     730    MA = ma.masked_greater(ma.masked_less(self.ImageZ,Zlim[0]),Zlim[1])
     731    MaskA = ma.getmaskarray(MA)
     732    A = G2img.ImageCompress(MA,imScale)
     733    AM = G2img.ImageCompress(MaskA,imScale)
     734   
     735    ImgM = Plot.imshow(AM,aspect='equal',cmap='Reds',
     736        interpolation='nearest',vmin=0,vmax=2,extent=[0,Xmax,Xmax,0])
    730737    Img = Plot.imshow(A,aspect='equal',cmap=acolor,
    731738        interpolation='nearest',vmin=Imin,vmax=Imax,extent=[0,Xmax,Xmax,0])
  • trunk/GSASIIpwdGUI.py

    r84 r85  
    253253                 
    254254    self.dataFrame.setSizePosLeft([700,150])
    255     maxTerm = 7
     255    maxTerm = 9
    256256    self.BackTable = []
    257257    N = len(data[0])
     
    388388        self.PatternTree.SetItemPyData(IndexId,data)
    389389       
     390    def OnReload(event):
     391        data = []
     392        peaks = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Peak List'))
     393        for peak in peaks:
     394            dsp = inst[1]/(2.0*sind(peak[0]/2.0))
     395            data.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0])
     396        self.PatternTree.SetItemPyData(IndexId,data)
     397        UpdateIndexPeaksGrid(self,data)
     398       
    390399    def KeyEditPickGrid(event):
    391400        colList = self.dataDisplay.GetSelectedCols()
     
    398407        elif event.GetKeyCode() == wx.WXK_SHIFT:
    399408            event.Skip(True)
    400         elif event.GetKeyCode() == wx.WXK_DELETE:
    401             dlg = wx.MessageDialog(self, 'Delete Index Peak List?', ' ', wx.YES | wx.NO)
    402             try:
    403                 result = dlg.ShowModal()
    404                 if result == wx.ID_YES:
    405                     oldlen = len(data)
    406                     data = []
    407                     self.PatternTree.SetItemPyData(IndexId,data)
    408                     self.dataDisplay.Clear()
    409                     self.dataDisplay.Destroy()
    410                     self.IndexPeaksTable = []
    411             finally:
    412                 dlg.Destroy()
    413409        elif colList:
    414410            self.dataDisplay.ClearSelection()
     
    424420        self.dataDisplay.Destroy()
    425421    self.dataFrame.setSizePosLeft([500,300])
    426     self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu)
     422    self.dataFrame.SetMenuBar(self.dataFrame.IndPeaksMenu)
     423    if not self.dataFrame.GetStatusBar():
     424        Status = self.dataFrame.CreateStatusBar()
     425    self.Bind(wx.EVT_MENU, OnReload, id=G2gd.wxID_INDXRELOAD)
    427426    inst = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Instrument Parameters'))[1]
    428427    self.IndexPeaksTable = []
    429     if not data:
    430         peaks = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Peak List'))
    431         for peak in peaks:
    432             dsp = inst[1]/(2.0*sind(peak[0]/2.0))
    433             data.append([peak[0],peak[2],True,False,0,0,0,dsp,0.0])
    434     else:
     428    if data:
    435429        cells = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,self.PatternId, 'Unit Cells List'))
    436430        if cells:
  • trunk/ImageCalibrants.py

    r42 r85  
    11#GSASII powder calibrants file; dictionary of substances commonly used for powder
    22#calibrations. Each entry consists of:
    3 # 'name':(Bravais no,(a,b,c,alpha,beta,gamma))
     3# 'name':(Bravais no,(a,b,c,alpha,beta,gamma),no. lines skipped)
    44#Useful Bravais nos.: F-cubic=0,I-cubic=1,P-cubic=2,R3/m(hex)=3, P6=4
    55Calibrants={
    66'':(0,(0,0,0,0,0,0)),
    7 'LaB6  SRM660a':(2,(4.1569162,4.1569162,4.1569162,90,90,90)),
    8 'LaB6  SRM660': (2,(4.15695,4.15695,4.15695,90,90,90)),
    9 'Si    SRM640c':(0,(5.4311946,5.4311946,5.4311946,90,90,90)),
    10 'CeO2  SRM674b':(0,(5.411651,5.411651,5.411651,90,90,90)),
    11 'Al2O3 SRM676a':(3,(4.759091,4.759091,12.991779,90,90,120)),
    12 'Ni   @ 298K':(0,(3.52475,3.52475,3.52475,90,90,90)),
    13 'NaCl @ 298K':(0,(5.6402,5.6402,5.6402,90,90,90))}
     7'LaB6  SRM660a':(2,(4.1569162,4.1569162,4.1569162,90,90,90),0),
     8'LaB6  SRM660a skip 1':(2,(4.1569162,4.1569162,4.1569162,90,90,90),1),
     9'LaB6  SRM660': (2,(4.15695,4.15695,4.15695,90,90,90),0),
     10'Si    SRM640c':(0,(5.4311946,5.4311946,5.4311946,90,90,90),0),
     11'CeO2  SRM674b':(0,(5.411651,5.411651,5.411651,90,90,90),0),
     12'Al2O3 SRM676a':(3,(4.759091,4.759091,12.991779,90,90,120),0),
     13'Ni   @ 298K':(0,(3.52475,3.52475,3.52475,90,90,90),0),
     14'NaCl @ 298K':(0,(5.6402,5.6402,5.6402,90,90,90),0)}
Note: See TracChangeset for help on using the changeset viewer.