Skip to content

analysis

Modules:

Name Description
analysis
analysis1d
analysis_base
fit_binding
parameter_analysis

Classes:

Name Description
Analysis

For analysing two-dimensional data, i.e. intensity as function of energy and Q.

ParameterAnalysis

For analysing fitted parameters.

Classes

Analysis(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, convolution_settings=None, detailed_balance_settings=None, extra_parameters=None)

For analysing two-dimensional data, i.e. intensity as function of energy and Q.

Supports independent fits of each Q value and simultaneous fits of all Q.

Parameters:

Name Type Description Default
display_name str | None

Display name of the analysis.

'MyAnalysis'
unique_name str | None

Unique name of the analysis. If None, a unique name is automatically generated.

None
experiment Experiment | None

The Experiment associated with this Analysis. If None, a default Experiment is created.

None
sample_model SampleModel | None

The SampleModel associated with this Analysis. If None, a default SampleModel is created.

None
instrument_model InstrumentModel | None

The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created.

None
convolution_settings ConvolutionSettings | None

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

None
detailed_balance_settings DetailedBalanceSettings | None

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

None
extra_parameters Parameter | list[Parameter] | None

Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added.

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

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.

normalize_resolution

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

get_parameters_near_bounds

Get a list of parameters that are near their bounds.

calculate

Calculate model data for a specific Q index.

fit

Fit the model to the experimental data.

plot_data_and_model

Plot the experimental data and the model prediction.

data_and_model_to_datagroup

Create a scipp DataGroup containing the experimental data, model calculation and optionally

parameters_to_dataset

Creates a scipp dataset with copies of the Parameters in the model.

plot_parameters

Plot fitted parameters as a function of Q.

fix_energy_offset

Fix the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index

free_energy_offset

Free the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index

get_fit_functions

Get fit functions for all Q indices, which can be used for simultaneous fitting.

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.

convolution_settings ConvolutionSettings

Get the convolution settings for this Analysis.

experiment Experiment

Get the Experiment associated with this Analysis.

sample_model SampleModel

Get the SampleModel associated with this Analysis.

instrument_model InstrumentModel

Get the InstrumentModel associated with this Analysis.

Q sc.Variable | None

Get the Q values from the associated Experiment, if available.

energy sc.Variable | None

Get the energy values from the associated Experiment, if available.

temperature Parameter | None

Get the temperature from the associated SampleModel, if available.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the SampleModel.

extra_parameters list[Parameter]

Get the extra parameters included in this Analysis.

analysis_list list[Analysis1d]

Get the Analysis1d objects associated with this Analysis.

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.

convolution_settings property writable

Get the convolution settings for this Analysis.

Returns:

Type Description
ConvolutionSettings

The convolution settings for this Analysis.

experiment property writable

Get the Experiment associated with this Analysis.

Returns:

Type Description
Experiment

The Experiment associated with this Analysis.

sample_model property writable

Get the SampleModel associated with this Analysis.

Returns:

Type Description
SampleModel

The SampleModel associated with this Analysis.

instrument_model property writable

Get the InstrumentModel associated with this Analysis.

Returns:

Type Description
InstrumentModel

The InstrumentModel associated with this Analysis.

Q property writable

Get the Q values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The Q values from the associated Experiment, if available, and None if not.

energy property writable

Get the energy values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The energy values from the associated.

temperature property writable

Get the temperature from the associated SampleModel, if available.

Returns:

Type Description
Parameter | None

The temperature from the associated SampleModel, if available, and None if not.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the SampleModel.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the SampleModel.

extra_parameters property writable

Get the extra parameters included in this Analysis.

Returns:

Type Description
list[Parameter]

The extra parameters included in this Analysis.

analysis_list property writable

Get the Analysis1d objects associated with this Analysis.

Returns:

Type Description
list[Analysis1d]

A list of Analysis1d objects, one for each Q index.

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

Returns:

Type Description
str

A string representation of the Analysis.

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.

normalize_resolution()

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

This is important for accurate fitting and interpretation of the results.

get_parameters_near_bounds(rtol=1e-05, atol=1e-08)

Get a list of parameters that are near their bounds.

Parameters:

Name Type Description Default
rtol float

Relative tolerance for determining if a parameter is near its bound.

1e-5
atol float

Absolute tolerance for determining if a parameter is near its bound.

1e-8

Returns:

Type Description
list[Parameter]

A list of parameters that are near their bounds.

Raises:

Type Description
TypeError

If rtol or atol is not a float.

ValueError

If rtol or atol is negative.

calculate(Q_index=None, energy=None)

Calculate model data for a specific Q index.

If Q_index is None, calculate for all Q indices and return a list of arrays.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to calculate for. If None, calculate for all Q values.

None
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None

Returns:

Type Description
list[np.ndarray] | np.ndarray

If Q_index is None, returns a list of numpy arrays, one for each Q index. If Q_index is an integer, returns a single numpy array for that Q index.

fit(fit_method='independent', Q_index=None)

Fit the model to the experimental data.

Parameters:

Name Type Description Default
fit_method str

Method to use for fitting. Options are "independent" (fit each Q index independently, one after the other) or "simultaneous" (fit all Q indices simultaneously).

'independent'
Q_index int | None

If fit_method is "independent", specify which Q index to fit. If None, fit all Q indices independently. Ignored if fit_method is "simultaneous".

None

Raises:

Type Description
ValueError

If fit_method is not "independent" or "simultaneous" or if there are no Q values available for fitting.

Returns:

Type Description
FitResults | list[FitResults]

A list of FitResults if fitting independently, or a single FitResults object if fitting simultaneously.

plot_data_and_model(Q_index=None, plot_components=True, add_background=True, plot_residuals=False, energy=None, **kwargs)

Plot the experimental data and the model prediction.

Optionally also plot the individual components of the model.

Uses Plopp for plotting: https://scipp.github.io/plopp/

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to plot. If None, plot all Q values.

None
plot_components bool

Whether to plot the individual components.

True
add_background bool

Whether to add background components to the sample model components when plotting. Default is True.

True
plot_residuals bool

Whether to plot the residuals (data - model). Default is False.

False
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None
**kwargs dict[str, Any]

Additional keyword arguments passed to plopp for customizing the plot.

{}

Raises:

Type Description
ValueError

If Q_index is out of bounds, or if there is no data to plot, or if there are no Q values available for plotting.

RuntimeError

If not in a Jupyter notebook environment.

TypeError

If plot_components or add_background is not True or False.

Returns:

Type Description
InteractiveFigure

A Plopp InteractiveFigure containing the plot of the data and model.

data_and_model_to_datagroup(energy=None, add_background=True, include_components=True, include_residuals=False)

Create a scipp DataGroup containing the experimental data, model calculation and optionally the individual components of the model.

Parameters:

Name Type Description Default
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None
add_background bool

Whether to add background components to the sample model components when creating the DataGroup.

True
include_components bool

Whether to include the individual components of the model in the DataGroup. If False, only the total model will be included.

True
include_residuals bool

Whether to include the residuals (data - model) in the DataGroup.

False

Raises:

Type Description
ValueError

If there is no data to include in the DataGroup, or if there are no Q values available for creating the DataGroup.

TypeError

If add_background is not True or False. If include_components is not True or False.

Returns:

Type Description
sc.DataGroup

A DataGroup containing the experimental data, model calculation, and optionally the individual components of the model.

parameters_to_dataset()

Creates a scipp dataset with copies of the Parameters in the model.

Ensures unit consistency across Q.

Raises:

Type Description
UnitError

If there are inconsistent units for the same parameter across different Q values.

Returns:

Type Description
sc.Dataset

A dataset where each entry is a parameter, with dimensions "Q" and values corresponding to the parameter values.

plot_parameters(names=None, **kwargs)

Plot fitted parameters as a function of Q.

Parameters:

Name Type Description Default
names str | list[str] | None

Name(s) of the parameter(s) to plot. If None, plots all parameters.

None
**kwargs dict[str, Any]

Additional keyword arguments passed to plopp.slicer for customizing the plot (e.g., title, linestyle, marker, color).

{}

Raises:

Type Description
TypeError

If names is not a string, list of strings, or None.

ValueError

If any of the specified parameter names are not found in the dataset.

Returns:

Type Description
InteractiveFigure

A Plopp InteractiveFigure containing the plot of the parameters.

fix_energy_offset(Q_index=None)

Fix the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index is None.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to fix the energy offset for. If None, fixes the energy offset for all Q values.

None
free_energy_offset(Q_index=None)

Free the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index is None.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to free the energy offset for. If None, frees the energy offset for all Q values.

None
get_fit_functions()

Get fit functions for all Q indices, which can be used for simultaneous fitting.

Returns:

Type Description
list[callable]

A list of fit functions, one for each Q index.

ParameterAnalysis(parameters=None, bindings=None, display_name='ParameterAnalysis', unique_name=None)

For analysing fitted parameters.

Can be used to fit parameters to ModelComponents, ComponentCollections, or DiffusionModelBase objects, and to plot the parameters and fit results. The parameters to be analyzed can be provided as a sc.Dataset or directly as an Analysis object. Multiple parameters can be fitted simultaneously, and the fit functions can be customized for each parameter. For diffusion models, the area and width can be fitted separately (or not at all) by specifying fit settings.

Parameters:

Name Type Description Default
parameters sc.Dataset | Analysis | None

The parameters to analyze. Can be provided as a sc.Dataset or as an Analysis (in which case the parameters will be extracted from the Analysis).

None
bindings FitBinding | list[FitBinding] | None

The fit bindings to use for fitting the parameters. Can be a single FitBinding or a list of FitBindings. If None, no fit bindings are provided.

None
display_name str | None

Display name of the analysis.

'ParameterAnalysis'
unique_name str | None

Unique name of the analysis. 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_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.

fit

Fit the parameters using the specified fit functions and settings.

plot

Plot the parameters and fit results.

calculate_model_dataset

Evaluate all bindings into a sc.Dataset of model predictions.

append_binding

Append a FitBinding to the list of bindings for the parameter analysis.

clear_bindings

Clear all FitBindings from the list of bindings for the parameter analysis.

get_all_variables

Get all variables from the fit functions.

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.

parameters sc.Dataset | None

Get the parameters for the parameter analysis.

bindings list[FitBinding]

Get the fit bindings for the parameter analysis.

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.

parameters property writable

Get the parameters for the parameter analysis.

Returns:

Type Description
sc.Dataset | None

The parameters for the parameter analysis.

bindings property writable

Get the fit bindings for the parameter analysis.

Returns:

Type Description
list[FitBinding]

The fit bindings for the parameter analysis.

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.

fit()

Fit the parameters using the specified fit functions and settings.

Returns:

Type Description
FitResults

The results of the fit

Raises:

Type Description
ValueError

If no parameters Dataset is provided. If no fit functions are provided. If no parameter names are found for the fit functions.

plot(names=None, **kwargs)

Plot the parameters and fit results.

Parameters:

Name Type Description Default
names str | list[str] | None

The names of the parameters to plot. If None, all parameters with bindings are plotted.

None
**kwargs dict[str, Any]

Additional keyword arguments to pass to the plotting function.

{}

Returns:

Type Description
InteractiveFigure

An interactive figure containing the plots of the parameters and fit results.

Raises:

Type Description
ValueError

If the units of the specified parameters are not consistent.

RuntimeError

If plot() is called outside of a Jupyter notebook environment.

calculate_model_dataset(bindings)

Evaluate all bindings into a sc.Dataset of model predictions.

Parameters:

Name Type Description Default
bindings list[FitBinding]

The bindings to evaluate.

required

Returns:

Type Description
sc.Dataset

A sc.Dataset containing the model predictions for all bindings.

Raises:

Type Description
ValueError

If any parameter name from the bindings is not found in the parameters Dataset.

TypeError

If bindings is not a list of FitBinding objects.

append_binding(binding)

Append a FitBinding to the list of bindings for the parameter analysis.

Parameters:

Name Type Description Default
binding FitBinding

The FitBinding to append.

required

Raises:

Type Description
TypeError

If binding is not a FitBinding object.

clear_bindings()

Clear all FitBindings from the list of bindings for the parameter analysis.

get_all_variables()

Get all variables from the fit functions.

Returns:

Type Description
list

A list of all variables from the fit functions.

Modules

analysis

Classes:

Name Description
Analysis

For analysing two-dimensional data, i.e. intensity as function of energy and Q.

Classes

Analysis(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, convolution_settings=None, detailed_balance_settings=None, extra_parameters=None)

For analysing two-dimensional data, i.e. intensity as function of energy and Q.

Supports independent fits of each Q value and simultaneous fits of all Q.

Parameters:

Name Type Description Default
display_name str | None

Display name of the analysis.

'MyAnalysis'
unique_name str | None

Unique name of the analysis. If None, a unique name is automatically generated.

None
experiment Experiment | None

The Experiment associated with this Analysis. If None, a default Experiment is created.

None
sample_model SampleModel | None

The SampleModel associated with this Analysis. If None, a default SampleModel is created.

None
instrument_model InstrumentModel | None

The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created.

None
convolution_settings ConvolutionSettings | None

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

None
detailed_balance_settings DetailedBalanceSettings | None

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

None
extra_parameters Parameter | list[Parameter] | None

Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added.

None

Methods:

Name Description
calculate

Calculate model data for a specific Q index.

fit

Fit the model to the experimental data.

plot_data_and_model

Plot the experimental data and the model prediction.

data_and_model_to_datagroup

Create a scipp DataGroup containing the experimental data, model calculation and optionally

parameters_to_dataset

Creates a scipp dataset with copies of the Parameters in the model.

plot_parameters

Plot fitted parameters as a function of Q.

fix_energy_offset

Fix the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index

free_energy_offset

Free the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index

get_fit_functions

Get fit functions for all Q indices, which can be used for simultaneous fitting.

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

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.

normalize_resolution

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

get_parameters_near_bounds

Get a list of parameters that are near their bounds.

Attributes:

Name Type Description
analysis_list list[Analysis1d]

Get the Analysis1d objects associated with this Analysis.

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.

convolution_settings ConvolutionSettings

Get the convolution settings for this Analysis.

experiment Experiment

Get the Experiment associated with this Analysis.

sample_model SampleModel

Get the SampleModel associated with this Analysis.

instrument_model InstrumentModel

Get the InstrumentModel associated with this Analysis.

Q sc.Variable | None

Get the Q values from the associated Experiment, if available.

energy sc.Variable | None

Get the energy values from the associated Experiment, if available.

temperature Parameter | None

Get the temperature from the associated SampleModel, if available.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the SampleModel.

extra_parameters list[Parameter]

Get the extra parameters included in this Analysis.

Attributes
analysis_list property writable

Get the Analysis1d objects associated with this Analysis.

Returns:

Type Description
list[Analysis1d]

A list of Analysis1d objects, one for each Q index.

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.

convolution_settings property writable

Get the convolution settings for this Analysis.

Returns:

Type Description
ConvolutionSettings

The convolution settings for this Analysis.

experiment property writable

Get the Experiment associated with this Analysis.

Returns:

Type Description
Experiment

The Experiment associated with this Analysis.

sample_model property writable

Get the SampleModel associated with this Analysis.

Returns:

Type Description
SampleModel

The SampleModel associated with this Analysis.

instrument_model property writable

Get the InstrumentModel associated with this Analysis.

Returns:

Type Description
InstrumentModel

The InstrumentModel associated with this Analysis.

Q property writable

Get the Q values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The Q values from the associated Experiment, if available, and None if not.

energy property writable

Get the energy values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The energy values from the associated.

temperature property writable

Get the temperature from the associated SampleModel, if available.

Returns:

Type Description
Parameter | None

The temperature from the associated SampleModel, if available, and None if not.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the SampleModel.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the SampleModel.

extra_parameters property writable

Get the extra parameters included in this Analysis.

Returns:

Type Description
list[Parameter]

The extra parameters included in this Analysis.

Functions
calculate(Q_index=None, energy=None)

Calculate model data for a specific Q index.

If Q_index is None, calculate for all Q indices and return a list of arrays.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to calculate for. If None, calculate for all Q values.

None
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None

Returns:

Type Description
list[np.ndarray] | np.ndarray

If Q_index is None, returns a list of numpy arrays, one for each Q index. If Q_index is an integer, returns a single numpy array for that Q index.

fit(fit_method='independent', Q_index=None)

Fit the model to the experimental data.

Parameters:

Name Type Description Default
fit_method str

Method to use for fitting. Options are "independent" (fit each Q index independently, one after the other) or "simultaneous" (fit all Q indices simultaneously).

'independent'
Q_index int | None

If fit_method is "independent", specify which Q index to fit. If None, fit all Q indices independently. Ignored if fit_method is "simultaneous".

None

Raises:

Type Description
ValueError

If fit_method is not "independent" or "simultaneous" or if there are no Q values available for fitting.

Returns:

Type Description
FitResults | list[FitResults]

A list of FitResults if fitting independently, or a single FitResults object if fitting simultaneously.

plot_data_and_model(Q_index=None, plot_components=True, add_background=True, plot_residuals=False, energy=None, **kwargs)

Plot the experimental data and the model prediction.

Optionally also plot the individual components of the model.

Uses Plopp for plotting: https://scipp.github.io/plopp/

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to plot. If None, plot all Q values.

None
plot_components bool

Whether to plot the individual components.

True
add_background bool

Whether to add background components to the sample model components when plotting. Default is True.

True
plot_residuals bool

Whether to plot the residuals (data - model). Default is False.

False
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None
**kwargs dict[str, Any]

Additional keyword arguments passed to plopp for customizing the plot.

{}

Raises:

Type Description
ValueError

If Q_index is out of bounds, or if there is no data to plot, or if there are no Q values available for plotting.

RuntimeError

If not in a Jupyter notebook environment.

TypeError

If plot_components or add_background is not True or False.

Returns:

Type Description
InteractiveFigure

A Plopp InteractiveFigure containing the plot of the data and model.

data_and_model_to_datagroup(energy=None, add_background=True, include_components=True, include_residuals=False)

Create a scipp DataGroup containing the experimental data, model calculation and optionally the individual components of the model.

Parameters:

Name Type Description Default
energy sc.Variable | None

The energy values to use for calculating the model. If None, uses the energy from the experiment.

None
add_background bool

Whether to add background components to the sample model components when creating the DataGroup.

True
include_components bool

Whether to include the individual components of the model in the DataGroup. If False, only the total model will be included.

True
include_residuals bool

Whether to include the residuals (data - model) in the DataGroup.

False

Raises:

Type Description
ValueError

If there is no data to include in the DataGroup, or if there are no Q values available for creating the DataGroup.

TypeError

If add_background is not True or False. If include_components is not True or False.

Returns:

Type Description
sc.DataGroup

A DataGroup containing the experimental data, model calculation, and optionally the individual components of the model.

parameters_to_dataset()

Creates a scipp dataset with copies of the Parameters in the model.

Ensures unit consistency across Q.

Raises:

Type Description
UnitError

If there are inconsistent units for the same parameter across different Q values.

Returns:

Type Description
sc.Dataset

A dataset where each entry is a parameter, with dimensions "Q" and values corresponding to the parameter values.

plot_parameters(names=None, **kwargs)

Plot fitted parameters as a function of Q.

Parameters:

Name Type Description Default
names str | list[str] | None

Name(s) of the parameter(s) to plot. If None, plots all parameters.

None
**kwargs dict[str, Any]

Additional keyword arguments passed to plopp.slicer for customizing the plot (e.g., title, linestyle, marker, color).

{}

Raises:

Type Description
TypeError

If names is not a string, list of strings, or None.

ValueError

If any of the specified parameter names are not found in the dataset.

Returns:

Type Description
InteractiveFigure

A Plopp InteractiveFigure containing the plot of the parameters.

fix_energy_offset(Q_index=None)

Fix the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index is None.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to fix the energy offset for. If None, fixes the energy offset for all Q values.

None
free_energy_offset(Q_index=None)

Free the energy offset parameter(s) for a specific Q index, or for all Q indices if Q_index is None.

Parameters:

Name Type Description Default
Q_index int | None

Index of the Q value to free the energy offset for. If None, frees the energy offset for all Q values.

None
get_fit_functions()

Get fit functions for all Q indices, which can be used for simultaneous fitting.

Returns:

Type Description
list[callable]

A list of fit functions, one for each Q index.

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

Returns:

Type Description
str

A string representation of the Analysis.

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.

normalize_resolution()

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

This is important for accurate fitting and interpretation of the results.

get_parameters_near_bounds(rtol=1e-05, atol=1e-08)

Get a list of parameters that are near their bounds.

Parameters:

Name Type Description Default
rtol float

Relative tolerance for determining if a parameter is near its bound.

1e-5
atol float

Absolute tolerance for determining if a parameter is near its bound.

1e-8

Returns:

Type Description
list[Parameter]

A list of parameters that are near their bounds.

Raises:

Type Description
TypeError

If rtol or atol is not a float.

ValueError

If rtol or atol is negative.

Functions

analysis1d

Classes:

Name Description
Analysis1d

For analysing one-dimensional data, i.e. intensity as function of energy for a single Q index.

Classes

Analysis1d(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, Q_index=None, convolution_settings=None, detailed_balance_settings=None, extra_parameters=None)

For analysing one-dimensional data, i.e. intensity as function of energy for a single Q index.

Is used primarily in the Analysis class, but can also be used on its own for simpler analyses.

Parameters:

Name Type Description Default
display_name str | None

Display name of the analysis.

'MyAnalysis'
unique_name str | None

Unique name of the analysis. If None, a unique name is automatically generated.

None
experiment Experiment | None

The Experiment associated with this Analysis. If None, a default Experiment is created.

None
sample_model SampleModel | None

The SampleModel associated with this Analysis. If None, a default SampleModel is created.

None
instrument_model InstrumentModel | None

The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created.

None
Q_index int | None

The Q index to analyze. If None, the analysis will not be able to calculate or fit until a Q index is set.

None
convolution_settings ConvolutionSettings | None

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

None
detailed_balance_settings DetailedBalanceSettings | None

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

None
extra_parameters Parameter | list[Parameter] | None

Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added.

None

Methods:

Name Description
calculate

Calculate the model prediction for the chosen Q index.

fit

Fit the model to the experimental data for the chosen Q index.

as_fit_function

Return self._calculate as a fit function.

get_all_variables

Get all variables used in the analysis.

plot_data_and_model

Plot the experimental data and the model prediction for the chosen Q index. Optionally also

data_and_model_to_datagroup

Create a scipp DataGroup containing the experimental data, model calculation, and

fix_energy_offset

Fix the energy offset parameter for the current Q index.

free_energy_offset

Free the energy offset parameter for the current Q index.

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

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.

normalize_resolution

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

get_parameters_near_bounds

Get a list of parameters that are near their bounds.

Attributes:

Name Type Description
Q_index int | None

Get the Q index associated with this Analysis.

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.

convolution_settings ConvolutionSettings

Get the convolution settings for this Analysis.

experiment Experiment

Get the Experiment associated with this Analysis.

sample_model SampleModel

Get the SampleModel associated with this Analysis.

instrument_model InstrumentModel

Get the InstrumentModel associated with this Analysis.

Q sc.Variable | None

Get the Q values from the associated Experiment, if available.

energy sc.Variable | None

Get the energy values from the associated Experiment, if available.

temperature Parameter | None

Get the temperature from the associated SampleModel, if available.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the SampleModel.

extra_parameters list[Parameter]

Get the extra parameters included in this Analysis.

Attributes
Q_index property writable

Get the Q index associated with this Analysis.

Returns:

Type Description
int | None

The Q index associated with this Analysis.

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.

convolution_settings property writable

Get the convolution settings for this Analysis.

Returns:

Type Description
ConvolutionSettings

The convolution settings for this Analysis.

experiment property writable

Get the Experiment associated with this Analysis.

Returns:

Type Description
Experiment

The Experiment associated with this Analysis.

sample_model property writable

Get the SampleModel associated with this Analysis.

Returns:

Type Description
SampleModel

The SampleModel associated with this Analysis.

instrument_model property writable

Get the InstrumentModel associated with this Analysis.

Returns:

Type Description
InstrumentModel

The InstrumentModel associated with this Analysis.

Q property writable

Get the Q values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The Q values from the associated Experiment, if available, and None if not.

energy property writable

Get the energy values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The energy values from the associated.

temperature property writable

Get the temperature from the associated SampleModel, if available.

Returns:

Type Description
Parameter | None

The temperature from the associated SampleModel, if available, and None if not.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the SampleModel.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the SampleModel.

extra_parameters property writable

Get the extra parameters included in this Analysis.

Returns:

Type Description
list[Parameter]

The extra parameters included in this Analysis.

Functions
calculate(energy=None)

Calculate the model prediction for the chosen Q index.

Makes sure the convolver is up to date before calculating.

Parameters:

Name Type Description Default
energy sc.Variable | None

Optional energy grid to use for calculation. If None, the energy grid from the experiment is used.

None

Returns:

Type Description
np.ndarray

The calculated model prediction.

fit()

Fit the model to the experimental data for the chosen Q index.

The energy grid is fixed for the duration of the fit. Convolution objects are created once and reused during parameter optimization for performance reasons.

Raises:

Type Description
ValueError

If no experiment is associated with this Analysis.

Returns:

Type Description
FitResults

The result of the fit.

as_fit_function(_x=None, **kwargs)

Return self._calculate as a fit function.

The EasyScience fitter requires x as input, but self._calculate() already uses the correct energy from the experiment. So we ignore the x input and just return the calculated model.

Parameters:

Name Type Description Default
_x np.ndarray | sc.Variable | None

Ignored. The energy grid is taken from the experiment.

None
**kwargs dict[str, Any]

Ignored. Included for compatibility with the EasyScience fitter.

{}

Returns:

Type Description
callable

A function that can be used as a fit function in the EasyScience fitter, which returns the calculated model.

get_all_variables()

Get all variables used in the analysis.

Returns:

Type Description
list[DescriptorNumber]

A list of all variables.

plot_data_and_model(plot_components=True, add_background=True, plot_residuals=False, energy=None, **kwargs)

Plot the experimental data and the model prediction for the chosen Q index. Optionally also plot the individual components of the model.

Uses Plopp for plotting: https://scipp.github.io/plopp/

Parameters:

Name Type Description Default
plot_components bool

Whether to plot the individual components of the model.

True
add_background bool

Whether to add the background to the model prediction when plotting individual components.

True
plot_residuals bool

Whether to plot the residuals (data - model).

False
energy sc.Variable | None

Optional energy grid to use for plotting. If None, the energy grid from the experiment is used.

None
**kwargs dict[str, Any]

Keyword arguments to pass to the plotting function.

{}

Returns:

Type Description
InteractiveFigure

A plot of the data and model.

data_and_model_to_datagroup(energy=None, add_background=True, include_components=True, include_residuals=False)

Create a scipp DataGroup containing the experimental data, model calculation, and optionally the individual components.

Parameters:

Name Type Description Default
energy sc.Variable | None

Optional energy grid to use for the model calculation. If None, the energy grid from the experiment is used.

None
add_background bool

Whether to add the background to the model prediction when plotting individual components.

True
include_components bool

Whether to include the individual components of the model in the DataGroup. If True, the DataGroup will include a DataArray for each component with the component's display name as the key

True
include_residuals bool

Whether to include the residuals (data - model) in the DataGroup. If True, the DataGroup will include a DataArray with key 'Residuals' containing the residuals.

False

Raises:

Type Description
ValueError

If no data is available in the experiment to include in the DataGroup. If no Q values are available in the experiment to create the DataGroup. If Q_index is not set to create the DataGroup.

TypeError

If add_background is not a boolean. If include_components is not a boolean.

Returns:

Type Description
sc.DataGroup

A DataGroup containing the experimental data, model calculation, and optionally the individual components.

fix_energy_offset()

Fix the energy offset parameter for the current Q index.

free_energy_offset()

Free the energy offset parameter for the current Q index.

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

Returns:

Type Description
str

A string representation of the Analysis.

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.

normalize_resolution()

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

This is important for accurate fitting and interpretation of the results.

get_parameters_near_bounds(rtol=1e-05, atol=1e-08)

Get a list of parameters that are near their bounds.

Parameters:

Name Type Description Default
rtol float

Relative tolerance for determining if a parameter is near its bound.

1e-5
atol float

Absolute tolerance for determining if a parameter is near its bound.

1e-8

Returns:

Type Description
list[Parameter]

A list of parameters that are near their bounds.

Raises:

Type Description
TypeError

If rtol or atol is not a float.

ValueError

If rtol or atol is negative.

Functions

analysis_base

Classes:

Name Description
AnalysisBase

Base class for analysis in EasyDynamics.

Classes

AnalysisBase(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, convolution_settings=None, detailed_balance_settings=None, extra_parameters=None)

Base class for analysis in EasyDynamics.

This class is not meant to be used directly.

An Analysis consists of an Experiment, a SampleModel, and an InstrumentModel. The Experiment contains the data to be fitted, the SampleModel contains the model for the sample, and the InstrumentModel contains the model for the instrument, including background and resolution

Parameters:

Name Type Description Default
display_name str | None

Display name of the analysis.

'MyAnalysis'
unique_name str | None

Unique name of the analysis. If None, a unique name is automatically generated. By default, None.

None
experiment Experiment | None

The Experiment associated with this Analysis. If None, a default Experiment is created.

None
sample_model SampleModel | None

The SampleModel associated with this Analysis. If None, a default SampleModel is created.

None
instrument_model InstrumentModel | None

The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created.

None
convolution_settings ConvolutionSettings | None

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

None
detailed_balance_settings DetailedBalanceSettings | None

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

None
extra_parameters Parameter | list[Parameter] | None

Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added.

None

Raises:

Type Description
TypeError

If experiment is not an Experiment or None or if sample_model is not a SampleModel or None or if instrument_model is not an InstrumentModel or None or if convolution_settings is not a ConvolutionSettings or None or if detailed_balance_settings is not a DetailedBalanceSettings or None or if extra_parameters is not a Parameter, a list of Parameters, or None.

Methods:

Name Description
normalize_resolution

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

get_parameters_near_bounds

Get a list of parameters that are near their bounds.

__repr__

Return a string representation of the Analysis.

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 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
experiment Experiment

Get the Experiment associated with this Analysis.

sample_model SampleModel

Get the SampleModel associated with this Analysis.

instrument_model InstrumentModel

Get the InstrumentModel associated with this Analysis.

Q sc.Variable | None

Get the Q values from the associated Experiment, if available.

energy sc.Variable | None

Get the energy values from the associated Experiment, if available.

temperature Parameter | None

Get the temperature from the associated SampleModel, if available.

convolution_settings ConvolutionSettings

Get the convolution settings for this Analysis.

detailed_balance_settings DetailedBalanceSettings

Get the DetailedBalanceSettings of the SampleModel.

extra_parameters list[Parameter]

Get the extra parameters included in this Analysis.

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
experiment property writable

Get the Experiment associated with this Analysis.

Returns:

Type Description
Experiment

The Experiment associated with this Analysis.

sample_model property writable

Get the SampleModel associated with this Analysis.

Returns:

Type Description
SampleModel

The SampleModel associated with this Analysis.

instrument_model property writable

Get the InstrumentModel associated with this Analysis.

Returns:

Type Description
InstrumentModel

The InstrumentModel associated with this Analysis.

Q property writable

Get the Q values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The Q values from the associated Experiment, if available, and None if not.

energy property writable

Get the energy values from the associated Experiment, if available.

Returns:

Type Description
sc.Variable | None

The energy values from the associated.

temperature property writable

Get the temperature from the associated SampleModel, if available.

Returns:

Type Description
Parameter | None

The temperature from the associated SampleModel, if available, and None if not.

convolution_settings property writable

Get the convolution settings for this Analysis.

Returns:

Type Description
ConvolutionSettings

The convolution settings for this Analysis.

detailed_balance_settings property writable

Get the DetailedBalanceSettings of the SampleModel.

Returns:

Type Description
DetailedBalanceSettings

The DetailedBalanceSettings of the SampleModel.

extra_parameters property writable

Get the extra parameters included in this Analysis.

Returns:

Type Description
list[Parameter]

The extra parameters included in this Analysis.

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
normalize_resolution()

Normalize the resolution in the InstrumentModel to ensure that it integrates to 1.

This is important for accurate fitting and interpretation of the results.

get_parameters_near_bounds(rtol=1e-05, atol=1e-08)

Get a list of parameters that are near their bounds.

Parameters:

Name Type Description Default
rtol float

Relative tolerance for determining if a parameter is near its bound.

1e-5
atol float

Absolute tolerance for determining if a parameter is near its bound.

1e-8

Returns:

Type Description
list[Parameter]

A list of parameters that are near their bounds.

Raises:

Type Description
TypeError

If rtol or atol is not a float.

ValueError

If rtol or atol is negative.

__repr__()

Return a string representation of the Analysis.

Returns:

Type Description
str

A string representation of the Analysis.

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.

fit_binding

Classes:

Name Description
FitBinding

Contract between dataset, model, and fit function for ParameterAnalysis. This class

Classes

FitBinding(parameter_name, model, modes=None, display_name=None, unique_name=None)

Contract between dataset, model, and fit function for ParameterAnalysis. This class encapsulates the necessary information to bind a dataset key to a model and convert it into a fit function callable.

Parameters:

Name Type Description Default
parameter_name str

The name of the parameter to fit. This should correspond to a key in the dataset.

required
model ModelComponent | ComponentCollection | DiffusionModelBase

The model to fit. This can be a single ModelComponent, a ComponentCollection, or a DiffusionModelBase.

required
modes str | list[str] | None

The modes to fit for diffusion models. This can be a single string, a list of strings, or None (which defaults to ["area", "width"]). Only applicable if the model is a DiffusionModelBase. Default is None.

None
display_name str | None

An optional display name for the FitBinding. If None, the unique_name will be used. Default is None.

None
unique_name str | None

An optional unique name for the FitBinding. If None, a unique name will be generated. Default is None.

None

Raises:

Type Description
TypeError

If parameter_name is not a string, if model is not a ModelComponent, ComponentCollection or DiffusionModelBase, or if modes is not a string, list of strings, or None.

Examples:

  1. Basic usage with a ModelComponent:
>>> import easydynamics.sample_model as sm
>>> import easydynamics as edyn
>>> fit_func = sm.Polynomial(coefficients=[3.7, -0.5], display_name='Straight line')
>>> binding = edyn.FitBinding(parameter_name='Gaussian area', model=fit_func)
>>> print(binding)
FitBinding(parameter_name='Gaussian area', model=Polynomial(unique_name = Polynomial_1,
unit = meV, coefficients = [Straight line_c0=3.7, Straight line_c1=-0.5]), modes=None)
  1. Usage with a DiffusionModelBase and specific modes:
>>> brownian_diffusion_model = sm.BrownianTranslationalDiffusion(
...     display_name='Brownian Translational Diffusion',
...     diffusion_coefficient=2.4e-9,
...     scale=0.5,
... )
>>> binding = edyn.FitBinding(
...     parameter_name='Lorentzian',
...     model=brownian_diffusion_model,
...     modes=['area', 'width'],
... )
FitBinding(parameter_name=Lorentzian, model=Brownian Translational Diffusion,
modes=['area', 'width'], display_name=FitBinding_1, unique_name=FitBinding_1)

Methods:

Name Description
build_callables

Build the callables for fitting based on the model and modes.

get_model_names

Get the names of the models based on the current modes.

get_parameter_names

Get the names of the parameters based on the current modes.

__repr__

Return a string representation of the FitBinding.

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
parameter_name str

The name of the parameter to fit. This should correspond to a key in the dataset.

model ModelComponent | ComponentCollection | DiffusionModelBase

The model to fit. This can be a single ModelComponent, a ComponentCollection, or a

modes str | list[str] | None

The modes to fit for diffusion models. This can be a single string, a list of strings, or

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.

Attributes
parameter_name property writable

The name of the parameter to fit. This should correspond to a key in the dataset.

Returns:

Type Description
str

The name of the parameter to fit.

model property writable

The model to fit. This can be a single ModelComponent, a ComponentCollection, or a DiffusionModelBase.

Returns:

Type Description
ModelComponent | ComponentCollection | DiffusionModelBase

The model to fit.

modes property writable

The modes to fit for diffusion models. This can be a single string, a list of strings, or None (which defaults to ["area", "width"]).

Returns:

Type Description
str | list[str] | None

The modes to fit for diffusion models.

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.

Functions
build_callables()

Build the callables for fitting based on the model and modes.

Returns:

Type Description
list[Callable]

A list of callables for fitting.

get_model_names()

Get the names of the models based on the current modes.

Returns:

Type Description
list[str]

A list of model names.

get_parameter_names()

Get the names of the parameters based on the current modes.

Returns:

Type Description
list[str]

A list of parameter names.

__repr__()

Return a string representation of the FitBinding.

Returns:

Type Description
str

A string representation of the FitBinding.

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.

parameter_analysis

Classes:

Name Description
ParameterAnalysis

For analysing fitted parameters.

Classes

ParameterAnalysis(parameters=None, bindings=None, display_name='ParameterAnalysis', unique_name=None)

For analysing fitted parameters.

Can be used to fit parameters to ModelComponents, ComponentCollections, or DiffusionModelBase objects, and to plot the parameters and fit results. The parameters to be analyzed can be provided as a sc.Dataset or directly as an Analysis object. Multiple parameters can be fitted simultaneously, and the fit functions can be customized for each parameter. For diffusion models, the area and width can be fitted separately (or not at all) by specifying fit settings.

Parameters:

Name Type Description Default
parameters sc.Dataset | Analysis | None

The parameters to analyze. Can be provided as a sc.Dataset or as an Analysis (in which case the parameters will be extracted from the Analysis).

None
bindings FitBinding | list[FitBinding] | None

The fit bindings to use for fitting the parameters. Can be a single FitBinding or a list of FitBindings. If None, no fit bindings are provided.

None
display_name str | None

Display name of the analysis.

'ParameterAnalysis'
unique_name str | None

Unique name of the analysis. If None, a unique name is automatically generated. By default, None.

None

Methods:

Name Description
fit

Fit the parameters using the specified fit functions and settings.

plot

Plot the parameters and fit results.

calculate_model_dataset

Evaluate all bindings into a sc.Dataset of model predictions.

append_binding

Append a FitBinding to the list of bindings for the parameter analysis.

clear_bindings

Clear all FitBindings from the list of bindings for the parameter analysis.

get_all_variables

Get all variables from the fit functions.

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 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
parameters sc.Dataset | None

Get the parameters for the parameter analysis.

bindings list[FitBinding]

Get the fit bindings for the parameter analysis.

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
parameters property writable

Get the parameters for the parameter analysis.

Returns:

Type Description
sc.Dataset | None

The parameters for the parameter analysis.

bindings property writable

Get the fit bindings for the parameter analysis.

Returns:

Type Description
list[FitBinding]

The fit bindings for the parameter analysis.

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
fit()

Fit the parameters using the specified fit functions and settings.

Returns:

Type Description
FitResults

The results of the fit

Raises:

Type Description
ValueError

If no parameters Dataset is provided. If no fit functions are provided. If no parameter names are found for the fit functions.

plot(names=None, **kwargs)

Plot the parameters and fit results.

Parameters:

Name Type Description Default
names str | list[str] | None

The names of the parameters to plot. If None, all parameters with bindings are plotted.

None
**kwargs dict[str, Any]

Additional keyword arguments to pass to the plotting function.

{}

Returns:

Type Description
InteractiveFigure

An interactive figure containing the plots of the parameters and fit results.

Raises:

Type Description
ValueError

If the units of the specified parameters are not consistent.

RuntimeError

If plot() is called outside of a Jupyter notebook environment.

calculate_model_dataset(bindings)

Evaluate all bindings into a sc.Dataset of model predictions.

Parameters:

Name Type Description Default
bindings list[FitBinding]

The bindings to evaluate.

required

Returns:

Type Description
sc.Dataset

A sc.Dataset containing the model predictions for all bindings.

Raises:

Type Description
ValueError

If any parameter name from the bindings is not found in the parameters Dataset.

TypeError

If bindings is not a list of FitBinding objects.

append_binding(binding)

Append a FitBinding to the list of bindings for the parameter analysis.

Parameters:

Name Type Description Default
binding FitBinding

The FitBinding to append.

required

Raises:

Type Description
TypeError

If binding is not a FitBinding object.

clear_bindings()

Clear all FitBindings from the list of bindings for the parameter analysis.

get_all_variables()

Get all variables from the fit functions.

Returns:

Type Description
list

A list of all variables from the fit 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.