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.
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()
m.fit()
m.fit_background()
#Reduce the element selection to the one of interest and quantify
kfactors = Assign_elements2Quant()
xray_lines_selected=si.metadata.Sample.xray_lines
m_int_fit = m.get_lines_intensity(xray_lines_selected)
m.store()
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.
EDS_model
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))
l.models
Out[82]:
└── 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__
self._load_dictionary(dictionary)
File "C:\Users\oldo\.conda\envs\hspy_env\lib\site-packages\hyperspy\model.py", line 306, in _load_dictionary
id_dict.update(self[-1]._load_dictionary(comp))
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
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!
line1=line_roi.interactive(data,color='yellow')
ValueError: linewidth is not supported for axis with different scale.
data.axes_manager
Out[53]:
<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
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()
root.withdraw()
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?
else:
print("END OF PROGRAM.")
Thanks for any help that you can provide!
%matplotlib notebook
does not work for the hyperspy plotting functions.notebook
and widget
backends, none of which seem to give a plot.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:
single_image=complete_dataset.inav[frame_number]
print(single_image.axes_manager[0].scale)
(The type of the complete_dataset is signal2D). Thanks a lot for your help! :)
Hi everyone, I am having trouble saving a signal or multiple signals loaded from .emd format to nexus format using the following command:
file_writer("test.nxs",s)
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:
file_writer("test.nxs",s,save_original_metadata=False)
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.plot()
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:
s_ll_thick
<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!
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]
m00.fit()
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.
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:
map_blocks()
interface by using the LiberTEM UDF interface instead.This message is to start a discussion on what could be useful and what steps to take in that direction. 😊
Hello,
I tried to have a interactive function to obtain chemical maps of EELS spectrum image datasets in hyperspy.
The idea of the following code is to plot the full spectrum, select interactively an energy range on it and then plot interactively the intensity map of the integrated energy range.
import numpy as np
import hyperspy.api as hs
spim = hs.load("file.hspy")
class cst_SpanROI (hs.roi.SpanROI) :
def mapping (self,spim = None, out_map = None) :
print(self.left)
out_map.data = spim.isig[self.left:self.right].sum(axis = 2).data
return out_map
# Get safe initial coordinates for the ROI.
half_e = spim.axes_manager[2].offset + spim.axes_manager[2].scale*0.5*spim.axes_manager[2].size
third_e = spim.axes_manager[2].offset + spim.axes_manager[2].scale*0.333*spim.axes_manager[2].size
# Sum over all the spectra of the spim
full_spectrum = spim.integrate1D(axis = (0,1))
# Initialize the ROI
spectrum_ROI = cst_SpanROI(third_e,half_e)
# Plot both the spectrum and the ROI (interactively)
full_spectrum.plot(True)
spectrum_ROI.interactive(full_spectrum)
# Initialize a Signal2D which will represent the map
out = hs.signals.Signal2D(np.zeros((spim.axes_manager[0].size,spim.axes_manager[1].size)))
# Link the spim, the map and the SpanROI interactively
map=hs.interactive(spectrum_ROI.mapping,recompute_out_event = spectrum_ROI.events.changed,spim = spim,out_map = out)
map.plot()
I am not sure it is the intended way to do this, however it worked in hyperpsy 1.6.5. It broke in 1.7.0
How to solve this issue ? Did I miss a more straightforward solution ? If it does not exist, can we ake it a feature ?
Hey everyone. I'm making an animation from a signal2D
object, in which the frames would just tick through the navigation axis (i.e., frame i
is the plot generated by map.isig[i].as_signal2D([0, 1]).plot()
. Is there a neat way to do this quickly with hyperspy? I've found a way to make it work with matplotlib using the AxesSubplot
object returned by hs.plot.plot_images()
:
plot = hs.plot.plot_images(tcspc.isig[0].as_signal2D([0, 1]))[0]
image = plot.get_images()[0]
def anim_func(frame):
new_data = tcspc.isig[frame].as_signal2D([0, 1])
image.set_data(new_data)
image.set_clim(vmin=new_data.data.min(), vmax=new_data.data.max())
anim_created = FuncAnimation(plt.gcf(), anim_func, frames=30, interval=300)
But I'm just wondering if there is a neater way to do it, as it feels like something people might want to do quite often using hyperspy. Thanks in advance!
KeyError Traceback (most recent call last)
Input In [9], in <cell line: 1>()
----> 1 s = hs.load("20220301_test1.asw")
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io.py:454, in load(filenames, signal_type, stack, stack_axis, new_axis_name, lazy, convert_units, escape_square_brackets, stack_metadata, load_original_metadata, show_progressbar, kwds)
451 objects.append(signal)
452 else:
453 # No stack, so simply we load all signals in all files separately
--> 454 objects = [load_single_file(filename, lazy=lazy, kwds)
455 for filename in filenames]
457 if len(objects) == 1:
458 objects = objects[0]
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io.py:454, in <listcomp>(.0)
451 objects.append(signal)
452 else:
453 # No stack, so simply we load all signals in all files separately
--> 454 objects = [load_single_file(filename, lazy=lazy, **kwds)
455 for filename in filenames]
457 if len(objects) == 1:
458 objects = objects[0]
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io.py:513, in load_single_file(filename, kwds)
506 raise ValueError(
507 "reader
should be one of None, str, "
508 "or a custom file reader object"
509 )
511 try:
512 # Try and load the file
--> 513 return load_with_reader(filename=filename, reader=reader, kwds)
515 except BaseException:
516 _logger.error(
517 "If this file format is supported, please "
518 "report this error to the HyperSpy developers."
519 )
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io.py:533, in load_with_reader(filename, reader, signal_type, convert_units, load_original_metadata, kwds)
531 """Load a supported file with a given reader."""
532 lazy = kwds.get('lazy', False)
--> 533 file_data_list = reader.file_reader(filename, kwds)
534 signal_list = []
536 for signal_dict in file_data_list:
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io_plugins/jeol.py:100, in file_reader(filename, kwds)
98 if sub_ext in extension_to_reader_mapping.keys():
99 reader_function = extension_to_reader_mapping[sub_ext]
--> 100 d = reader_function(file_path, scale, kwds)
101 if isinstance(d, list):
102 dictionary.extend(d)
File /ceph/users/gbz45948/miniconda3/envs/hyperspy_env/lib/python3.10/site-packages/hyperspy/io_plugins/jeol.py:159, in _read_img(filename, scale, **kwargs)
139 axes = [
140 {
141 "name": "y",
(...)
153 },
154 ]
156 datefile = datetime(1899, 12, 30) + timedelta(
157 days=header_long["Image"]["Created"]
158 )
--> 159 hv = header_long["Instrument"]["AccV"]
160 if hv <= 30.0:
161 mode = "SEM"
KeyError: 'AccV'
Hi Everyone,
I am wondering how I may modify/edit the code for my own needs (and hopefully later I may pull/contribute). I have googled and it seems there is a lack of a comphrehensive guide.
I know from the HyperSpy website, I need to:
Could you suggest a website or a video which could answer my questions if it is hard to explain by texts? Thanks very much.