HyperSpy is an open-source Python library, currently at version 2.4.0, providing a comprehensive framework for the interactive analysis of multidimensional datasets, particularly within scientific domains like electron microscopy. It offers tools for efficient exploration, manipulation, and visualization of complex data arrays, including those larger than available memory. The project maintains an active development pace with several minor releases annually, and significant architectural changes in major versions like 2.0.
pip install hyperspyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import HyperSpy, load an example dataset, and plot it. It also includes commented-out code to illustrate how to create a signal directly from a NumPy array and set its axes properties, which is useful for custom data.
For I/O, ensure `RosettaSciIO` is installed (it's a dependency of `hyperspy`). For domain-specific signals, install the relevant HyperSpy extension package (e.g., `hyperspy-eels`, `hyperspy-eds`). Check the official documentation for specific migration paths.
Ensure your environment uses Python 3.10 or newer (as per current PyPI requirements). If you must use Python 2, install HyperSpy 0.8.3 or earlier.
If you rely on interactive GUI elements, explicitly install the necessary GUI package: `pip install hyperspy-gui-ipywidgets` or `pip install hyperspy-gui-traitsui` (or `conda install` equivalent).
Always use `import hyperspy.api as hs` for importing HyperSpy functionalities.
Familiarize yourself with HyperSpy's axis management (e.g., `s.axes_manager`, `s.metadata.axes`). Understand that `s.data` is the underlying NumPy array, but HyperSpy's methods operate on the `Signal` object which handles these distinctions automatically.
Install the relevant HyperSpy extension package, e.g., `pip install hyperspy-eds`. Check the HyperSpy documentation for a list of available extensions.
Install the desired GUI package, e.g., `pip install hyperspy-gui-ipywidgets`, then restart your Python environment. Ensure you have the necessary GUI backend installed (e.g., `ipywidgets` for Jupyter Notebooks).
Use the explicit indexing methods: `s.isig[...]` for signal dimensions and `s.inav[...]` for navigation dimensions to avoid ambiguity and ensure correct slicing and access.
For fitting, pass `calculate_errors=False` to `multifit()` if errors are not immediately needed, or consider using a nonlinear optimizer in a second pass once parameters are optimized. When possible, use lazy loading or Dask arrays for out-of-core processing of large datasets, which HyperSpy supports implicitly through its `BaseSignal` abstraction. Consider increasing available RAM or processing data in smaller chunks.