Skip to content

convolution

Modules:

Name Description
analytical_convolution
convolution
convolution_base
energy_grid
numerical_convolution
numerical_convolution_base

Classes:

Name Description
Convolution

Convolution class that combines analytical and numerical convolution methods to efficiently

Classes

Convolution(energy, sample_components, resolution_components, energy_offset=0.0, convolution_settings=None, temperature=None, temperature_unit='K', detailed_balance_settings=None, x_unit='meV', y_unit='dimensionless', display_name='MyConvolution', unique_name=None)

Convolution class that combines analytical and numerical convolution methods to efficiently perform convolutions of ComponentCollections with ResolutionComponents.

Supports analytical convolution for pairs of analytical model components (DeltaFunction, Gaussian, Lorentzian, Voigt), while using numerical convolution for other components. If temperature is provided, detailed balance correction is applied to the sample model. In this case, all convolutions are handled numerically. Includes a setting to normalize the detailed balance correction. Includes optional upsampling and extended range to improve accuracy of the numerical convolutions. Also warns about numerical instabilities if peaks are very wide or very narrow.

Examples:

Convolving a sample model with a resolution function

Analytical convolution is used automatically when both components are DeltaFunction, Gaussian, Lorentzian, or Voigt:

import numpy as np
import easydynamics.sample_model as sm
from easydynamics.convolution import Convolution

sample_components = sm.ComponentCollection(
    components=[sm.DeltaFunction(area=0.5), sm.Lorentzian(area=1.0, width=0.3)]
)
resolution_components = sm.ComponentCollection(components=[sm.Gaussian(width=0.05)])
energy = np.linspace(-2, 2, 100)

convolver = Convolution(
    sample_components=sample_components,
    resolution_components=resolution_components,
    energy=energy,
)
y = convolver.convolution()

Including detailed balance and improving numerical accuracy

Providing temperature switches to numerical convolution with detailed balance applied. Increase upsample_factor and extension_factor for better accuracy with narrow peaks:

convolver = Convolution(
    sample_components=sample_components,
    resolution_components=resolution_components,
    energy=energy,
    temperature=10.0,
)
convolver.upsample_factor = 5
convolver.extension_factor = 0.5
y = convolver.convolution()

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent

The sample components to be convolved.

required
resolution_components ComponentCollection | ModelComponent

The resolution components to convolve with.

required
energy_offset Numeric | Parameter

An energy offset to apply to the energy values before convolution.

0.0
convolution_settings ConvolutionSettings | None

The settings for the convolution. If None, default settings will be used.

None
temperature Parameter | Numeric | None

The temperature to use for detailed balance correction.

None
temperature_unit str | sc.Unit

The unit of the temperature parameter.

'K'
detailed_balance_settings DetailedBalanceSettings | None

The settings for detailed balance. If None, default settings will be used.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Methods:

Name Description
to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

energy

Set the energy array and invalidate this convolver's plan.

convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

convolution

Perform convolution using analytical convolutions where possible, and numerical

convert_y_unit

Convert the y-axis unit and propagate it to the analytical and numerical sub-convolvers.

__setattr__

Custom setattr to invalidate convolution plan on relevant attribute changes, and build a

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

temperature Parameter | None

Get the temperature.

convolution_settings ConvolutionSettings

Get the convolution settings.

upsample_factor Numeric | None

Get the upsample factor.

extension_factor float

Get the extension factor.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the Convolution.

Attributes

unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

temperature property writable

Get the temperature.

Returns:

Type Description
Parameter | None

The temperature parameter, or None if detailed balance correction is disabled.

convolution_settings property writable

Get the convolution settings.

Returns:

Type Description
ConvolutionSettings

The convolution settings.

upsample_factor property writable

Get the upsample factor.

Returns:

Type Description
Numeric | None

The upsample factor.

extension_factor property writable

Get the extension factor.

The extension factor determines how much the energy range is extended on both sides before convolution. 0.2 means extending by 20% of the original energy span on each side

Returns:

Type Description
float

The extension factor.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the Convolution.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the Convolution.

Methods:

to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

energy(energy)

Set the energy array and invalidate this convolver's plan.

The dense grid is rebuilt lazily on the next convolution. Other convolvers sharing the same ConvolutionSettings are unaffected — a new energy array is a convolver-local change.

Parameters:

Name Type Description Default
energy np.ndarray

The new energy array.

required
convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convolution()

Perform convolution using analytical convolutions where possible, and numerical convolutions for the remaining components.

Returns:

Type Description
np.ndarray

The convolved values evaluated at energy.

convert_y_unit(unit)

Convert the y-axis unit and propagate it to the analytical and numerical sub-convolvers.

Parameters:

Name Type Description Default
unit str

The new y-axis unit.

required
__setattr__(name, value)

Custom setattr to invalidate convolution plan on relevant attribute changes, and build a new plan.

The new plan is only built after initialization (when _reactions_enabled is True) to avoid issues during init.

Parameters:

Name Type Description Default
name str

The name of the attribute to set.

required
value any

The value to set the attribute to.

required

Modules

analytical_convolution

Classes:

Name Description
AnalyticalConvolution

Analytical convolution of a ModelComponent or ComponentCollection with a ResolutionModel.

Classes

AnalyticalConvolution(energy, sample_components=None, resolution_components=None, x_unit='meV', y_unit='dimensionless', energy_offset=0.0, display_name='MyConvolution', unique_name=None)

Analytical convolution of a ModelComponent or ComponentCollection with a ResolutionModel.

Possible analytical convolutions are any combination of delta functions, Gaussians, Lorentzians and Voigt profiles.

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent | None

The sample model to be convolved.

None
resolution_components ComponentCollection | ModelComponent | None

The resolution model to convolve with.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
energy_offset Numeric | Parameter

The energy offset applied to the convolution.

0.0
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Raises:

Type Description
TypeError

If energy is not a numpy ndarray or a scipp Variable or if energy_unit is not a string or scipp unit, or if energy_offset is not a number or a Parameter, or if sample_components is not a ComponentCollection or ModelComponent, or if resolution_components is not a ComponentCollection or ModelComponent.

Methods:

Name Description
convolution

Convolve sample with resolution analytically if possible.

to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

convert_y_unit

Convert the y-axis unit of the sample components.

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

energy sc.Variable

Get the energy.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

Attributes
unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

energy property writable

Get the energy.

Returns:

Type Description
sc.Variable

The energy values where the convolution is evaluated.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

Methods:
convolution()

Convolve sample with resolution analytically if possible.

Accepts ComponentCollection or single ModelComponent for each. Possible analytical convolutions are any combination of delta functions, Gaussians, Lorentzians and Voigt profiles.

Returns:

Type Description
np.ndarray

The convolution of the sample_components and resolution_components values evaluated at self.energy.

to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convert_y_unit(unit)

Convert the y-axis unit of the sample components.

Only propagates to sample components (resolution is normalised and unit-independent). If any component raises during unit conversion, the conversion is rolled back best-effort before the exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The new y-axis unit.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convolution

Classes:

Name Description
Convolution

Convolution class that combines analytical and numerical convolution methods to efficiently

Classes

Convolution(energy, sample_components, resolution_components, energy_offset=0.0, convolution_settings=None, temperature=None, temperature_unit='K', detailed_balance_settings=None, x_unit='meV', y_unit='dimensionless', display_name='MyConvolution', unique_name=None)

Convolution class that combines analytical and numerical convolution methods to efficiently perform convolutions of ComponentCollections with ResolutionComponents.

Supports analytical convolution for pairs of analytical model components (DeltaFunction, Gaussian, Lorentzian, Voigt), while using numerical convolution for other components. If temperature is provided, detailed balance correction is applied to the sample model. In this case, all convolutions are handled numerically. Includes a setting to normalize the detailed balance correction. Includes optional upsampling and extended range to improve accuracy of the numerical convolutions. Also warns about numerical instabilities if peaks are very wide or very narrow.

Examples:

Convolving a sample model with a resolution function

Analytical convolution is used automatically when both components are DeltaFunction, Gaussian, Lorentzian, or Voigt:

import numpy as np
import easydynamics.sample_model as sm
from easydynamics.convolution import Convolution

sample_components = sm.ComponentCollection(
    components=[sm.DeltaFunction(area=0.5), sm.Lorentzian(area=1.0, width=0.3)]
)
resolution_components = sm.ComponentCollection(components=[sm.Gaussian(width=0.05)])
energy = np.linspace(-2, 2, 100)

convolver = Convolution(
    sample_components=sample_components,
    resolution_components=resolution_components,
    energy=energy,
)
y = convolver.convolution()

Including detailed balance and improving numerical accuracy

Providing temperature switches to numerical convolution with detailed balance applied. Increase upsample_factor and extension_factor for better accuracy with narrow peaks:

convolver = Convolution(
    sample_components=sample_components,
    resolution_components=resolution_components,
    energy=energy,
    temperature=10.0,
)
convolver.upsample_factor = 5
convolver.extension_factor = 0.5
y = convolver.convolution()

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent

The sample components to be convolved.

required
resolution_components ComponentCollection | ModelComponent

The resolution components to convolve with.

required
energy_offset Numeric | Parameter

An energy offset to apply to the energy values before convolution.

0.0
convolution_settings ConvolutionSettings | None

The settings for the convolution. If None, default settings will be used.

None
temperature Parameter | Numeric | None

The temperature to use for detailed balance correction.

None
temperature_unit str | sc.Unit

The unit of the temperature parameter.

'K'
detailed_balance_settings DetailedBalanceSettings | None

The settings for detailed balance. If None, default settings will be used.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Methods:

Name Description
convolution

Perform convolution using analytical convolutions where possible, and numerical

convert_y_unit

Convert the y-axis unit and propagate it to the analytical and numerical sub-convolvers.

__setattr__

Custom setattr to invalidate convolution plan on relevant attribute changes, and build a

to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

energy

Set the energy array and invalidate this convolver's plan.

convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

temperature Parameter | None

Get the temperature.

convolution_settings ConvolutionSettings

Get the convolution settings.

upsample_factor Numeric | None

Get the upsample factor.

extension_factor float

Get the extension factor.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the Convolution.

Attributes
unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

temperature property writable

Get the temperature.

Returns:

Type Description
Parameter | None

The temperature parameter, or None if detailed balance correction is disabled.

convolution_settings property writable

Get the convolution settings.

Returns:

Type Description
ConvolutionSettings

The convolution settings.

upsample_factor property writable

Get the upsample factor.

Returns:

Type Description
Numeric | None

The upsample factor.

extension_factor property writable

Get the extension factor.

The extension factor determines how much the energy range is extended on both sides before convolution. 0.2 means extending by 20% of the original energy span on each side

Returns:

Type Description
float

The extension factor.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the Convolution.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the Convolution.

Methods:
convolution()

Perform convolution using analytical convolutions where possible, and numerical convolutions for the remaining components.

Returns:

Type Description
np.ndarray

The convolved values evaluated at energy.

convert_y_unit(unit)

Convert the y-axis unit and propagate it to the analytical and numerical sub-convolvers.

Parameters:

Name Type Description Default
unit str

The new y-axis unit.

required
__setattr__(name, value)

Custom setattr to invalidate convolution plan on relevant attribute changes, and build a new plan.

The new plan is only built after initialization (when _reactions_enabled is True) to avoid issues during init.

Parameters:

Name Type Description Default
name str

The name of the attribute to set.

required
value any

The value to set the attribute to.

required
to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

energy(energy)

Set the energy array and invalidate this convolver's plan.

The dense grid is rebuilt lazily on the next convolution. Other convolvers sharing the same ConvolutionSettings are unaffected — a new energy array is a convolver-local change.

Parameters:

Name Type Description Default
energy np.ndarray

The new energy array.

required
convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convolution_base

Classes:

Name Description
ConvolutionBase

Base class for convolutions of sample and resolution models.

Classes

ConvolutionBase(energy, sample_components=None, resolution_components=None, x_unit='meV', y_unit='dimensionless', energy_offset=0.0, display_name='MyConvolution', unique_name=None)

Base class for convolutions of sample and resolution models.

This base class has no convolution functionality.

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent | None

The sample model to be convolved.

None
resolution_components ComponentCollection | ModelComponent | None

The resolution model to convolve with.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
energy_offset Numeric | Parameter

The energy offset applied to the convolution.

0.0
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Raises:

Type Description
TypeError

If energy is not a numpy ndarray or a scipp Variable or if energy_unit is not a string or scipp unit, or if energy_offset is not a number or a Parameter, or if sample_components is not a ComponentCollection or ModelComponent, or if resolution_components is not a ComponentCollection or ModelComponent.

Methods:

Name Description
convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

convert_y_unit

Convert the y-axis unit of the sample components.

to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

Attributes:

Name Type Description
energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

energy sc.Variable

Get the energy.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

Attributes
energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

energy property writable

Get the energy.

Returns:

Type Description
sc.Variable

The energy values where the convolution is evaluated.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

Methods:
convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convert_y_unit(unit)

Convert the y-axis unit of the sample components.

Only propagates to sample components (resolution is normalised and unit-independent). If any component raises during unit conversion, the conversion is rolled back best-effort before the exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The new y-axis unit.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

Functions:

energy_grid

Classes:

Name Description
EnergyGrid

Container for the dense energy grid and related metadata.

Classes

EnergyGrid(energy_dense, energy_dense_centered, energy_dense_step, energy_span_dense, energy_even_length_offset) dataclass

Container for the dense energy grid and related metadata.

Attributes:

Name Type Description
energy_dense np.ndarray

The upsampled and extended energy array.

energy_dense_centered np.ndarray

The centered version of energy_dense (used for resolution evaluation).

energy_dense_step float

The spacing of energy_dense (used for width checks and normalization).

energy_span_dense float

The total span of energy_dense. (used for width checks).

energy_even_length_offset float

The offset to apply if energy_dense has even length (used for convolution alignment).

numerical_convolution

Classes:

Name Description
NumericalConvolution

Numerical convolution of a ComponentCollection with a ComponentCollection using FFT.

Classes

NumericalConvolution(energy, sample_components, resolution_components, energy_offset=0.0, convolution_settings=None, temperature=None, temperature_unit='K', detailed_balance_settings=None, x_unit='meV', y_unit='dimensionless', display_name='MyConvolution', unique_name=None)

Numerical convolution of a ComponentCollection with a ComponentCollection using FFT.

Includes optional upsampling and extended range to improve accuracy. Warns about very wide or very narrow peaks in the models. If temperature is provided, detailed balance correction is applied to the sample model.

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent

The components to be convolved.

required
resolution_components ComponentCollection | ModelComponent

The resolution components to convolve with.

required
energy_offset Numeric | Parameter

An energy offset to apply to the energy values before convolution.

0.0
convolution_settings ConvolutionSettings | None

The settings for the convolution. If None, default settings will be used.

None
temperature Parameter | Numeric | None

The temperature to use for detailed balance correction.

None
temperature_unit str | sc.Unit

The unit of the temperature parameter.

'K'
detailed_balance_settings DetailedBalanceSettings | None

The settings for detailed balance. If None, default settings will be used.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Raises:

Type Description
TypeError

If temperature is not None, a number, or a Parameter, or if temperature_unit is not a string or sc.Unit.

Methods:

Name Description
convolution

Calculate the convolution of the sample and resolution models at the values given in

to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

energy

Set the energy array and invalidate this convolver's plan.

convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

convert_y_unit

Convert the y-axis unit of the sample components.

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

temperature Parameter | None

Get the temperature.

convolution_settings ConvolutionSettings

Get the convolution settings.

upsample_factor Numeric | None

Get the upsample factor.

extension_factor float

Get the extension factor.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the Convolution.

Attributes
unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

temperature property writable

Get the temperature.

Returns:

Type Description
Parameter | None

The temperature parameter, or None if detailed balance correction is disabled.

convolution_settings property writable

Get the convolution settings.

Returns:

Type Description
ConvolutionSettings

The convolution settings.

upsample_factor property writable

Get the upsample factor.

Returns:

Type Description
Numeric | None

The upsample factor.

extension_factor property writable

Get the extension factor.

The extension factor determines how much the energy range is extended on both sides before convolution. 0.2 means extending by 20% of the original energy span on each side

Returns:

Type Description
float

The extension factor.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the Convolution.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the Convolution.

Methods:
convolution()

Calculate the convolution of the sample and resolution models at the values given in energy. Includes detailed balance correction if temperature is provided.

Returns:

Type Description
np.ndarray

The convolved values evaluated at energy.

to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

energy(energy)

Set the energy array and invalidate this convolver's plan.

The dense grid is rebuilt lazily on the next convolution. Other convolvers sharing the same ConvolutionSettings are unaffected — a new energy array is a convolver-local change.

Parameters:

Name Type Description Default
energy np.ndarray

The new energy array.

required
convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convert_y_unit(unit)

Convert the y-axis unit of the sample components.

Only propagates to sample components (resolution is normalised and unit-independent). If any component raises during unit conversion, the conversion is rolled back best-effort before the exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The new y-axis unit.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

Functions:

numerical_convolution_base

Classes:

Name Description
NumericalConvolutionBase

Base class for numerical convolutions of sample and resolution models.

Classes

NumericalConvolutionBase(energy, sample_components, resolution_components, energy_offset=0.0, convolution_settings=None, temperature=None, temperature_unit='K', detailed_balance_settings=None, x_unit='meV', y_unit='dimensionless', display_name='MyConvolution', unique_name=None)

Base class for numerical convolutions of sample and resolution models.

Provides methods to handle upsampling, extension, and detailed balance correction. This base class has no convolution functionality.

Parameters:

Name Type Description Default
energy np.ndarray | sc.Variable

1D array of energy values where the convolution is evaluated.

required
sample_components ComponentCollection | ModelComponent

The components to be convolved.

required
resolution_components ComponentCollection | ModelComponent

The resolution components to convolve with.

required
energy_offset Numeric | Parameter

An energy offset to apply to the energy values before convolution.

0.0
convolution_settings ConvolutionSettings | None

The settings for the convolution. If None, default settings will be used.

None
temperature Parameter | Numeric | None

The temperature to use for detailed balance correction.

None
temperature_unit str | sc.Unit

The unit of the temperature parameter.

'K'
detailed_balance_settings DetailedBalanceSettings | None

The settings for detailed balance. If None, default settings will be used.

None
x_unit str | sc.Unit

The unit of the energy axis.

'meV'
y_unit str | sc.Unit

The unit of the model output (intensity).

'dimensionless'
display_name str | None

Display name of the model.

'MyConvolution'
unique_name str | None

Unique name of the model. If None, a unique name will be generated.

None

Raises:

Type Description
TypeError

If temperature is not None, a number, or a Parameter, or if temperature_unit is not a string or sc.Unit.

Methods:

Name Description
energy

Set the energy array and invalidate this convolver's plan.

to_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

__copy__

Return a copy of the object.

get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

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 get_free_parameters.

convert_x_unit

Convert the energy axis, energy_offset, and all components to the specified unit.

convert_y_unit

Convert the y-axis unit of the sample components.

Attributes:

Name Type Description
convolution_settings ConvolutionSettings

Get the convolution settings.

upsample_factor Numeric | None

Get the upsample factor.

extension_factor float

Get the extension factor.

temperature Parameter | None

Get the temperature.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the Convolution.

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.

x_unit str | sc.Unit | None

Get the unit of the x-axis.

y_unit str | sc.Unit | None

Get the unit of the model output.

energy_offset Parameter

Get the energy offset.

energy_with_offset sc.Variable

Get the energy with the offset applied.

sample_components ComponentCollection | ModelComponent

Get the sample model.

resolution_components ComponentCollection | ModelComponent

Get the resolution model.

Attributes
convolution_settings property writable

Get the convolution settings.

Returns:

Type Description
ConvolutionSettings

The convolution settings.

upsample_factor property writable

Get the upsample factor.

Returns:

Type Description
Numeric | None

The upsample factor.

extension_factor property writable

Get the extension factor.

The extension factor determines how much the energy range is extended on both sides before convolution. 0.2 means extending by 20% of the original energy span on each side

Returns:

Type Description
float

The extension factor.

temperature property writable

Get the temperature.

Returns:

Type Description
Parameter | None

The temperature parameter, or None if detailed balance correction is disabled.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the Convolution.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the Convolution.

unique_name property writable

Get the unique name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

name property writable

Get the name of the model.

Returns:

Type Description
str

The name of the model.

x_unit property writable

Get the unit of the x-axis.

Returns:

Type Description
str | sc.Unit | None

The unit of the x-axis.

y_unit property writable

Get the unit of the model output.

Returns:

Type Description
str | sc.Unit | None

The unit of the y-axis.

energy_offset property writable

Get the energy offset.

Returns:

Type Description
Parameter

The energy offset applied to the convolution.

energy_with_offset property

Get the energy with the offset applied.

Returns:

Type Description
sc.Variable

The energy values with the offset applied.

sample_components property writable

Get the sample model.

Returns:

Type Description
ComponentCollection | ModelComponent

The sample model to be convolved.

resolution_components property writable

Get the resolution model.

Returns:

Type Description
ComponentCollection | ModelComponent

The resolution model to be convolved.

Methods:
energy(energy)

Set the energy array and invalidate this convolver's plan.

The dense grid is rebuilt lazily on the next convolution. Other convolvers sharing the same ConvolutionSettings are unaffected — a new energy array is a convolver-local change.

Parameters:

Name Type Description Default
energy np.ndarray

The new energy array.

required
to_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerBases generic convert_to_dict method.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the dictionary. By default, None.

None

Returns:

Type Description
Dict[str, Any]

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.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

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.

convert_x_unit(unit)

Convert the energy axis, energy_offset, and all components to the specified unit.

If any conversion fails, the already-converted state is rolled back best-effort before the failing conversion's exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The unit of the energy.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.

convert_y_unit(unit)

Convert the y-axis unit of the sample components.

Only propagates to sample components (resolution is normalised and unit-independent). If any component raises during unit conversion, the conversion is rolled back best-effort before the exception is re-raised.

Parameters:

Name Type Description Default
unit str | sc.Unit

The new y-axis unit.

required

Raises:

Type Description
TypeError

If unit is not a string or scipp unit.