hyperspy.axes module

class hyperspy.axes.AxesManager(axes_list)

Bases: traits.has_traits.HasTraits

Contains and manages the data axes.

It supports indexing, slicing, subscripting and iteration. As an iterator, iterate over the navigation coordinates returning the current indices. It can only be indexed and sliced to access the DataAxis objects that it contains. Standard indexing and slicing follows the “natural order” as in Signal, i.e. [nX, nY, …,sX, sY,…] where n indicates a navigation axis and s a signal axis. In addition AxesManager support indexing using complex numbers a + bj, where b can be one of 0, 1, 2 and 3 and a a valid index. If b is 3 AxesManager is indexed using the order of the axes in the array. If b is 1(2), indexes only the navigation(signal) axes in the natural order. In addition AxesManager supports subscription using axis name.

coordinates

tuple – Get and set the current coordinates if the navigation dimension is not 0. If the navigation dimension is 0 it raises AttributeError when attempting to set its value.

indices

tuple – Get and set the current indices if the navigation dimension is not 0. If the navigation dimension is 0 it raises AttributeError when attempting to set its value.

signal_axes, navigation_axes

list – Contain the corresponding DataAxis objects

Examples

Create a spectrum with random data

>>> s = hs.signals.Signal1D(np.random.random((2,3,4,5)))
>>> s.axes_manager
<Axes manager, axes: (4, 3, 2|5)>
            Name |   size |  index |  offset |   scale |  units
================ | ====== | ====== | ======= | ======= | ======
     <undefined> |      4 |      0 |       0 |       1 | <undefined>
     <undefined> |      3 |      0 |       0 |       1 | <undefined>
     <undefined> |      2 |      0 |       0 |       1 | <undefined>
---------------- | ------ | ------ | ------- | ------- | ------
     <undefined> |      5 |        |       0 |       1 | <undefined>
>>> s.axes_manager[0]
<Unnamed 0th axis, size: 4, index: 0>
>>> s.axes_manager[3j]
<Unnamed 2nd axis, size: 2, index: 0>
>>> s.axes_manager[1j]
<Unnamed 0th axis, size: 4, index: 0>
>>> s.axes_manager[2j]
<Unnamed 3rd axis, size: 5>
>>> s.axes_manager[1].name = "y"
>>> s.axes_manager["y"]
<y axis, size: 3, index: 0>
>>> for i in s.axes_manager:
...     print(i, s.axes_manager.indices)
...
(0, 0, 0) (0, 0, 0)
(1, 0, 0) (1, 0, 0)
(2, 0, 0) (2, 0, 0)
(3, 0, 0) (3, 0, 0)
(0, 1, 0) (0, 1, 0)
(1, 1, 0) (1, 1, 0)
(2, 1, 0) (2, 1, 0)
(3, 1, 0) (3, 1, 0)
(0, 2, 0) (0, 2, 0)
(1, 2, 0) (1, 2, 0)
(2, 2, 0) (2, 2, 0)
(3, 2, 0) (3, 2, 0)
(0, 0, 1) (0, 0, 1)
(1, 0, 1) (1, 0, 1)
(2, 0, 1) (2, 0, 1)
(3, 0, 1) (3, 0, 1)
(0, 1, 1) (0, 1, 1)
(1, 1, 1) (1, 1, 1)
(2, 1, 1) (2, 1, 1)
(3, 1, 1) (3, 1, 1)
(0, 2, 1) (0, 2, 1)
(1, 2, 1) (1, 2, 1)
(2, 2, 1) (2, 2, 1)
(3, 2, 1) (3, 2, 1)
as_dictionary()
axes_are_aligned_with_data

Verify if the data axes are aligned with the signal axes.

When the data are aligned with the axes the axes order in self._axes is [nav_n, nav_n-1, …, nav_0, sig_m, sig_m-1 …, sig_0].

Returns:aligned
Return type:bool
coordinates

Get the coordinates of the navigation axes.

Returns:
Return type:list
copy()
create_axes(axes_list)

Given a list of dictionaries defining the axes properties create the DataAxis instances and add them to the AxesManager.

The index of the axis in the array and in the _axes lists can be defined by the index_in_array keyword if given for all axes. Otherwise it is defined by their index in the list.

See also

_append_axis()

deepcopy()
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.
gui_navigation_sliders(title='', display=True, toolkit=None)

Navigation sliders to control the index of the navigation axes.

Parameters:
  • title (str) –
  • %s
  • %s
indices

Get the index of the navigation axes.

Returns:
Return type:list
key_navigator(event)
navigation_extent
navigation_indices_in_array
remove(axes)

Remove one or more axes

set_signal_dimension(value)

Set the dimension of the signal.

value

int

Raises:
  • ValueError if value if greater than the number of axes or
  • is negative
shape
show()
signal_extent
signal_indices_in_array
update_axes_attributes_from(axes, attributes=['scale', 'offset', 'units'])

Update the axes attributes to match those given.

The axes are matched by their index in the array. The purpose of this method is to update multiple axes triggering any_axis_changed only once.

Parameters:
  • axes (iterable of DataAxis instances.) – The axes to copy the attributes from.
  • attributes (iterable of strings.) – The attributes to copy.
class hyperspy.axes.DataAxis(size, index_in_array=None, name=<undefined>, scale=1.0, offset=0.0, units=<undefined>, navigate=<undefined>)

Bases: traits.has_traits.HasTraits

calibrate(value_tuple, index_tuple, modify_calibration=True)
copy()
get_axis_dictionary()
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.
index2value(index)
index_in_array
index_in_axes_manager
update_axis()
update_from(axis, attributes=['scale', 'offset', 'units'])

Copy values of specified axes fields from the passed AxesManager.

Parameters:
  • axis (DataAxis) – The DataAxis instance to use as a source for values.
  • attributes (iterable container of strings.) – The name of the attribute to update. If the attribute does not exist in either of the AxesManagers, an AttributeError will be raised.
Returns:

Return type:

A boolean indicating whether any changes were made.

update_index_bounds()
value2index(value, rounding=<built-in function round>)

Return the closest index to the given value if between the limit.

Parameters:value (number or numpy array) –
Returns:index
Return type:integer or numpy array
Raises:ValueError if any value is out of the axis limits.
value_range_to_indices(v1, v2)

Convert the given range to index range.

When an out of the axis limits, the endpoint is used instead.

Parameters:v2 (v1,) – The end points of the interval in the axis units. v2 must be greater than v1.
hyperspy.axes.generate_axis(offset, scale, size, offset_index=0)

Creates an axis given the offset, scale and number of channels

Alternatively, the offset_index of the offset channel can be specified.

Parameters:
  • offset (float) –
  • scale (float) –
  • size (number of channels) –
  • offset_index (int) – offset_index number of the offset
Returns:

Return type:

Numpy array

class hyperspy.axes.ndindex_nat(*shape)

Bases: numpy.lib.index_tricks.ndindex