Changeset 397


Ignore:
Timestamp:
Oct 21, 2011 12:15:50 PM (12 years ago)
Author:
vondreele
Message:

collect default settings for Sample in one routine
add recalibrate routine for images
azimuths from image integration are now the center angle of each azimuth bin
put in 1/2 pixel offset in image calibration/integration calcs

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r395 r397  
    344344                    DataType = DataType.strip()[0:3]                                #just 1st 3 chars
    345345                    wx.BeginBusyCursor()
    346                     Sample = {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False],
    347                         'DisplaceX':[0.0,False],'DisplaceY':[0.0,False],'Diffuse':[],
    348                         'Temperature':Temperature,'Pressure':1.0,'Humidity':0.0,'Voltage':0.0,'Force':0.0,
    349                         'Gonio. radius':200.0,'Omega':0.0,'Chi':0.0,'Phi':0.0}
     346                    Sample = G2pdG.GetDefaultSample()
    350347                    try:
    351348                        for Item in Data:
     
    762759                    Id = self.PatternTree.AppendItem(parent=self.root,text=outname)
    763760                    if Id:
    764                         Sample = {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False],
    765                             'DisplaceX':[0.0,False],'DisplaceY':[0.0,False],'Diffuse':[],
    766                             'Temperature':300.,'Pressure':1.0,'Humidity':0.0,
    767                             'Voltage':0.0,'Force':0.0,'Gonio. radius':200.0,
    768                             'Omega':0.0,'Chi':0.0,'Phi':0.0}
     761                        Sample = G2pdG.SetDefaultSample()
    769762                        self.PatternTree.SetItemPyData(Id,[[''],[Xsum,Ysum,Wsum,YCsum,YBsum,YDsum]])
    770763                        self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Comments'),Comments)                   
  • trunk/GSASIIIO.py

    r391 r397  
    1919import GSASIIspc as G2spc
    2020import GSASIIlattice as G2lat
     21import GSASIIpwdGUI as G2pdG
    2122import GSASIIElem as G2el
    2223import os.path as ospath
     
    848849       
    849850def SaveIntegration(self,PickId,data):
    850     azms = self.Integrate[1][:-1]
     851    azms = self.Integrate[1]
    851852    X = self.Integrate[2][:-1]
    852853    Xminmax = [X[0],X[-1]]
     
    859860    codes = [0 for i in range(11)]
    860861    LRazm = data['LRazimuth']
     862    Azms = []
    861863    if data['fullIntegrate'] and data['outAzimuths'] == 1:
    862864        Azms = [45.0,]                              #a poor man's average?
    863     for i,azm in enumerate(azms):
     865    else:
     866        for i,azm in enumerate(azms[:-1]):
     867            Azms.append((azms[i+1]+azm)/2.)
     868    for i,azm in enumerate(azms[:-1]):
    864869        item, cookie = self.PatternTree.GetFirstChild(self.root)
    865870        Id = 0
     
    869874                Id = item
    870875            item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
    871         parms = ['PXC',data['wavelength'],0.0,0.99,1.0,-0.10,0.4,0.30,1.0,0.0001,azm]    #set polarization for synchrotron radiation!
     876        parms = ['PXC',data['wavelength'],0.0,0.99,1.0,-0.10,0.4,0.30,1.0,0.0001,Azms[i]]    #set polarization for synchrotron radiation!
    872877        Y = self.Integrate[0][i]
    873878        W = 1./Y                    #probably not true
    874         Sample = {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False],'DisplaceX':[0.0,False],
    875             'DisplaceY':[0.0,False],'Diffuse':[],'Temperature':300.,'Pressure':1.0,'Humidity':0.0,'Voltage':0.0,'Force':0.0}
     879        Sample = G2pdG.SetDefaultSample()
    876880        if Id:
    877881            self.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(self,Id, 'Comments'),Comments)                   
     
    884888            self.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(self,Id,'Reflection Lists'),{})             
    885889        else:
    886             Id = self.PatternTree.AppendItem(parent=self.root,text=name+" Azm= %.2f"%(azm))
     890            Id = self.PatternTree.AppendItem(parent=self.root,text=name+" Azm= %.2f"%(Azms[i]))
    887891            self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Comments'),Comments)                   
    888892            self.PatternTree.SetItemPyData(self.PatternTree.AppendItem(Id,text='Limits'),[tuple(Xminmax),Xminmax])
  • trunk/GSASIIgrid.py

    r395 r397  
    3232] = [wx.NewId() for _init_coll_DrawAtom_Items in range(10)]
    3333
    34 [ wxID_IMCALIBRATE, wxID_IMINTEGRATE, wxID_IMCLEARCALIB, 
     34[ wxID_IMCALIBRATE,wxID_IMRECALIBRATE,wxID_IMINTEGRATE, wxID_IMCLEARCALIB, 
    3535    wxID_IMCOPYCONTROLS, wxID_INTEGRATEALL, wxID_IMSAVECONTROLS, wxID_IMLOADCONTROLS,
    36 ] = [wx.NewId() for _init_coll_IMAGE_Items in range(7)]
     36] = [wx.NewId() for _init_coll_IMAGE_Items in range(8)]
    3737
    3838[ wxID_MASKCOPY, wxID_MASKSAVE, wxID_MASKLOAD,
     
    204204        parent.Append(help='Calibrate detector by fitting to calibrant lines',
    205205            id=wxID_IMCALIBRATE, kind=wx.ITEM_NORMAL,text='Calibrate')
     206        parent.Append(help='Recalibrate detector by fitting to calibrant lines',
     207            id=wxID_IMRECALIBRATE, kind=wx.ITEM_NORMAL,text='Realibrate')
    206208        parent.Append(help='Clear calibration data points and rings',id=wxID_IMCLEARCALIB,
    207209            kind=wx.ITEM_NORMAL,text='Clear calibration')
  • trunk/GSASIIimage.py

    r396 r397  
    376376    tay = ma.compressed(ma.array(tay.flatten(),mask=tam))
    377377    return zip(tax,tay)
     378   
     379def ImageRecalibrate(self,data):
     380    import copy
     381    import ImageCalibrants as calFile
     382    print 'Image recalibration:'
     383    time0 = time.time()
     384    pixelSize = data['pixelSize']
     385    scalex = 1000./pixelSize[0]
     386    scaley = 1000./pixelSize[1]
     387    pixLimit = data['pixLimit']
     388    cutoff = data['cutoff']
     389    data['rings'] = []
     390    data['ellipses'] = []
     391    if not data['calibrant']:
     392        print 'no calibration material selected'
     393        return True
     394   
     395    skip = data['calibskip']
     396    dmin = data['calibdmin']
     397    Bravais,Cells = calFile.Calibrants[data['calibrant']][:2]
     398    HKL = []
     399    for bravais,cell in zip(Bravais,Cells):
     400        A = G2lat.cell2A(cell)
     401        hkl = G2lat.GenHBravais(dmin,bravais,A)[skip:]
     402        HKL += hkl
     403    HKL = G2lat.sortHKLd(HKL,True,False)
     404    wave = data['wavelength']
     405    cent = data['center']   
     406    dist = data['distance']
     407    cent = data['center']
     408    tilt = data['tilt']
     409    phi = data['rotation']
     410    for H in HKL:
     411        dsp = H[3]
     412        ellipse = GetEllipse(dsp,data)
     413        Ring,delt = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,self.ImageZ)
     414        if Ring:
     415            numZ = len(Ring)
     416            data['rings'].append(np.array(Ring))
     417            data['ellipses'].append(copy.deepcopy(ellipse+('r',)))
     418        else:
     419            continue
     420    rings = np.concatenate((data['rings']),axis=0)
     421    p0 = [dist,cent[0],cent[1],phi,tilt]
     422    result,newWave = FitDetector(rings,p0,wave)
     423    data['distance'] = result[0]
     424    data['center'] = result[1:3]
     425    data['rotation'] = np.mod(result[3],360.0)
     426    data['tilt'] = result[4]
     427    N = len(data['ellipses'])
     428    data['ellipses'] = []           #clear away individual ellipse fits
     429    for H in HKL[:N]:
     430        ellipse = GetEllipse(H[3],data)
     431        data['ellipses'].append(copy.deepcopy(ellipse+('b',)))
     432   
     433    print 'calibration time = ',time.time()-time0
     434    G2plt.PlotImage(self,newImage=True)       
     435    return True
     436   
    378437           
    379438def ImageCalibrate(self,data):
     
    545604    p0 = [dist,cent[0],cent[1],phi,tilt]
    546605    result,newWave = FitDetector(rings,p0,wave)
    547 #    print 'Suggested new wavelength = ',('%.5f')%(newWave),' (not reliable if distance > 2m)'
    548606    data['distance'] = result[0]
    549607    data['center'] = result[1:3]
  • trunk/GSASIIimgGUI.py

    r342 r397  
    215215        data['ellipses'] = []
    216216        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=False)   
     217        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMRECALIBRATE,enable=False)   
    217218        G2plt.PlotExposedImage(self,event=event)
    218219           
    219220    def OnCalibrate(event):       
    220221        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=True)   
     222        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMRECALIBRATE,enable=True)   
    221223        self.dataFrame.GetStatusBar().SetStatusText('Select > 4 points on 1st used ring; LB to pick, RB on point to delete else RB to finish')
    222224        self.ifGetRing = True
     225       
     226    def OnRecalibrate(event):
     227        G2img.ImageRecalibrate(self,data)
    223228       
    224229    def OnIntegrate(event):
     
    390395        self.dataFrame.CreateStatusBar()
    391396    self.dataFrame.Bind(wx.EVT_MENU, OnCalibrate, id=G2gd.wxID_IMCALIBRATE)
     397    self.dataFrame.Bind(wx.EVT_MENU, OnRecalibrate, id=G2gd.wxID_IMRECALIBRATE)
    392398    self.dataFrame.Bind(wx.EVT_MENU, OnClearCalib, id=G2gd.wxID_IMCLEARCALIB)
    393399    if not data['rings']:
    394400        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=False)   
     401        self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMRECALIBRATE,enable=False)   
    395402    self.dataFrame.Bind(wx.EVT_MENU, OnIntegrate, id=G2gd.wxID_IMINTEGRATE)
    396403    self.dataFrame.Bind(wx.EVT_MENU, OnIntegrateAll, id=G2gd.wxID_INTEGRATEALL)
  • trunk/GSASIIphsGUI.py

    r395 r397  
    20902090            G2plt.PlotStrain(self,data)
    20912091           
     2092        def OnCopyData(event):
     2093            #how about HKLF data? This is only for PWDR data
     2094            Obj = event.GetEventObject()
     2095            Obj.SetValue(False)
     2096            hist = Indx[Obj.GetId()]
     2097            sourceDict = UseList[hist]
     2098            copyNames = ['Scale','Pref.Ori.','Size','Mustrain','HStrain','Extinction']
     2099            copyDict = {}
     2100            for name in copyNames:
     2101                copyDict[name] = sourceDict[name]
     2102            keyList = ['All',]+UseList.keys()
     2103            if UseList:
     2104                copyList = []
     2105                dlg = wx.MultiChoiceDialog(self,
     2106                    'Copy parameters to which histograms?', 'Copy parameters',
     2107                    keyList, wx.CHOICEDLG_STYLE)
     2108                try:
     2109                    if dlg.ShowModal() == wx.ID_OK:
     2110                        result = dlg.GetSelections()
     2111                        for i in result:
     2112                            copyList.append(keyList[i])
     2113                        if 'All' in copyList:
     2114                            copyList = keyList[1:]
     2115                        for item in copyList:
     2116                            UseList[item].update(copyDict)
     2117                        UpdateDData()
     2118                finally:
     2119                    dlg.Destroy()
     2120           
    20922121        def OnScaleRef(event):
    20932122            Obj = event.GetEventObject()
     
    23022331            histData = UseList[item]
    23032332            mainSizer.Add((5,5),0)
     2333           
     2334            showSizer = wx.BoxSizer(wx.HORIZONTAL)
    23042335            showData = wx.CheckBox(dataDisplay,-1,label=' Show '+item)
    23052336            showData.SetValue(UseList[item]['Show'])
    23062337            Indx[showData.GetId()] = item
    23072338            showData.Bind(wx.EVT_CHECKBOX, OnShowData)
    2308             mainSizer.Add(showData,0,wx.ALIGN_CENTER_VERTICAL)
     2339            showSizer.Add(showData,0,wx.ALIGN_CENTER_VERTICAL)
     2340            copyData = wx.CheckBox(dataDisplay,-1,label=' Copy?')
     2341            Indx[copyData.GetId()] = item
     2342            copyData.Bind(wx.EVT_CHECKBOX,OnCopyData)
     2343            showSizer.Add(copyData,wx.ALIGN_CENTER_VERTICAL)
     2344            mainSizer.Add(showSizer,0,wx.ALIGN_CENTER_VERTICAL)
    23092345            mainSizer.Add((0,5),0)
     2346           
    23102347            if UseList[item]['Show']:
    23112348                scaleSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    26122649        SGData = generalData['SGData']
    26132650        UseList = data['Histograms']
     2651        newList = []
    26142652        NShkl = len(G2spc.MustrainNames(SGData))
    26152653        NDij = len(G2spc.HStrainNames(SGData))
    26162654        keyList = UseList.keys()
    2617         TextList = []
     2655        TextList = ['All PWDR']
    26182656        if self.PatternTree.GetCount():
    26192657            item, cookie = self.PatternTree.GetFirstChild(self.root)
     
    26272665                if dlg.ShowModal() == wx.ID_OK:
    26282666                    result = dlg.GetSelections()
    2629                     for i in result:
    2630                         histoName = TextList[i]
     2667                    for i in result: newList.append(TextList[i])
     2668                    if 'All PWDR' in newList:
     2669                        newList = TextList[1:]
     2670                    for histoName in newList:
    26312671                        pId = G2gd.GetPatternTreeItemId(self,self.root,histoName)
    26322672                        UseList[histoName] = {'Histogram':histoName,'Show':False,
     
    26462686    def OnDataDelete(event):
    26472687        UseList = data['Histograms']
    2648         keyList = UseList.keys()
     2688        keyList = ['All',]+UseList.keys()
    26492689        keyList.sort()
    26502690        DelList = []
     
    26572697                if dlg.ShowModal() == wx.ID_OK:
    26582698                    result = dlg.GetSelections()
    2659                     for i in result: DelList.append(keyList[i])
     2699                    for i in result:
     2700                        DelList.append(keyList[i])
     2701                    if 'All' in DelList:
     2702                        DelList = keyList[1:]
    26602703                    for i in DelList:
    26612704                        del UseList[i]
  • trunk/GSASIIpwdGUI.py

    r395 r397  
    4343    else:
    4444        return False
    45    
     45
     46def SetDefaultSample():
     47    return {'Scale':[1.0,True],'Type':'Debye-Scherrer','Absorption':[0.0,False],
     48        'DisplaceX':[0.0,False],'DisplaceY':[0.0,False],'Diffuse':[],
     49        'Temperature':300.,'Pressure':1.0,'Humidity':0.0,
     50        'Voltage':0.0,'Force':0.0,'Gonio. radius':200.0,
     51        'Omega':0.0,'Chi':0.0,'Phi':0.0}   
    4652       
    4753def UpdatePeakGrid(self, data):
  • trunk/GSASIIstruct.py

    r395 r397  
    22852285        Ftol = Controls['min dM/M']
    22862286        Factor = Controls['shift factor']
    2287         try:
    2288             if Controls['deriv type'] == 'analytic':
    2289                 result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
    2290                     ftol=Ftol,col_deriv=True,factor=Factor,
    2291                     args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    2292                 ncyc = int(result[2]['nfev']/2)               
    2293             else:           #'numeric'
    2294                 result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
    2295                     args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    2296                 ncyc = int(result[2]['nfev']/len(varyList))
    2297 #            table = dict(zip(varyList,zip(values,result[0],(result[0]-values))))
    2298 #            for item in table: print item,table[item]               #useful debug - are things shifting?
    2299         except Exception:
    2300             result = [parmDict['saved values'],None]
     2287        if Controls['deriv type'] == 'analytic':
     2288            result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
     2289                ftol=Ftol,col_deriv=True,factor=Factor,
     2290                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2291            ncyc = int(result[2]['nfev']/2)               
     2292        else:           #'numeric'
     2293            result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
     2294                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2295            ncyc = int(result[2]['nfev']/len(varyList))
     2296#        table = dict(zip(varyList,zip(values,result[0],(result[0]-values))))
     2297#        for item in table: print item,table[item]               #useful debug - are things shifting?
    23012298        runtime = time.time()-begin
    23022299        chisq = np.sum(result[2]['fvec']**2)
Note: See TracChangeset for help on using the changeset viewer.