10. Simple interface¶
sasmodels.direct_model
¶
Class interface to the model calculator.
Calling a model is somewhat non-trivial since the functions called depend on the data type. For 1D data the Iq kernel needs to be called, for 2D data the Iqxy kernel needs to be called, and for SESANS data the Iq kernel needs to be called followed by a Hankel transform. Before the kernel is called an appropriate q calculation vector needs to be constructed. This is not the simple q vector where you have measured the data since the resolution calculation will require values beyond the range of the measured data. After the calculation the resolution calculator must be called to return the predicted value for each measured data point.
DirectModel
is a callable object that takes parameter=value
keyword arguments and returns the appropriate theory values for the data.
DataMixin
does the real work of interpreting the data and calling
the model calculator. This is used by DirectModel
, which uses
direct parameter values and by bumps_model.Experiment
which wraps
the parameter values in boxes so that the user can set fitting ranges, etc.
on the individual parameters and send the model to the Bumps optimizers.
-
class
sasmodels.direct_model.
DataMixin
¶ Bases:
object
DataMixin captures the common aspects of evaluating a SAS model for a particular data set, including calculating Iq and evaluating the resolution function. It is used in particular by
DirectModel
, which evaluates a SAS model parameters as key word arguments to the calculator method, and bybumps_model.Experiment
, which wraps the model and data for use with the Bumps fitting engine. It is not currently used bysasview_model.SasviewModel
since this will require a number of changes to SasView before we can do it._interpret_data()
initializes the data structures necessary to manage the calculations. This sets attributes in the child class such as data_type and resolution._calc_theory()
evaluates the model at the given control values._set_data()
sets the intensity data in the data object, possibly with random noise added. This is useful for simulating a dataset with the results from_calc_theory()
.
-
class
sasmodels.direct_model.
DirectModel
(data, model, cutoff=1e-05)¶ Bases:
sasmodels.direct_model.DataMixin
Create a calculator object for a model.
data is 1D SAS, 2D SAS or SESANS data
model is a model calculator return from
generate.load_model()
cutoff is the polydispersity weight cutoff.
-
profile
(**pars)¶ Generate a plottable profile.
-
simulate_data
(noise=None, **pars)¶ Generate simulated data for the model.
-
-
sasmodels.direct_model.
call_ER
(model_info, pars)¶ Call the model ER function using values.
model_info is either model.info if you have a loaded model, or kernel.info if you have a model kernel prepared for evaluation.
-
sasmodels.direct_model.
call_VR
(model_info, pars)¶ Call the model VR function using pars.
model_info is either model.info if you have a loaded model, or kernel.info if you have a model kernel prepared for evaluation.
-
sasmodels.direct_model.
call_kernel
(calculator, pars, cutoff=0.0, mono=False)¶ Call kernel returned from model.make_kernel with parameters pars.
cutoff is the limiting value for the product of dispersion weights used to perform the multidimensional dispersion calculation more quickly at a slight cost to accuracy. The default value of cutoff=0 integrates over the entire dispersion cube. Using cutoff=1e-5 can be 50% faster, but with an error of about 1%, which is usually less than the measurement uncertainty.
mono is True if polydispersity should be set to none on all parameters.
-
sasmodels.direct_model.
call_profile
(model_info, **pars)¶ Returns the profile x, y, (xlabel, ylabel) representing the model.
-
sasmodels.direct_model.
get_mesh
(model_info, values, dim='1d', mono=False)¶ Retrieve the dispersity mesh described by the parameter set.
Returns a list of (value, dispersity, weights) with one tuple for each parameter in the model call parameters. Inactive parameters return the default value with a weight of 1.0.
-
sasmodels.direct_model.
main
()¶ Program to evaluate a particular model at a set of q values.