Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jun 25 03:17
    jat255 commented #2965
  • Jun 24 16:33
    zezhong-zhang commented #2815
  • Jun 23 01:49
    AinomN closed #2969
  • Jun 23 01:49
    AinomN commented #2969
  • Jun 22 23:25
    Divyadeep00 commented #1355
  • Jun 22 10:38
    ericpre milestoned #2970
  • Jun 22 10:38
    ericpre labeled #2970
  • Jun 22 10:38
    ericpre opened #2970
  • Jun 22 10:21
    jlaehne commented #2966
  • Jun 22 10:05
    thomasaarholt commented #2968
  • Jun 22 10:03
    jlaehne commented #2967
  • Jun 22 10:03
    thomasaarholt commented #2968
  • Jun 22 10:03
    thomasaarholt commented #2968
  • Jun 22 10:00
    jlaehne commented #2967
  • Jun 22 08:47
    ericpre unlabeled #2967
  • Jun 22 08:47
    ericpre labeled #2967
  • Jun 22 08:26
    ericpre edited #2969
  • Jun 22 08:26
    ericpre commented #2969
  • Jun 22 08:01
    ericpre commented #2968
  • Jun 22 05:46
    codecov[bot] commented #2968

@thomasaarholt Hi,
I try to get quantified EDS from a sample with many elements (Al,C,Co,Cu,Cr,Mo,O,Pt,W,Zn) with a strong peak overlap between Cr-L (0.571 eV) and O-K (0.523 eV).
One layer is expected to be CrC but appears as CrO... the quantification output 30% of O in it, which is very unexpected for several reasons. Checking the EDS spectrum manually I can see the peak shift by maybe 1 channel when seeing Cr-L instead of O-K but the model fitting doesn't.
I am using the EDS model fitting and after several hours in the documentation I come here to ask: Is there a solution to this? is there a function somewhere that can for instance estimate Cr-L from the Cr-K intensity and subtract it from the O-K signal before saving the O-K intensity? I hope this question is clear enough!


18 replies

I am trying to run the following code :

import hyperspy.api as hs
input_filename = "file1.emd"
spim = hs.load(input_filename)[-1] 
# the output of the load function is a list in which the last element is an EDSTEM object.


It ouputs : ValueError: All the data are masked, change the mask.

It seems to me that the crop functions are at the source of this issue since when I comment them everything is fine.
I am asking here to check if I am missing something. But I will post an issue on github if not.

3 replies

Hi, I'm not sure if it's just me missing something. But when I import images from Velox EMD (this particular file has 9538 HAADF frames), only the scaling from the first frame is retained in the axes_manager values. I've copied my code snippet below.

%matplotlib qt
import hyperspy.api as hs
import numpy as np
import matplotlib.pyplot as plt
import scipy
import hyperspy.misc as hsm
#prevent figure opening

#load file
s = hs.load("211217/HeatedTEM/HeatedTEM.emd")


#format and save image with time stamp
for single_image in s:

    ####### Failed attempt at scaling




    a = single_image.plot(colorbar=False, scalebar=True, axes_ticks=False)
    plt.savefig('test/image %s.png' % str(s.axes_manager.indices), bbox_inches = 'tight', pad_inches = 0.1)
    #single_image.save("test/image %s.png" % str(image_stack.axes_manager.indices))

But every single_image.axis_manager contains the same value as s.axis_manager (in this case 0.37nm) so the scaling is the same for every image

5 replies
Hi, I wonder if I want to use two windows (before and after edge) to fit an EELS spectrum, what should I do?

in Pycharm I had the below code that worked before with giving interactive hyperspy plots with s.plot()

import matplotlib
matplotlib.rcParams["backend"] = "Agg"
import hyperspy.api as hs

I am getting the following error and no plots shown. Please help if possible, and let me know if you need more information.
Thank you!

WARNING:hyperspy_gui_traitsui:The agg matplotlib backend is not compatible with the traitsui GUI elements. For more information, read http://hyperspy.readthedocs.io/en/stable/user_guide/getting_started.html#possible-warnings-when-importing-hyperspy.
WARNING:hyperspy_gui_traitsui:The traitsui GUI elements are not available.
Also, having trouble with plotting an .emd. The navigator window comes up just fine, but is completely black. Should be the HAADF image - unsure how navigator sums/integrates/chooses the file for the navigator where the loaded data list has multiple signals: e.g. Any help in understanding why the navigator pane/window is black? Thank you!
[<EDSTEMSpectrum, title: EDS, dimensions: (|4096)>,
 <EDSTEMSpectrum, title: EDS, dimensions: (|4096)>,
 <EDSTEMSpectrum, title: EDS, dimensions: (|4096)>,
 <EDSTEMSpectrum, title: EDS, dimensions: (|4096)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: HAADF, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <Signal2D, title: x, dimensions: (|512, 512)>,
 <EDSTEMSpectrum, title: EDS, dimensions: (512, 512|4096)>]
1 reply
Hello, I analyze my EELS data using hyperspy. It worked well before. However, today when I ran remove_background function, it gave me error. Does anyone can help me with this problem? Thanks!
Hello everyone, how are you? I saw in the documentation the new option to read the ASW files in the version 1.7dev. I can extract my image spectra frame by frame this way, but I cannot obtain the DF images frame by frame. I am obtaining in the list generated by the hs.load(), only the first DF image used to acquired the spectral image. Is it possible to extract all the DF images acquired? Using the AnalysisStation software I can see them but with Hyperspy I am having problems yet. Thank you!
1 reply
Thomas Aarholt
Screenshot 2022-01-26 at 14.18.06.png
@MurilooMoreira, I just made a function for you for the colormap you asked for. I thought it was a fun exercise. https://gist.github.com/thomasaarholt/169a1cf29048dd96c8a6c9b980adb9b6
See the gist for creating the cmap. This is how you would use it:
from scipy.misc import face
img = face(gray=True)
plt.imshow(img, cmap=cmap)
I was very surprised that there wasn't a built-in function to do this.

Hey all, I am trying to get the decomposition of a sum of a section of the frames of a EDS signal.

When I load the entire signal with sum_frames=True, the decomposition works fine. But when I load it with sum_frames=False and then sum all the frames using .sum('Time'), the resulting signal looks differently (lower intensity) and the decomposition works but the result is different (worse). What is the difference between the sum_frames=True argument and summing the frames after loading using .sum('Time')?
Also, when I try to sum a section of the frames in time (e.g. the first 20) I get the error message: ValueError: All the data are masked, change the mask.
Is there a way to avoid this error and get the decomposition over a range of time?
Thank you!

1 reply
@thomasaarholt thank you man, I will try, test and maybe modify this function for other colors also, thank you very much. Yeah, I always tought strange that it was not possible to do it with hyperspy, I always use the matplotlib cmaps, but I didn't know how to create new ones. Thank you
1 reply
To whom it may regard, hyperspy/tests/io/test_jeol.py is not running smoothly on my device. Is this the correct place to ask for help?

When I replace the test files with actual files I have on my device (same extensions), and I run the test script I get the following messages:

WARNING:hyperspy.io:Unable to infer file type from extension 'ASW'. Will attempt to load the file with the Python imaging library.
ERROR:hyperspy.io:If this file format is supported, please report this error to the HyperSpy developers.

2 replies

Hi, I am using EDS models and have trouble to restore the stored ones.
I create a model m, fit it and store it, and also copy it to a EDS_model variable

#create a model using all selected elements:
m = si.create_model()
#Reduce the element selection to the one of interest and quantify
kfactors = Assign_elements2Quant()
m_int_fit = m.get_lines_intensity(xray_lines_selected)
EDS_model = m

After this, the "si" is saved to a .hspy file.
If i look at the EDS_model, it is fine, I can plot it and so on.

Out[80]: <EDSTEMModel, title: EDX>

But then I try to load the .hspy file again, I see the model is there, with the components, but cannot restore it or plot it... why?

l = hs.load(signal_type="EDS_TEM", escape_square_brackets=(True))
└── a
    ├── components
    │   ├── Al_Ka
    │   ├── Al_Kb
    │   ├── C_Ka
    │   ├── Co_Ka
    │   ├── Co_Kb
    │   ├── Co_La
    │   ├── Co_Lb3
    │   ├── Co_Ll
    │   ├── Co_Ln
    │   ├── Cr_Ka
    │   ├── Cr_Kb
    │   ├── Cr_La
    │   ├── Cr_Lb3
    │   ├── Cr_Ll
    │   ├── Cr_Ln
    │   ├── Mo_Ka
    │   ├── Mo_Kb
    │   ├── Mo_La
    │   ├── Mo_Lb1
    │   ├── Mo_Lb2
    │   ├── Mo_Lb3
    │   ├── Mo_Lg1
    │   ├── Mo_Lg3
    │   ├── Mo_Ll
    │   ├── Mo_Ln
    │   ├── O_Ka
    │   ├── W_La
    │   ├── W_Lb1
    │   ├── W_Lb2
    │   ├── W_Lb3
    │   ├── W_Lb4
    │   ├── W_Lg1
    │   ├── W_Lg3
    │   ├── W_Ll
    │   ├── W_Ln
    │   ├── W_M2N4
    │   ├── W_M3O4
    │   ├── W_M3O5
    │   ├── W_Ma
    │   ├── W_Mb
    │   ├── W_Mg
    │   ├── W_Mz
    │   ├── Zn_Ka
    │   ├── Zn_Kb
    │   ├── Zn_La
    │   ├── Zn_Lb1
    │   ├── Zn_Lb3
    │   ├── Zn_Ll
    │   ├── Zn_Ln
    │   └── background_order_6
    ├── date = 2022-02-08 12:09:22
    └── dimensions = (96, 89|2048)

Mymodel = l.models.a.restore()
Traceback (most recent call last):

  File "C:\Users\oldo\AppData\Local\Temp/ipykernel_14272/3459143043.py", line 1, in <module>
    Mymodel = l.models.a.restore()

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\signal.py", line 82, in <lambda>
    self.restore = lambda: mm.restore(self._name)

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\signal.py", line 241, in restore
    return self._signal.create_model(dictionary=copy.deepcopy(d))

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\_signals\eds_tem.py", line 745, in create_model
    model = EDSTEMModel(self,

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\models\edstemmodel.py", line 45, in __init__
    EDSModel.__init__(self, spectrum, auto_background, auto_add_lines,

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\models\edsmodel.py", line 131, in __init__
    Model1D.__init__(self, spectrum, *args, **kwargs)

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\models\model1d.py", line 279, in __init__

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\model.py", line 306, in _load_dictionary

  File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\component.py", line 1223, in _load_dictionary
    raise ValueError(

ValueError: _id_name of parameters in component and dictionary do not match
Thomas Weatherley
Hey all - I'm trying to make an analysis using hyperspy as reproducible as possible, and as part of that I want a virtual environment that can be reproduced from an environment.yml file. However, for my analysis I need to use nonlinear functionality, which isn't included in hyperspy v1.6.5 - but cloning RELEASE_next_minor is something which can't be tracked using an environment.yml file. Does anyone have a suggestion for how to get nonlinear functionality in a reproducible way? @LMSC-NTappy proposed forking RELEASE_next_minor to my own GitHub, pip installing the fork, and then leaving that fork unchanged - this is what I'll do for now. But I'm always grateful for other suggestions - thanks!
5 replies
the line2D interactive ROI raises an error when I try to integrate over a width "linewidth is not supported for axis with different scale", however the axes_manager says that the scale is the same for both axes... is it a rounding problem? can I correct it?
the EDS map is from Velox (.emd)

ValueError: linewidth is not supported for axis with different scale.

<Axes manager, axes: (|118, 81)>
            Name |   size |  index |  offset |   scale |  units 
================ | ====== | ====== | ======= | ======= | ====== 
---------------- | ------ | ------ | ------- | ------- | ------ 
               x |    118 |        |   0.043 |    0.14 |     nm 
               y |     81 |        |    -2.8 |    0.14 |     nm
6 replies

Hello, I hope you are very well. I am studying how to do an analysis of my EELS spectrum using richarson lucy deconvolution I have a 2D spectrum in a cvs file. Does anyone know how to define the psf function from the spectrum?

I thank you in advance.

8 replies
Giulio Guzzinati
Hello, I'm writing a patch to add support for the data files of the CEOS energy filter software (e.g. eftem images or EELS data cubes), and I'm trying translate calibrations as well as I can. However I can't quite understand if and how intensity calibrations are handled in hyperspy.

Hi everyone,

I am using Velox to acquire EM images and I am looking to use HyperSpy to help with the analysis. I do not have access to Velox on my personal computer, so I am using HyperSpy to load the EMD files. I am recording videos on Velox, however, to my knowledge it does not appear that I can save each individual frame of the video as a TIF in the Velox software itself (for single images I can easily export the data as a TIF on Velox). Using HyperSpy I am trying to convert the EMD files to TIF. However, I noticed that my scalebar is missing in the TIF when I open it later. Is there a way to save the scalebar information from the metadata using HyperSpy? I could come up with other solutions but I am looking for something more elegant since I know that HyperSpy can access the metadata. I see that there is a module for drawing scalebars in HyperSpy but I have not found a way to implement this correctly.

Here is some very basic code that I have written in Python to save the EMD images to TIF:

import hyperspy.api as hs
import tkinter as tk
from tkinter import filedialog

root = tk.Tk()

file_path = filedialog.askopenfilename()
s = hs.load(file_path)
s.plot() # I can see the scalebar from the metadata

save_input = input("Would you like to save? (Y/N)? ")
if save_input == "Y" or save_input == "Yes" or save_input == "yes" or save_input == "y":
save_path = filedialog.asksaveasfilename()
s.save(save_path) # I can no longer see the scalebar here, how can I flatten the overlay?
print("END OF PROGRAM.")

Thanks for any help that you can provide!

1 reply
Jordi Ferrer Orri
I was wondering if hyperspy interactive functions work with Google Colab. I saw a comment from a few years ago on how %matplotlib notebook does not work for the hyperspy plotting functions.
I have currently tried both notebook and widget backends, none of which seem to give a plot.
Any advice/workarounds?
HI everyone,
I did some analysis using blind_source_separation function and I observed two things:
  1. sklearn_fastica provides very instalbe results. Each run gives completely different solution. Is it normal?
  1. I tried to use FastIca algorithm from MDP. So I installed MDP but when type the command "import hyperspy as hs" it give me the following error:module 'scipy' has no attribute 'typeDict'.
3 replies
Please could you help me with these? Thank you very much.
I use Anaconda on windows 10.
Hello All, I met probelms when using PCA to analyze my data. I notice that the reconstructed results of the spectrum always includes peaks with minus intensity. I try the whole and local region PCA analysis, with the same results. Could you help to figure out the reason of this?
3 replies
Hi everyone. Hope you're all good. I'm very new to everything HyperSpy, microscopy, and python - but at work I have a task to write some scripts to analyze some data from a JEOL in DM4 format. I know the DM3/4 support is somewhat limited compared to other formats but I am wondering if there's any way to extract temperature metadata from these formats? I have loaded an example file and performed a file.metadata command to see the tree, but temperature doesn't seem to feature.
3 replies

Hi everyone, I have recorded a HAADF-STEM video in Velox with 500 image frames. During recording, I changed the magnification, zoomed in and out. I am already able to export each individual frame. However, the scalebar is the same for each frame (whereas in Velox it shows different scale bars for each individual frame). Do you have any solution for that? What did NOT work:

(The type of the complete_dataset is signal2D). Thanks a lot for your help! :)

4 replies

Hi everyone, I am having trouble saving a signal or multiple signals loaded from .emd format to nexus format using the following command:


I got the following error :

AttributeError: 'dict' object has no attribute 'dtype'

it works fine using the following command , but the original metadata would be not saved:


Can someone help please, i need to save the metadata also .


Hi all,

I am new to hyperspy and still a bit lost getting the thickness out of an EEL spectrum.
I have tried this:

s_ll = hs.load("20220315/data.dm3")
s_ll.set_microscope_parameters(beam_energy = 200, collection_angle=6.0, convergence_angle=0.021)
s.set_microscope_parameters(beam_energy = 200, collection_angle=6.0, convergence_angle=0.021)


s_ll.align_zero_loss_peak(subpixel=True, also_align=[s])

th = s_ll.estimate_elastic_scattering_threshold(window=10)

density = 5.515

s_ll_thick = s_ll.estimate_thickness(threshold=th, density=density)

and as a result I obtain this:

<BaseSignal, title: E8-FeNiO-PS71-T_0043 thickness (nm), dimensions: (1|)>

What does it mean? I would like to obtain a value and not a signal. Sorry, if this is an obvious answer. ;-)

Thank you for your help!

2 replies
Eric Leroy
Hi, I have EELS datacubes in the low-loss region. I would like to perform PCA or ICA and for this it seems that it is better to remove the zero loss peak. I search for an equivalent to the extract zero loss function of GMS but I didn’t found, could you help me to do this ?
9 replies
Hi, may I ask if there is a way to speed up multifit process for EELS spectrum imaging?
15 replies
Eric R. Hoglund
Is it possible to set the dtype a signal reads in as? I have some moderate size spectrum images that could either be int or small bit floats. HS is defaulting to float32 which takes the data from manageable to unmanageable
1 reply
Can any one help me look at the gaussian fit of Ni L3? Why it has a hump at around 880eV? So strange
4 replies
Yisong Han

m = s_fit.create_model()
g1 = hs.model.components1D.GaussianHF()
g2 = hs.model.components1D.GaussianHF()
g3 = hs.model.components1D.GaussianHF()
m.extend([g1, g2, g3])
m00 = m.inav[0]

How can I get the fitted data for each component after running m00.fit() (including the sum) so I can plot them myself rather than using the s.plot()? Do I have to compute them myself? Thanks very much.

23 replies
Dieter Weber

Hi all, greetings from LiberTEM! With the latest release we implemented full Dask array integration. That means LiberTEM and HyperSpy (lazy) signals can now interoperate. That opens a range of opportunities:

  • Share the same file readers for both projects. See our supported formats. In particular, support for K2IS raw, FRMS6 and Direct Electron SEQ could be added to HyperSpy with little effort.
  • Simplify implementing routines in HyperSpy that would require Dask’s map_blocks() interface by using the LiberTEM UDF interface instead.
  • Use the same implementation for scientific algorithms in both projects. As an example, fast ptychography could be offered in HyperSpy, or strain, phase and orientation mapping in pyxem could be applied to live data streams.

This message is to start a discussion on what could be useful and what steps to take in that direction. 😊

6 replies
Friedrich Bohr
Hello! I am trying to import EDS data from Aztec Oxford Instrument. Aztec export the data in two files: .raw and .rpl. If I load the .rpl file in the python (e.g., s=hs.load('Data.rpl') it seems that I miss the meta data as they system cannot identify that the data studied is EDS data. is there a command to load both rpl and raw file? Thanks.
1 reply
Hi. I have EELS data from a FEI Tecnai Remote TCPIP. This is taken in two spatial dimensions, with a grid of pixels and each pixel contains a spectrum. I would like to determine the size of pixels used when taking the measurement, but I cannot find this information in the metadata. Does anyone know how I can extract this information?
I know i can find out by contacting the TEM technician I'm working with but I'd quite like to have a self-contained bit of code which can automate things as much as possible, so it should automatically get the pixel size from the data I have
4 replies
Hi, I am trying robust PCA on my EELS data. I want to know how to determine the "output_dimension" value in the "RPCA" method. Thank you!
Additionally, how to perform the RPCA processed result?