hyperspy.component module¶
-
class
hyperspy.component.
Component
(parameter_name_list)¶ Bases:
traits.has_traits.HasTraits
-
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 dictionariesReturns: dic – A dictionary, containing at least the following fields: parameters : list a list of dictionaries of the parameters, one per- _whitelist : dictionary
- 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
¶ float or array – The value of the parameter for the current location. The value for other locations is stored in map.
-
bmin, bmax
float – Lower and upper bounds of the parameter value.
-
twin
¶ {None, Parameter} – 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
-
twin_function_expr
¶ str – Expression of the
twin_function
that enables setting a functional relationship between the parameter and its twin. Iftwin
is notNone
, 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.
-
twin_inverse_function
¶ str – Expression of the
twin_inverse_function
that enables setting the value of the twin parameter. Iftwin
is notNone
, 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.
-
twin_function
¶ 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.
-
twin_inverse_function
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.
-
ext_force_positive
¶ bool – 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.
-
ext_bounded
¶ bool – 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.
-
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_name : string
- _id_name of the original parameter, used to create the dictionary. Has to match with the self._id_name
- _twins : list
- a list of ids of the twins of the parameter
- _whitelist : dictionary
- 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. See also
-
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
- folder (str or None) –
-
ext_bounded
-
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()
Set the minimum and maximum displayed values
>>> parameter.plot(vmin=0, vmax=1)
-
store_current_value_in_array
()¶ Store the value and std attributes.
See also
-
twin
-
twin_function
= None
-
twin_function_expr
-
twin_inverse_function
-
twin_inverse_function_expr
¶
-