Extrapolations at highest q¶
superclass of functions for extrapolation of SAS data past available range
-
class
jldesmear.jl_api.extrapolation.
Extrapolation
[source]¶ superclass of functions for extrapolation of SAS data past available range
The general case to (forward) slit-smear small-angle scattering involves integration at \(q\) values past any measurable range.
\[\int_{-\infty}^{\infty} P_l(q_l) I(q,q_l) dq_l.\]Due to symmetry, the integral is usually folded around zero,thus becoming
\[2 \int_0^{\infty} P_l(q_l) I(q,q_l) dq_l.\]Even when the upper limit is reduced due to finite slit dimension (the so-called slit-length, \(l_0\)),
\[2 l_0^{-1} \int_0^{\l_0} I(\sqrt{q^2+q_l^2}) dq_l,\]it is still necessary to evaluate \(I(\sqrt{q^2+q_l^2})\) beyond the last measured data point, just to evaluate the integral.
An extrapolation function is used to describe the \(I(q)\) beyond the measured data. In the most trivial case, zero would be returned. Since this simplification is known to introduce truncation errors, a model form for the last few available data points is assumed. Fitting coefficients are determined from the final data points (in the method
fit()
) and are used subsequently to generate the extrapolation at a specific \(q\) value (in the methodcalc()
).Examples:
See the subclasses for examples implementations of extrapolations.
extrap_constant
extrap_linear
extrap_powerlaw
extrap_Porod
Example Linear Extrapolation:
Here is an example linear extrapolation class:
import extrapolation class Extrapolation(extrapolation.Extrapolation): name = 'linear' # unique identifier for users def __init__(self): # initialize whatever is needed internally self.coefficients = {'B': 0, 'm': 0} def __str__(self): form = "linear: I(q) = " + str(self.coefficients['B']) form += " + q*(" + str(self.coefficients['m']) + ")" return form def calc(self, q): # evaluate at given q return self.coefficients['B'] + self.coefficients['m'] * q def fit_result(self, reg): # evaluate fitting parameters with regression object (constant, slope) = reg.LinearRegression() self.coefficients = dict(B=constant, m=slope)
Basics:
Create an Extrapolation class which is a subclass of
extrapolation.Extrapolation
.The basic methods to override are
__str__()
: string representationcalc()
: determines \(I(q)\) fromq
andself.coefficients
dictionaryfit_result()
: assigns fit coefficients toself.coefficients
dictionary
By default, the base class Extrapolation uses the
jldesmear.api.StatsReg
module to accumulate data and evaluate fitted parameters. Override any or all of these methods to define your own handling:See the source code of
Extrapolation
for an example.documentation from source code:
-
SetCoefficients
(coefficients)[source]¶ define the function coefficients
Parameters: coefficients (dict) – named terms used in evaluating the extrapolation
-
calc
(q)[source]¶ evaluate the extrapolation function at the given q
Note: must override in subclass Parameters: q (float) – magnitude of scattering vector Returns: value of extrapolation function at q Return type: float
-
fit
(q, I, dI)[source]¶ fit the function coefficients to the data
Note: might override in subclass
Parameters: - q (float) – magnitude of scattering vector
- I (float) – intensity or cross-section
- dI (float) – estimated uncertainty of intensity or cross-section
-
fit_add
(reg, x, y, z)[source]¶ Add a data point to the statistics registers. Called from
fit_loop()
.Note: might override in subclass
Parameters: - reg (StatsRegClass object) – statistics registers (created in
fit()
) - x (float) – independent axis
- y (float) – dependent axis
- z (float) – estimated uncertainty of y
- reg (StatsRegClass object) – statistics registers (created in
-
fit_loop
(reg, x, y, z)[source]¶ Add a dataset to the statistics registers for use in curve fitting. Called from
fit()
.Note: might override in subclass
Parameters: - reg (StatsRegClass object) – statistics registers (created in fit())
- x (numpy.ndarray) – independent axis
- y (numpy.ndarray) – dependent axis
- z (numpy.ndarray) – estimated uncertainties of y
-
fit_result
(reg)[source]¶ Determine the results of the fit and store them as the set of coefficients in the self.coefficients dictionary. Called from
fit()
.Example:
def fit_result(self, reg): (constant, slope) = reg.LinearRegression() self.coefficients['B'] = constant self.coefficients['m'] = slope
Note: must override in subclass otherwise fit_result()
will raise an exceptionParameters: reg (StatsRegClass object) – statistics registers (created in fit()
)
-
fit_setup
()[source]¶ Create a set of statistics registers to evaluate the coefficients of the curve fit. Called from
fit()
.Note: might override in subclass Returns: statistics registers Return type: StatsRegClass object
-
jldesmear.jl_api.extrapolation.
discover_extrapolations
()[source]¶ return a dictionary of the available extrapolations
Extrapolation functions must be in a file named
extrap_KEY.py
whereKEY
is the key name of the extrapolation function. The file is placed in the source code tree in the same directory as the module:extrapolation
.The
calc()
method should be capable of handlingq
as anumpy.ndarray
or as afloat
.The file must contain:
- Extrapolation: a subclass of
Extrapolation
- Extrapolation: a subclass of