Index: _modules/sas/invariant/invariant.html
===================================================================
--- _modules/sas/invariant/invariant.html	(revision a462c6a6616628a6536b55fc2886d9ab1224149a)
+++ _modules/sas/invariant/invariant.html	(revision a462c6a6616628a6536b55fc2886d9ab1224149a)
@@ -0,0 +1,1056 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>sas.invariant.invariant &mdash; SasView 3.0.0 documentation</title>
+    
+    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../',
+        VERSION:     '3.0.0',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+    <link rel="top" title="SasView 3.0.0 documentation" href="../../../index.html" />
+    <link rel="up" title="Module code" href="../../index.html" /> 
+  </head>
+  <body>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../../../index.html">SasView 3.0.0 documentation</a> &raquo;</li>
+          <li><a href="../../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>  
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body">
+            
+  <h1>Source code for sas.invariant.invariant</h1><div class="highlight"><pre>
+<span class="c">#####################################################################</span>
+<span class="c">#This software was developed by the University of Tennessee as part of the</span>
+<span class="c">#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)</span>
+<span class="c">#project funded by the US National Science Foundation. </span>
+<span class="c">#See the license text in license.txt</span>
+<span class="c">#copyright 2010, University of Tennessee</span>
+<span class="c">######################################################################</span>
+
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">This module implements invariant and its related computations.</span>
+
+<span class="sd">:author: Gervaise B. Alina/UTK</span>
+<span class="sd">:author: Mathieu Doucet/UTK</span>
+<span class="sd">:author: Jae Cho/UTK</span>
+
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="kn">import</span> <span class="nn">math</span> 
+<span class="kn">import</span> <span class="nn">numpy</span>
+
+<span class="kn">from</span> <span class="nn">sas.dataloader.data_info</span> <span class="kn">import</span> <span class="n">Data1D</span> <span class="k">as</span> <span class="n">LoaderData1D</span>
+
+<span class="c"># The minimum q-value to be used when extrapolating</span>
+<span class="n">Q_MINIMUM</span>  <span class="o">=</span> <span class="mf">1e-5</span>
+
+<span class="c"># The maximum q-value to be used when extrapolating</span>
+<span class="n">Q_MAXIMUM</span>  <span class="o">=</span> <span class="mi">10</span>
+
+<span class="c"># Number of steps in the extrapolation</span>
+<span class="n">INTEGRATION_NSTEPS</span> <span class="o">=</span> <span class="mi">1000</span>
+
+<div class="viewcode-block" id="Transform"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform">[docs]</a><span class="k">class</span> <span class="nc">Transform</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Define interface that need to compute a function or an inverse</span>
+<span class="sd">    function given some x, y </span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    
+<div class="viewcode-block" id="Transform.linearize_data"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.linearize_data">[docs]</a>    <span class="k">def</span> <span class="nf">linearize_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Linearize data so that a linear fit can be performed. </span>
+<span class="sd">        Filter out the data that can&#39;t be transformed.</span>
+<span class="sd">        </span>
+<span class="sd">        :param data: LoadData1D instance</span>
+<span class="sd">        </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Check that the vector lengths are equal</span>
+        <span class="k">assert</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span><span class="o">==</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+        <span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="k">assert</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span><span class="o">==</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="p">))</span>
+            <span class="n">dy</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">dy</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">dy</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+            
+        <span class="c"># Transform the data</span>
+        <span class="n">data_points</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">dy</span><span class="p">)</span>
+
+        <span class="n">output_points</span> <span class="o">=</span> <span class="p">[(</span><span class="bp">self</span><span class="o">.</span><span class="n">linearize_q_value</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
+                          <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
+                          <span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">/</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">data_points</span> <span class="k">if</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span> <span class="ow">and</span> \
+                          <span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span> <span class="ow">and</span> <span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">]</span>
+        
+        <span class="n">x_out</span><span class="p">,</span> <span class="n">y_out</span><span class="p">,</span> <span class="n">dy_out</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">output_points</span><span class="p">)</span>
+       
+        <span class="c"># Create Data1D object</span>
+        <span class="n">x_out</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">x_out</span><span class="p">)</span>
+        <span class="n">y_out</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">y_out</span><span class="p">)</span>
+        <span class="n">dy_out</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">dy_out</span><span class="p">)</span>
+        <span class="n">linear_data</span> <span class="o">=</span> <span class="n">LoaderData1D</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x_out</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y_out</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="n">dy_out</span><span class="p">)</span>
+        
+        <span class="k">return</span> <span class="n">linear_data</span>
+    </div>
+<div class="viewcode-block" id="Transform.get_allowed_bins"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.get_allowed_bins">[docs]</a>    <span class="k">def</span> <span class="nf">get_allowed_bins</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Goes through the data points and returns a list of boolean values</span>
+<span class="sd">        to indicate whether each points is allowed by the model or not.</span>
+<span class="sd">        </span>
+<span class="sd">        :param data: Data1D object</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="p">[</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span> <span class="ow">and</span> <span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span> <span class="ow">and</span> <span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
+                                                           <span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="p">)]</span>
+        </div>
+<div class="viewcode-block" id="Transform.linearize_q_value"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.linearize_q_value">[docs]</a>    <span class="k">def</span> <span class="nf">linearize_q_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Transform the input q-value for linearization</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">NotImplemented</span>
+</div>
+<div class="viewcode-block" id="Transform.extract_model_parameters"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.extract_model_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">extract_model_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constant</span><span class="p">,</span> <span class="n">slope</span><span class="p">,</span> <span class="n">dconstant</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dslope</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        set private member</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">NotImplemented</span>
+     </div>
+<div class="viewcode-block" id="Transform.evaluate_model"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.evaluate_model">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns an array f(x) values where f is the Transform function.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">NotImplemented</span>
+    </div>
+<div class="viewcode-block" id="Transform.evaluate_model_errors"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Transform.evaluate_model_errors">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model_errors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns an array of I(q) errors</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">NotImplemented</span>
+    </div></div>
+<div class="viewcode-block" id="Guinier"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Guinier">[docs]</a><span class="k">class</span> <span class="nc">Guinier</span><span class="p">(</span><span class="n">Transform</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    class of type Transform that performs operations related to guinier </span>
+<span class="sd">    function</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">radius</span><span class="o">=</span><span class="mi">60</span><span class="p">):</span>
+        <span class="n">Transform</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">=</span> <span class="n">scale</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">=</span> <span class="n">radius</span>
+        <span class="c">## Uncertainty of scale parameter</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dscale</span>  <span class="o">=</span> <span class="mi">0</span>
+        <span class="c">## Unvertainty of radius parameter</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dradius</span> <span class="o">=</span> <span class="mi">0</span>
+        
+<div class="viewcode-block" id="Guinier.linearize_q_value"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Guinier.linearize_q_value">[docs]</a>    <span class="k">def</span> <span class="nf">linearize_q_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Transform the input q-value for linearization</span>
+<span class="sd">        </span>
+<span class="sd">        :param value: q-value</span>
+<span class="sd">        </span>
+<span class="sd">        :return: q*q</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="n">value</span> <span class="o">*</span> <span class="n">value</span>
+    </div>
+<div class="viewcode-block" id="Guinier.extract_model_parameters"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Guinier.extract_model_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">extract_model_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constant</span><span class="p">,</span> <span class="n">slope</span><span class="p">,</span> <span class="n">dconstant</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dslope</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">	    assign new value to the scale and the radius</span>
+<span class="sd">    	&quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">constant</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">slope</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">slope</span> <span class="o">=</span> <span class="mf">0.0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span> <span class="o">*</span> <span class="n">slope</span><span class="p">)</span>
+        <span class="c"># Errors</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dscale</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">constant</span><span class="p">)</span><span class="o">*</span><span class="n">dconstant</span>
+        <span class="k">if</span> <span class="n">slope</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
+            <span class="n">n_zero</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.0e-24</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">dradius</span> <span class="o">=</span> <span class="o">-</span><span class="mf">3.0</span><span class="o">/</span><span class="mf">2.0</span><span class="o">/</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span> <span class="o">*</span> <span class="n">n_zero</span><span class="p">)</span><span class="o">*</span><span class="n">dslope</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">dradius</span> <span class="o">=</span> <span class="o">-</span><span class="mf">3.0</span><span class="o">/</span><span class="mf">2.0</span><span class="o">/</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span> <span class="o">*</span> <span class="n">slope</span><span class="p">)</span><span class="o">*</span><span class="n">dslope</span>
+        
+        <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span><span class="p">],</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">dradius</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dscale</span><span class="p">]</span>
+        </div>
+<div class="viewcode-block" id="Guinier.evaluate_model"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Guinier.evaluate_model">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        return F(x)= scale* e-((radius*x)**2/3)</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_guinier</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
+             </div>
+<div class="viewcode-block" id="Guinier.evaluate_model_errors"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Guinier.evaluate_model_errors">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model_errors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns the error on I(q) for the given array of q-values</span>
+<span class="sd">        </span>
+<span class="sd">        :param x: array of q-values</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">p1</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">dscale</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">*</span> <span class="n">q</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span> \
+                          <span class="k">for</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">x</span><span class="p">])</span>
+        <span class="n">p2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">*</span> <span class="n">q</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span>\
+                     <span class="o">*</span> <span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">q</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">dradius</span> <span class="k">for</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">x</span><span class="p">])</span>
+        <span class="n">diq2</span> <span class="o">=</span> <span class="n">p1</span><span class="o">*</span><span class="n">p1</span> <span class="o">+</span> <span class="n">p2</span><span class="o">*</span><span class="n">p2</span>        
+        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span> <span class="p">[</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="k">for</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">diq2</span><span class="p">]</span> <span class="p">)</span>
+             </div>
+    <span class="k">def</span> <span class="nf">_guinier</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Retrieve the guinier function after apply an inverse guinier function</span>
+<span class="sd">        to x</span>
+<span class="sd">        Compute a F(x) = scale* e-((radius*x)**2/3).</span>
+<span class="sd">        </span>
+<span class="sd">        :param x: a vector of q values </span>
+<span class="sd">        :param scale: the scale value</span>
+<span class="sd">        :param radius: the guinier radius value</span>
+<span class="sd">        </span>
+<span class="sd">        :return: F(x)</span>
+<span class="sd">        &quot;&quot;&quot;</span>   
+        <span class="c"># transform the radius of coming from the inverse guinier function to a </span>
+        <span class="c"># a radius of a guinier function</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Rg expected positive value, but got </span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>  
+        <span class="n">value</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">*</span> <span class="n">i</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="mi">3</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span> <span class="p">])</span> 
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span> <span class="n">value</span>
+</div>
+<div class="viewcode-block" id="PowerLaw"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.PowerLaw">[docs]</a><span class="k">class</span> <span class="nc">PowerLaw</span><span class="p">(</span><span class="n">Transform</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    class of type transform that perform operation related to power_law </span>
+<span class="sd">    function</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">power</span><span class="o">=</span><span class="mi">4</span><span class="p">):</span>
+        <span class="n">Transform</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">=</span> <span class="n">scale</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">power</span> <span class="o">=</span> <span class="n">power</span>
+   
+<div class="viewcode-block" id="PowerLaw.linearize_q_value"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.PowerLaw.linearize_q_value">[docs]</a>    <span class="k">def</span> <span class="nf">linearize_q_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Transform the input q-value for linearization</span>
+<span class="sd">        </span>
+<span class="sd">        :param value: q-value</span>
+<span class="sd">        </span>
+<span class="sd">        :return: log(q)</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
+    </div>
+<div class="viewcode-block" id="PowerLaw.extract_model_parameters"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.PowerLaw.extract_model_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">extract_model_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constant</span><span class="p">,</span> <span class="n">slope</span><span class="p">,</span> <span class="n">dconstant</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dslope</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Assign new value to the scale and the power </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">power</span> <span class="o">=</span> <span class="o">-</span><span class="n">slope</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">constant</span><span class="p">)</span>
+        
+        <span class="c"># Errors</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dscale</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">constant</span><span class="p">)</span><span class="o">*</span><span class="n">dconstant</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dpower</span> <span class="o">=</span> <span class="o">-</span><span class="n">dslope</span>
+        
+        <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">power</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span><span class="p">],</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">dpower</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dscale</span><span class="p">]</span>
+        </div>
+<div class="viewcode-block" id="PowerLaw.evaluate_model"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.PowerLaw.evaluate_model">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        given a scale and a radius transform x, y using a power_law</span>
+<span class="sd">        function</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_power_law</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
+    </div>
+<div class="viewcode-block" id="PowerLaw.evaluate_model_errors"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.PowerLaw.evaluate_model_errors">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_model_errors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns the error on I(q) for the given array of q-values</span>
+<span class="sd">        :param x: array of q-values</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">p1</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">dscale</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pow</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">power</span><span class="p">)</span> <span class="k">for</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">x</span><span class="p">])</span>
+        <span class="n">p2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">power</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pow</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">power</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>\
+                           <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">dpower</span> <span class="k">for</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">x</span><span class="p">])</span>
+        <span class="n">diq2</span> <span class="o">=</span> <span class="n">p1</span><span class="o">*</span><span class="n">p1</span> <span class="o">+</span> <span class="n">p2</span><span class="o">*</span><span class="n">p2</span>        
+        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span> <span class="p">[</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="k">for</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">diq2</span><span class="p">]</span> <span class="p">)</span>
+       </div>
+    <span class="k">def</span> <span class="nf">_power_law</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        F(x) = scale* (x)^(-power)</span>
+<span class="sd">            when power= 4. the model is porod </span>
+<span class="sd">            else power_law</span>
+<span class="sd">        The model has three parameters: ::</span>
+<span class="sd">            1. x: a vector of q values</span>
+<span class="sd">            2. power: power of the function</span>
+<span class="sd">            3. scale : scale factor value</span>
+<span class="sd">        </span>
+<span class="sd">        :param x: array</span>
+<span class="sd">        :return: F(x)</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">power</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Power_law function expected positive power,&quot;</span>
+            <span class="n">msg</span> <span class="o">+=</span> <span class="s">&quot; but got </span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="bp">self</span><span class="o">.</span><span class="n">power</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;scale expected positive value, but got </span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="bp">self</span><span class="o">.</span><span class="n">scale</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> 
+       
+        <span class="n">value</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span> <span class="n">math</span><span class="o">.</span><span class="n">pow</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">power</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span> <span class="p">])</span>  
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span> <span class="n">value</span>
+</div>
+<div class="viewcode-block" id="Extrapolator"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Extrapolator">[docs]</a><span class="k">class</span> <span class="nc">Extrapolator</span><span class="p">:</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Extrapolate I(q) distribution using a given model</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Determine a and b given a linear equation y = ax + b</span>
+<span class="sd">        </span>
+<span class="sd">        If a model is given, it will be used to linearize the data before </span>
+<span class="sd">        the extrapolation is performed. If None,</span>
+<span class="sd">        a simple linear fit will be done.</span>
+<span class="sd">        </span>
+<span class="sd">        :param data: data containing x and y  such as  y = ax + b </span>
+<span class="sd">        :param model: optional Transform object </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data</span>  <span class="o">=</span> <span class="n">data</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">model</span>
+       
+        <span class="c"># Set qmin as the lowest non-zero value</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">qmin</span> <span class="o">=</span> <span class="n">Q_MINIMUM</span>
+        <span class="k">for</span> <span class="n">q_value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">q_value</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span> 
+                <span class="bp">self</span><span class="o">.</span><span class="n">qmin</span> <span class="o">=</span> <span class="n">q_value</span>
+                <span class="k">break</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">qmax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
+             
+<div class="viewcode-block" id="Extrapolator.fit"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.Extrapolator.fit">[docs]</a>    <span class="k">def</span> <span class="nf">fit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">power</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">qmin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">qmax</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Fit data for y = ax + b  return a and b</span>
+<span class="sd">       </span>
+<span class="sd">        :param power: a fixed, otherwise None</span>
+<span class="sd">        :param qmin: Minimum Q-value</span>
+<span class="sd">        :param qmax: Maximum Q-value</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="n">qmin</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">qmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">qmin</span>
+        <span class="k">if</span> <span class="n">qmax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">qmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">qmax</span>
+            
+        <span class="c"># Identify the bin range for the fit</span>
+        <span class="n">idx</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span> <span class="o">&gt;=</span> <span class="n">qmin</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span> <span class="o">&lt;=</span> <span class="n">qmax</span><span class="p">)</span>
+        
+        <span class="n">fx</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">))</span>
+
+        <span class="c"># Uncertainty</span>
+        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span><span class="o">==</span><span class="n">numpy</span><span class="o">.</span><span class="n">ndarray</span> <span class="ow">and</span> \
+            <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span><span class="o">==</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="ow">and</span> \
+            <span class="n">numpy</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">):</span>
+            <span class="n">sigma</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">sigma</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">))</span>
+
+        <span class="c"># Compute theory data f(x)</span>
+        <span class="n">fx</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
+        
+        <span class="c"># Linearize the data</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">linearized_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">linearize_data</span><span class="p">(</span>\
+                                            <span class="n">LoaderData1D</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span>
+                                                                <span class="n">fx</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span>
+                                                            <span class="n">dy</span> <span class="o">=</span> <span class="n">sigma</span><span class="p">[</span><span class="n">idx</span><span class="p">]))</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">linearized_data</span> <span class="o">=</span> <span class="n">LoaderData1D</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span>
+                                           <span class="n">fx</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span>
+                                           <span class="n">dy</span> <span class="o">=</span> <span class="n">sigma</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>
+        
+        <span class="c">##power is given only for function = power_law    </span>
+        <span class="k">if</span> <span class="n">power</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">sigma2</span> <span class="o">=</span> <span class="n">linearized_data</span><span class="o">.</span><span class="n">dy</span> <span class="o">*</span> <span class="n">linearized_data</span><span class="o">.</span><span class="n">dy</span>
+            <span class="n">a</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="n">power</span><span class="p">)</span>
+            <span class="n">b</span> <span class="o">=</span> <span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">y</span><span class="o">/</span><span class="n">sigma2</span><span class="p">)</span> \
+                 <span class="o">-</span> <span class="n">a</span><span class="o">*</span><span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">x</span><span class="o">/</span><span class="n">sigma2</span><span class="p">))</span><span class="o">/</span><span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">sigma2</span><span class="p">)</span>
+            
+            
+            <span class="n">deltas</span> <span class="o">=</span> <span class="n">linearized_data</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">a</span> <span class="o">+</span> \
+                    <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">x</span><span class="p">))</span><span class="o">*</span><span class="n">b</span><span class="o">-</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">y</span>
+            <span class="n">residuals</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">deltas</span><span class="o">*</span><span class="n">deltas</span><span class="o">/</span><span class="n">sigma2</span><span class="p">)</span>
+
+            <span class="n">err</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">residuals</span><span class="p">)</span> <span class="o">/</span> <span class="n">numpy</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">sigma2</span><span class="p">)</span>
+            <span class="k">return</span> <span class="p">[</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">err</span><span class="p">)]</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">A</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">vstack</span><span class="p">([</span> <span class="n">linearized_data</span><span class="o">.</span><span class="n">x</span><span class="o">/</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">dy</span><span class="p">,</span>
+                               <span class="mf">1.0</span><span class="o">/</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">dy</span><span class="p">])</span><span class="o">.</span><span class="n">T</span>        
+            <span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">residuals</span><span class="p">,</span> <span class="n">rank</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">lstsq</span><span class="p">(</span><span class="n">A</span><span class="p">,</span>
+                                        <span class="n">linearized_data</span><span class="o">.</span><span class="n">y</span><span class="o">/</span><span class="n">linearized_data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span>
+            
+            <span class="c"># Get the covariance matrix, defined as inv_cov = a_transposed * a</span>
+            <span class="n">err</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">inv_cov</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">transpose</span><span class="p">(),</span> <span class="n">A</span><span class="p">)</span>
+                <span class="n">cov</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">pinv</span><span class="p">(</span><span class="n">inv_cov</span><span class="p">)</span>
+                <span class="n">err_matrix</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">residuals</span><span class="p">)</span> <span class="o">*</span> <span class="n">cov</span>
+                <span class="n">err</span> <span class="o">=</span> <span class="p">[</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">err_matrix</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]),</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">err_matrix</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])]</span>
+            <span class="k">except</span><span class="p">:</span>
+                <span class="n">err</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">1.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">]</span>
+                
+            <span class="k">return</span> <span class="n">p</span><span class="p">,</span> <span class="n">err</span>
+        
+</div></div>
+<div class="viewcode-block" id="InvariantCalculator"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator">[docs]</a><span class="k">class</span> <span class="nc">InvariantCalculator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Compute invariant if data is given.</span>
+<span class="sd">    Can provide volume fraction and surface area if the user provides</span>
+<span class="sd">    Porod constant  and contrast values.</span>
+<span class="sd">    </span>
+<span class="sd">    :precondition:  the user must send a data of type DataLoader.Data1D</span>
+<span class="sd">                    the user provide background and scale values.</span>
+<span class="sd">                    </span>
+<span class="sd">    :note: Some computations depends on each others. </span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">background</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mi">1</span> <span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Initialize variables.</span>
+<span class="sd">        </span>
+<span class="sd">        :param data: data must be of type DataLoader.Data1D</span>
+<span class="sd">        :param background: Background value. The data will be corrected </span>
+<span class="sd">            before processing</span>
+<span class="sd">        :param scale: Scaling factor for I(q). The data will be corrected</span>
+<span class="sd">            before processing</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Background and scale should be private data member if the only way to</span>
+        <span class="c"># change them are by instantiating a new object.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_background</span> <span class="o">=</span> <span class="n">background</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_scale</span> <span class="o">=</span> <span class="n">scale</span>
+        <span class="c"># slit height for smeared data</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="c"># The data should be private</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+        <span class="c"># get the dxl if the data is smeared: This is done only once on init.</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">dxl</span> <span class="o">!=</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">dxl</span><span class="o">.</span><span class="n">all</span><span class="p">()</span> <span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
+            <span class="c"># assumes constant dxl</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">dxl</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+      
+        <span class="c"># Since there are multiple variants of Q*, you should force the</span>
+        <span class="c"># user to use the get method and keep Q* a private data member</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span> <span class="o">=</span> <span class="bp">None</span>
+        
+        <span class="c"># You should keep the error on Q* so you can reuse it without</span>
+        <span class="c"># recomputing the whole thing.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span> <span class="o">=</span> <span class="mi">0</span>
+        
+        <span class="c"># Extrapolation parameters</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_npts</span> <span class="o">=</span> <span class="mi">4</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span> <span class="o">=</span> <span class="n">Guinier</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power_fitted</span> <span class="o">=</span> <span class="bp">None</span>
+   
+        <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_npts</span> <span class="o">=</span> <span class="mi">4</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_function</span> <span class="o">=</span> <span class="n">PowerLaw</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power_fitted</span> <span class="o">=</span> <span class="bp">None</span>
+        
+        <span class="c"># Extrapolation range</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span> <span class="o">=</span> <span class="n">Q_MINIMUM</span>
+        
+    <span class="k">def</span> <span class="nf">_get_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        :note: this function must be call before computing any type</span>
+<span class="sd">         of invariant</span>
+<span class="sd">         </span>
+<span class="sd">        :return: new data = self._scale *data - self._background</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="n">LoaderData1D</span><span class="p">):</span>
+            <span class="c">#Process only data that inherited from DataLoader.Data_info.Data1D</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span><span class="s">&quot;Data must be of type DataLoader.Data1D&quot;</span>
+        <span class="c">#from copy import deepcopy</span>
+        <span class="n">new_data</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_scale</span> <span class="o">*</span> <span class="n">data</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">_background</span>   
+        
+        <span class="c"># Check that the vector lengths are equal</span>
+        <span class="k">assert</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span><span class="o">==</span><span class="nb">len</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+        
+        <span class="c"># Verify that the errors are set correctly</span>
+        <span class="k">if</span> <span class="n">new_data</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span> <span class="ow">or</span> \
+            <span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span> <span class="ow">and</span> <span class="nb">max</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">):</span>
+            <span class="n">new_data</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">new_data</span><span class="o">.</span><span class="n">x</span><span class="p">))</span>  
+        <span class="k">return</span>  <span class="n">new_data</span>
+     
+    <span class="k">def</span> <span class="nf">_fit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">qmin</span><span class="o">=</span><span class="n">Q_MINIMUM</span><span class="p">,</span> <span class="n">qmax</span><span class="o">=</span><span class="n">Q_MAXIMUM</span><span class="p">,</span> <span class="n">power</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        fit data with function using </span>
+<span class="sd">        data = self._get_data()</span>
+<span class="sd">        fx = Functor(data , function)</span>
+<span class="sd">        y = data.y</span>
+<span class="sd">        slope, constant = linalg.lstsq(y,fx)</span>
+<span class="sd">        </span>
+<span class="sd">        :param qmin: data first q value to consider during the fit</span>
+<span class="sd">        :param qmax: data last q value to consider during the fit</span>
+<span class="sd">        :param power : power value to consider for power-law </span>
+<span class="sd">        :param function: the function to use during the fit</span>
+<span class="sd">        </span>
+<span class="sd">        :return a: the scale of the function</span>
+<span class="sd">        :return b: the other parameter of the function for guinier will be radius</span>
+<span class="sd">                for power_law will be the power value</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">extrapolator</span> <span class="o">=</span> <span class="n">Extrapolator</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">)</span>
+        <span class="n">p</span><span class="p">,</span> <span class="n">dp</span> <span class="o">=</span> <span class="n">extrapolator</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">power</span><span class="o">=</span><span class="n">power</span><span class="p">,</span> <span class="n">qmin</span><span class="o">=</span><span class="n">qmin</span><span class="p">,</span> <span class="n">qmax</span><span class="o">=</span><span class="n">qmax</span><span class="p">)</span> 
+        
+        <span class="k">return</span> <span class="n">model</span><span class="o">.</span><span class="n">extract_model_parameters</span><span class="p">(</span><span class="n">constant</span><span class="o">=</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">slope</span><span class="o">=</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
+                                              <span class="n">dconstant</span><span class="o">=</span><span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dslope</span><span class="o">=</span><span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
+    
+    <span class="k">def</span> <span class="nf">_get_qstar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute invariant for pinhole data.</span>
+<span class="sd">        This invariant is given by: ::</span>
+<span class="sd">    </span>
+<span class="sd">            q_star = x0**2 *y0 *dx0 +x1**2 *y1 *dx1 </span>
+<span class="sd">                        + ..+ xn**2 *yn *dxn    for non smeared data</span>
+<span class="sd">                        </span>
+<span class="sd">            q_star = dxl0 *x0 *y0 *dx0 +dxl1 *x1 *y1 *dx1 </span>
+<span class="sd">                        + ..+ dlxn *xn *yn *dxn    for smeared data</span>
+<span class="sd">                        </span>
+<span class="sd">            where n &gt;= len(data.x)-1</span>
+<span class="sd">            dxl = slit height dQl</span>
+<span class="sd">            dxi = 1/2*(xi+1 - xi) + (xi - xi-1)</span>
+<span class="sd">            dx0 = (x1 - x0)/2</span>
+<span class="sd">            dxn = (xn - xn-1)/2</span>
+<span class="sd">            </span>
+<span class="sd">        :param data: the data to use to compute invariant.</span>
+<span class="sd">        </span>
+<span class="sd">        :return q_star: invariant value for pinhole data. q_star &gt; 0</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span><span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">):</span>
+            <span class="n">msg</span> <span class="o">=</span>  <span class="s">&quot;Length x and y must be equal&quot;</span>
+            <span class="n">msg</span> <span class="o">+=</span> <span class="s">&quot; and greater than 1; got x=</span><span class="si">%s</span><span class="s">, y=</span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">),</span>
+                                                          <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">msg</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="c"># Take care of smeared data</span>
+            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+                <span class="n">gx</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span>
+            <span class="c"># assumes that len(x) == len(dxl).</span>
+            <span class="k">else</span><span class="p">:</span>               
+                <span class="n">gx</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">dxl</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span> 
+                
+            <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span><span class="o">-</span> <span class="mi">1</span>
+            <span class="c">#compute the first delta q</span>
+            <span class="n">dx0</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+            <span class="c">#compute the last delta q</span>
+            <span class="n">dxn</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+            <span class="nb">sum</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="nb">sum</span> <span class="o">+=</span> <span class="n">gx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">dx0</span>
+            <span class="nb">sum</span> <span class="o">+=</span> <span class="n">gx</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">dxn</span>
+            
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
+                <span class="k">return</span> <span class="nb">sum</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="c">#iterate between for element different</span>
+                <span class="c">#from the first and the last</span>
+                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
+                    <span class="n">dxi</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+                    <span class="nb">sum</span> <span class="o">+=</span> <span class="n">gx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">dxi</span>
+                <span class="k">return</span> <span class="nb">sum</span>
+            
+    <span class="k">def</span> <span class="nf">_get_qstar_uncertainty</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute invariant uncertainty with with pinhole data.</span>
+<span class="sd">        This uncertainty is given as follow: ::</span>
+<span class="sd">        </span>
+<span class="sd">           dq_star = math.sqrt[(x0**2*(dy0)*dx0)**2 +</span>
+<span class="sd">                (x1**2 *(dy1)*dx1)**2 + ..+ (xn**2 *(dyn)*dxn)**2 ]</span>
+<span class="sd">        where n &gt;= len(data.x)-1</span>
+<span class="sd">        dxi = 1/2*(xi+1 - xi) + (xi - xi-1)</span>
+<span class="sd">        dx0 = (x1 - x0)/2</span>
+<span class="sd">        dxn = (xn - xn-1)/2</span>
+<span class="sd">        dyn: error on dy</span>
+<span class="sd">       </span>
+<span class="sd">        :param data:</span>
+<span class="sd">        :note: if data doesn&#39;t contain dy assume dy= math.sqrt(data.y)</span>
+<span class="sd">        &quot;&quot;&quot;</span>          
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="ow">or</span> \
+            <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">)</span> <span class="ow">or</span> \
+            <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">dy</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">))):</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Length of data.x and data.y must be equal&quot;</span>
+            <span class="n">msg</span> <span class="o">+=</span> <span class="s">&quot; and greater than 1; got x=</span><span class="si">%s</span><span class="s">, y=</span><span class="si">%s</span><span class="s">&quot;</span><span class="o">%</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">),</span>
+                                                         <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">msg</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="c">#Create error for data without dy error</span>
+            <span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">dy</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+                <span class="n">dy</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">)</span> 
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">dy</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">dy</span>
+            <span class="c"># Take care of smeared data</span>
+            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+                <span class="n">gx</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span>
+            <span class="c"># assumes that len(x) == len(dxl).</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">gx</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">dxl</span> <span class="o">*</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span>
+  
+            <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
+            <span class="c">#compute the first delta</span>
+            <span class="n">dx0</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+            <span class="c">#compute the last delta</span>
+            <span class="n">dxn</span><span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+            <span class="nb">sum</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="nb">sum</span> <span class="o">+=</span> <span class="p">(</span><span class="n">gx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">dy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">dx0</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
+            <span class="nb">sum</span> <span class="o">+=</span> <span class="p">(</span><span class="n">gx</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">dy</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">dxn</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
+                <span class="k">return</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="c">#iterate between for element different</span>
+                <span class="c">#from the first and the last</span>
+                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
+                    <span class="n">dxi</span> <span class="o">=</span> <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mi">2</span>
+                    <span class="nb">sum</span> <span class="o">+=</span> <span class="p">(</span><span class="n">gx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">dxi</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
+                <span class="k">return</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">)</span>
+        
+    <span class="k">def</span> <span class="nf">_get_extrapolated_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">npts</span><span class="o">=</span><span class="n">INTEGRATION_NSTEPS</span><span class="p">,</span>
+                              <span class="n">q_start</span><span class="o">=</span><span class="n">Q_MINIMUM</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">Q_MAXIMUM</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        :return: extrapolate data create from data</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c">#create new Data1D to compute the invariant</span>
+        <span class="n">q</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">start</span><span class="o">=</span><span class="n">q_start</span><span class="p">,</span>
+                           <span class="n">stop</span><span class="o">=</span><span class="n">q_end</span><span class="p">,</span>
+                           <span class="n">num</span><span class="o">=</span><span class="n">npts</span><span class="p">,</span>
+                           <span class="n">endpoint</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
+        <span class="n">iq</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">evaluate_model</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
+        <span class="n">diq</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">evaluate_model_errors</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
+         
+        <span class="n">result_data</span> <span class="o">=</span> <span class="n">LoaderData1D</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">q</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">iq</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="n">diq</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">result_data</span><span class="o">.</span><span class="n">dxl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_smeared</span> <span class="o">*</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">q</span><span class="p">))</span>
+        <span class="k">return</span> <span class="n">result_data</span>
+    
+<div class="viewcode-block" id="InvariantCalculator.get_data"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        :return: self._data</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_extrapolation_power"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_extrapolation_power">[docs]</a>    <span class="k">def</span> <span class="nf">get_extrapolation_power</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">range</span><span class="o">=</span><span class="s">&#39;high&#39;</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        :return: the fitted power for power law function for a given</span>
+<span class="sd">            extrapolation range</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="nb">range</span> <span class="o">==</span> <span class="s">&#39;low&#39;</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power_fitted</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power_fitted</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_qstar_low"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_qstar_low">[docs]</a>    <span class="k">def</span> <span class="nf">get_qstar_low</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute the invariant for extrapolated data at low q range.</span>
+<span class="sd">        </span>
+<span class="sd">        Implementation:</span>
+<span class="sd">            data = self._get_extra_data_low()</span>
+<span class="sd">            return self._get_qstar()</span>
+<span class="sd">            </span>
+<span class="sd">        :return q_star: the invariant for data extrapolated at low q.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Data boundaries for fitting</span>
+        <span class="n">qmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="n">qmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_npts</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
+        
+        <span class="c"># Extrapolate the low-Q data</span>
+        <span class="n">p</span><span class="p">,</span> <span class="n">dp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fit</span><span class="p">(</span><span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span><span class="p">,</span>
+      		     	      <span class="n">qmin</span><span class="o">=</span><span class="n">qmin</span><span class="p">,</span>
+                       	  <span class="n">qmax</span><span class="o">=</span><span class="n">qmax</span><span class="p">,</span>
+                          <span class="n">power</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power_fitted</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+        
+        <span class="c"># Distribution starting point</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span> <span class="o">=</span> <span class="n">Q_MINIMUM</span>
+        <span class="k">if</span> <span class="n">Q_MINIMUM</span> <span class="o">&gt;=</span> <span class="n">qmin</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span> <span class="o">=</span> <span class="n">qmin</span><span class="o">/</span><span class="mi">10</span>
+        
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_extrapolated_data</span><span class="p">(</span>\
+                                    <span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span><span class="p">,</span>
+                                            <span class="n">npts</span><span class="o">=</span><span class="n">INTEGRATION_NSTEPS</span><span class="p">,</span>
+                                        <span class="n">q_start</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">qmin</span><span class="p">)</span>
+        
+        <span class="c"># Systematic error</span>
+        <span class="c"># If we have smearing, the shape of the I(q) distribution at low Q will</span>
+        <span class="c"># may not be a Guinier or simple power law. The following is </span>
+        <span class="c"># a conservative estimation for the systematic error.</span>
+        <span class="n">err</span> <span class="o">=</span> <span class="n">qmin</span><span class="o">*</span><span class="n">qmin</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">((</span><span class="n">qmin</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span><span class="p">)</span><span class="o">*</span>\
+                                  <span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">data</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">INTEGRATION_NSTEPS</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar_uncertainty</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><span class="o">+</span><span class="n">err</span>
+        </div>
+<div class="viewcode-block" id="InvariantCalculator.get_qstar_high"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_qstar_high">[docs]</a>    <span class="k">def</span> <span class="nf">get_qstar_high</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute the invariant for extrapolated data at high q range.</span>
+<span class="sd">        </span>
+<span class="sd">        Implementation:</span>
+<span class="sd">            data = self._get_extra_data_high()</span>
+<span class="sd">            return self._get_qstar()</span>
+<span class="sd">            </span>
+<span class="sd">        :return q_star: the invariant for data extrapolated at high q.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Data boundaries for fitting</span>
+        <span class="n">x_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
+        <span class="n">qmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">x_len</span> <span class="o">-</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_npts</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)]</span>
+        <span class="n">qmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">x_len</span><span class="p">]</span>
+        
+        <span class="c"># fit the data with a model to get the appropriate parameters</span>
+        <span class="n">p</span><span class="p">,</span> <span class="n">dp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fit</span><span class="p">(</span><span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_function</span><span class="p">,</span>
+                          <span class="n">qmin</span><span class="o">=</span><span class="n">qmin</span><span class="p">,</span>
+                          <span class="n">qmax</span><span class="o">=</span><span class="n">qmax</span><span class="p">,</span>
+                          <span class="n">power</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power_fitted</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+        
+        <span class="c">#create new Data1D to compute the invariant</span>
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_extrapolated_data</span><span class="p">(</span>\
+                                    <span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_function</span><span class="p">,</span>
+                                           <span class="n">npts</span><span class="o">=</span><span class="n">INTEGRATION_NSTEPS</span><span class="p">,</span>
+                                           <span class="n">q_start</span><span class="o">=</span><span class="n">qmax</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">Q_MAXIMUM</span><span class="p">)</span>        
+        
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar_uncertainty</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_extra_data_low"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_extra_data_low">[docs]</a>    <span class="k">def</span> <span class="nf">get_extra_data_low</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">npts_in</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">q_start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">npts</span><span class="o">=</span><span class="mi">20</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns the extrapolated data used for the loew-Q invariant calculation.</span>
+<span class="sd">        By default, the distribution will cover the data points used for the </span>
+<span class="sd">        extrapolation. The number of overlap points is a parameter (npts_in).</span>
+<span class="sd">        By default, the maximum q-value of the distribution will be  </span>
+<span class="sd">        the minimum q-value used when extrapolating for the purpose of the </span>
+<span class="sd">        invariant calculation. </span>
+<span class="sd">        </span>
+<span class="sd">        :param npts_in: number of data points for which</span>
+<span class="sd">            the extrapolated data overlap</span>
+<span class="sd">        :param q_start: is the minimum value to uses for extrapolated data</span>
+<span class="sd">        :param npts: the number of points in the extrapolated distribution</span>
+<span class="sd">           </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Get extrapolation range</span>
+        <span class="k">if</span> <span class="n">q_start</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">q_start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_low_q_limit</span>
+            
+        <span class="k">if</span> <span class="n">npts_in</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">npts_in</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_npts</span>
+        <span class="n">q_end</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">npts_in</span><span class="o">-</span><span class="mi">1</span><span class="p">)]</span>
+        
+        <span class="k">if</span> <span class="n">q_start</span> <span class="o">&gt;=</span> <span class="n">q_end</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_extrapolated_data</span><span class="p">(</span>\
+                                    <span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span><span class="p">,</span>
+                                           <span class="n">npts</span><span class="o">=</span><span class="n">npts</span><span class="p">,</span>
+                                           <span class="n">q_start</span><span class="o">=</span><span class="n">q_start</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">q_end</span><span class="p">)</span>
+          </div>
+<div class="viewcode-block" id="InvariantCalculator.get_extra_data_high"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_extra_data_high">[docs]</a>    <span class="k">def</span> <span class="nf">get_extra_data_high</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">npts_in</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">Q_MAXIMUM</span><span class="p">,</span> <span class="n">npts</span><span class="o">=</span><span class="mi">20</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Returns the extrapolated data used for the high-Q invariant calculation.</span>
+<span class="sd">        By default, the distribution will cover the data points used for the </span>
+<span class="sd">        extrapolation. The number of overlap points is a parameter (npts_in).</span>
+<span class="sd">        By default, the maximum q-value of the distribution will be Q_MAXIMUM, </span>
+<span class="sd">        the maximum q-value used when extrapolating for the purpose of the </span>
+<span class="sd">        invariant calculation. </span>
+<span class="sd">        </span>
+<span class="sd">        :param npts_in: number of data points for which the</span>
+<span class="sd">            extrapolated data overlap</span>
+<span class="sd">        :param q_end: is the maximum value to uses for extrapolated data</span>
+<span class="sd">        :param npts: the number of points in the extrapolated distribution</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Get extrapolation range</span>
+        <span class="k">if</span> <span class="n">npts_in</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">npts_in</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_npts</span>
+        <span class="n">_npts</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
+        <span class="n">q_start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="nb">min</span><span class="p">(</span><span class="n">_npts</span><span class="p">,</span> <span class="n">_npts</span><span class="o">-</span><span class="n">npts_in</span><span class="p">)]</span>
+        
+        <span class="k">if</span> <span class="n">q_start</span> <span class="o">&gt;=</span> <span class="n">q_end</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">numpy</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+        
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_extrapolated_data</span><span class="p">(</span>\
+                                <span class="n">model</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_function</span><span class="p">,</span>
+                                           <span class="n">npts</span><span class="o">=</span><span class="n">npts</span><span class="p">,</span>
+                                           <span class="n">q_start</span><span class="o">=</span><span class="n">q_start</span><span class="p">,</span> <span class="n">q_end</span><span class="o">=</span><span class="n">q_end</span><span class="p">)</span>
+     </div>
+<div class="viewcode-block" id="InvariantCalculator.set_extrapolation"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.set_extrapolation">[docs]</a>    <span class="k">def</span> <span class="nf">set_extrapolation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">range</span><span class="p">,</span> <span class="n">npts</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">function</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">power</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Set the extrapolation parameters for the high or low Q-range.</span>
+<span class="sd">        Note that this does not turn extrapolation on or off.</span>
+<span class="sd">        </span>
+<span class="sd">        :param range: a keyword set the type of extrapolation . type string</span>
+<span class="sd">        :param npts: the numbers of q points of data to consider</span>
+<span class="sd">            for extrapolation</span>
+<span class="sd">        :param function: a keyword to select the function to use</span>
+<span class="sd">            for extrapolation.</span>
+<span class="sd">            of type string.</span>
+<span class="sd">        :param power: an power to apply power_low function</span>
+<span class="sd">                </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">range</span> <span class="o">=</span> <span class="nb">range</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+        <span class="k">if</span> <span class="nb">range</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;high&#39;</span><span class="p">,</span> <span class="s">&#39;low&#39;</span><span class="p">]:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="s">&quot;Extrapolation range should be &#39;high&#39; or &#39;low&#39;&quot;</span>
+        <span class="n">function</span> <span class="o">=</span> <span class="n">function</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+        <span class="k">if</span> <span class="n">function</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;power_law&#39;</span><span class="p">,</span> <span class="s">&#39;guinier&#39;</span><span class="p">]:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Extrapolation function should be &#39;guinier&#39; or &#39;power_law&#39;&quot;</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">msg</span>
+        
+        <span class="k">if</span> <span class="nb">range</span> <span class="o">==</span> <span class="s">&#39;high&#39;</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">function</span> <span class="o">!=</span> <span class="s">&#39;power_law&#39;</span><span class="p">:</span>
+                <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Extrapolation only allows a power law at high Q&quot;</span>
+                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">msg</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_npts</span>  <span class="o">=</span> <span class="n">npts</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power</span> <span class="o">=</span> <span class="n">power</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_high_extrapolation_power_fitted</span> <span class="o">=</span> <span class="n">power</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">function</span> <span class="o">==</span> <span class="s">&#39;power_law&#39;</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span> <span class="o">=</span> <span class="n">PowerLaw</span><span class="p">()</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_function</span> <span class="o">=</span> <span class="n">Guinier</span><span class="p">()</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_npts</span>  <span class="o">=</span> <span class="n">npts</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power</span> <span class="o">=</span> <span class="n">power</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_low_extrapolation_power_fitted</span> <span class="o">=</span> <span class="n">power</span>
+        </div>
+<div class="viewcode-block" id="InvariantCalculator.get_qstar"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_qstar">[docs]</a>    <span class="k">def</span> <span class="nf">get_qstar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute the invariant of the local copy of data.</span>
+<span class="sd">       </span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation </span>
+<span class="sd">           </span>
+<span class="sd">        :return q_star: invariant of the data within data&#39;s q range</span>
+<span class="sd">        </span>
+<span class="sd">        :warning: When using setting data to Data1D ,</span>
+<span class="sd">            the user is responsible of</span>
+<span class="sd">            checking that the scale and the background are</span>
+<span class="sd">            properly apply to the data</span>
+<span class="sd">        </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_qstar_uncertainty</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_data</span><span class="p">)</span>
+        
+        <span class="k">if</span> <span class="n">extrapolation</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>
+        
+        <span class="c"># Compute invariant plus invariant of extrapolated data</span>
+        <span class="n">extrapolation</span> <span class="o">=</span> <span class="n">extrapolation</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>    
+        <span class="k">if</span> <span class="n">extrapolation</span> <span class="o">==</span> <span class="s">&quot;low&quot;</span><span class="p">:</span>
+            <span class="n">qs_low</span><span class="p">,</span> <span class="n">dqs_low</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar_low</span><span class="p">()</span>
+            <span class="n">qs_hi</span><span class="p">,</span> <span class="n">dqs_hi</span>   <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
+            
+        <span class="k">elif</span> <span class="n">extrapolation</span> <span class="o">==</span> <span class="s">&quot;high&quot;</span><span class="p">:</span>
+            <span class="n">qs_low</span><span class="p">,</span> <span class="n">dqs_low</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
+            <span class="n">qs_hi</span><span class="p">,</span> <span class="n">dqs_hi</span>   <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar_high</span><span class="p">()</span>
+            
+        <span class="k">elif</span> <span class="n">extrapolation</span> <span class="o">==</span> <span class="s">&quot;both&quot;</span><span class="p">:</span>
+            <span class="n">qs_low</span><span class="p">,</span> <span class="n">dqs_low</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar_low</span><span class="p">()</span>
+            <span class="n">qs_hi</span><span class="p">,</span> <span class="n">dqs_hi</span>   <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar_high</span><span class="p">()</span>
+            
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>     <span class="o">+=</span> <span class="n">qs_low</span> <span class="o">+</span> <span class="n">qs_hi</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span> \
+                                    <span class="o">+</span> <span class="n">dqs_low</span><span class="o">*</span><span class="n">dqs_low</span> <span class="o">+</span> <span class="n">dqs_hi</span><span class="o">*</span><span class="n">dqs_hi</span><span class="p">)</span>
+        
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>
+       </div>
+<div class="viewcode-block" id="InvariantCalculator.get_surface"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_surface">[docs]</a>    <span class="k">def</span> <span class="nf">get_surface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">porod_const</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute the specific surface from the data.</span>
+<span class="sd">        </span>
+<span class="sd">        Implementation::</span>
+<span class="sd">        </span>
+<span class="sd">          V =  self.get_volume_fraction(contrast, extrapolation)</span>
+<span class="sd">    </span>
+<span class="sd">          Compute the surface given by:</span>
+<span class="sd">            surface = (2*pi *V(1- V)*porod_const)/ q_star</span>
+<span class="sd">           </span>
+<span class="sd">        :param contrast: contrast value to compute the volume</span>
+<span class="sd">        :param porod_const: Porod constant to compute the surface </span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation</span>
+<span class="sd">        </span>
+<span class="sd">        :return: specific surface </span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># Compute the volume</span>
+        <span class="n">volume</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_volume_fraction</span><span class="p">(</span><span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="p">)</span>
+        <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">volume</span> <span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">volume</span><span class="p">)</span> <span class="o">*</span> \
+            <span class="nb">float</span><span class="p">(</span><span class="n">porod_const</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>
+        </div>
+<div class="viewcode-block" id="InvariantCalculator.get_volume_fraction"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_volume_fraction">[docs]</a>    <span class="k">def</span> <span class="nf">get_volume_fraction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute volume fraction is deduced as follow: ::</span>
+<span class="sd">        </span>
+<span class="sd">            q_star = 2*(pi*contrast)**2* volume( 1- volume)</span>
+<span class="sd">            for k = 10^(-8)*q_star/(2*(pi*|contrast|)**2)</span>
+<span class="sd">            we get 2 values of volume:</span>
+<span class="sd">                 with   1 - 4 * k &gt;= 0</span>
+<span class="sd">                 volume1 = (1- sqrt(1- 4*k))/2</span>
+<span class="sd">                 volume2 = (1+ sqrt(1- 4*k))/2</span>
+<span class="sd">           </span>
+<span class="sd">            q_star: the invariant value included extrapolation is applied</span>
+<span class="sd">                         unit  1/A^(3)*1/cm</span>
+<span class="sd">                    q_star = self.get_qstar()</span>
+<span class="sd">                    </span>
+<span class="sd">            the result returned will be 0 &lt;= volume &lt;= 1</span>
+<span class="sd">        </span>
+<span class="sd">        :param contrast: contrast value provides by the user of type float.</span>
+<span class="sd">                 contrast unit is 1/A^(2)= 10^(16)cm^(2)</span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation</span>
+<span class="sd">        </span>
+<span class="sd">        :return: volume fraction</span>
+<span class="sd">        </span>
+<span class="sd">        :note: volume fraction must have no unit</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="n">contrast</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="s">&quot;The contrast parameter must be greater than zero&quot;</span>  
+        
+        <span class="c"># Make sure Q star is up to date</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar</span><span class="p">(</span><span class="n">extrapolation</span><span class="p">)</span>
+        
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Invalid invariant: Invariant Q* must be greater than zero&quot;</span>
+            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">,</span> <span class="n">msg</span>
+        
+        <span class="c"># Compute intermediate constant</span>
+        <span class="n">k</span> <span class="o">=</span>  <span class="mf">1.e-8</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">contrast</span><span class="p">)))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
+        <span class="c"># Check discriminant value</span>
+        <span class="n">discrim</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">k</span>
+        
+        <span class="c"># Compute volume fraction</span>
+        <span class="k">if</span> <span class="n">discrim</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Could not compute the volume fraction: negative discriminant&quot;</span>
+            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">,</span> <span class="n">msg</span>
+        <span class="k">elif</span> <span class="n">discrim</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="mi">2</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">volume1</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">discrim</span><span class="p">))</span>
+            <span class="n">volume2</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">discrim</span><span class="p">))</span>
+            
+            <span class="k">if</span> <span class="mi">0</span> <span class="o">&lt;=</span> <span class="n">volume1</span> <span class="ow">and</span> <span class="n">volume1</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span>
+                <span class="k">return</span> <span class="n">volume1</span>
+            <span class="k">elif</span> <span class="mi">0</span> <span class="o">&lt;=</span> <span class="n">volume2</span> <span class="ow">and</span> <span class="n">volume2</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span> 
+                <span class="k">return</span> <span class="n">volume2</span> 
+            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;Could not compute the volume fraction: inconsistent results&quot;</span>
+            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">,</span> <span class="n">msg</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_qstar_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_qstar_with_error">[docs]</a>    <span class="k">def</span> <span class="nf">get_qstar_with_error</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute the invariant uncertainty.</span>
+<span class="sd">        This uncertainty computation depends on whether or not the data is</span>
+<span class="sd">        smeared.</span>
+<span class="sd">        </span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation</span>
+<span class="sd">        </span>
+<span class="sd">        :return: invariant, the invariant uncertainty</span>
+<span class="sd">        &quot;&quot;&quot;</span>    
+        <span class="bp">self</span><span class="o">.</span><span class="n">get_qstar</span><span class="p">(</span><span class="n">extrapolation</span><span class="p">)</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_volume_fraction_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_volume_fraction_with_error">[docs]</a>    <span class="k">def</span> <span class="nf">get_volume_fraction_with_error</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute uncertainty on volume value as well as the volume fraction</span>
+<span class="sd">        This uncertainty is given by the following equation: ::</span>
+<span class="sd">        </span>
+<span class="sd">            dV = 0.5 * (4*k* dq_star) /(2* math.sqrt(1-k* q_star))</span>
+<span class="sd">                                 </span>
+<span class="sd">            for k = 10^(-8)*q_star/(2*(pi*|contrast|)**2)</span>
+<span class="sd">            </span>
+<span class="sd">            q_star: the invariant value including extrapolated value if existing</span>
+<span class="sd">            dq_star: the invariant uncertainty</span>
+<span class="sd">            dV: the volume uncertainty</span>
+<span class="sd">        </span>
+<span class="sd">        The uncertainty will be set to -1 if it can&#39;t be computed.</span>
+<span class="sd">        </span>
+<span class="sd">        :param contrast: contrast value </span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation</span>
+<span class="sd">        </span>
+<span class="sd">        :return: V, dV = volume fraction, error on volume fraction</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">volume</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_volume_fraction</span><span class="p">(</span><span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="p">)</span>
+        
+        <span class="c"># Compute error</span>
+        <span class="n">k</span> <span class="o">=</span>  <span class="mf">1.e-8</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span> <span class="o">/</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">contrast</span><span class="p">)))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
+        <span class="c"># Check value inside the sqrt function</span>
+        <span class="n">value</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">k</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">uncertainty</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
+        <span class="c"># Compute uncertainty</span>
+        <span class="n">uncertainty</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">((</span><span class="mf">0.5</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">k</span> <span class="o">*</span> \
+                        <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">k</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span><span class="p">)))</span>
+        
+        <span class="k">return</span> <span class="n">volume</span><span class="p">,</span> <span class="n">uncertainty</span>
+    </div>
+<div class="viewcode-block" id="InvariantCalculator.get_surface_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant.InvariantCalculator.get_surface_with_error">[docs]</a>    <span class="k">def</span> <span class="nf">get_surface_with_error</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">porod_const</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Compute uncertainty of the surface value as well as the surface value.</span>
+<span class="sd">        The uncertainty is given as follow: ::</span>
+<span class="sd">        </span>
+<span class="sd">            dS = porod_const *2*pi[( dV -2*V*dV)/q_star</span>
+<span class="sd">                 + dq_star(v-v**2)</span>
+<span class="sd">                 </span>
+<span class="sd">            q_star: the invariant value</span>
+<span class="sd">            dq_star: the invariant uncertainty</span>
+<span class="sd">            V: the volume fraction value</span>
+<span class="sd">            dV: the volume uncertainty</span>
+<span class="sd">        </span>
+<span class="sd">        :param contrast: contrast value</span>
+<span class="sd">        :param porod_const: porod constant value </span>
+<span class="sd">        :param extrapolation: string to apply optional extrapolation</span>
+<span class="sd">        </span>
+<span class="sd">        :return S, dS: the surface, with its uncertainty</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="c"># We get the volume fraction, with error</span>
+        <span class="c">#   get_volume_fraction_with_error calls get_volume_fraction</span>
+        <span class="c">#   get_volume_fraction calls get_qstar</span>
+        <span class="c">#   which computes Qstar and dQstar</span>
+        <span class="n">v</span><span class="p">,</span> <span class="n">dv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_volume_fraction_with_error</span><span class="p">(</span><span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="p">)</span>
+
+        <span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_surface</span><span class="p">(</span><span class="n">contrast</span><span class="o">=</span><span class="n">contrast</span><span class="p">,</span> <span class="n">porod_const</span><span class="o">=</span><span class="n">porod_const</span><span class="p">,</span> 
+                             <span class="n">extrapolation</span><span class="o">=</span><span class="n">extrapolation</span><span class="p">)</span>
+        <span class="n">ds</span> <span class="o">=</span> <span class="n">porod_const</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="p">((</span> <span class="n">dv</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">v</span> <span class="o">*</span> <span class="n">dv</span><span class="p">)</span><span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar</span>\
+                 <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_qstar_err</span> <span class="o">*</span> <span class="p">(</span> <span class="n">v</span> <span class="o">-</span> <span class="n">v</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
+
+        <span class="k">return</span> <span class="n">s</span><span class="p">,</span> <span class="n">ds</span></div></div>
+</pre></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="sphinxsidebar">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+  <h3>Quick search</h3>
+    <form class="search" action="../../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../../../index.html">SasView 3.0.0 documentation</a> &raquo;</li>
+          <li><a href="../../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        &copy; Copyright 2013, The SasView Project.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+    </div>
+  </body>
+</html>
Index: _modules/sas/invariant/invariant_mapper.html
===================================================================
--- _modules/sas/invariant/invariant_mapper.html	(revision a462c6a6616628a6536b55fc2886d9ab1224149a)
+++ _modules/sas/invariant/invariant_mapper.html	(revision a462c6a6616628a6536b55fc2886d9ab1224149a)
@@ -0,0 +1,140 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>sas.invariant.invariant_mapper &mdash; SasView 3.0.0 documentation</title>
+    
+    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../',
+        VERSION:     '3.0.0',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+    <link rel="top" title="SasView 3.0.0 documentation" href="../../../index.html" />
+    <link rel="up" title="Module code" href="../../index.html" /> 
+  </head>
+  <body>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../../../index.html">SasView 3.0.0 documentation</a> &raquo;</li>
+          <li><a href="../../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>  
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body">
+            
+  <h1>Source code for sas.invariant.invariant_mapper</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">This module is a wrapper to a map function. It allows to loop through </span>
+<span class="sd">different invariant objects to call the same function</span>
+<span class="sd">&quot;&quot;&quot;</span>
+
+
+<div class="viewcode-block" id="get_qstar"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_qstar">[docs]</a><span class="k">def</span> <span class="nf">get_qstar</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get invariant value (Q*)</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_qstar</span><span class="p">(</span><span class="n">extrapolation</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_qstar_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_qstar_with_error">[docs]</a><span class="k">def</span> <span class="nf">get_qstar_with_error</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get invariant value with uncertainty</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_qstar_with_error</span><span class="p">(</span><span class="n">extrapolation</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_volume_fraction"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_volume_fraction">[docs]</a><span class="k">def</span> <span class="nf">get_volume_fraction</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get volume fraction</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_volume_fraction</span><span class="p">(</span><span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_volume_fraction_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_volume_fraction_with_error">[docs]</a><span class="k">def</span> <span class="nf">get_volume_fraction_with_error</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get volume fraction with uncertainty</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_volume_fraction_with_error</span><span class="p">(</span><span class="n">contrast</span><span class="p">,</span>
+                                                    <span class="n">extrapolation</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_surface"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_surface">[docs]</a><span class="k">def</span> <span class="nf">get_surface</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> <span class="n">porod_const</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get surface with uncertainty</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_surface</span><span class="p">(</span><span class="n">contrast</span><span class="o">=</span><span class="n">contrast</span><span class="p">,</span>
+                                      <span class="n">porod_const</span><span class="o">=</span><span class="n">porod_const</span><span class="p">,</span>
+                                      <span class="n">extrapolation</span><span class="o">=</span><span class="n">extrapolation</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_surface_with_error"><a class="viewcode-back" href="../../../dev/api/sas.invariant.html#sas.invariant.invariant_mapper.get_surface_with_error">[docs]</a><span class="k">def</span> <span class="nf">get_surface_with_error</span><span class="p">(</span><span class="n">inv</span><span class="p">,</span> <span class="n">contrast</span><span class="p">,</span> 
+                           <span class="n">porod_const</span><span class="p">,</span> <span class="n">extrapolation</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Get surface with uncertainty</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">return</span> <span class="n">inv</span><span class="o">.</span><span class="n">get_surface_with_error</span><span class="p">(</span><span class="n">contrast</span><span class="o">=</span><span class="n">contrast</span><span class="p">,</span>
+                                      <span class="n">porod_const</span><span class="o">=</span><span class="n">porod_const</span><span class="p">,</span>
+                                      <span class="n">extrapolation</span><span class="o">=</span><span class="n">extrapolation</span><span class="p">)</span>
+</pre></div></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="sphinxsidebar">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+  <h3>Quick search</h3>
+    <form class="search" action="../../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li><a href="../../../index.html">SasView 3.0.0 documentation</a> &raquo;</li>
+          <li><a href="../../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        &copy; Copyright 2013, The SasView Project.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+    </div>
+  </body>
+</html>
