Changeset 1456
 Timestamp:
 Aug 4, 2014 2:29:15 PM (9 years ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIobj.py
r1453 r1456 1271 1271 'Mustrain;.*' : 'Microstrain coef.', 1272 1272 'Size;.*' : 'Crystallite size value', 1273 'eA ' : 'Cubic mustrain value',1274 'Ep ' : 'Primary extinction',1275 'Es ' : 'Secondary type II extinction',1276 'Eg ' : 'Secondary type I extinction',1273 'eA$' : 'Cubic mustrain value', 1274 'Ep$' : 'Primary extinction', 1275 'Es$' : 'Secondary type II extinction', 1276 'Eg$' : 'Secondary type I extinction', 1277 1277 #Histogram vars (:h:<var>) 1278 1278 'Absorption' : 'Absorption coef.', 
trunk/GSASIIstrMath.py
r1455 r1456 1401 1401 wave = parmDict[hfx+'Lam'] 1402 1402 else: 1403 print 'TOF Undefined at present' 1404 raise ValueError 1403 print 'TOF Undefined at present  might be nothing need be done here' 1405 1404 for phase in Histogram['Reflection Lists']: 1406 1405 refDict = Histogram['Reflection Lists'][phase] … … 1721 1720 G2mv.Dict2Deriv(varylist,depDerivDict,dMdv) 1722 1721 return dMdv 1722 1723 def dervHKLF(Histogram,Phase,calcControls,varylist,parmDict,rigidbodyDict): 1724 '''Loop over reflections ina HKLF histogram and compute derivatives of the fitting 1725 model (M) with respect to all parameters. Independent and dependant dM/dp arrays 1726 are returned to either dervRefine or HessRefine. 1727 1728 :returns: 1729 ''' 1730 nobs = Histogram['Residuals']['Nobs'] 1731 hId = Histogram['hId'] 1732 hfx = ':%d:'%(hId) 1733 pfx = '%d::'%(Phase['pId']) 1734 phfx = '%d:%d:'%(Phase['pId'],hId) 1735 SGData = Phase['General']['SGData'] 1736 A = [parmDict[pfx+'A%d'%(i)] for i in range(6)] 1737 G,g = G2lat.A2Gmat(A) #recip & real metric tensors 1738 refDict = Histogram['Data'] 1739 dFdvDict = StructureFactorDerv(refDict,G,hfx,pfx,SGData,calcControls,parmDict) 1740 ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase) 1741 dMdvh = np.zeros((len(varylist),len(refDict['RefList']))) 1742 dependentVars = G2mv.GetDependentVars() 1743 depDerivDict = {} 1744 for j in dependentVars: 1745 depDerivDict[j] = np.zeros(shape=(len(refDict['RefList']))) 1746 wdf = np.zeros(len(refDict['RefList'])) 1747 if calcControls['F**2']: 1748 for iref,ref in enumerate(refDict['RefList']): 1749 if ref[6] > 0: 1750 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11] 1751 w = 1.0/ref[6] 1752 if w*ref[5] >= calcControls['minF/sig']: 1753 wdf[iref] = w*(ref[5]ref[7]) 1754 for j,var in enumerate(varylist): 1755 if var in dFdvDict: 1756 dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale'] 1757 for var in dependentVars: 1758 if var in dFdvDict: 1759 depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale'] 1760 if phfx+'Scale' in varylist: 1761 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor 1762 elif phfx+'Scale' in dependentVars: 1763 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor 1764 for item in ['Ep','Es','Eg']: 1765 if phfx+item in varylist and dervDict: 1766 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor 1767 elif phfx+item in dependentVars and dervDict: 1768 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor 1769 for item in ['BabA','BabU']: 1770 if phfx+item in varylist: 1771 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor 1772 elif phfx+item in dependentVars: 1773 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor 1774 else: 1775 for iref,ref in enumerate(refDict['RefList']): 1776 if ref[5] > 0.: 1777 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11] 1778 Fo = np.sqrt(ref[5]) 1779 Fc = np.sqrt(ref[7]) 1780 w = 1.0/ref[6] 1781 if 2.0*Fo*w*Fo >= calcControls['minF/sig']: 1782 wdf[iref] = 2.0*Fo*w*(FoFc) 1783 for j,var in enumerate(varylist): 1784 if var in dFdvDict: 1785 dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale'] 1786 for var in dependentVars: 1787 if var in dFdvDict: 1788 depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale'] 1789 if phfx+'Scale' in varylist: 1790 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor 1791 elif phfx+'Scale' in dependentVars: 1792 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor 1793 for item in ['Ep','Es','Eg']: 1794 if phfx+item in varylist and dervDict: 1795 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor #correct 1796 elif phfx+item in dependentVars and dervDict: 1797 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor 1798 for item in ['BabA','BabU']: 1799 if phfx+item in varylist: 1800 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor 1801 elif phfx+item in dependentVars: 1802 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor 1803 return dMdvh,depDerivDict,wdf 1804 1723 1805 1724 1806 def dervRefine(values,HistoPhases,parmDict,varylist,calcControls,pawleyLookup,dlg): … … 1755 1837 elif 'HKLF' in histogram[:4]: 1756 1838 Histogram = Histograms[histogram] 1757 nobs = Histogram['Residuals']['Nobs']1758 1839 phase = Histogram['Reflection Lists'] 1759 1840 Phase = Phases[phase] 1760 hId = Histogram['hId']1761 hfx = ':%d:'%( hId)1841 dMdvh,depDerivDict,wdf = dervHKLF(Histogram,Phase,calcControls,varylist,parmDict,rigidbodyDict) 1842 hfx = ':%d:'%(Histogram['hId']) 1762 1843 wtFactor = calcControls[hfx+'wtFactor'] 1763 pfx = '%d::'%(Phase['pId'])1764 phfx = '%d:%d:'%(Phase['pId'],hId)1765 SGData = Phase['General']['SGData']1766 A = [parmDict[pfx+'A%d'%(i)] for i in range(6)]1767 G,g = G2lat.A2Gmat(A) #recip & real metric tensors1768 refDict = Histogram['Data']1769 dFdvDict = StructureFactorDerv(refDict,G,hfx,pfx,SGData,calcControls,parmDict)1770 ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)1771 dMdvh = np.zeros((len(varylist),len(refDict['RefList'])))1772 dependentVars = G2mv.GetDependentVars()1773 depDerivDict = {}1774 for j in dependentVars:1775 depDerivDict[j] = np.zeros(shape=(len(refDict['RefList'])))1776 if calcControls['F**2']:1777 for iref,ref in enumerate(refDict['RefList']):1778 if ref[6] > 0:1779 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11]1780 w = 1.0/ref[6]1781 if w*ref[5] >= calcControls['minF/sig']:1782 for j,var in enumerate(varylist):1783 if var in dFdvDict:1784 dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']1785 for var in dependentVars:1786 if var in dFdvDict:1787 depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']1788 if phfx+'Scale' in varylist:1789 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor1790 elif phfx+'Scale' in dependentVars:1791 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor1792 for item in ['Ep','Es','Eg']:1793 if phfx+item in varylist and dervDict:1794 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor1795 elif phfx+item in dependentVars and dervDict:1796 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor1797 for item in ['BabA','BabU']:1798 if phfx+item in varylist:1799 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1800 elif phfx+item in dependentVars:1801 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1802 else:1803 for iref,ref in enumerate(refDict['RefList']):1804 if ref[5] > 0.:1805 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11]1806 Fo = np.sqrt(ref[5])1807 Fc = np.sqrt(ref[7])1808 w = 1.0/ref[6]1809 if 2.0*Fo*w*Fo >= calcControls['minF/sig']:1810 for j,var in enumerate(varylist):1811 if var in dFdvDict:1812 dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']1813 for var in dependentVars:1814 if var in dFdvDict:1815 depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']1816 if phfx+'Scale' in varylist:1817 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor1818 elif phfx+'Scale' in dependentVars:1819 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor1820 for item in ['Ep','Es','Eg']:1821 if phfx+item in varylist and dervDict:1822 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor #correct1823 elif phfx+item in dependentVars and dervDict:1824 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor1825 for item in ['BabA','BabU']:1826 if phfx+item in varylist:1827 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1828 elif phfx+item in dependentVars:1829 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1830 1844 # now process derivatives in constraints 1831 1845 G2mv.Dict2Deriv(varylist,depDerivDict,dMdvh) … … 1892 1906 elif 'HKLF' in histogram[:4]: 1893 1907 Histogram = Histograms[histogram] 1894 nobs = Histogram['Residuals']['Nobs']1895 1908 phase = Histogram['Reflection Lists'] 1896 1909 Phase = Phases[phase] 1910 dMdvh,depDerivDict,wdf = dervHKLF(Histogram,Phase,calcControls,varylist,parmDict,rigidbodyDict) 1897 1911 hId = Histogram['hId'] 1898 hfx = ':%d:'%( hId)1912 hfx = ':%d:'%(Histogram['hId']) 1899 1913 wtFactor = calcControls[hfx+'wtFactor'] 1900 pfx = '%d::'%(Phase['pId'])1901 phfx = '%d:%d:'%(Phase['pId'],hId)1902 SGData = Phase['General']['SGData']1903 A = [parmDict[pfx+'A%d'%(i)] for i in range(6)]1904 G,g = G2lat.A2Gmat(A) #recip & real metric tensors1905 refDict = Histogram['Data']1906 time0 = time.time()1907 dFdvDict = StructureFactorDerv(refDict,G,hfx,pfx,SGData,calcControls,parmDict)1908 # print 'sfderiv time: %.3f'%(time.time()time0)1909 ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)1910 dMdvh = np.zeros((len(varylist),len(refDict['RefList'])))1911 dependentVars = G2mv.GetDependentVars()1912 depDerivDict = {}1913 for j in dependentVars:1914 depDerivDict[j] = np.zeros(shape=(len(refDict['RefList'])))1915 wdf = np.zeros(len(refDict['RefList']))1916 time0 = time.time()1917 if calcControls['F**2']:1918 for iref,ref in enumerate(refDict['RefList']):1919 if ref[6] > 0:1920 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11]1921 w = 1.0/ref[6]1922 if w*ref[5] >= calcControls['minF/sig']:1923 wdf[iref] = w*(ref[5]ref[7])1924 for j,var in enumerate(varylist):1925 if var in dFdvDict:1926 dMdvh[j][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor1927 for var in dependentVars:1928 if var in dFdvDict:1929 depDerivDict[var][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor1930 if phfx+'Scale' in varylist:1931 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor1932 elif phfx+'Scale' in dependentVars:1933 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor1934 for item in ['Ep','Es','Eg']:1935 if phfx+item in varylist and dervDict:1936 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor1937 elif phfx+item in dependentVars and dervDict:1938 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor1939 for item in ['BabA','BabU']:1940 if phfx+item in varylist:1941 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1942 elif phfx+item in dependentVars:1943 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1944 else:1945 for iref,ref in enumerate(refDict['RefList']):1946 if ref[5] > 0.:1947 dervCor,dervDict = SCExtinction(ref,phfx,hfx,pfx,calcControls,parmDict,varylist) #puts correction in refl[11]1948 Fo = np.sqrt(ref[5])1949 Fc = np.sqrt(ref[7])1950 w = 1.0/ref[6]1951 if 2.0*Fo*w*Fo >= calcControls['minF/sig']:1952 wdf[iref] = 2.0*Fo*w*(FoFc)1953 for j,var in enumerate(varylist):1954 if var in dFdvDict:1955 dMdvh[j][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor1956 for var in dependentVars:1957 if var in dFdvDict:1958 depDerivDict[var][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor1959 if phfx+'Scale' in varylist:1960 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor1961 elif phfx+'Scale' in dependentVars:1962 depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor1963 for item in ['Ep','Es','Eg']:1964 if phfx+item in varylist and dervDict:1965 dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]/dervCor1966 elif phfx+item in dependentVars and dervDict:1967 depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]/dervCor1968 for item in ['BabA','BabU']:1969 if phfx+item in varylist:1970 dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1971 elif phfx+item in dependentVars:1972 depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor1973 1914 # now process derivatives in constraints 1974 1915 G2mv.Dict2Deriv(varylist,depDerivDict,dMdvh) … … 2078 2019 ref[8] = ref[5]/(parmDict[phfx+'Scale']*ref[11]) 2079 2020 if w*ref[5] >= calcControls['minF/sig']: 2080 sumFo2 += ref[5]2081 2021 Fo = np.sqrt(ref[5]) 2082 2022 sumFo += Fo 
trunk/testDeriv.py
r1454 r1456 50 50 def _init_ctrls(self, parent): 51 51 wx.Frame.__init__(self, name='testDeriv', parent=parent, 52 size=wx.Size( 460, 250),style=wx.DEFAULT_FRAME_STYLE, title='Test Jacobian Derivatives')52 size=wx.Size(750, 250),style=wx.DEFAULT_FRAME_STYLE, title='Test Jacobian Derivatives') 53 53 self.testDerivMenu = wx.MenuBar() 54 54 self.File = wx.Menu(title='') … … 142 142 self.testDerivPanel.SetSizer(mainSizer) 143 143 Size = mainSizer.Fit(self.testDerivPanel) 144 Size[0] = 7 00144 Size[0] = 750 145 145 Size[1] = max(Size[1],290) + 35 146 146 self.testDerivPanel.SetScrollbars(10,10,Size[0]/104,Size[1]/101) … … 163 163 hplot.plot(dMdV[self.varylist.index(name)],'b',label='analytic deriv') 164 164 if name in self.varylist: 165 print 'parameter:',name,self.values[self.varylist.index(name)],delt 165 166 self.values[self.varylist.index(name)] = delt 166 167 M0 = G2stMth.errRefine(self.values,self.HistoPhases,self.parmDict,
Note: See TracChangeset
for help on using the changeset viewer.