sample_model
Modules:
| Name | Description |
|---|---|
background_model |
|
component_collection |
|
components |
|
diffusion_model |
|
instrument_model |
|
model_base |
|
resolution_model |
|
sample_model |
|
Classes:
| Name | Description |
|---|---|
BackgroundModel |
BackgroundModel represents a model of the background in an experiment at various Q. |
ComponentCollection |
Collection of model components. |
DampedHarmonicOscillator |
Model of a Damped Harmonic Oscillator (DHO). |
DeltaFunction |
Delta function. |
Exponential |
Model of an exponential function. |
ExpressionComponent |
Model component defined by a symbolic expression. |
Gaussian |
Model of a Gaussian function. |
Lorentzian |
Model of a Lorentzian function. |
Polynomial |
Polynomial function component. |
Voigt |
Voigt profile, a convolution of Gaussian and Lorentzian. |
BrownianTranslationalDiffusion |
Model of Brownian translational diffusion, consisting of a Lorentzian function for each |
DeltaLorentz |
Model of Delta function and Lorentzian with intensities given by the Debye-Waller factor. $$ I |
JumpTranslationalDiffusion |
Model of Jump translational diffusion. |
InstrumentModel |
InstrumentModel represents a model of the instrument in an experiment at various Q. |
ResolutionModel |
ResolutionModel represents a model of the instrment resolution in an experiment at various Q. |
SampleModel |
SampleModel represents a model of a sample with components and diffusion models, parameterized |
Classes
BackgroundModel(display_name='MyBackgroundModel', unique_name=None, unit='meV', components=None, Q=None)
BackgroundModel represents a model of the background in an experiment at various Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None
|
Display name of the model. |
'MyBackgroundModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
__repr__ |
Return a string representation of the ModelBase. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
evaluate |
Evaluate the sample model at all Q for the given x values. |
append_component |
Append a ModelComponent or ComponentCollection to the SampleModel. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
ComponentCollection(components=None, unit='meV', name='ComponentCollection', display_name=None, unique_name=None)
Collection of model components.
Examples:
Create a ComponentCollection with two components:
>>> import easydynamics.sample_model as sm
>>> component1 = sm.Gaussian(name='Gaussian1', area=1.0, width=1.0)
>>> component2 = sm.Lorentzian(name='Lorentzian1', area=2.0, width=0.5)
>>> collection = sm.ComponentCollection(components=[component1, component2])
Append a component to the collection:
>>> component3 = sm.Gaussian(name='Gaussian2', area=0.5, width=0.8)
>>> collection.append(component3)
Evaluate the collection at a given energy axis:
>>> import numpy as np
>>> x = np.linspace(-5, 5, 100)
>>> values = collection.evaluate(x)
Remove a component by name:
>>> collection.remove('Gaussian1')
List component names:
>>> collection.list_component_names()
['Lorentzian1', 'Gaussian2']
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ModelComponent | list[ModelComponent] | None
|
Initial model components to add to the ComponentCollection. |
None
|
unit
|
str | sc.Unit
|
Unit of the collection. |
'meV'
|
name
|
str
|
Name of the collection. |
'ComponentCollection'
|
display_name
|
str | None
|
Display name of the collection. |
None
|
unique_name
|
str | None
|
Unique name of the collection. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If components is not a list of ModelComponent. |
Methods:
| Name | Description |
|---|---|
__dir__ |
This creates auto-completion and helps out in iPython |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
__getitem__ |
Get an item by index, slice, or unique_name. |
__setitem__ |
Set an item at an index. |
__delitem__ |
Delete an item by index, slice, or name. |
__len__ |
Return the number of items in the collection. |
insert |
Insert an item into the list at a specific index. |
sort |
Sort the collection according to the given key function. |
pop |
Remove and return an item at a specific index or name. |
append |
Append an item to the end of the list. |
get_names |
Get a list of the names of all items in the list. |
get_duplicate_names |
Get a list of duplicate names in the list. |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
append_component |
Append a model component or the components from another ComponentCollection to this |
list_component_names |
List the names of all components in the model. |
normalize_area |
Normalize the areas of all components so they sum to 1. |
get_all_variables |
Get all parameters from the model component. |
evaluate |
Evaluate the sum of all components. |
evaluate_component |
Evaluate a single component by name. |
fix_all_parameters |
Fix all free parameters in the model. |
free_all_parameters |
Free all fixed parameters in the model. |
__repr__ |
Return a string representation of the ComponentCollection. |
__copy__ |
Create a deep copy of the ComponentCollection. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
is_empty |
bool
|
Check if the ComponentCollection has no components. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
is_empty
property
writable
Check if the ComponentCollection has no components.
Returns:
| Type | Description |
|---|---|
bool
|
True if the collection has no components, False otherwise. |
Functions
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
__getitem__(idx)
Get an item by index, slice, or unique_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int | slice | str
|
|
required |
Returns:
| Type | Description |
|---|---|
ProtectedType_ | EasyDynamicsList[ProtectedType_]
|
The item at the specified index or name, or a new EasyDynamicsList if a slice is provided. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If idx is not an int, slice, or str. |
KeyError
|
If idx is a str and no item with that name is found. |
AmbiguousNameError
|
If idx is a str and multiple items with that name are found. |
__setitem__(idx, value)
__setitem__(idx: int, value: ProtectedType_) -> None
__setitem__(
idx: slice, value: Iterable[ProtectedType_]
) -> None
Set an item at an index.
:param idx: Index to set :param value: New value
__delitem__(idx)
Delete an item by index, slice, or name.
:param idx: Index, slice, or name of item to delete
__len__()
Return the number of items in the collection.
insert(index, value)
Insert an item into the list at a specific index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index at which to insert the item. |
required |
value
|
ProtectedType_
|
The item to insert. Must be an instance of one of the protected types. |
required |
sort(key=None, reverse=False)
Sort the collection according to the given key function.
:param key: Mapping function to sort by :param reverse: Whether to reverse the sort
pop(index=-1)
Remove and return an item at a specific index or name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | str
|
The index or name at which to pop the item. |
-1
|
Returns:
| Type | Description |
|---|---|
ProtectedType_
|
The item that was popped. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If index is not an int or str. |
KeyError
|
If index is a str and no item with that name is found. |
append(value)
Append an item to the end of the list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
ProtectedType_
|
The item to append. Must be an instance of one of the protected types. |
required |
get_names()
Get a list of the names of all items in the list.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of the names of all items in the list. |
get_duplicate_names()
Get a list of duplicate names in the list.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of duplicate names in the list. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If any component cannot be converted to the specified unit. |
append_component(component)
Append a model component or the components from another ComponentCollection to this ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The component to append. If a ComponentCollection is provided, all of its components will be appended. |
required |
list_component_names()
List the names of all components in the model.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of names of the components in the collection. |
normalize_area()
Normalize the areas of all components so they sum to 1.
This is useful for convolutions.
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model or if the total area is zero or not finite, which would prevent normalization. |
get_all_variables()
Get all parameters from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of parameters in the component. |
evaluate(x)
Evaluate the sum of all components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated model values. |
evaluate_component(x, name)
Evaluate a single component by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
name
|
str
|
Component name. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model. |
TypeError
|
If name is not a string. |
KeyError
|
If no component with the given name exists in the collection. |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated values for the specified component. |
fix_all_parameters()
Fix all free parameters in the model.
free_all_parameters()
Free all fixed parameters in the model.
__repr__()
Return a string representation of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ComponentCollection. |
__copy__()
Create a deep copy of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
A deep copy of the ComponentCollection. |
DampedHarmonicOscillator(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area under the curve. |
1.0
|
center
|
Numeric
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Damped Harmonic Oscillator at the given x values. |
__repr__ |
Return a string representation of the Damped Harmonic Oscillator. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
DeltaFunction(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Delta function at the given x values. |
__repr__ |
Return a string representation of the Delta function. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
Exponential(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
evaluate |
Evaluate the Exponential at the given x values. |
convert_unit |
Convert the unit of the Parameters in the component. |
__repr__ |
Return a string representation of the Exponential. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
amplitude |
Parameter
|
Get the amplitude parameter. |
center |
Parameter
|
Get the center parameter. |
rate |
Parameter
|
Get the rate parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
ExpressionComponent(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Model component defined by a symbolic expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
evaluate |
Evaluate the expression for given x values. |
get_all_variables |
Return all parameters. |
convert_unit |
Convert the unit of the expression. |
__getattr__ |
Allow access to parameters as attributes. |
__setattr__ |
Allow setting parameter values as attributes. |
__dir__ |
Include parameter names in dir() output for better IDE support. |
__repr__ |
Return a string representation of the ExpressionComponent. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
expression |
str
|
Return the original expression string. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
Gaussian(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Gaussian at the given x values. |
__repr__ |
Return a string representation of the Gaussian. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (standard deviation). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
Lorentzian(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Lorentzian at the given x values. |
__repr__ |
Return a string representation of the Lorentzian. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (HWHM). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
Polynomial(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
coefficient_values |
Get the coefficients of the polynomial as a list. |
evaluate |
Evaluate the Polynomial at the given x values. |
get_all_variables |
Get all variables from the model component. |
convert_unit |
Convert the unit of the polynomial. |
__repr__ |
Return a string representation of the Polynomial. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
coefficients |
list[Parameter]
|
Get the coefficients of the polynomial as a list of Parameters. |
degree |
int
|
Get the degree of the polynomial. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
Voigt(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Voigt at the given x values. |
__repr__ |
Return a string representation of the Voigt. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
gaussian_width |
Parameter
|
Get the Gaussian width parameter. |
lorentzian_width |
Parameter
|
Get the Lorentzian width parameter (HWHM). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
BrownianTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, Q=None, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the lorentzian_name. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
ValueError
|
If scale or diffusion_coefficient is negative. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the Brownian translational diffusion model at |
__repr__ |
String representation of the BrownianTranslationalDiffusion model. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q=None)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q=None)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
DeltaLorentz(scale=1.0, mean_u_squared=0.0, A_0=1.0, lorentzian_width=1.0, allow_Q_variation=None, Q=None, unit='meV', name='DeltaLorentz', display_name=None, lorentzian_name='Lorentzian', lorentzian_display_name=None, delta_name='Delta function', delta_display_name=None, unique_name=None)
Model of Delta function and Lorentzian with intensities given by the Debye-Waller factor. $$ I = K \exp \left( \frac{-\langle u^2 \rangle Q^2}{3} \right)[A_0 \delta(E) + (A_1) L(E, \Gamma)] $$,
where \(K\) is the scale factor, \(\langle u^2 \rangle\) is the mean square displacement, \(Q\) is the scattering vector, \(A_0\) and \(A_1\) are the relative amplitudes of the delta function and Lorentzian, respectively, with the constraint that \(A_0+A_1=1\), and \(L(E, \Gamma)\) is the Lorentzian function with width \(\Gamma\). \(A_0\), \(A_1\) and the width of the Lorentzian can be the same at all \(Q\) or be allowed to vary with \(Q\).
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> mean_u_squared = 0.02
>>> A_0 = 0.7
>>> lorentzian_width = 1.0
>>> model = DeltaLorentz(
... display_name='DiffusionModel',
... scale=scale,
... mean_u_squared=mean_u_squared,
... A_0=A_0,
... lorentzian_width=lorentzian_width,
... allow_Q_variation={'A_0': True, 'lorentzian_width': True},
... Q=Q,
... )
See also the tutorials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
mean_u_squared
|
Numeric
|
Mean square displacement in angstrom^2. |
0.0
|
A_0
|
Numeric
|
Amplitude of the delta function. |
1.0
|
lorentzian_width
|
Numeric
|
Width of the Lorentzian function. |
1.0
|
allow_Q_variation
|
dict | None
|
Dict describing whether to allow Q variation of A_0 and the Lorentzian width. The dict can have the keys "A_0" and/or "lorentzian_width", with boolean values indicating whether to allow Q-dependence for each parameter. If None, no Q-dependence will be allowed. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'DeltaLorentz'
|
display_name
|
str | None
|
Display name of the diffusion model. |
None
|
lorentzian_name
|
str
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
'Lorentzian'
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the display name of the diffusion model. |
None
|
delta_name
|
str
|
Name of the delta function component. |
'Delta function'
|
delta_display_name
|
str | None
|
Display name of the delta function component. If None, it will be set to the display name of the delta function component. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If delta_name is not a string or if delta_display_name is not a string or None. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_component_collections |
Get the ComponentCollection at the given Q index. |
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. If the width is |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF) for the diffusion model. |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollections for the DeltaLorentz model at given Q values. |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_all_variables |
Get a list of all variables (Parameters and Descriptors) in the model. |
__repr__ |
String representation of the DeltaLorentz model. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
mean_u_squared |
Parameter
|
Get the mean square displacement parameter. |
A_0 |
Parameter
|
Get the amplitude of the delta function. |
A_1 |
Parameter
|
Get the amplitude of the Lorentzian function. |
lorentzian_width |
Parameter
|
Get the width of the Lorentzian function. |
delta_name |
str
|
Get the name of the delta function component. |
delta_display_name |
str
|
Get the display name of the delta function component. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
mean_u_squared
property
writable
Get the mean square displacement parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
Mean square displacement in angstrom^2. |
A_0
property
writable
Get the amplitude of the delta function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Amplitude of the delta function. |
A_1
property
writable
Get the amplitude of the Lorentzian function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Amplitude of the Lorentzian function. |
lorentzian_width
property
writable
Get the width of the Lorentzian function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Width of the Lorentzian function. |
delta_name
property
writable
Get the name of the delta function component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the delta function component. |
delta_display_name
property
writable
Get the display name of the delta function component.
Returns:
| Type | Description |
|---|---|
str
|
Display name of the delta function component. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. If the width is allowed to vary with Q then the Q stored in the model is used and the input is ignored. If the width is not allowed to vary then the same width is returned for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q=None)
Calculate the Elastic Incoherent Structure Factor (EISF) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q=None)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollections for the DeltaLorentz model at given Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian and delta function components for each Q value. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_all_variables(Q_index=None)
Get a list of all variables (Parameters and Descriptors) in the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the variables. If None, variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[DescriptorNumber]
|
List of all variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
__repr__()
String representation of the DeltaLorentz model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the DeltaLorentz model. |
JumpTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, relaxation_time=1.0, Q=None, unit='meV', name='JumpTranslationalDiffusion', display_name='JumpTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Jump translational diffusion.
The model consists of a Lorentzian function for each Q-value, where the width is given by
where \(D\) is the diffusion coefficient and \(t\) is the relaxation time. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> relaxation_time = 1.0 # ps
>>> diffusion_model = JumpTranslationalDiffusion(
... scale=scale,
... diffusion_coefficient=diffusion_coefficient,
... relaxation_time=relaxation_time,
... Q=Q,
... )
>>> component_collections = diffusion_model.create_component_collections()
See also the tutorials..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
relaxation_time
|
Numeric
|
Relaxation time t in ps. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'JumpTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'JumpTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model with '_Lorentzian' appended. By default, None. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the display name of the diffusion model with '_Lorentzian' appended. By default, None |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale, diffusion_coefficient, or relaxation_time are not numbers. |
ValueError
|
If scale, diffusion_coefficient, or relaxation_time are negative. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. $\Gamma(Q) = |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF). |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the diffusion model at given Q values. |
__repr__ |
String representation of the JumpTranslationalDiffusion model. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
relaxation_time |
Parameter
|
Get the relaxation time parameter t. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D. |
relaxation_time
property
writable
Get the relaxation time parameter t.
Returns:
| Type | Description |
|---|---|
Parameter
|
Relaxation time t in ps. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. \(\Gamma(Q) = Q^2/(1+D t Q^2)\), where \(D\) is the diffusion coefficient and \(t\) is the relaxation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. If None, Q values stored in the model are used. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the diffusion model at given Q values.
TypeError If component_display_name is not a string. If component_name is not a string.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Jump Diffusion Lorentzian components. |
__repr__()
String representation of the JumpTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the JumpTranslationalDiffusion model. |
InstrumentModel(display_name='MyInstrumentModel', unique_name=None, Q=None, resolution_model=None, background_model=None, energy_offset=None, unit='meV')
InstrumentModel represents a model of the instrument in an experiment at various Q.
It can contain a model of the resolution function for convolutions, of the background and an offset in the energy axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
The display name of the InstrumentModel. |
'MyInstrumentModel'
|
unique_name
|
str | None
|
The unique name of the InstrumentModel. |
None
|
Q
|
Q_type | None
|
The Q values where the instrument is modelled. |
None
|
resolution_model
|
ResolutionModel | SampleModel | None
|
The resolution model of the instrument. If a SampleModel it will be converted to a ResolutionModel. If None, an empty resolution model is created and no resolution convolution is carried out. |
None
|
background_model
|
BackgroundModel | None
|
The background model of the instrument. If None, an empty background model is created, and the background evaluates to 0. |
None
|
energy_offset
|
Numeric | None
|
Template energy offset of the instrument. Will be copied to each Q value. If None, the energy offset will be 0. |
None
|
unit
|
str | sc.Unit
|
The unit of the energy axis. |
'meV'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If resolution_model is not a ResolutionModel or None, or if background_model is not a BackgroundModel or None, or if energy_offset is not a number or None. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object from a full encoded |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
clear_Q |
Clear the Q values of the InstrumentModel and any associated ResolutionModel and |
convert_unit |
Convert the unit of the InstrumentModel. |
get_all_variables |
Get all variables in the InstrumentModel. |
fix_resolution_parameters |
Fix all parameters in the resolution model. |
free_resolution_parameters |
Free all parameters in the resolution model. |
normalize_resolution |
Normalize the resolution model to have area 1. |
get_energy_offset |
Get the energy offset Parameter at a specific Q index. |
fix_energy_offset |
Fix energy offset parameters. |
free_energy_offset |
Free energy offset parameters. |
__repr__ |
Return a string representation of the InstrumentModel. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
resolution_model |
ResolutionModel
|
Get the resolution model of the instrument. |
background_model |
BackgroundModel
|
Get the background model of the instrument. |
Q |
np.ndarray | None
|
Get the Q values of the InstrumentModel. |
unit |
str | sc.Unit
|
Get the unit of the InstrumentModel. |
energy_offset |
Parameter
|
Get the energy offset template parameter of the instrument model. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
resolution_model
property
writable
Get the resolution model of the instrument.
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
The resolution model of the instrument. |
background_model
property
writable
Get the background model of the instrument.
Returns:
| Type | Description |
|---|---|
BackgroundModel
|
The background model of the instrument. |
Q
property
writable
Get the Q values of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the InstrumentModel, or None if not set. |
unit
property
writable
Get the unit of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the InstrumentModel. |
energy_offset
property
writable
Get the energy offset template parameter of the instrument model.
Returns:
| Type | Description |
|---|---|
Parameter
|
The energy offset template parameter of the instrument model. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
clear_Q(confirm=False)
Clear the Q values of the InstrumentModel and any associated ResolutionModel and BackgroundModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit_str)
Convert the unit of the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_str
|
str | sc.Unit
|
The unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unit_str is not a valid unit string or scipp Unit. |
get_all_variables(Q_index=None)
Get all variables in the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get variables for. If None, get variables for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the Q values in the InstrumentModel. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all variables in the InstrumentModel. If Q_index is specified, only variables from the ComponentCollection at the given Q index are included. Otherwise, all variables in the InstrumentModel are included. |
fix_resolution_parameters()
Fix all parameters in the resolution model.
free_resolution_parameters()
Free all parameters in the resolution model.
normalize_resolution()
Normalize the resolution model to have area 1.
get_energy_offset(Q_index=None)
Get the energy offset Parameter at a specific Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get the energy offset for. If None, get the energy offset for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no Q values are set in the InstrumentModel. |
IndexError
|
If Q_index is out of bounds. |
TypeError
|
If Q_index is not an int or None. |
Returns:
| Type | Description |
|---|---|
Parameter | list[Parameter]
|
The energy offset Parameter at the specified Q index, or a list of Parameters if Q_index is None. |
fix_energy_offset(Q_index=None)
Fix energy offset parameters.
If Q_index is specified, only fix the energy offset for that Q value. If Q_index is None, fix energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to fix the energy offset for. If None, fix energy offsets for all Q values. |
None
|
free_energy_offset(Q_index=None)
Free energy offset parameters.
If Q_index is specified, only free the energy offset for that Q value. If Q_index is None, free energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to free the energy offset for. If None, free energy offsets for all Q values. |
None
|
__repr__()
Return a string representation of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the InstrumentModel. |
ResolutionModel(display_name='MyResolutionModel', unique_name=None, unit='meV', components=None, Q=None)
ResolutionModel represents a model of the instrment resolution in an experiment at various Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyResolutionModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
__repr__ |
Return a string representation of the ModelBase. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
evaluate |
Evaluate the sample model at all Q for the given x values. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
append_component |
Append a component to the ResolutionModel. |
from_sample_model |
Create a ResolutionModel from a SampleModel. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
append_component(component)
Append a component to the ResolutionModel.
Does not allow DeltaFunction or Polynomial components, as these are not physical resolution components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
Component(s) to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the component is a DeltaFunction or Polynomial. |
from_sample_model(sample_model, normalize_area=True, fix_parameters=True)
classmethod
Create a ResolutionModel from a SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_model
|
SampleModel
|
SampleModel to create the ResolutionModel from. |
required |
normalize_area
|
bool
|
Whether to normalize the components in the ResolutionModel to have area 1. |
True
|
fix_parameters
|
bool
|
Whether to fix the parameters in the ResolutionModel. |
True
|
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
ResolutionModel created from the SampleModel. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sample_model is not a SampleModel, or if normalize_area or fix_parameters are not bool. |
SampleModel(display_name='MySampleModel', unique_name=None, unit='meV', components=None, Q=None, diffusion_models=None, temperature=None, temperature_unit='K', detailed_balance_settings=None)
SampleModel represents a model of a sample with components and diffusion models, parameterized by Q and optionally temperature. Generates ComponentCollections for each Q value, combining components from the base model and diffusion models.
Applies detailed balancing based on temperature if provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MySampleModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. If None,. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
diffusion_models
|
DiffusionModelBase | list[DiffusionModelBase] | None
|
Diffusion models to include in the SampleModel. If None, no diffusion models are added. |
None
|
temperature
|
float | None
|
Temperature for detailed balancing. If None, no detailed balancing is applied. By default, None. |
None
|
temperature_unit
|
str | sc.Unit
|
Unit of the temperature. |
'K'
|
detailed_balance_settings
|
DetailedBalanceSettings | None
|
Settings for detailed balancing. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If diffusion_models is not a DiffusionModelBase, a list of DiffusionModelBase, or None, or if temperature is not a number or None, or if detailed_balance_settings is not a DetailedBalanceSettings instance. |
ValueError
|
If temperature is negative. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
append_component |
Append a ModelComponent or ComponentCollection to the SampleModel. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
append_diffusion_model |
Append a DiffusionModel to the SampleModel. |
remove_diffusion_model |
Remove a DiffusionModel from the SampleModel by name. |
clear_diffusion_models |
Clear all DiffusionModels from the SampleModel. |
convert_temperature_unit |
Convert the unit of the temperature Parameter. |
evaluate |
Evaluate the sample model at all Q for the given x values. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel. |
__repr__ |
Return a string representation of the SampleModel. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
diffusion_models |
list[DiffusionModelBase]
|
Get the diffusion models of the SampleModel. |
temperature |
Parameter | None
|
Get the temperature of the SampleModel. |
temperature_unit |
str | sc.Unit
|
Get the temperature unit of the SampleModel. |
normalize_detailed_balance |
bool
|
Get whether to divide the detailed balance factor by temperature. |
use_detailed_balance |
bool
|
Get whether to apply detailed balance to the model. |
detailed_balance_settings |
DetailedBalanceSettings
|
Get the DetailedBalanceSettings of the SampleModel. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
diffusion_models
property
writable
Get the diffusion models of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[DiffusionModelBase]
|
The diffusion models of the SampleModel. |
temperature
property
writable
Get the temperature of the SampleModel.
Returns:
| Type | Description |
|---|---|
Parameter | None
|
The temperature Parameter of the SampleModel, or None if not set. |
temperature_unit
property
writable
Get the temperature unit of the SampleModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the temperature Parameter. |
normalize_detailed_balance
property
writable
Get whether to divide the detailed balance factor by temperature.
Returns:
| Type | Description |
|---|---|
bool
|
True if the detailed balance factor is divided by temperature, False otherwise. |
use_detailed_balance
property
writable
Get whether to apply detailed balance to the model.
Returns:
| Type | Description |
|---|---|
bool
|
True if detailed balance is applied, False otherwise. |
detailed_balance_settings
property
writable
Get the DetailedBalanceSettings of the SampleModel.
Returns:
| Type | Description |
|---|---|
DetailedBalanceSettings
|
The DetailedBalanceSettings of the SampleModel. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
append_diffusion_model(diffusion_model)
Append a DiffusionModel to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_model
|
DiffusionModelBase
|
The DiffusionModel to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the diffusion_model is not a DiffusionModelBase. |
remove_diffusion_model(name)
Remove a DiffusionModel from the SampleModel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the DiffusionModel to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no DiffusionModel with the given name is found. |
clear_diffusion_models()
Clear all DiffusionModels from the SampleModel.
convert_temperature_unit(unit)
Convert the unit of the temperature Parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit to convert the temperature Parameter to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature is not set or conversion fails. |
Exception
|
If the provided unit is invalid or cannot be converted. |
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values to evaluate the model at. Can be a number, list, numpy array, scipp Variable, or scipp DataArray. |
required |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
List of evaluated model values for each Q. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel.
Also includes temperature if set and all variables from diffusion models. Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If specified, only get variables from the ComponentCollection at the given Q index. If None, get variables from all ComponentCollections. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all Parameters and Descriptors, including temperature if set and all variables from diffusion models. |
__repr__()
Return a string representation of the SampleModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the SampleModel. |
Modules
background_model
Classes:
| Name | Description |
|---|---|
BackgroundModel |
BackgroundModel represents a model of the background in an experiment at various Q. |
Classes
BackgroundModel(display_name='MyBackgroundModel', unique_name=None, unit='meV', components=None, Q=None)
BackgroundModel represents a model of the background in an experiment at various Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None
|
Display name of the model. |
'MyBackgroundModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
__repr__ |
Return a string representation of the ModelBase. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
evaluate |
Evaluate the sample model at all Q for the given x values. |
append_component |
Append a ModelComponent or ComponentCollection to the SampleModel. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
component_collection
Classes:
| Name | Description |
|---|---|
ComponentCollection |
Collection of model components. |
Classes
ComponentCollection(components=None, unit='meV', name='ComponentCollection', display_name=None, unique_name=None)
Collection of model components.
Examples:
Create a ComponentCollection with two components:
>>> import easydynamics.sample_model as sm
>>> component1 = sm.Gaussian(name='Gaussian1', area=1.0, width=1.0)
>>> component2 = sm.Lorentzian(name='Lorentzian1', area=2.0, width=0.5)
>>> collection = sm.ComponentCollection(components=[component1, component2])
Append a component to the collection:
>>> component3 = sm.Gaussian(name='Gaussian2', area=0.5, width=0.8)
>>> collection.append(component3)
Evaluate the collection at a given energy axis:
>>> import numpy as np
>>> x = np.linspace(-5, 5, 100)
>>> values = collection.evaluate(x)
Remove a component by name:
>>> collection.remove('Gaussian1')
List component names:
>>> collection.list_component_names()
['Lorentzian1', 'Gaussian2']
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ModelComponent | list[ModelComponent] | None
|
Initial model components to add to the ComponentCollection. |
None
|
unit
|
str | sc.Unit
|
Unit of the collection. |
'meV'
|
name
|
str
|
Name of the collection. |
'ComponentCollection'
|
display_name
|
str | None
|
Display name of the collection. |
None
|
unique_name
|
str | None
|
Unique name of the collection. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If components is not a list of ModelComponent. |
Methods:
| Name | Description |
|---|---|
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
append_component |
Append a model component or the components from another ComponentCollection to this |
list_component_names |
List the names of all components in the model. |
normalize_area |
Normalize the areas of all components so they sum to 1. |
get_all_variables |
Get all parameters from the model component. |
evaluate |
Evaluate the sum of all components. |
evaluate_component |
Evaluate a single component by name. |
fix_all_parameters |
Fix all free parameters in the model. |
free_all_parameters |
Free all fixed parameters in the model. |
__repr__ |
Return a string representation of the ComponentCollection. |
__copy__ |
Create a deep copy of the ComponentCollection. |
__dir__ |
This creates auto-completion and helps out in iPython |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
__getitem__ |
Get an item by index, slice, or unique_name. |
__setitem__ |
Set an item at an index. |
__delitem__ |
Delete an item by index, slice, or name. |
__len__ |
Return the number of items in the collection. |
insert |
Insert an item into the list at a specific index. |
sort |
Sort the collection according to the given key function. |
pop |
Remove and return an item at a specific index or name. |
append |
Append an item to the end of the list. |
get_names |
Get a list of the names of all items in the list. |
get_duplicate_names |
Get a list of duplicate names in the list. |
Attributes:
| Name | Type | Description |
|---|---|---|
is_empty |
bool
|
Check if the ComponentCollection has no components. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
Attributes
is_empty
property
writable
Check if the ComponentCollection has no components.
Returns:
| Type | Description |
|---|---|
bool
|
True if the collection has no components, False otherwise. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
Functions
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If any component cannot be converted to the specified unit. |
append_component(component)
Append a model component or the components from another ComponentCollection to this ComponentCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The component to append. If a ComponentCollection is provided, all of its components will be appended. |
required |
list_component_names()
List the names of all components in the model.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of names of the components in the collection. |
normalize_area()
Normalize the areas of all components so they sum to 1.
This is useful for convolutions.
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model or if the total area is zero or not finite, which would prevent normalization. |
get_all_variables()
Get all parameters from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of parameters in the component. |
evaluate(x)
Evaluate the sum of all components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated model values. |
evaluate_component(x, name)
Evaluate a single component by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis. |
required |
name
|
str
|
Component name. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model. |
TypeError
|
If name is not a string. |
KeyError
|
If no component with the given name exists in the collection. |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated values for the specified component. |
fix_all_parameters()
Fix all free parameters in the model.
free_all_parameters()
Free all fixed parameters in the model.
__repr__()
Return a string representation of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ComponentCollection. |
__copy__()
Create a deep copy of the ComponentCollection.
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
A deep copy of the ComponentCollection. |
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
__getitem__(idx)
Get an item by index, slice, or unique_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int | slice | str
|
|
required |
Returns:
| Type | Description |
|---|---|
ProtectedType_ | EasyDynamicsList[ProtectedType_]
|
The item at the specified index or name, or a new EasyDynamicsList if a slice is provided. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If idx is not an int, slice, or str. |
KeyError
|
If idx is a str and no item with that name is found. |
AmbiguousNameError
|
If idx is a str and multiple items with that name are found. |
__setitem__(idx, value)
__setitem__(idx: int, value: ProtectedType_) -> None
__setitem__(
idx: slice, value: Iterable[ProtectedType_]
) -> None
Set an item at an index.
:param idx: Index to set :param value: New value
__delitem__(idx)
Delete an item by index, slice, or name.
:param idx: Index, slice, or name of item to delete
__len__()
Return the number of items in the collection.
insert(index, value)
Insert an item into the list at a specific index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index at which to insert the item. |
required |
value
|
ProtectedType_
|
The item to insert. Must be an instance of one of the protected types. |
required |
sort(key=None, reverse=False)
Sort the collection according to the given key function.
:param key: Mapping function to sort by :param reverse: Whether to reverse the sort
pop(index=-1)
Remove and return an item at a specific index or name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | str
|
The index or name at which to pop the item. |
-1
|
Returns:
| Type | Description |
|---|---|
ProtectedType_
|
The item that was popped. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If index is not an int or str. |
KeyError
|
If index is a str and no item with that name is found. |
append(value)
Append an item to the end of the list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
ProtectedType_
|
The item to append. Must be an instance of one of the protected types. |
required |
get_names()
Get a list of the names of all items in the list.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of the names of all items in the list. |
get_duplicate_names()
Get a list of duplicate names in the list.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of duplicate names in the list. |
components
Modules:
| Name | Description |
|---|---|
damped_harmonic_oscillator |
|
delta_function |
|
exponential |
|
expression_component |
|
gaussian |
|
lorentzian |
|
mixins |
|
model_component |
|
polynomial |
|
voigt |
|
Classes:
| Name | Description |
|---|---|
DampedHarmonicOscillator |
Model of a Damped Harmonic Oscillator (DHO). |
DeltaFunction |
Delta function. |
Exponential |
Model of an exponential function. |
ExpressionComponent |
Model component defined by a symbolic expression. |
Gaussian |
Model of a Gaussian function. |
Lorentzian |
Model of a Lorentzian function. |
Polynomial |
Polynomial function component. |
Voigt |
Voigt profile, a convolution of Gaussian and Lorentzian. |
Classes
DampedHarmonicOscillator(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area under the curve. |
1.0
|
center
|
Numeric
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Damped Harmonic Oscillator at the given x values. |
__repr__ |
Return a string representation of the Damped Harmonic Oscillator. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
DeltaFunction(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Delta function at the given x values. |
__repr__ |
Return a string representation of the Delta function. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
Exponential(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
evaluate |
Evaluate the Exponential at the given x values. |
convert_unit |
Convert the unit of the Parameters in the component. |
__repr__ |
Return a string representation of the Exponential. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
amplitude |
Parameter
|
Get the amplitude parameter. |
center |
Parameter
|
Get the center parameter. |
rate |
Parameter
|
Get the rate parameter. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
ExpressionComponent(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Model component defined by a symbolic expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
evaluate |
Evaluate the expression for given x values. |
get_all_variables |
Return all parameters. |
convert_unit |
Convert the unit of the expression. |
__getattr__ |
Allow access to parameters as attributes. |
__setattr__ |
Allow setting parameter values as attributes. |
__dir__ |
Include parameter names in dir() output for better IDE support. |
__repr__ |
Return a string representation of the ExpressionComponent. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
expression |
str
|
Return the original expression string. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
Gaussian(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Gaussian at the given x values. |
__repr__ |
Return a string representation of the Gaussian. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (standard deviation). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
Lorentzian(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Lorentzian at the given x values. |
__repr__ |
Return a string representation of the Lorentzian. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (HWHM). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
Polynomial(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
coefficient_values |
Get the coefficients of the polynomial as a list. |
evaluate |
Evaluate the Polynomial at the given x values. |
get_all_variables |
Get all variables from the model component. |
convert_unit |
Convert the unit of the polynomial. |
__repr__ |
Return a string representation of the Polynomial. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
coefficients |
list[Parameter]
|
Get the coefficients of the polynomial as a list of Parameters. |
degree |
int
|
Get the degree of the polynomial. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
Voigt(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Evaluate the Voigt at the given x values. |
__repr__ |
Return a string representation of the Voigt. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
gaussian_width |
Parameter
|
Get the Gaussian width parameter. |
lorentzian_width |
Parameter
|
Get the Lorentzian width parameter (HWHM). |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
Modules
damped_harmonic_oscillator
Classes:
| Name | Description |
|---|---|
DampedHarmonicOscillator |
Model of a Damped Harmonic Oscillator (DHO). |
Classes
DampedHarmonicOscillator(area=1.0, center=1.0, width=1.0, unit='meV', name='DampedHarmonicOscillator', display_name=None, unique_name=None)
Model of a Damped Harmonic Oscillator (DHO).
The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area under the curve. |
1.0
|
center
|
Numeric
|
Resonance frequency, approximately the peak position. |
1.0
|
width
|
Numeric
|
Damping constant, approximately the half width at half max (HWHM) of the peaks. By default, 1.0. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DampedHarmonicOscillator'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Damped Harmonic Oscillator at the given x values. |
__repr__ |
Return a string representation of the Damped Harmonic Oscillator. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
Attributes:
| Name | Type | Description |
|---|---|---|
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Damped Harmonic Oscillator at the given x values.
If x is a scipp Variable, the unit of the DHO will be converted to match x. The intensity is given by $$ I(x) = \frac{2 A x_0^2 \gamma}{\pi \left( (x^2 - x_0^2)^2 + (2 \gamma x)^2 \right)}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\gamma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the DHO. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the DHO at the given x values. |
__repr__()
Return a string representation of the Damped Harmonic Oscillator.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Damped Harmonic Oscillator. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
delta_function
Classes:
| Name | Description |
|---|---|
DeltaFunction |
Delta function. |
Classes
DeltaFunction(center=None, area=1.0, unit='meV', name='DeltaFunction', display_name=None, unique_name=None)
Delta function.
Evaluates to zero everywhere, except in convolutions, where it acts as an identity. This is handled by the Convolution method. If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Numeric | None
|
Center of the delta function. If None, it will be centered at 0 and fixed. |
None
|
area
|
Numeric
|
Total area under the curve. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'DeltaFunction'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Delta function at the given x values. |
__repr__ |
Return a string representation of the Delta function. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
Attributes:
| Name | Type | Description |
|---|---|---|
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Delta function at the given x values.
The Delta function evaluates to zero everywhere, except at the center. Its numerical integral is equal to the area. It acts as an identity in convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Delta function. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Delta function at the given x values. |
__repr__()
Return a string representation of the Delta function.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Delta function. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
exponential
Classes:
| Name | Description |
|---|---|
Exponential |
Model of an exponential function. |
Classes
Exponential(amplitude=1.0, center=None, rate=1.0, unit='meV', name='Exponential', display_name=None, unique_name=None)
Model of an exponential function.
The intensity is given by
where \(A\) is the amplitude, \(x_0\) is the center, and \(B\) describes the rate of decay or growth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amplitude
|
Numeric
|
Amplitude of the Exponential. |
1.0
|
center
|
Numeric | None
|
Center of the Exponential. If None, the center is fixed at 0. |
None
|
rate
|
Numeric
|
Decay or growth constant of the Exponential. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Exponential'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If amplitude, center, or rate are not numbers or Parameters. |
ValueError
|
If amplitude, center or rate are not finite numbers. |
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Exponential at the given x values. |
convert_unit |
Convert the unit of the Parameters in the component. |
__repr__ |
Return a string representation of the Exponential. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
Attributes:
| Name | Type | Description |
|---|---|---|
amplitude |
Parameter
|
Get the amplitude parameter. |
center |
Parameter
|
Get the center parameter. |
rate |
Parameter
|
Get the rate parameter. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
amplitude
property
writable
Get the amplitude parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The amplitude parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
rate
property
writable
Get the rate parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The rate parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Exponential at the given x values.
If x is a scipp Variable, the unit of the Exponential will be converted to match x. The intensity is given by $$ I(x) = A \exp\left( r (x - x_0) \right) $$
where \(A\) is the amplitude, \(x_0\) is the center, and \(r\) is the rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Exponential. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Exponential at the given x values. |
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If unit is not a string or sc.Unit. |
Exception
|
If conversion fails for any parameter. |
__repr__()
Return a string representation of the Exponential.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Exponential. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
expression_component
Classes:
| Name | Description |
|---|---|
ExpressionComponent |
Model component defined by a symbolic expression. |
Classes
ExpressionComponent(expression, parameters=None, unit='meV', name='Expression', display_name=None, unique_name=None)
Model component defined by a symbolic expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
The symbolic expression as a string. Must contain 'x' as the independent variable. |
required |
parameters
|
dict[str, Numeric] | None
|
Dictionary of parameter names and their initial values. |
None
|
unit
|
str | sc.Unit
|
Unit of the output. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Expression'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name for the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is invalid or does not contain 'x'. |
TypeError
|
If any parameter value is not numeric. |
Examples:
>>> expr = ExpressionComponent(
... 'A * exp(-(x - x0)**2 / (2*sigma**2))',
... parameters={'A': 10, 'x0': 0, 'sigma': 1},
... unit='meV',
... display_name='Gaussian Peak',
... )
>>> expr.A = 5
>>> y = expr.evaluate(x)
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the expression for given x values. |
get_all_variables |
Return all parameters. |
convert_unit |
Convert the unit of the expression. |
__getattr__ |
Allow access to parameters as attributes. |
__setattr__ |
Allow setting parameter values as attributes. |
__dir__ |
Include parameter names in dir() output for better IDE support. |
__repr__ |
Return a string representation of the ExpressionComponent. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
Attributes:
| Name | Type | Description |
|---|---|---|
expression |
str
|
Return the original expression string. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
expression
property
writable
Return the original expression string.
Returns:
| Type | Description |
|---|---|
str
|
The original expression string provided at initialization. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the expression for given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Input values for the independent variable. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated results. |
get_all_variables()
Return all parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all parameters in the expression. |
convert_unit(_new_unit)
Convert the unit of the expression.
Unit conversion is not implemented for ExpressionComponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_new_unit
|
str | sc.Unit
|
The new unit to convert to (ignored). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised to indicate unit conversion is not supported. |
__getattr__(name)
Allow access to parameters as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to access. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the parameter does not exist. |
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter with the given name. |
__setattr__(name, value)
Allow setting parameter values as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parameter to set. |
required |
value
|
Numeric
|
New value for the parameter. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not numeric. |
__dir__()
Include parameter names in dir() output for better IDE support.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of attribute names, including parameters. |
__repr__()
Return a string representation of the ExpressionComponent.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the ExpressionComponent. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
gaussian
Classes:
| Name | Description |
|---|---|
Gaussian |
Model of a Gaussian function. |
Classes
Gaussian(area=1.0, center=None, width=1.0, unit='meV', name='Gaussian', display_name=None, unique_name=None)
Model of a Gaussian function.
The intensity is given by
$$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Gaussian. |
1.0
|
center
|
Numeric | None
|
Center of the Gaussian. If None. |
None
|
width
|
Numeric
|
Standard deviation. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Gaussian'
|
display_name
|
str | None
|
Name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. if None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Gaussian at the given x values. |
__repr__ |
Return a string representation of the Gaussian. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
Attributes:
| Name | Type | Description |
|---|---|---|
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (standard deviation). |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (standard deviation).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Gaussian at the given x values.
If x is a scipp Variable, the unit of the Gaussian will be converted to match x. The intensity is given by $$ I(x) = \frac{A}{\sigma \sqrt{2\pi}} \exp\left( -\frac{1}{2} \left(\frac{x - x_0}{\sigma}\right)^2 \right) $$
where \(A\) is the area, \(x_0\) is the center, and \(\sigma\) is the width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Gaussian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Gaussian at the given x values. |
__repr__()
Return a string representation of the Gaussian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Gaussian. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
lorentzian
Classes:
| Name | Description |
|---|---|
Lorentzian |
Model of a Lorentzian function. |
Classes
Lorentzian(area=1.0, center=None, width=1.0, unit='meV', name='Lorentzian', display_name=None, unique_name=None)
Model of a Lorentzian function.
The intensity is given by $$ I(x) = \frac{A}{\pi} \frac{\Gamma}{(x - x_0)^2 + \Gamma^2}, $$ where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric
|
Area of the Lorentzian. |
1.0
|
center
|
Numeric | None
|
Center of the Lorentzian. If None, defaults to 0 and is fixed. |
None
|
width
|
Numeric
|
Half width at half maximum (HWHM). |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Lorentzian'
|
display_name
|
str | None
|
Display name for the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Lorentzian at the given x values. |
__repr__ |
Return a string representation of the Lorentzian. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
Attributes:
| Name | Type | Description |
|---|---|---|
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
width |
Parameter
|
Get the width parameter (HWHM). |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
width
property
writable
Get the width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The width parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Lorentzian at the given x values.
If x is a scipp Variable, the unit of the Lorentzian will be converted to match x. The intensity is given by
where \(A\) is the area, \(x_0\) is the center, and \(\Gamma\) is the half width at half maximum (HWHM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Lorentzian. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Lorentzian at the given x values. |
__repr__()
Return a string representation of the Lorentzian.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Lorentzian. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
mixins
Classes:
| Name | Description |
|---|---|
CreateParametersMixin |
Provides parameter creation and validation methods for model components. |
Classes
CreateParametersMixin
Provides parameter creation and validation methods for model components.
This mixin provides methods to create and validate common physics parameters (area, center, width) with appropriate bounds and type checking.
model_component
Classes:
| Name | Description |
|---|---|
ModelComponent |
Abstract base class for all model components. |
Classes
ModelComponent(unit='meV', name='ModelComponent', display_name=None, unique_name=None)
Abstract base class for all model components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit of the model component. |
'meV'
|
name
|
str
|
The name of the model component for indexing. |
'ModelComponent'
|
display_name
|
str | None
|
A human-readable name for the component. |
None
|
unique_name
|
str | None
|
A unique identifier for the component. |
None
|
Methods:
| Name | Description |
|---|---|
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
evaluate |
Abstract method to evaluate the model component at input x. |
__repr__ |
Return a string representation of the ModelComponent. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
str
|
Get the unit. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
evaluate(x)
abstractmethod
Abstract method to evaluate the model component at input x.
Must be implemented by subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the component. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Evaluated function values. |
__repr__()
Return a string representation of the ModelComponent.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelComponent. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
polynomial
Classes:
| Name | Description |
|---|---|
Polynomial |
Polynomial function component. |
Classes
Polynomial(coefficients=(0.0,), unit='meV', name='Polynomial', display_name=None, unique_name=None)
Polynomial function component.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
Sequence[Numeric | Parameter]
|
Coefficients c0, c1, ..., cN. |
(0.0,)
|
unit
|
str | sc.Unit
|
Unit of the Polynomial component. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Polynomial'
|
display_name
|
str | None
|
Display name of the Polynomial component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coefficients is not a sequence of numbers or Parameters or if any item in coefficients is not a number or Parameter. |
ValueError
|
If coefficients is an empty sequence. |
Methods:
| Name | Description |
|---|---|
coefficient_values |
Get the coefficients of the polynomial as a list. |
evaluate |
Evaluate the Polynomial at the given x values. |
get_all_variables |
Get all variables from the model component. |
convert_unit |
Convert the unit of the polynomial. |
__repr__ |
Return a string representation of the Polynomial. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
Attributes:
| Name | Type | Description |
|---|---|---|
coefficients |
list[Parameter]
|
Get the coefficients of the polynomial as a list of Parameters. |
degree |
int
|
Get the degree of the polynomial. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
coefficients
property
writable
Get the coefficients of the polynomial as a list of Parameters.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The coefficients of the polynomial. |
degree
property
writable
Get the degree of the polynomial.
Returns:
| Type | Description |
|---|---|
int
|
The degree of the polynomial. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
coefficient_values()
Get the coefficients of the polynomial as a list.
Returns:
| Type | Description |
|---|---|
list[float]
|
The coefficient values of the polynomial. |
evaluate(x)
Evaluate the Polynomial at the given x values.
The intensity is given by $$ I(x) = c_0 + c_1 x + c_2 x^2 + ... + c_N x^N, $$ where \(C_i\) are the coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Polynomial. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The evaluated Polynomial at the given x values. |
get_all_variables()
Get all variables from the model component.
Returns:
| Type | Description |
|---|---|
list[DescriptorBase]
|
List of variables in the component. |
convert_unit(unit)
Convert the unit of the polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The target unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the provided unit is not a string or sc.Unit. |
__repr__()
Return a string representation of the Polynomial.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Polynomial. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
voigt
Classes:
| Name | Description |
|---|---|
Voigt |
Voigt profile, a convolution of Gaussian and Lorentzian. |
Classes
Voigt(area=1.0, center=None, gaussian_width=1.0, lorentzian_width=1.0, unit='meV', name='Voigt', display_name=None, unique_name=None)
Voigt profile, a convolution of Gaussian and Lorentzian.
If the center is not provided, it will be centered at 0 and fixed, which is typically what you want in QENS.
Use scipy.special.voigt_profile to evaluate the Voigt profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area
|
Numeric | Parameter
|
Total area under the curve. |
1.0
|
center
|
Numeric | Parameter | None
|
Center of the Voigt profile. |
None
|
gaussian_width
|
Numeric | Parameter
|
Standard deviation of the Gaussian part. |
1.0
|
lorentzian_width
|
Numeric | Parameter
|
Half width at half max (HWHM) of the Lorentzian part. |
1.0
|
unit
|
str | sc.Unit
|
Unit of the parameters. |
'meV'
|
name
|
str
|
Name of the component for indexing. |
'Voigt'
|
display_name
|
str | None
|
Display name of the component. |
None
|
unique_name
|
str | None
|
Unique name of the component. If None, a unique_name is automatically generated. By default, None. |
None
|
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the Voigt at the given x values. |
__repr__ |
Return a string representation of the Voigt. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
fix_all_parameters |
Fix all parameters in the model component. |
free_all_parameters |
Free all parameters in the model component. |
convert_unit |
Convert the unit of the Parameters in the component. |
Attributes:
| Name | Type | Description |
|---|---|---|
area |
Parameter
|
Get the area parameter. |
center |
Parameter
|
Get the center parameter. |
gaussian_width |
Parameter
|
Get the Gaussian width parameter. |
lorentzian_width |
Parameter
|
Get the Lorentzian width parameter (HWHM). |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str
|
Get the unit. |
area
property
writable
Get the area parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The area parameter. |
center
property
writable
Get the center parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The center parameter. |
gaussian_width
property
writable
Get the Gaussian width parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
The Gaussian width parameter. |
lorentzian_width
property
writable
Get the Lorentzian width parameter (HWHM).
Returns:
| Type | Description |
|---|---|
Parameter
|
The Lorentzian width parameter. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
The unit of the model component. |
evaluate(x)
Evaluate the Voigt at the given x values.
If x is a scipp Variable, the unit of the Voigt will be converted to match x. The Voigt evaluates to the convolution of a Gaussian with sigma gaussian_width and a Lorentzian with half width at half max lorentzian_width, centered at center, with area equal to area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values at which to evaluate the Voigt. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
The intensity of the Voigt at the given x values. |
__repr__()
Return a string representation of the Voigt.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the Voigt. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables()
Get all Descriptor and Parameter objects as a list.
:return: List of Descriptor and Parameter objects.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
fix_all_parameters()
Fix all parameters in the model component.
free_all_parameters()
Free all parameters in the model component.
convert_unit(unit)
Convert the unit of the Parameters in the component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a str or sc.Unit. |
Exception
|
If the provided unit is invalid or incompatible with the component's parameters. |
diffusion_model
Modules:
| Name | Description |
|---|---|
brownian_translational_diffusion |
|
delta_lorentz |
|
diffusion_model_base |
|
jump_translational_diffusion |
|
Classes:
| Name | Description |
|---|---|
BrownianTranslationalDiffusion |
Model of Brownian translational diffusion, consisting of a Lorentzian function for each |
JumpTranslationalDiffusion |
Model of Jump translational diffusion. |
Classes
BrownianTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, Q=None, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the lorentzian_name. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
ValueError
|
If scale or diffusion_coefficient is negative. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the Brownian translational diffusion model at |
__repr__ |
String representation of the BrownianTranslationalDiffusion model. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q=None)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q=None)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
JumpTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, relaxation_time=1.0, Q=None, unit='meV', name='JumpTranslationalDiffusion', display_name='JumpTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Jump translational diffusion.
The model consists of a Lorentzian function for each Q-value, where the width is given by
where \(D\) is the diffusion coefficient and \(t\) is the relaxation time. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> relaxation_time = 1.0 # ps
>>> diffusion_model = JumpTranslationalDiffusion(
... scale=scale,
... diffusion_coefficient=diffusion_coefficient,
... relaxation_time=relaxation_time,
... Q=Q,
... )
>>> component_collections = diffusion_model.create_component_collections()
See also the tutorials..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
relaxation_time
|
Numeric
|
Relaxation time t in ps. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'JumpTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'JumpTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model with '_Lorentzian' appended. By default, None. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the display name of the diffusion model with '_Lorentzian' appended. By default, None |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale, diffusion_coefficient, or relaxation_time are not numbers. |
ValueError
|
If scale, diffusion_coefficient, or relaxation_time are negative. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. $\Gamma(Q) = |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF). |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the diffusion model at given Q values. |
__repr__ |
String representation of the JumpTranslationalDiffusion model. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
relaxation_time |
Parameter
|
Get the relaxation time parameter t. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D. |
relaxation_time
property
writable
Get the relaxation time parameter t.
Returns:
| Type | Description |
|---|---|
Parameter
|
Relaxation time t in ps. |
Functions
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. \(\Gamma(Q) = Q^2/(1+D t Q^2)\), where \(D\) is the diffusion coefficient and \(t\) is the relaxation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. If None, Q values stored in the model are used. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the diffusion model at given Q values.
TypeError If component_display_name is not a string. If component_name is not a string.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Jump Diffusion Lorentzian components. |
__repr__()
String representation of the JumpTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the JumpTranslationalDiffusion model. |
Modules
brownian_translational_diffusion
Classes:
| Name | Description |
|---|---|
BrownianTranslationalDiffusion |
Model of Brownian translational diffusion, consisting of a Lorentzian function for each |
Classes
BrownianTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, Q=None, unit='meV', name='BrownianTranslationalDiffusion', display_name='BrownianTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Brownian translational diffusion, consisting of a Lorentzian function for each Q-value, where the width is given by \(D Q^2\), where \(D\) is the diffusion coefficient. The area of the Lorentzians is given by the scale parameter multiplied by the QISF, which is 1 for this model. The EISF is 0 for this model, so there is no delta function component. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q=np.linspace(0.5,2,7) >>>energy=np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> diffusion_model=BrownianTranslationalDiffusion(name="DiffusionModel",
>>> scale=scale, diffusion_coefficient= diffusion_coefficient,)
>>> component_collections = diffusion_model.create_component_collections(Q)
See also the tutorials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'BrownianTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the lorentzian_name. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale or diffusion_coefficient is not a number. |
ValueError
|
If scale or diffusion_coefficient is negative. |
Methods:
| Name | Description |
|---|---|
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the Brownian translational diffusion model at |
__repr__ |
String representation of the BrownianTranslationalDiffusion model. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
Attributes:
| Name | Type | Description |
|---|---|---|
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D in m^2/s. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q=None)
Calculate the Elastic Incoherent Structure Factor (EISF) for the Brownian translational diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q=None)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the Brownian translational diffusion model at given Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian components for each Q value. Each Lorentzian has a width given by \(D*Q^2\) and an area given by the scale parameter multiplied by the QISF (which is 1 for this model). |
__repr__()
String representation of the BrownianTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the BrownianTranslationalDiffusion model. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
delta_lorentz
Classes:
| Name | Description |
|---|---|
DeltaLorentz |
Model of Delta function and Lorentzian with intensities given by the Debye-Waller factor. $$ I |
Classes
DeltaLorentz(scale=1.0, mean_u_squared=0.0, A_0=1.0, lorentzian_width=1.0, allow_Q_variation=None, Q=None, unit='meV', name='DeltaLorentz', display_name=None, lorentzian_name='Lorentzian', lorentzian_display_name=None, delta_name='Delta function', delta_display_name=None, unique_name=None)
Model of Delta function and Lorentzian with intensities given by the Debye-Waller factor. $$ I = K \exp \left( \frac{-\langle u^2 \rangle Q^2}{3} \right)[A_0 \delta(E) + (A_1) L(E, \Gamma)] $$,
where \(K\) is the scale factor, \(\langle u^2 \rangle\) is the mean square displacement, \(Q\) is the scattering vector, \(A_0\) and \(A_1\) are the relative amplitudes of the delta function and Lorentzian, respectively, with the constraint that \(A_0+A_1=1\), and \(L(E, \Gamma)\) is the Lorentzian function with width \(\Gamma\). \(A_0\), \(A_1\) and the width of the Lorentzian can be the same at all \(Q\) or be allowed to vary with \(Q\).
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> mean_u_squared = 0.02
>>> A_0 = 0.7
>>> lorentzian_width = 1.0
>>> model = DeltaLorentz(
... display_name='DiffusionModel',
... scale=scale,
... mean_u_squared=mean_u_squared,
... A_0=A_0,
... lorentzian_width=lorentzian_width,
... allow_Q_variation={'A_0': True, 'lorentzian_width': True},
... Q=Q,
... )
See also the tutorials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
mean_u_squared
|
Numeric
|
Mean square displacement in angstrom^2. |
0.0
|
A_0
|
Numeric
|
Amplitude of the delta function. |
1.0
|
lorentzian_width
|
Numeric
|
Width of the Lorentzian function. |
1.0
|
allow_Q_variation
|
dict | None
|
Dict describing whether to allow Q variation of A_0 and the Lorentzian width. The dict can have the keys "A_0" and/or "lorentzian_width", with boolean values indicating whether to allow Q-dependence for each parameter. If None, no Q-dependence will be allowed. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'DeltaLorentz'
|
display_name
|
str | None
|
Display name of the diffusion model. |
None
|
lorentzian_name
|
str
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
'Lorentzian'
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the display name of the diffusion model. |
None
|
delta_name
|
str
|
Name of the delta function component. |
'Delta function'
|
delta_display_name
|
str | None
|
Display name of the delta function component. If None, it will be set to the display name of the delta function component. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If delta_name is not a string or if delta_display_name is not a string or None. |
Methods:
| Name | Description |
|---|---|
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. If the width is |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF) for the diffusion model. |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollections for the DeltaLorentz model at given Q values. |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_all_variables |
Get a list of all variables (Parameters and Descriptors) in the model. |
__repr__ |
String representation of the DeltaLorentz model. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_component_collections |
Get the ComponentCollection at the given Q index. |
Attributes:
| Name | Type | Description |
|---|---|---|
mean_u_squared |
Parameter
|
Get the mean square displacement parameter. |
A_0 |
Parameter
|
Get the amplitude of the delta function. |
A_1 |
Parameter
|
Get the amplitude of the Lorentzian function. |
lorentzian_width |
Parameter
|
Get the width of the Lorentzian function. |
delta_name |
str
|
Get the name of the delta function component. |
delta_display_name |
str
|
Get the display name of the delta function component. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
mean_u_squared
property
writable
Get the mean square displacement parameter.
Returns:
| Type | Description |
|---|---|
Parameter
|
Mean square displacement in angstrom^2. |
A_0
property
writable
Get the amplitude of the delta function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Amplitude of the delta function. |
A_1
property
writable
Get the amplitude of the Lorentzian function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Amplitude of the Lorentzian function. |
lorentzian_width
property
writable
Get the width of the Lorentzian function.
Returns:
| Type | Description |
|---|---|
Parameter
|
Width of the Lorentzian function. |
delta_name
property
writable
Get the name of the delta function component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the delta function component. |
delta_display_name
property
writable
Get the display name of the delta function component.
Returns:
| Type | Description |
|---|---|
str
|
Display name of the delta function component. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. If the width is allowed to vary with Q then the Q stored in the model is used and the input is ignored. If the width is not allowed to vary then the same width is returned for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q=None)
Calculate the Elastic Incoherent Structure Factor (EISF) for the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q=None)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollections for the DeltaLorentz model at given Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Lorentzian and delta function components for each Q value. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_all_variables(Q_index=None)
Get a list of all variables (Parameters and Descriptors) in the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the variables. If None, variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[DescriptorNumber]
|
List of all variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
__repr__()
String representation of the DeltaLorentz model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the DeltaLorentz model. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
diffusion_model_base
Classes:
| Name | Description |
|---|---|
DiffusionModelBase |
Base class for constructing diffusion models. |
Classes
DiffusionModelBase(scale=1.0, Q=None, unit='meV', name='DiffusionModel', display_name='DiffusionModel', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Base class for constructing diffusion models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'DiffusionModel'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'DiffusionModel'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the lorentzian_name. |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale is not a number. |
UnitError
|
If unit is not a string or scipp Unit, or if it cannot be converted to meV. |
ValueError
|
If scale is negative. |
Methods:
| Name | Description |
|---|---|
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
create_component_collections |
Create the ComponentCollections for the diffusion model based on the current Q values. |
get_component_collections |
Get the ComponentCollection at the given Q index. |
__repr__ |
String representation of the Diffusion model. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
Attributes:
| Name | Type | Description |
|---|---|---|
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
create_component_collections()
Create the ComponentCollections for the diffusion model based on the current Q values.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
A list of ComponentCollections corresponding to the current Q values. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
__repr__()
String representation of the Diffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the DiffusionModel. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
jump_translational_diffusion
Classes:
| Name | Description |
|---|---|
JumpTranslationalDiffusion |
Model of Jump translational diffusion. |
Classes
JumpTranslationalDiffusion(scale=1.0, diffusion_coefficient=1.0, relaxation_time=1.0, Q=None, unit='meV', name='JumpTranslationalDiffusion', display_name='JumpTranslationalDiffusion', lorentzian_name=None, lorentzian_display_name=None, unique_name=None)
Model of Jump translational diffusion.
The model consists of a Lorentzian function for each Q-value, where the width is given by
where \(D\) is the diffusion coefficient and \(t\) is the relaxation time. Q is assumed to have units of 1/angstrom. Creates ComponentCollections with Lorentzian components for given Q-values.
Examples:
>>> Q = np.linspace(0.5, 2, 7)
>>> energy = np.linspace(-2, 2, 501)
>>> scale = 1.0
>>> diffusion_coefficient = 2.4e-9 # m^2/s
>>> relaxation_time = 1.0 # ps
>>> diffusion_model = JumpTranslationalDiffusion(
... scale=scale,
... diffusion_coefficient=diffusion_coefficient,
... relaxation_time=relaxation_time,
... Q=Q,
... )
>>> component_collections = diffusion_model.create_component_collections()
See also the tutorials..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Numeric
|
Scale factor for the diffusion model. Must be a non-negative number. |
1.0
|
diffusion_coefficient
|
Numeric
|
Diffusion coefficient D in m^2/s. |
1.0
|
relaxation_time
|
Numeric
|
Relaxation time t in ps. |
1.0
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
unit
|
str | sc.Unit
|
Unit of the diffusion model. Must be convertible to meV. |
'meV'
|
name
|
str
|
Name of the diffusion model. |
'JumpTranslationalDiffusion'
|
display_name
|
str | None
|
Display name of the diffusion model. |
'JumpTranslationalDiffusion'
|
lorentzian_name
|
str | None
|
Name of the Lorentzian component. If None, it will be set to the name of the diffusion model with '_Lorentzian' appended. By default, None. |
None
|
lorentzian_display_name
|
str | None
|
Display name of the Lorentzian component. If None, it will be set to the display name of the diffusion model with '_Lorentzian' appended. By default, None |
None
|
unique_name
|
str | None
|
Unique name of the diffusion model. If None, a unique name will be generated. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If scale, diffusion_coefficient, or relaxation_time are not numbers. |
ValueError
|
If scale, diffusion_coefficient, or relaxation_time are negative. |
Methods:
| Name | Description |
|---|---|
calculate_width |
Calculate the half-width at half-maximum (HWHM) for the diffusion model. $\Gamma(Q) = |
calculate_EISF |
Calculate the Elastic Incoherent Structure Factor (EISF). |
calculate_QISF |
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF). |
create_component_collections |
Create ComponentCollection components for the diffusion model at given Q values. |
__repr__ |
String representation of the JumpTranslationalDiffusion model. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_variables |
Get all variables from the diffusion model. |
get_all_parameters |
Get all Parameters from the diffusion model. |
get_fittable_parameters |
Get all fittable Parameters from the diffusion model. |
get_free_parameters |
Get all free Parameters from the diffusion model. |
get_fit_parameters |
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
get_global_variables |
Get all global variables from the diffusion model. |
get_independent_variables |
Get the independent variables from the diffusion model. If Q_index is provided, only the |
get_component_collections |
Get the ComponentCollection at the given Q index. |
Attributes:
| Name | Type | Description |
|---|---|---|
diffusion_coefficient |
Parameter
|
Get the diffusion coefficient parameter D. |
relaxation_time |
Parameter
|
Get the relaxation time parameter t. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
scale |
Parameter
|
Get the scale parameter of the diffusion model. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
lorentzian_name |
str
|
Get the name of the Lorentzian component. |
lorentzian_display_name |
str | None
|
Get the display name of the Lorentzian component. |
diffusion_coefficient
property
writable
Get the diffusion coefficient parameter D.
Returns:
| Type | Description |
|---|---|
Parameter
|
Diffusion coefficient D. |
relaxation_time
property
writable
Get the relaxation time parameter t.
Returns:
| Type | Description |
|---|---|
Parameter
|
Relaxation time t in ps. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
scale
property
writable
Get the scale parameter of the diffusion model.
Returns:
| Type | Description |
|---|---|
Parameter
|
Scale parameter of the diffusion model. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
lorentzian_name
property
writable
Get the name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the Lorentzian component. |
lorentzian_display_name
property
writable
Get the display name of the Lorentzian component.
Returns:
| Type | Description |
|---|---|
str | None
|
Display name of the Lorentzian component, or None if not set. |
calculate_width(Q=None)
Calculate the half-width at half-maximum (HWHM) for the diffusion model. \(\Gamma(Q) = Q^2/(1+D t Q^2)\), where \(D\) is the diffusion coefficient and \(t\) is the relaxation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type | None
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. If None, Q values stored in the model are used. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
HWHM values in the unit of the model (e.g., meV). |
calculate_EISF(Q)
Calculate the Elastic Incoherent Structure Factor (EISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
EISF values (dimensionless). |
calculate_QISF(Q)
Calculate the Quasi-Elastic Incoherent Structure Factor (QISF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q_type
|
Scattering vector in 1/angstrom. Can be a single value or an array of values. |
required |
Returns:
| Type | Description |
|---|---|
np.ndarray
|
QISF values (dimensionless). |
create_component_collections()
Create ComponentCollection components for the diffusion model at given Q values.
TypeError If component_display_name is not a string. If component_name is not a string.
Returns:
| Type | Description |
|---|---|
list[ComponentCollection]
|
List of ComponentCollections with Jump Diffusion Lorentzian components. |
__repr__()
String representation of the JumpTranslationalDiffusion model.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the JumpTranslationalDiffusion model. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_variables(Q_index=None)
Get all variables from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get variables from. If None, all variables from all ComponentCollections are returned, in addition to the global variables. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds for the number of ComponentCollections. |
get_all_parameters(Q_index=None)
Get all Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get parameters from. If None, all parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters from the diffusion model. |
get_fittable_parameters(Q_index=None)
Get all fittable Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fittable parameters from. If None, all fittable parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fittable Parameters from the diffusion model. |
get_free_parameters(Q_index=None)
Get all free Parameters from the diffusion model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get free parameters from. If None, all free parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all free Parameters from the diffusion model. |
get_fit_parameters(Q_index=None)
Get all fit Parameters from the diffusion model. This is an alias for get_free_parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the ComponentCollection to get fit parameters from. If None, all fit parameters from all ComponentCollections are returned. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all fit Parameters from the diffusion model. |
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
get_global_variables()
Get all global variables from the diffusion model.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all global variables from the diffusion model. |
get_independent_variables(Q_index=None)
Get the independent variables from the diffusion model. If Q_index is provided, only the independent variables for the specified Q value will be returned. If Q_index is None, independent variables for all Q values will be returned. These are variables that are not global but also not part of the component collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value for which to get the independent variables. If None, independent variables for all Q values will be included. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of independent variables in the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is not None and is not a valid index for the Q values in the model. |
get_component_collections(Q_index=None)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the desired ComponentCollection. If None, all ComponentCollections are returned. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection | list[ComponentCollection]
|
The ComponentCollection at the specified Q index. If Q_index is None, a list of all ComponentCollections is returned. |
instrument_model
Classes:
| Name | Description |
|---|---|
InstrumentModel |
InstrumentModel represents a model of the instrument in an experiment at various Q. |
Classes
InstrumentModel(display_name='MyInstrumentModel', unique_name=None, Q=None, resolution_model=None, background_model=None, energy_offset=None, unit='meV')
InstrumentModel represents a model of the instrument in an experiment at various Q.
It can contain a model of the resolution function for convolutions, of the background and an offset in the energy axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
The display name of the InstrumentModel. |
'MyInstrumentModel'
|
unique_name
|
str | None
|
The unique name of the InstrumentModel. |
None
|
Q
|
Q_type | None
|
The Q values where the instrument is modelled. |
None
|
resolution_model
|
ResolutionModel | SampleModel | None
|
The resolution model of the instrument. If a SampleModel it will be converted to a ResolutionModel. If None, an empty resolution model is created and no resolution convolution is carried out. |
None
|
background_model
|
BackgroundModel | None
|
The background model of the instrument. If None, an empty background model is created, and the background evaluates to 0. |
None
|
energy_offset
|
Numeric | None
|
Template energy offset of the instrument. Will be copied to each Q value. If None, the energy offset will be 0. |
None
|
unit
|
str | sc.Unit
|
The unit of the energy axis. |
'meV'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If resolution_model is not a ResolutionModel or None, or if background_model is not a BackgroundModel or None, or if energy_offset is not a number or None. |
Methods:
| Name | Description |
|---|---|
clear_Q |
Clear the Q values of the InstrumentModel and any associated ResolutionModel and |
convert_unit |
Convert the unit of the InstrumentModel. |
get_all_variables |
Get all variables in the InstrumentModel. |
fix_resolution_parameters |
Fix all parameters in the resolution model. |
free_resolution_parameters |
Free all parameters in the resolution model. |
normalize_resolution |
Normalize the resolution model to have area 1. |
get_energy_offset |
Get the energy offset Parameter at a specific Q index. |
fix_energy_offset |
Fix energy offset parameters. |
free_energy_offset |
Free energy offset parameters. |
__repr__ |
Return a string representation of the InstrumentModel. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object from a full encoded |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
Attributes:
| Name | Type | Description |
|---|---|---|
resolution_model |
ResolutionModel
|
Get the resolution model of the instrument. |
background_model |
BackgroundModel
|
Get the background model of the instrument. |
Q |
np.ndarray | None
|
Get the Q values of the InstrumentModel. |
unit |
str | sc.Unit
|
Get the unit of the InstrumentModel. |
energy_offset |
Parameter
|
Get the energy offset template parameter of the instrument model. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
Attributes
resolution_model
property
writable
Get the resolution model of the instrument.
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
The resolution model of the instrument. |
background_model
property
writable
Get the background model of the instrument.
Returns:
| Type | Description |
|---|---|
BackgroundModel
|
The background model of the instrument. |
Q
property
writable
Get the Q values of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the InstrumentModel, or None if not set. |
unit
property
writable
Get the unit of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the InstrumentModel. |
energy_offset
property
writable
Get the energy offset template parameter of the instrument model.
Returns:
| Type | Description |
|---|---|
Parameter
|
The energy offset template parameter of the instrument model. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
Functions
clear_Q(confirm=False)
Clear the Q values of the InstrumentModel and any associated ResolutionModel and BackgroundModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit_str)
Convert the unit of the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_str
|
str | sc.Unit
|
The unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unit_str is not a valid unit string or scipp Unit. |
get_all_variables(Q_index=None)
Get all variables in the InstrumentModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get variables for. If None, get variables for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the Q values in the InstrumentModel. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all variables in the InstrumentModel. If Q_index is specified, only variables from the ComponentCollection at the given Q index are included. Otherwise, all variables in the InstrumentModel are included. |
fix_resolution_parameters()
Fix all parameters in the resolution model.
free_resolution_parameters()
Free all parameters in the resolution model.
normalize_resolution()
Normalize the resolution model to have area 1.
get_energy_offset(Q_index=None)
Get the energy offset Parameter at a specific Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to get the energy offset for. If None, get the energy offset for all Q values. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no Q values are set in the InstrumentModel. |
IndexError
|
If Q_index is out of bounds. |
TypeError
|
If Q_index is not an int or None. |
Returns:
| Type | Description |
|---|---|
Parameter | list[Parameter]
|
The energy offset Parameter at the specified Q index, or a list of Parameters if Q_index is None. |
fix_energy_offset(Q_index=None)
Fix energy offset parameters.
If Q_index is specified, only fix the energy offset for that Q value. If Q_index is None, fix energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to fix the energy offset for. If None, fix energy offsets for all Q values. |
None
|
free_energy_offset(Q_index=None)
Free energy offset parameters.
If Q_index is specified, only free the energy offset for that Q value. If Q_index is None, free energy offsets for all Q values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
The index of the Q value to free the energy offset for. If None, free energy offsets for all Q values. |
None
|
__repr__()
Return a string representation of the InstrumentModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the InstrumentModel. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
model_base
Classes:
| Name | Description |
|---|---|
ModelBase |
Base class for Sample Models. |
Classes
ModelBase(display_name='MyModelBase', unique_name=None, unit='meV', components=None, Q=None)
Base class for Sample Models.
Contains common functionality for models with components and Q dependence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyModelBase'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit | None
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If components is not a ModelComponent or ComponentCollection. |
Methods:
| Name | Description |
|---|---|
evaluate |
Evaluate the sample model at all Q for the given x values. |
append_component |
Append a ModelComponent or ComponentCollection to the SampleModel. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
__repr__ |
Return a string representation of the ModelBase. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
Attributes:
| Name | Type | Description |
|---|---|---|
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
Attributes
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
Functions
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
resolution_model
Classes:
| Name | Description |
|---|---|
ResolutionModel |
ResolutionModel represents a model of the instrment resolution in an experiment at various Q. |
Classes
ResolutionModel(display_name='MyResolutionModel', unique_name=None, unit='meV', components=None, Q=None)
ResolutionModel represents a model of the instrment resolution in an experiment at various Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MyResolutionModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
Methods:
| Name | Description |
|---|---|
append_component |
Append a component to the ResolutionModel. |
from_sample_model |
Create a ResolutionModel from a SampleModel. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
__repr__ |
Return a string representation of the ModelBase. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
evaluate |
Evaluate the sample model at all Q for the given x values. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
Attributes
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
Functions
append_component(component)
Append a component to the ResolutionModel.
Does not allow DeltaFunction or Polynomial components, as these are not physical resolution components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
Component(s) to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the component is a DeltaFunction or Polynomial. |
from_sample_model(sample_model, normalize_area=True, fix_parameters=True)
classmethod
Create a ResolutionModel from a SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_model
|
SampleModel
|
SampleModel to create the ResolutionModel from. |
required |
normalize_area
|
bool
|
Whether to normalize the components in the ResolutionModel to have area 1. |
True
|
fix_parameters
|
bool
|
Whether to fix the parameters in the ResolutionModel. |
True
|
Returns:
| Type | Description |
|---|---|
ResolutionModel
|
ResolutionModel created from the SampleModel. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sample_model is not a SampleModel, or if normalize_area or fix_parameters are not bool. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
__repr__()
Return a string representation of the ModelBase.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the ModelBase. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the ModelBase. Parameters Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If None, get variables for all ComponentCollections. If int, get variables for the ComponentCollection at this index. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int or None. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
A list of all Parameters and Descriptors from the ComponentCollections in the ModelBase. |
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
Energy axis values to evaluate the model at. If a scipp Variable or DataArray is provided, the unit of the model will be converted to match the unit of x for evaluation, and the result will be returned in the same unit as x. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no components in the model to evaluate. |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
A list of numpy arrays containing the evaluated model values for each Q. The length of the list will match the number of Q values in the model. |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.
sample_model
Classes:
| Name | Description |
|---|---|
SampleModel |
SampleModel represents a model of a sample with components and diffusion models, parameterized |
Classes
SampleModel(display_name='MySampleModel', unique_name=None, unit='meV', components=None, Q=None, diffusion_models=None, temperature=None, temperature_unit='K', detailed_balance_settings=None)
SampleModel represents a model of a sample with components and diffusion models, parameterized by Q and optionally temperature. Generates ComponentCollections for each Q value, combining components from the base model and diffusion models.
Applies detailed balancing based on temperature if provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Display name of the model. |
'MySampleModel'
|
unique_name
|
str | None
|
Unique name of the model. If None, a unique name will be generated. |
None
|
unit
|
str | sc.Unit
|
Unit of the model. If None,. |
'meV'
|
components
|
ModelComponent | ComponentCollection | None
|
Template components of the model. If None, no components are added. These components are copied into ComponentCollections for each Q value. |
None
|
Q
|
Q_type | None
|
Q values for the model. If None, Q is not set. |
None
|
diffusion_models
|
DiffusionModelBase | list[DiffusionModelBase] | None
|
Diffusion models to include in the SampleModel. If None, no diffusion models are added. |
None
|
temperature
|
float | None
|
Temperature for detailed balancing. If None, no detailed balancing is applied. By default, None. |
None
|
temperature_unit
|
str | sc.Unit
|
Unit of the temperature. |
'K'
|
detailed_balance_settings
|
DetailedBalanceSettings | None
|
Settings for detailed balancing. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If diffusion_models is not a DiffusionModelBase, a list of DiffusionModelBase, or None, or if temperature is not a number or None, or if detailed_balance_settings is not a DetailedBalanceSettings instance. |
ValueError
|
If temperature is negative. |
Methods:
| Name | Description |
|---|---|
append_diffusion_model |
Append a DiffusionModel to the SampleModel. |
remove_diffusion_model |
Remove a DiffusionModel from the SampleModel by name. |
clear_diffusion_models |
Clear all DiffusionModels from the SampleModel. |
convert_temperature_unit |
Convert the unit of the temperature Parameter. |
evaluate |
Evaluate the sample model at all Q for the given x values. |
get_all_variables |
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel. |
__repr__ |
Return a string representation of the SampleModel. |
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object with DescriptorNumber |
__dir__ |
This creates auto-completion and helps out in iPython |
__copy__ |
Return a copy of the object. |
get_all_parameters |
Get all |
get_fittable_parameters |
Get all parameters which can be fitted as a list. |
get_free_parameters |
Get all parameters which are currently free to be fitted as a |
get_fit_parameters |
This is an alias for |
append_component |
Append a ModelComponent or ComponentCollection to the SampleModel. |
remove_component |
Remove a ModelComponent from the SampleModel by its name. |
clear_components |
Clear all ModelComponents from the SampleModel. |
clear_Q |
Clear the Q values of the SampleModel, removing all component collections and their |
convert_unit |
Convert the unit of the ComponentCollection and all its components. |
fix_all_parameters |
Fix all Parameters in all ComponentCollections. |
free_all_parameters |
Free all Parameters in all ComponentCollections. |
get_component_collection |
Get the ComponentCollection at the given Q index. |
normalize_area |
Normalize the area of the model across all Q values. |
Attributes:
| Name | Type | Description |
|---|---|---|
diffusion_models |
list[DiffusionModelBase]
|
Get the diffusion models of the SampleModel. |
temperature |
Parameter | None
|
Get the temperature of the SampleModel. |
temperature_unit |
str | sc.Unit
|
Get the temperature unit of the SampleModel. |
normalize_detailed_balance |
bool
|
Get whether to divide the detailed balance factor by temperature. |
use_detailed_balance |
bool
|
Get whether to apply detailed balance to the model. |
detailed_balance_settings |
DetailedBalanceSettings
|
Get the DetailedBalanceSettings of the SampleModel. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
name |
str
|
Get the name of the model. |
unit |
str | sc.Unit | None
|
Get the unit of the model. |
components |
list[ModelComponent]
|
Get the components of the SampleModel. |
Q |
np.ndarray | None
|
Get the Q values of the SampleModel. |
Attributes
diffusion_models
property
writable
Get the diffusion models of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[DiffusionModelBase]
|
The diffusion models of the SampleModel. |
temperature
property
writable
Get the temperature of the SampleModel.
Returns:
| Type | Description |
|---|---|
Parameter | None
|
The temperature Parameter of the SampleModel, or None if not set. |
temperature_unit
property
writable
Get the temperature unit of the SampleModel.
Returns:
| Type | Description |
|---|---|
str | sc.Unit
|
The unit of the temperature Parameter. |
normalize_detailed_balance
property
writable
Get whether to divide the detailed balance factor by temperature.
Returns:
| Type | Description |
|---|---|
bool
|
True if the detailed balance factor is divided by temperature, False otherwise. |
use_detailed_balance
property
writable
Get whether to apply detailed balance to the model.
Returns:
| Type | Description |
|---|---|
bool
|
True if detailed balance is applied, False otherwise. |
detailed_balance_settings
property
writable
Get the DetailedBalanceSettings of the SampleModel.
Returns:
| Type | Description |
|---|---|
DetailedBalanceSettings
|
The DetailedBalanceSettings of the SampleModel. |
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the model.
Returns:
| Type | Description |
|---|---|
str
|
The name of the model. |
unit
property
writable
Get the unit of the model.
Returns:
| Type | Description |
|---|---|
str | sc.Unit | None
|
The unit of the model. |
components
property
writable
Get the components of the SampleModel.
Returns:
| Type | Description |
|---|---|
list[ModelComponent]
|
The components of the SampleModel. |
Q
property
writable
Get the Q values of the SampleModel.
Returns:
| Type | Description |
|---|---|
np.ndarray | None
|
The Q values of the SampleModel, or None if not set. |
Functions
append_diffusion_model(diffusion_model)
Append a DiffusionModel to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_model
|
DiffusionModelBase
|
The DiffusionModel to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the diffusion_model is not a DiffusionModelBase. |
remove_diffusion_model(name)
Remove a DiffusionModel from the SampleModel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the DiffusionModel to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no DiffusionModel with the given name is found. |
clear_diffusion_models()
Clear all DiffusionModels from the SampleModel.
convert_temperature_unit(unit)
Convert the unit of the temperature Parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The unit to convert the temperature Parameter to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature is not set or conversion fails. |
Exception
|
If the provided unit is invalid or cannot be converted. |
evaluate(x)
Evaluate the sample model at all Q for the given x values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Numeric | list | np.ndarray | sc.Variable | sc.DataArray
|
The x values to evaluate the model at. Can be a number, list, numpy array, scipp Variable, or scipp DataArray. |
required |
Returns:
| Type | Description |
|---|---|
list[np.ndarray]
|
List of evaluated model values for each Q. |
get_all_variables(Q_index=None)
Get all Parameters and Descriptors from all ComponentCollections in the SampleModel.
Also includes temperature if set and all variables from diffusion models. Ignores the Parameters and Descriptors in self._components as these are just templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None
|
If specified, only get variables from the ComponentCollection at the given Q index. If None, get variables from all ComponentCollections. |
None
|
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
List of all Parameters and Descriptors, including temperature if set and all variables from diffusion models. |
__repr__()
Return a string representation of the SampleModel.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the SampleModel. |
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object with DescriptorNumber attributes from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto- completion
__copy__()
Return a copy of the object.
get_all_parameters()
Get all Parameter objects as a list.
:return: List of Parameter objects.
get_fittable_parameters()
Get all parameters which can be fitted as a list.
:return: List of Parameter objects.
get_free_parameters()
Get all parameters which are currently free to be fitted as a list.
:return: List of Parameter objects.
get_fit_parameters()
This is an alias for get_free_parameters.
To be removed when fully moved to new base classes and minimizer can be changed.
append_component(component)
Append a ModelComponent or ComponentCollection to the SampleModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ModelComponent | ComponentCollection
|
The ModelComponent or ComponentCollection to append. |
required |
remove_component(name)
Remove a ModelComponent from the SampleModel by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the ModelComponent to remove. |
required |
clear_components()
Clear all ModelComponents from the SampleModel.
clear_Q(confirm=False)
Clear the Q values of the SampleModel, removing all component collections and their associated Parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confirm
|
bool
|
Confirmation to clear Q values. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If confirm is not True. |
convert_unit(unit)
Convert the unit of the ComponentCollection and all its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str | sc.Unit
|
The new unit to convert to. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the provided unit is not a string or sc.Unit. |
Exception
|
If the provided unit is not compatible with the current unit. |
fix_all_parameters()
Fix all Parameters in all ComponentCollections.
free_all_parameters()
Free all Parameters in all ComponentCollections.
get_component_collection(Q_index)
Get the ComponentCollection at the given Q index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int
|
The index of the desired ComponentCollection. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If Q_index is not an int. |
IndexError
|
If Q_index is out of bounds for the number of ComponentCollections. |
Returns:
| Type | Description |
|---|---|
ComponentCollection
|
The ComponentCollection at the. |
normalize_area()
Normalize the area of the model across all Q values.