model creation: xray lines are not set up correctly?
Describe the bug
after
- creation of a model from an EDSTEMSignal and
- requesting the weights of the lines to be fixed w.r.t. each other
warnings about missing xray lines are raised though the EDSTEMSignal instance contains all lines. Only alpha lines are created, no matter how explictely generation of all lines is requested.
However, listing the components of the model shows all lines.
To Reproduce
Steps to reproduce the behavior in a Jupyter Notebook:
import numpy as np
import hyperspy.api as hs
data = np.random.randint(0, 100, size=(100,100, 2048))
eds_si = hs.signals.EDSTEMSpectrum(data)
eds_si.set_microscope_parameters(beam_energy=200)
eds_si.axes_manager.signal_axes[0].units='keV'
eds_si.axes_manager.signal_axes[0].scale=0.01
# eds_si.axes_manager
eds_si.add_elements(['Al', 'Pd', 'Mn'])
eds_si.set_lines([], only_one=False, only_lines=[])
print(eds_si.metadata)
model = eds_si.create_model()
# remove comment from next line to more explicitely ask for addition of xray lines
# model.add_family_lines(xray_lines=eds_si.metadata.Sample.xray_lines)
model.fix_sub_xray_lines_weight()
for comp in model:
print(comp)
eds_si.metadata
├── Acquisition_instrument
│ └── TEM
│ ├── Detector
│ │ └── EDS
│ │ ├── azimuth_angle = 0.0
│ │ ├── elevation_angle = 35.0
│ │ └── energy_resolution_MnKa = 130.0
│ ├── Stage
│ │ └── tilt_alpha = 0.0
│ └── beam_energy = 200
├── General
│ └── title =
├── Sample
│ ├── elements = ['Al', 'Mn', 'Pd']
│ └── xray_lines <list>
│ ╠══ [0] = Al_Ka
│ ╠══ [1] = Al_Kb
│ ╠══ [10] = Pd_Lb2
│ ╠══ [11] = Pd_Lb3
│ ╠══ [12] = Pd_Lb4
│ ╠══ [13] = Pd_Lg1
│ ╠══ [14] = Pd_Lg3
│ ╠══ [15] = Pd_Ll
│ ╠══ [16] = Pd_Ln
│ ╠══ [2] = Mn_Ka
│ ╠══ [3] = Mn_Kb
│ ╠══ [4] = Mn_La
│ ╠══ [5] = Mn_Lb3
│ ╠══ [6] = Mn_Ll
│ ╠══ [7] = Mn_Ln
│ ╠══ [8] = Pd_La
│ ╚══ [9] = Pd_Lb1
└── Signal
└── signal_type = EDS_TEM
Warnings (truncated):
/home/cri/Software/hyperspy/hyperspy/models/edsmodel.py:695: UserWarning: The X-ray line Al_Kb expected to be in the model was not found
warnings.warn(warning_text)
/home/cri/Software/hyperspy/hyperspy/models/edsmodel.py:695: UserWarning: The X-ray line Mn_Kb expected to be in the model was not found
warnings.warn(warning_text)
/home/cri/Software/hyperspy/hyperspy/models/edsmodel.py:695: UserWarning: The X-ray line Mn_Ln expected to be in the model was not found
warnings.warn(warning_text)
/home/cri/Software/hyperspy/hyperspy/models/edsmodel.py:695: UserWarning: The X-ray line Mn_Ll expected to be in the model was not found
warnings.warn(warning_text)
/home/cri/Software/hyperspy/hyperspy/models/edsmodel.py:695: UserWarning: The X-ray line Mn_Lb3 expected to be in the model was not found
warnings.warn(warning_text)
...
(Note that I am using my fork of hyperspy, that has a modified warning message, i.e. it includes the xray line's name. See my pull request also)
Expected behavior
No warnings and all lines from the EDS data set are also setup in the created model
Python environement:
- HyperSpy version: 1.8.0.dev0
- Python version: 3.8
I looked into the code at
edsmodel.py:695
I think the if clause in line 686:
if xray_sub in self:
might be replaced by something like this:
if xray_sub in [_comp.name for _comp in self]:
I will push this to my fork of hyperspy and create a pull request.
Hope that helps.
Best wishes and a nice weekend!