Changeset 2500 for trunk/testDeriv.py


Ignore:
Timestamp:
Oct 21, 2016 2:58:47 PM (5 years ago)
Author:
vondreele
Message:

protect a dlg in DoIndexPeaks?
fix a lost G2frame.LimitsTable? - need to go back to tree instead
add depVarList to testDeriv file
more work on mag derivs.
modify testDeriv to show depVar derivatives

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/testDeriv.py

    r1860 r2500  
    9595                self.values = cPickle.load(file)
    9696                self.HistoPhases = cPickle.load(file)
    97                 (self.constrDict,self.fixedList) = cPickle.load(file)
     97                (self.constrDict,self.fixedList,self.depVarList) = cPickle.load(file)
    9898                self.parmDict = cPickle.load(file)
    9999                self.varylist = cPickle.load(file)
    100100                self.calcControls = cPickle.load(file)
    101101                self.pawleyLookup = cPickle.load(file)
    102                 self.use = [False for i in range(len(self.varylist))]
    103                 self.delt = [max(abs(self.parmDict[name])*0.001,1e-6) for name in self.varylist]
     102                self.use = [False for i in range(len(self.varylist+self.depVarList))]
     103                self.delt = [max(abs(self.parmDict[name])*0.001,1e-6) for name in self.varylist+self.depVarList]
    104104                file.close()
    105105                groups,parmlist = G2mv.GroupConstraints(self.constrDict)
     
    107107                self.UpdateControls(event)
    108108                print G2mv.VarRemapShow(self.varylist)
     109                print 'Dependent Vary List:',self.depVarList
    109110        finally:
    110111            dlg.Destroy()
     
    118119           
    119120        def OnDelValue(event):
     121            event.Skip()
    120122            Obj = event.GetEventObject()
    121123            item = ObjInd[Obj.GetId()]
     
    130132        ObjInd = {}
    131133        varylist = self.varylist
     134        depVarList = self.depVarList
    132135        use = self.use
    133136        delt = self.delt
    134137        mainSizer = wx.FlexGridSizer(0,8,5,5)
    135         for id,[ck,name,d] in enumerate(zip(use,varylist,delt)):
     138        for id,[ck,name,d] in enumerate(zip(use,varylist+depVarList,delt)):
    136139            useVal = wx.CheckBox(self.testDerivPanel,label=name)
    137140            useVal.SetValue(ck)
     
    164167           
    165168            Title = 'derivatives test for '+name
     169            varyList = self.varylist+self.depVarList
    166170            hplot = self.plotNB.add(Title).gca()
    167171            dMdV = G2stMth.dervRefine(self.values,self.HistoPhases,self.parmDict,
    168                 self.varylist,self.calcControls,self.pawleyLookup,None)
    169             hplot.plot(dMdV[self.varylist.index(name)],'b',label='analytic deriv')
    170             if name in self.varylist:
    171                 print 'parameter:',name,self.values[self.varylist.index(name)],delt
    172                 self.values[self.varylist.index(name)] -= delt
     172                varyList,self.calcControls,self.pawleyLookup,None)
     173            hplot.plot(dMdV[varyList.index(name)],'b',label='analytic deriv')
     174            if name in varyList:
     175                mmin = np.min(dMdV[varyList.index(name)])
     176                mmax = np.max(dMdV[varyList.index(name)])
     177                print 'parameter:',name,self.parmDict[name],delt,mmin,mmax
     178                if name in self.varylist:
     179                    self.values[self.varylist.index(name)] -= delt
     180                else:
     181                    self.parmDict[name] -= delt
    173182                M0 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    174                     self.varylist,self.calcControls,self.pawleyLookup,None)
    175                 self.values[self.varylist.index(name)] += 2.*delt
     183                    varyList,self.calcControls,self.pawleyLookup,None)
     184                if name in self.varylist:
     185                    self.values[self.varylist.index(name)] += 2.*delt
     186                else:
     187                    self.parmDict[name] += 2.*delt
    176188                M1 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    177                     self.varylist,self.calcControls,self.pawleyLookup,None)
    178                 self.values[self.varylist.index(name)] -= delt   
     189                    varyList,self.calcControls,self.pawleyLookup,None)
     190                if name in self.varylist:
     191                    self.values[self.varylist.index(name)] -= delt
     192                else:
     193                    self.parmDict[name] -= delt   
    179194                Mn = (M1-M0)/(2.*delt)
    180195                hplot.plot(Mn,'r',label='numeric deriv')
    181                 hplot.plot(dMdV[self.varylist.index(name)]-Mn,'g',label='diff')
     196                hplot.plot(dMdV[varyList.index(name)]-Mn,'g',label='diff')
     197#            GSASIIpath.IPyBreak()
    182198            hplot.legend(loc='best')           
    183199           
    184200        while self.plotNB.nb.GetPageCount():
    185201            self.plotNB.nb.DeletePage(0)
    186         test1()
    187         for use,name,delt in zip(self.use,self.varylist,self.delt):
     202        for use,name,delt in zip(self.use,self.varylist+self.depVarList,self.delt):
    188203            if use:
    189204                test2(name,delt)
     
    204219   
    205220if __name__ == '__main__':
     221    GSASIIpath.InvokeDebugOpts()
    206222    main()
Note: See TracChangeset for help on using the changeset viewer.