Component#

class hyperspy.component.Component(parameter_name_list, linear_parameter_list=None, *args, **kwargs)#

Bases: HasTraits

The component of a model.

Attributes:
activebool
namestr
free_parameterslist

The list of free parameters of the component.

parameterslist

The list of parameters of the component.

Parameters:
parameter_name_listlist

The list of parameter names.

linear_parameter_listlist, optional

The list of linear parameter. The default is None.

property active_is_multidimensional#

In multidimensional signals it is possible to store the value of the active attribute at each navigation index.

as_dictionary(fullcopy=True)#

Returns component as a dictionary. For more information on method and conventions, see export_to_dictionary().

Parameters:
fullcopybool, optional False

Copies of objects are stored, not references. If any found, functions will be pickled and signals converted to dictionaries

Returns:
dicdict

A dictionary, containing at least the following fields:

  • parameters: a list of dictionaries of the parameters, one per component.

  • _whitelist: a dictionary with keys used as references saved attributes, for more information, see export_to_dictionary().

  • any field from _whitelist.keys().

export(folder=None, format='hspy', save_std=False, only_free=True)#

Plot the value of the parameters of the model

Parameters:
folderstr or None

The path to the folder where the file will be saved. If None the current folder is used by default.

formatstr

The extension of the file format, default “hspy”.

save_stdbool

If True, also the standard deviation will be saved.

only_freebool

If True, only the value of the parameters that are free will be exported.

Notes

The name of the files will be determined by each the Component and each Parameter name attributes. Therefore, it is possible to customise the file names modify the name attributes.

fetch_values_from_array(p, p_std=None, onlyfree=False)#

Fetch the parameter values from an array p and optionally standard deviation from p_std. Places them component.parameter.value and …std, according to their position in the component.

Parameters:
parray

array containing new values for the parameters in a component

p_stdarray, optional

array containing the corresponding standard deviation.

property free_parameters#

The list of free parameters of the component.

gui(display=True, toolkit=None, **kwargs)#

Display or return interactive GUI element if available.

Parameters:
displaybool

If True, display the user interface widgets. If False, return the widgets container in a dictionary, usually for customisation or testing.

toolkitstr, iterable of str or None

If None (default), all available widgets are displayed or returned. If string, only the widgets of the selected toolkit are displayed if available. If an interable of toolkit strings, the widgets of all listed toolkits are displayed or returned.

init_parameters(parameter_name_list, linear_parameter_list=None)#

Initialise the parameters of the component.

Parameters:
parameter_name_listlist

The list of parameter names.

linear_parameter_listlist, optional

The list of linear parameter. The default is None.

property parameters#

The list of parameters of the component.

plot(only_free=True)#

Plot the value of the parameters of the model

Parameters:
only_freebool
If True, only the value of the parameters that are free will

be plotted

print_current_values(only_free=False)#

Prints the current values of the component’s parameters.

Parameters:
only_freebool

If True, only free parameters will be printed.

set_parameters_free(parameter_name_list=None, only_linear=False, only_nonlinear=False)#

Sets parameters in a component to free.

Parameters:
parameter_name_listNone or list of str, optional

If None, will set all the parameters to free. If list of strings, will set all the parameters with the same name as the strings in parameter_name_list to free.

only_linearbool

If True, only sets a parameter free if it is linear

only_nonlinearbool

If True, only sets a parameter free if it is nonlinear

Examples

>>> v1 = hs.model.components1D.Voigt()
>>> v1.set_parameters_free()
>>> v1.set_parameters_free(parameter_name_list=['area','centre'])
>>> v1.set_parameters_free(only_linear=True)
set_parameters_not_free(parameter_name_list=None, only_linear=False, only_nonlinear=False)#

Sets parameters in a component to not free.

Parameters:
parameter_name_listNone or list of str, optional

If None, will set all the parameters to not free. If list of strings, will set all the parameters with the same name as the strings in parameter_name_list to not free.

only_linearbool

If True, only sets a parameter not free if it is linear

only_nonlinearbool

If True, only sets a parameter not free if it is nonlinear

Examples

>>> v1 = hs.model.components1D.Voigt()
>>> v1.set_parameters_not_free()
>>> v1.set_parameters_not_free(parameter_name_list=['area','centre'])
>>> v1.set_parameters_not_free(only_linear=True)