hyperspy.component module

class hyperspy.component.Component(parameter_name_list)

Bases: traits.has_traits.HasTraits

property active_is_multidimensional
as_dictionary(fullcopy=True)

Returns component as a dictionary For more information on method and conventions, see hyperspy.misc.export_dictionary.export_to_dictionary() :param fullcopy: Copies of objects are stored, not references. If any found,

functions will be pickled and signals converted to dictionaries

Returns

dic – A dictionary, containing at least the following fields: parameters : list

a list of dictionaries of the parameters, one per

_whitelistdictionary

a dictionary with keys used as references saved attributes, for more information, see hyperspy.misc.export_dictionary.export_to_dictionary()

  • any field from _whitelist.keys() *

Return type

dictionary

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

Plot the value of the parameters of the model

Parameters
  • folder (str or None) – The path to the folder where the file will be saved. If None the current folder is used by default.

  • format (str) – The extension of the file format, default “hspy”.

  • save_std (bool) – If True, also the standard deviation will be saved.

  • only_free (bool) –

    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_stored_values(only_fixed=False)
fetch_values_from_array(p, p_std=None, onlyfree=False)
gui(display=True, toolkit=None, **kwargs)

Display or return interactive GUI element if available.

Parameters
  • display (bool) – If True, display the user interface widgets. If False, return the widgets container in a dictionary, usually for customisation or testing.

  • toolkit (str, iterable of strings 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)
plot(only_free=True)

Plot the value of the parameters of the model

Parameters

only_free (bool) –

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

be plotted

set_parameters_free(parameter_name_list=None)

Sets parameters in a component to free.

Parameters

parameter_name_list (None or list of strings, 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.

Examples

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

Sets parameters in a component to not free.

Parameters

parameter_name_list (None or list of strings, 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.

Examples

>>> v1 = hs.model.components1D.Voigt()
>>> v1.set_parameters_not_free()
>>> v1.set_parameters_not_free(parameter_name_list=['area','centre'])
store_current_parameters_in_map()
summary()
update_number_parameters()
class hyperspy.component.NoneFloat(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)

Bases: traits.trait_types.CFloat

default_value = None
validate(object, name, value)

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class hyperspy.component.Parameter

Bases: traits.has_traits.HasTraits

Model parameter

value

The value of the parameter for the current location. The value for other locations is stored in map.

Type

float or array

bmin, bmax

Lower and upper bounds of the parameter value.

Type

float

twin

If it is not None, the value of the current parameter is a function of the given Parameter. The function is by default the identity function, but it can be defined by twin_function

Type

{None, Parameter}

twin_function_expr

Expression of the twin_function that enables setting a functional relationship between the parameter and its twin. If twin is not None, the parameter value is calculated as the output of calling the twin function with the value of the twin parameter. The string is parsed using sympy, so permitted values are any valid sympy expressions of one variable. If the function is invertible the twin inverse function is set automatically.

Type

str

twin_inverse_function

Expression of the twin_inverse_function that enables setting the value of the twin parameter. If twin is not None, its value is set to the output of calling the twin inverse function with the value provided. The string is parsed using sympy, so permitted values are any valid sympy expressions of one variable.

Type

str

twin_function

Setting this attribute manually is deprecated in HyperSpy newer than 1.1.2. It will become private in HyperSpy 2.0. Please use ``twin_function_expr`` instead.

Type

function

twin_inverse_function

Setting this attribute manually is deprecated in HyperSpy newer than 1.1.2. It will become private in HyperSpy 2.0. Please use ``twin_inverse_function_expr`` instead.

Type

function

ext_force_positive

If True, the parameter value is set to be the absolute value of the input value i.e. if we set Parameter.value = -3, the value stored is 3 instead. This is useful to bound a value to be positive in an optimization without actually using an optimizer that supports bounding.

Type

bool

ext_bounded

Similar to ext_force_positive, but in this case the bounds are defined by bmin and bmax. It is a better idea to use an optimizer that supports bounding though.

Type

bool

as_signal(field = 'values')

Get a parameter map as a signal object

plot()

Plots the value of the Parameter at all locations.

export(folder=None, name=None, format=None, save_std=False)

Saves the value of the parameter map to the specified format

connect, disconnect(function)

Call the functions connected when the value attribute changes.

as_dictionary(fullcopy=True)

Returns parameter as a dictionary, saving all attributes from self._whitelist.keys() For more information see hyperspy.misc.export_dictionary.export_to_dictionary()

Parameters

fullcopy (Bool (optional, False)) – Copies of objects are stored, not references. If any found, functions will be pickled and signals converted to dictionaries

Returns

dic

_id_namestring

_id_name of the original parameter, used to create the dictionary. Has to match with the self._id_name

_twinslist

a list of ids of the twins of the parameter

_whitelistdictionary

a dictionary, which keys are used as keywords to match with the parameter attributes. For more information see hyperspy.misc.export_dictionary.export_to_dictionary()

  • any field from _whitelist.keys() *

Return type

dictionary with the following keys:

as_signal(field='values')

Get a parameter map as a signal object.

Please note that this method only works when the navigation dimension is greater than 0.

Parameters

field ({'values', 'std', 'is_set'}) –

:raises NavigationDimensionError : if the navigation dimension is 0:

assign_current_value_to_all(mask=None)

Assign the current value attribute to all the indices

Parameters

mask ({None, boolean numpy array}) – Set only the indices that are not masked i.e. where mask is False.

default_traits_view()

Returns the name of the default traits view for the object’s class.

export(folder=None, name=None, format='hspy', save_std=False)

Save the data to a file.

All the arguments are optional.

Parameters
  • folder (str or None) –

    The path to the folder where the file will be saved.

    If None the current folder is used by default.

  • name (str or None) –

    The name of the file. If None the Components name followed
    by the Parameter name attributes will be used by default.

    If a file with the same name exists the name will be modified by appending a number to the file path.

  • save_std (bool) – If True, also the standard deviation will be saved

  • format (str) – The extension of any file format supported by HyperSpy, default hspy

property ext_bounded
property ext_force_positive
fetch()

Fetch the stored value and std attributes.

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

Display or return interactive GUI element if available.

Parameters
  • display (bool) – If True, display the user interface widgets. If False, return the widgets container in a dictionary, usually for customisation or testing.

  • toolkit (str, iterable of strings 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.

plot(**kwargs)

Plot parameter signal.

Parameters

**kwargs – Any extra keyword arguments are passed to the signal plot.

Example

>>> parameter.plot() #doctest: +SKIP

Set the minimum and maximum displayed values

>>> parameter.plot(vmin=0, vmax=1) #doctest: +SKIP
store_current_value_in_array()

Store the value and std attributes.

property twin
twin_function = None
property twin_function_expr
property twin_inverse_function
property twin_inverse_function_expr