hyperspy.models.model2d module

class hyperspy.models.model2d.Model2D(signal2D, dictionary=None)

Bases: hyperspy.model.BaseModel

Model and data fitting for two dimensional signals.

A model is constructed as a linear combination of components2D that are added to the model using append() or extend(). There are many predifined components available in the in the components2D module. If needed, new components can be created easily using the code of existing components as a template.

Once defined, the model can be fitted to the data using fit() or multifit(). Once the optimizer reaches the convergence criteria or the maximum number of iterations the new value of the component parameters are stored in the components.

It is possible to access the components in the model by their name or by the index in the model. An example is given at the end of this docstring.

Note that methods are not yet defined for plotting 2D models or using gradient based optimisation methods - these will be added soon.


Signal2D instance – It contains the data to fit.


A Signal of floats – Chi-squared of the signal (or np.nan if not yet fit)


A Signal of integers – Degrees of freedom of the signal (0 if not yet fit)


Signal instance – Reduced chi-squared.


ModelComponents instance – The components of the model are attributes of this class. This provides a convinient way to access the model components when working in IPython as it enables tab completion.


Append one component to the model.


Append multiple components to the model.


Remove component from model.

fit, multifit

Fit the model to the data at the current position or the full dataset.

See also

Base, Model1D


add_signal_range(*args, **kwargs)
enable_adjust_position(components=None, fix_them=True, show_label=True)
remove_signal_range(*args, **kwargs)
set_signal_range(*args, **kwargs)