27. Sasview interface¶
sasmodels.sasview_model
¶
Sasview model constructor.
Given a module defining an OpenCL kernel such as sasmodels.models.cylinder, create a sasview model class to run that kernel as follows:
from sasmodels.sasview_model import load_custom_model
CylinderModel = load_custom_model('sasmodels/models/cylinder.py')
-
class
sasmodels.sasview_model.
MultiplicityInfo
(number, control, choices, x_axis_label)¶ Bases:
tuple
Create new instance of MultiplicityInfo(number, control, choices, x_axis_label)
-
count
(value) → integer -- return number of occurrences of value¶
-
index
(value[, start[, stop]]) → integer -- return first index of value.¶ Raises ValueError if the value is not present.
-
choices
¶ Alias for field number 2
-
control
¶ Alias for field number 1
-
number
¶ Alias for field number 0
-
x_axis_label
¶ Alias for field number 3
-
-
sasmodels.sasview_model.
MultiplicityInfoType
¶
-
class
sasmodels.sasview_model.
SasviewModel
(multiplicity=None)¶ Bases:
object
Sasview wrapper for opencl/ctypes model.
-
calc_composition_models
(qx)¶ returns parts of the composition model or None if not a composition model.
-
calculate_ER
()¶ Calculate the effective radius for P(q)*S(q)
Returns: the value of the effective radius
-
calculate_Iq
(qx, qy=None)¶ Calculate Iq for one set of q with the current parameters.
If the model is 1D, use q. If 2D, use qx, qy.
This should NOT be used for fitting since it copies the q vectors to the card for each evaluation.
-
calculate_VR
()¶ Calculate the volf ratio for P(q)*S(q)
Returns: the value of the volf ratio
-
clone
()¶ Return a identical copy of self
-
evalDistribution
(qdist)¶ Evaluate a distribution of q-values.
Parameters: qdist – array of q or a list of arrays [qx,qy] - For 1D, a numpy array is expected as input
evalDistribution(q) where *q* is a numpy array.
- For 2D, a list of [qx,qy] is expected with 1D arrays as input
qx = [ qx[0], qx[1], qx[2], ....] qy = [ qy[0], qy[1], qy[2], ....]
If the model is 1D only, then
\[q = \sqrt{q_x^2+q_y^2}\]
-
getDispParamList
()¶ Return a list of polydispersity parameters for the model
-
getParam
(name)¶ Set the value of a model parameter
Parameters: name – name of the parameter
-
getParamList
()¶ Return a list of all available parameters for the model
-
getProfile
()¶ Get SLD profile
- : return: (z, beta) where z is a list of depth of the transition points
- beta is a list of the corresponding SLD values
-
is_fittable
(par_name)¶ Check if a given parameter is fittable or not
Parameters: par_name – the parameter name to check
-
run
(x=0.0)¶ Evaluate the model
Parameters: x – input q, or [q,phi] Returns: scattering function P(q) DEPRECATED: use calculate_Iq instead
-
runXY
(x=0.0)¶ Evaluate the model in cartesian coordinates
Parameters: x – input q, or [qx, qy] Returns: scattering function P(q) DEPRECATED: use calculate_Iq instead
-
setParam
(name, value)¶ Set the value of a model parameter
Parameters: - name – name of the parameter
- value – value of the parameter
-
set_dispersion
(parameter, dispersion)¶ Set the dispersion object for a model parameter
Parameters: - parameter – name of the parameter [string]
- dispersion – dispersion object of type Dispersion
-
category
= None¶ default model category
-
cutoff
= 1e-05¶ default cutoff for polydispersity
-
description
= None¶ short model description
-
details
= None¶ units and limits for each parameter
-
dispersion
= None¶ values for dispersion width, npts, nsigmas and type
-
fixed
= None¶ names of the fittable parameters
-
id
= None¶ load/save name for the model
-
input_name
= 'Q'¶
-
input_unit
= 'A^{-1}'¶
-
is_form_factor
= False¶ True if model should appear as a form factor
-
is_multiplicity_model
= False¶ True if model has multiplicity
-
is_structure_factor
= False¶ True if model should appear as a structure factor
-
magnetic_params
= None¶ names of the magnetic parameters in the order they appear
-
multiplicity
= None¶ multiplicity value, or None if no multiplicity on the model
-
multiplicity_info
= None¶ Multiplicity information
-
name
= None¶ display name for the model
-
non_fittable
= ()¶ parameters that are not fitted
-
orientation_params
= None¶ names of the orientation parameters in the order they appear
-
output_name
= 'Intensity'¶
-
output_unit
= 'cm^{-1}'¶
-
params
= None¶ parameter {name: value} mapping
-
-
sasmodels.sasview_model.
MultiplicationModel
(form_factor, structure_factor)¶ Returns a constructed product model from form_factor and structure_factor.
-
sasmodels.sasview_model.
find_model
(modelname)¶ Find a model by name. If the model name ends in py, try loading it from custom models, otherwise look for it in the list of builtin models.
-
sasmodels.sasview_model.
load_custom_model
(path)¶ Load a custom model given the model path.
-
sasmodels.sasview_model.
load_standard_models
()¶ Load and return the list of predefined models.
If there is an error loading a model, then a traceback is logged and the model is not returned.
-
sasmodels.sasview_model.
make_model_from_info
(model_info)¶ Convert model_info into a SasView model wrapper.
-
sasmodels.sasview_model.
test_cylinder
()¶ Test that the cylinder model runs, returning the value at [0.1,0.1].
-
sasmodels.sasview_model.
test_empty_distribution
()¶ Make sure that sasmodels returns NaN when there are no polydispersity points
-
sasmodels.sasview_model.
test_model_list
()¶ Make sure that all models build as sasview models
-
sasmodels.sasview_model.
test_old_name
()¶ Load and run cylinder model as sas-models-CylinderModel
-
sasmodels.sasview_model.
test_product
()¶ Test that 2-D hardsphere model runs and doesn’t produce NaN.
-
sasmodels.sasview_model.
test_rpa
()¶ Test that the 2-D RPA model runs
-
sasmodels.sasview_model.
test_structure_factor
()¶ Test that 2-D hardsphere model runs and doesn’t produce NaN.
-
sasmodels.sasview_model.
MODELS
= {}¶ set of defined models (standard and custom)
-
sasmodels.sasview_model.
MODEL_BY_PATH
= {}¶ custom model {path: model} mapping so we can check timestamps
-
sasmodels.sasview_model.
SUPPORT_OLD_STYLE_PLUGINS
= True¶ True if pre-existing plugins, with the old names and parameters, should continue to be supported.