2. Bumps interface¶
sasmodels.bumps_model¶
Wrap sasmodels for direct use by bumps.
Model is a wrapper for the sasmodels kernel which defines a
bumps Parameter box for each kernel parameter. Model accepts keyword
arguments to set the initial value for each parameter.
Experiment combines the Model function with a data file loaded by
the sasview data loader. Experiment takes a cutoff parameter controlling
how far the polydispersity integral extends.
- sasmodels.bumps_model.BumpsParameter¶
alias of
Parameter
- class sasmodels.bumps_model.Experiment(data: Data1D | Data2D, model: Model, cutoff: float = 1e-05, name: str | None = None, extra_pars: dict[str, Parameter] | None = None)¶
Bases:
DataMixinBumps wrapper for a SAS experiment.
data is a
data.Data1D,data.Data2Dordata.SesansDataobject. Usedata.empty_data1D()ordata.empty_data2D()to define \(q, \Delta q\) calculation points for displaying the SANS curve when there is no measured data.model is a
Modelobject.cutoff is the integration cutoff, which avoids computing the the SAS model where the polydispersity weight is low.
The resulting model can be used directly in a Bumps FitProblem call.
- __class__¶
alias of
type
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__module__': 'sasmodels.bumps_model', '__firstlineno__': 127, '__doc__': '\nBumps wrapper for a SAS experiment.\n\n*data* is a :class:`.data.Data1D`, :class:`.data.Data2D` or\n:class:`.data.SesansData` object. Use :func:`.data.empty_data1D` or\n:func:`.data.empty_data2D` to define $q, \\Delta q$ calculation\npoints for displaying the SANS curve when there is no measured data.\n\n*model* is a :class:`Model` object.\n\n*cutoff* is the integration cutoff, which avoids computing the\nthe SAS model where the polydispersity weight is low.\n\nThe resulting model can be used directly in a Bumps FitProblem call.\n', '_cache': None, '__init__': <function Experiment.__init__>, 'update': <function Experiment.update>, 'numpoints': <function Experiment.numpoints>, 'resolution': <property object>, 'parameters': <function Experiment.parameters>, 'theory': <function Experiment.theory>, 'residuals': <function Experiment.residuals>, 'nllf': <function Experiment.nllf>, 'plot': <function Experiment.plot>, 'simulate_data': <function Experiment.simulate_data>, 'save': <function Experiment.save>, '__getstate__': <function Experiment.__getstate__>, '__setstate__': <function Experiment.__setstate__>, '__static_attributes__': ('__dict__', '_cache', '_resolution', '_resolution_pars', 'cutoff', 'extra_pars', 'model', 'name'), '__annotations__': {'_cache': 'dict[str, np.ndarray]'}})¶
- __dir__()¶
Default dir() implementation.
- __doc__ = '\nBumps wrapper for a SAS experiment.\n\n*data* is a :class:`.data.Data1D`, :class:`.data.Data2D` or\n:class:`.data.SesansData` object. Use :func:`.data.empty_data1D` or\n:func:`.data.empty_data2D` to define $q, \\Delta q$ calculation\npoints for displaying the SANS curve when there is no measured data.\n\n*model* is a :class:`Model` object.\n\n*cutoff* is the integration cutoff, which avoids computing the\nthe SAS model where the polydispersity weight is low.\n\nThe resulting model can be used directly in a Bumps FitProblem call.\n'¶
- __eq__(value, /)¶
Return self==value.
- __firstlineno__ = 127¶
- __format__(format_spec, /)¶
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
- __ge__(value, /)¶
Return self>=value.
- __getattribute__(name, /)¶
Return getattr(self, name).
- __getstate__() dict[str, Any]¶
Helper for pickle.
- __gt__(value, /)¶
Return self>value.
- __hash__()¶
Return hash(self).
- __init__(data: Data1D | Data2D, model: Model, cutoff: float = 1e-05, name: str | None = None, extra_pars: dict[str, Parameter] | None = None) None¶
- classmethod __init_subclass__()¶
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __le__(value, /)¶
Return self<=value.
- __lt__(value, /)¶
Return self<value.
- __module__ = 'sasmodels.bumps_model'¶
- __ne__(value, /)¶
Return self!=value.
- classmethod __new__(*args, **kwargs)¶
- __reduce__()¶
Helper for pickle.
- __reduce_ex__(protocol, /)¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __setstate__(state: dict[str, Any]) None¶
- __sizeof__()¶
Size of object in memory, in bytes.
- __static_attributes__ = ('__dict__', '_cache', '_resolution', '_resolution_pars', 'cutoff', 'extra_pars', 'model', 'name')¶
- __str__()¶
Return str(self).
- classmethod __subclasshook__(object, /)¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- __weakref__¶
list of weak references to the object
- _cache: dict[str, ndarray] = None¶
- _calc_theory(pars: ParameterSet, cutoff: float = 0.0) np.ndarray¶
- _interpret_data(data: Data1D | Data2D | SesansData, model: KernelModel) None¶
- _set_data(Iq: np.ndarray, noise: float | None = None) None¶
- nllf() float¶
Return the negative log likelihood of seeing data given the model parameters, up to a normalizing constant which depends on the data uncertainty.
- numpoints() float¶
Return the number of data points
- parameters() dict[str, Parameter]¶
Return a dictionary of parameters
- plot(view: str = None) None¶
Plot the data and residuals.
- residuals() ndarray¶
Return theory minus data normalized by uncertainty.
- property resolution: None | Resolution¶
resolution.Resolutionapplied to the data, if any.
- save(basename: str) None¶
Save the model parameters and data into a file.
Not Implemented except for sesans fits.
- simulate_data(noise: float = None) None¶
Generate simulated data. noise is the fractional uncertainty in percent.
- theory() ndarray¶
Return the theory corresponding to the model parameters.
This method uses lazy evaluation, and requires model.update() to be called when the parameters have changed.
- update() None¶
Call when model parameters have changed and theory needs to be recalculated.
- class sasmodels.bumps_model.Model(model: KernelModel, **kwargs: dict[str, float | Parameter])¶
Bases:
objectBumps wrapper for a SAS model.
model is a runnable module as returned from
core.load_model().cutoff is the polydispersity weight cutoff.
Any additional key=value pairs are model dependent parameters.
- __class__¶
alias of
type
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__module__': 'sasmodels.bumps_model', '__firstlineno__': 88, '__doc__': '\nBumps wrapper for a SAS model.\n\n*model* is a runnable module as returned from :func:`.core.load_model`.\n\n*cutoff* is the polydispersity weight cutoff.\n\nAny additional *key=value* pairs are model dependent parameters.\n', '__init__': <function Model.__init__>, 'parameters': <function Model.parameters>, 'state': <function Model.state>, '__static_attributes__': ('_parameter_names', '_pd_type_names', 'sasmodel'), '__dict__': <attribute '__dict__' of 'Model' objects>, '__weakref__': <attribute '__weakref__' of 'Model' objects>, '__annotations__': {}})¶
- __dir__()¶
Default dir() implementation.
- __doc__ = '\nBumps wrapper for a SAS model.\n\n*model* is a runnable module as returned from :func:`.core.load_model`.\n\n*cutoff* is the polydispersity weight cutoff.\n\nAny additional *key=value* pairs are model dependent parameters.\n'¶
- __eq__(value, /)¶
Return self==value.
- __firstlineno__ = 88¶
- __format__(format_spec, /)¶
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
- __ge__(value, /)¶
Return self>=value.
- __getattribute__(name, /)¶
Return getattr(self, name).
- __getstate__()¶
Helper for pickle.
- __gt__(value, /)¶
Return self>value.
- __hash__()¶
Return hash(self).
- __init__(model: KernelModel, **kwargs: dict[str, float | Parameter]) None¶
- classmethod __init_subclass__()¶
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __le__(value, /)¶
Return self<=value.
- __lt__(value, /)¶
Return self<value.
- __module__ = 'sasmodels.bumps_model'¶
- __ne__(value, /)¶
Return self!=value.
- classmethod __new__(*args, **kwargs)¶
- __reduce__()¶
Helper for pickle.
- __reduce_ex__(protocol, /)¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __sizeof__()¶
Size of object in memory, in bytes.
- __static_attributes__ = ('_parameter_names', '_pd_type_names', 'sasmodel')¶
- __str__()¶
Return str(self).
- classmethod __subclasshook__(object, /)¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- __weakref__¶
list of weak references to the object
- parameters() dict[str, Parameter]¶
Return a dictionary of parameters objects for the parameters, excluding polydispersity distribution type.
- state() dict[str, Parameter | str]¶
Return a dictionary of current values for all the parameters, including polydispersity distribution type.