Changeset 3774 for trunk/testDeriv.py


Ignore:
Timestamp:
Jan 3, 2019 9:32:48 AM (3 years ago)
Author:
vondreele
Message:

fix super indexing problem in transposeHKLF
fix reflection generation for incommensurate mag case in G2lattice & G2pwd
clean up non Fourier modulation calcs & remove analytic derivative stuff (now numeric)
fix uij derivative bug
work on incommensurate magnetic sturcture factors - not working yet
clean up of testDeriv - better choices for delt & force reflection regeneration before each derivative test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/testDeriv.py

    r3711 r3774  
    4444    return testDeriv(parent)
    4545   
    46 [wxID_FILEEXIT, wxID_FILEOPEN, wxID_MAKEPLOTS,
    47 ] = [wx.NewId() for _init_coll_File_Items in range(3)]
     46[wxID_FILEEXIT, wxID_FILEOPEN, wxID_MAKEPLOTS, wxID_CLEARSEL,
     47] = [wx.NewId() for _init_coll_File_Items in range(4)]
    4848
    4949def FileDlgFixExt(dlg,file):            #this is needed to fix a problem in linux wx.FileDialog
     
    6262        self.File.Append(wxID_FILEOPEN,'Open testDeriv file','Open testDeriv')
    6363        self.File.Append(wxID_MAKEPLOTS,'Make plots','Make derivative plots')
     64        self.File.Append(wxID_CLEARSEL,'Clear selections')
    6465        self.File.Append(wxID_FILEEXIT,'Exit','Exit from testDeriv')
    65         self.Bind(wx.EVT_MENU, self.OnTestRead, id=wxID_FILEOPEN)
     66        self.Bind(wx.EVT_MENU,self.OnTestRead, id=wxID_FILEOPEN)
    6667        self.Bind(wx.EVT_MENU,self.OnMakePlots,id=wxID_MAKEPLOTS)
    67         self.Bind(wx.EVT_MENU, self.OnFileExit, id=wxID_FILEEXIT)
     68        self.Bind(wx.EVT_MENU,self.ClearSelect,id=wxID_CLEARSEL)
     69        self.Bind(wx.EVT_MENU,self.OnFileExit, id=wxID_FILEEXIT)
    6870        self.testDerivMenu.Append(menu=self.File, title='File')
    6971        self.SetMenuBar(self.testDerivMenu)
     
    9597            self.dataFrame.Destroy()
    9698        self.Close()
     99       
     100    def ClearSelect(self,event):
     101        self.use = [False for i in range(len(self.names))]
     102        self.UpdateControls(event)
    97103
    98104    def OnTestRead(self,event):
     
    128134            self.calcControls = cPickle.load(file,encoding='Latin-1')
    129135            self.pawleyLookup = cPickle.load(file,encoding='Latin-1')
    130         self.use = [False for i in range(len(self.varylist+self.depVarList))]
    131         self.delt = [max(abs(self.parmDict[name])*0.0001,1e-6) for name in self.varylist+self.depVarList]
     136        self.names = self.varylist+self.depVarList
     137        self.use = [False for i in range(len(self.names))]
     138        self.delt = [max(abs(self.parmDict[name])*0.0001,1e-6) for name in self.names]
     139        for iname,name in enumerate(self.names):
     140            if name.split(':')[-1] in ['Shift','DisplaceX','DisplaceY',]:
     141                self.delt[iname] = 0.1
    132142        file.close()
    133143        msg = G2mv.EvaluateMultipliers(self.constrDict,self.parmDict)
     
    159169        self.testDerivPanel.DestroyChildren()
    160170        ObjInd = {}
    161         varylist = self.varylist
    162         depVarList = self.depVarList
     171        names = self.names
    163172        use = self.use
    164173        delt = self.delt
    165174        mainSizer = wx.FlexGridSizer(0,8,5,5)
    166         for id,[ck,name,d] in enumerate(zip(use,varylist+depVarList,delt)):
     175        for id,[ck,name,d] in enumerate(zip(use,names,delt)):
    167176            useVal = wx.CheckBox(self.testDerivPanel,label=name)
    168177            useVal.SetValue(ck)
     
    202211        def test2(name,delt,doProfile):
    203212            Title = 'derivatives test for '+name
    204             varyList = self.varylist+self.depVarList
     213            names = self.names
    205214            hplot = self.plotNB.add(Title).gca()
    206215            if doProfile:
    207216                pr = cProfile.Profile()
    208217                pr.enable()
     218            #regenerate minimization fxn
     219            G2stMth.errRefine(self.values,self.HistoPhases,
     220                self.parmDict,self.varylist,self.calcControls,
     221                self.pawleyLookup,None)
    209222            dMdV = G2stMth.dervRefine(self.values,self.HistoPhases,self.parmDict,
    210                 varyList,self.calcControls,self.pawleyLookup,None)
     223                names,self.calcControls,self.pawleyLookup,None)
    211224            if doProfile:
    212225                pr.disable()
     
    217230                print('Profiler of '+name+' derivative calculation; top 50% of routines:')
    218231                print(s.getvalue())
    219             M2 = dMdV[varyList.index(name)]
     232            M2 = dMdV[names.index(name)]
    220233            hplot.plot(M2,'b',label='analytic deriv')
    221             mmin = np.min(dMdV[varyList.index(name)])
    222             mmax = np.max(dMdV[varyList.index(name)])
     234            mmin = np.min(dMdV[names.index(name)])
     235            mmax = np.max(dMdV[names.index(name)])
    223236            print('parameter:',name,self.parmDict[name],delt,mmin,mmax)
    224237            if name in self.varylist:
    225238                self.values[self.varylist.index(name)] -= delt
    226239                M0 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    227                     varyList,self.calcControls,self.pawleyLookup,None)
     240                    names,self.calcControls,self.pawleyLookup,None)
    228241                self.values[self.varylist.index(name)] += 2.*delt
    229242                M1 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    230                     varyList,self.calcControls,self.pawleyLookup,None)
     243                    names,self.calcControls,self.pawleyLookup,None)
    231244                self.values[self.varylist.index(name)] -= delt
    232245            elif name in self.depVarList:   #in depVarList
     
    236249                self.parmDict[name] -= delt
    237250                M0 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    238                     varyList,self.calcControls,self.pawleyLookup,None)
     251                    names,self.calcControls,self.pawleyLookup,None)
    239252                self.parmDict[name] += 2.*delt
    240253                M1 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
    241                     varyList,self.calcControls,self.pawleyLookup,None)
     254                    names,self.calcControls,self.pawleyLookup,None)
    242255                self.parmDict[name] -= delt   
    243256            Mn = (M1-M0)/(2.*abs(delt))
Note: See TracChangeset for help on using the changeset viewer.