HyperSpy API is changing in version 2.0, see the release notes!

Parameter#

class hyperspy.component.Parameter#

Bases: HasTraits

The parameter of a component.

Attributes:
bminfloat

The lower bound of the parameter.

bmaxfloat

The upper bound of the parameter.

ext_force_positivebool

If True, the parameter value is set to be the absolute value of the input value i.e.

ext_boundedbool

Similar to ext_force_positive, but in this case the bounds are defined by bmin and bmax.

freebool
mapnumpy.ndarray
twinNone or Parameter

If it is not None, the value of the current parameter is a function of the given Parameter.

twin_function_exprstr

Expression of the function that enables setting a functional relationship between the parameter and its twin.

twin_inverse_function_exprstr

Expression of the function that enables setting the value of the twin parameter.

valuefloat or array

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

value#
free#
map#
as_dictionary(fullcopy=True)#

Returns parameter as a dictionary, saving all attributes from self._whitelist.keys() For more information see py:meth:~hyperspy.misc.export_dictionary.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:
dict

A dictionary, containing at least the following fields:

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

  • _twins: a list of ids of the twins of the parameter

  • _whitelist: a dictionary, which keys are used as keywords to match with the parameter attributes. For more information see export_to_dictionary()

  • any field from _whitelist.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’}

Field to return as signal.

assign_current_value_to_all(mask=None)#

Assign the current value attribute to all the indices, setting parameter.map for all parameters in the component.

Takes the current parameter.value and sets it for all indices in parameter.map[‘values’].

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:
folderstr or None

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

namestr 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_stdbool

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#

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.

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

fetch()#

Fetch the stored value and std attributes from the parameter.map[‘values’] and …[‘std’] if parameter.map[‘is_set’] is True for that index. Updates parameter.value and parameter.std. If not stored, then .value and .std will remain from their previous values, i.e. from a fit in a previous pixel.

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.

plot(**kwargs)#

Plot parameter signal.

Parameters:
**kwargs

Any extra keyword arguments are passed to the signal plot.

Examples

>>> parameter.plot() 

Set the minimum and maximum displayed values

>>> parameter.plot(vmin=0, vmax=1) 
store_current_value_in_array()#

Store the value and std attributes.

property 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_expr

property twin_function_expr#

Expression of the 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.

property twin_inverse_function_expr#

Expression of the 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.