Ignore:
Timestamp:
Apr 23, 2014 5:11:13 PM (8 years ago)
Author:
toby
Message:

Start on parametric fitting; Time for new manual; fix minor formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sphinxdocs/build/html/_modules/GSASIIstrMath.html

    r1183 r1298  
    5757<span class="sd">&#39;&#39;&#39;</span>
    5858<span class="c">########### SVN repository information ###################</span>
    59 <span class="c"># $Date: 2013-12-19 09:37:07 -0600 (Thu, 19 Dec 2013) $</span>
     59<span class="c"># $Date: 2014-04-18 15:55:06 -0500 (Fri, 18 Apr 2014) $</span>
    6060<span class="c"># $Author: vondreele $</span>
    61 <span class="c"># $Revision: 1175 $</span>
     61<span class="c"># $Revision: 1286 $</span>
    6262<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/GSASIIstrMath.py $</span>
    63 <span class="c"># $Id: GSASIIstrMath.py 1175 2013-12-19 15:37:07Z vondreele $</span>
     63<span class="c"># $Id: GSASIIstrMath.py 1286 2014-04-18 20:55:06Z vondreele $</span>
    6464<span class="c">########### SVN repository information ###################</span>
    6565<span class="kn">import</span> <span class="nn">time</span>
     
    7272<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="kn">as</span> <span class="nn">st</span>
    7373<span class="kn">import</span> <span class="nn">GSASIIpath</span>
    74 <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1175 $&quot;</span><span class="p">)</span>
     74<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1286 $&quot;</span><span class="p">)</span>
    7575<span class="kn">import</span> <span class="nn">GSASIIElem</span> <span class="kn">as</span> <span class="nn">G2el</span>
    7676<span class="kn">import</span> <span class="nn">GSASIIlattice</span> <span class="kn">as</span> <span class="nn">G2lat</span>
     
    445445                                <span class="n">pWsum</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">+=</span> <span class="n">wt</span><span class="o">*</span><span class="p">((</span><span class="n">obs</span><span class="o">-</span><span class="n">calc</span><span class="p">)</span><span class="o">/</span><span class="n">esd</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
    446446         
     447    <span class="n">pWsum</span><span class="p">[</span><span class="s">&#39;PWLref&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>
    447448    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">varyList</span><span class="p">:</span>
    448449        <span class="k">if</span> <span class="s">&#39;PWLref&#39;</span> <span class="ow">in</span> <span class="n">item</span> <span class="ow">and</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">item</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
     
    452453                <span class="n">pVals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">item</span><span class="p">])</span>
    453454                <span class="n">pWt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">negWt</span><span class="p">[</span><span class="n">pId</span><span class="p">])</span>
    454                 <span class="n">pWsum</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">+=</span> <span class="n">negWt</span><span class="p">[</span><span class="n">pId</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">item</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
     455                <span class="n">pWsum</span><span class="p">[</span><span class="s">&#39;PWLref&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">negWt</span><span class="p">[</span><span class="n">pId</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">item</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
    455456    <span class="n">pVals</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pVals</span><span class="p">)</span>
    456457    <span class="n">pWt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pWt</span><span class="p">)</span>         <span class="c">#should this be np.sqrt?</span>
     
    10871088    </div>
    10881089<div class="viewcode-block" id="GetIntensityCorr"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.GetIntensityCorr">[docs]</a><span class="k">def</span> <span class="nf">GetIntensityCorr</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">uniq</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
    1089     <span class="s">&#39;Needs a doc string&#39;</span>
     1090    <span class="s">&#39;Needs a doc string&#39;</span>    <span class="c">#need powder extinction!</span>
    10901091    <span class="n">Icorr</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">parmDict</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">refl</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>               <span class="c">#scale*multiplicity</span>
    10911092    <span class="k">if</span> <span class="s">&#39;X&#39;</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;Type&#39;</span><span class="p">]:</span>
     
    10981099    </div>
    10991100<div class="viewcode-block" id="GetIntensityDerv"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.GetIntensityDerv">[docs]</a><span class="k">def</span> <span class="nf">GetIntensityDerv</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">uniq</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
    1100     <span class="s">&#39;Needs a doc string&#39;</span>
     1101    <span class="s">&#39;Needs a doc string&#39;</span>    <span class="c">#need powder extinction derivs!</span>
    11011102    <span class="n">dIdsh</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">parmDict</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span>
    11021103    <span class="n">dIdsp</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span>
     
    14481449        <span class="n">SGData</span> <span class="o">=</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">][</span><span class="s">&#39;SGData&#39;</span><span class="p">]</span>
    14491450        <span class="n">SGMT</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    1450         <span class="n">A</span> <span class="o">=</span> <span class="p">[</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;A</span><span class="si">%d</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
     1451        <span class="n">A</span> <span class="o">=</span> <span class="p">[</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;A</span><span class="si">%d</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>     <span class="c">#Do I want to modify by Dij?</span>
    14511452        <span class="n">G</span><span class="p">,</span><span class="n">g</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">A2Gmat</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>       <span class="c">#recip &amp; real metric tensors</span>
    14521453        <span class="n">GA</span><span class="p">,</span><span class="n">GB</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">Gmat2AB</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>    <span class="c">#Orthogonalization matricies</span>
     
    14551456            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    14561457            <span class="n">StructureFactor2</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    1457             <span class="k">print</span> <span class="s">&#39;sf calc time: </span><span class="si">%.3f</span><span class="s">s&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
     1458<span class="c">#            print &#39;sf calc time: %.3fs&#39;%(time.time()-time0)</span>
    14581459        <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    14591460        <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
     
    14951496                <span class="k">print</span> <span class="s">&#39;TOF Undefined at present&#39;</span>
    14961497                <span class="k">raise</span> <span class="ne">Exception</span>    <span class="c">#no TOF yet</span>
    1497         <span class="k">print</span> <span class="s">&#39;profile calc time: </span><span class="si">%.3f</span><span class="s">s&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
     1498<span class="c">#        print &#39;profile calc time: %.3fs&#39;%(time.time()-time0)</span>
    14981499    <span class="k">return</span> <span class="n">yc</span><span class="p">,</span><span class="n">yb</span>
    14991500    </div>
     
    15481549    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">varylist</span><span class="p">:</span>
    15491550        <span class="k">if</span> <span class="s">&#39;BkPk&#39;</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
    1550             <span class="nb">id</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
    1551             <span class="n">parm</span> <span class="o">=</span> <span class="n">name</span><span class="p">[:</span><span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">rindex</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">))]</span>
    1552             <span class="n">ip</span> <span class="o">=</span> <span class="n">names</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">parm</span><span class="p">)</span>
    1553             <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">name</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dMdpk</span><span class="p">[</span><span class="mi">4</span><span class="o">*</span><span class="nb">id</span><span class="o">+</span><span class="n">ip</span><span class="p">]</span>
     1551            <span class="n">parm</span><span class="p">,</span><span class="nb">id</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;;&#39;</span><span class="p">)</span>
     1552            <span class="nb">id</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">id</span><span class="p">)</span>
     1553            <span class="k">if</span> <span class="n">parm</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
     1554                <span class="n">ip</span> <span class="o">=</span> <span class="n">names</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">parm</span><span class="p">)</span>
     1555                <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">name</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dMdpk</span><span class="p">[</span><span class="mi">4</span><span class="o">*</span><span class="nb">id</span><span class="o">+</span><span class="n">ip</span><span class="p">]</span>
    15541556    <span class="n">cw</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    15551557    <span class="n">cw</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cw</span><span class="p">,</span><span class="n">cw</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
     
    15751577        <span class="n">pfx</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%d</span><span class="s">::&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">pId</span><span class="p">)</span>
    15761578        <span class="n">phfx</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%d</span><span class="s">:</span><span class="si">%d</span><span class="s">:&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">pId</span><span class="p">,</span><span class="n">hId</span><span class="p">)</span>
    1577         <span class="n">A</span> <span class="o">=</span> <span class="p">[</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;A</span><span class="si">%d</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
     1579        <span class="n">A</span> <span class="o">=</span> <span class="p">[</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;A</span><span class="si">%d</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>     <span class="c">#And modify here by Dij?</span>
    15781580        <span class="n">G</span><span class="p">,</span><span class="n">g</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">A2Gmat</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>       <span class="c">#recip &amp; real metric tensors</span>
    15791581        <span class="n">GA</span><span class="p">,</span><span class="n">GB</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">Gmat2AB</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>    <span class="c">#Orthogonalization matricies</span>
     
    15811583            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    15821584            <span class="n">dFdvDict</span> <span class="o">=</span> <span class="n">StructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    1583             <span class="k">print</span> <span class="s">&#39;sf-derv time </span><span class="si">%.3f</span><span class="s">s&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
     1585<span class="c">#            print &#39;sf-derv time %.3fs&#39;%(time.time()-time0)</span>
    15841586            <span class="n">ApplyRBModelDervs</span><span class="p">(</span><span class="n">dFdvDict</span><span class="p">,</span><span class="n">parmDict</span><span class="p">,</span><span class="n">rigidbodyDict</span><span class="p">,</span><span class="n">Phase</span><span class="p">)</span>
    15851587        <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
     
    17521754                        <span class="k">if</span> <span class="n">Ka2</span><span class="p">:</span>
    17531755                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">corr2</span>
    1754         <span class="k">print</span> <span class="s">&#39;profile derv time: </span><span class="si">%.3f</span><span class="s">s&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
     1756<span class="c">#        print &#39;profile derv time: %.3fs&#39;%(time.time()-time0)</span>
    17551757    <span class="c"># now process derivatives in constraints</span>
    17561758    <span class="n">G2mv</span><span class="o">.</span><span class="n">Dict2Deriv</span><span class="p">(</span><span class="n">varylist</span><span class="p">,</span><span class="n">depDerivDict</span><span class="p">,</span><span class="n">dMdv</span><span class="p">)</span>
Note: See TracChangeset for help on using the changeset viewer.