Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find element database and get_xray_lines_near_energy() #45

Open
Sl4artiB4rtF4rst opened this issue May 8, 2024 · 11 comments · May be fixed by #59
Open

Cannot find element database and get_xray_lines_near_energy() #45

Sl4artiB4rtF4rst opened this issue May 8, 2024 · 11 comments · May be fixed by #59

Comments

@Sl4artiB4rtF4rst
Copy link

Dear team of Exspy!
I really love the work you have done with exspy and hyperspy in general. I am just getting started in evaluating and analyzing EDS (TEM) data. I wanted to use the elemental database as well as the get_xray_lines_near_energy() function but cannot find it both in the Exspy and well as the hyperspy references. I noticed proviously that some functions where relocated to other (sub) libraries - maybe herin lies the problem.

Can you help me out where exactly to find the functions and possibly update the references as well as the EDS user guide (https://hyperspy.org/exspy/user_guide/eds.html) to show the correct usage.

I am using hyperspy and exspy in anaconda and have installed the newest versions (from conda forge). I could not, however find the correct command to check which version I have installed exactly, sorry.

Thank you in advance and kind regards!

@ericpre
Copy link
Member

ericpre commented May 8, 2024

Here are the database:
https://github.com/hyperspy/exspy/blob/main/exspy/misc/elements.py
https://github.com/hyperspy/exspy/blob/main/exspy/misc/elements.py

And the get_xray_lines_near_energy function (which I found by putting the function name in the search bar of this repository):

def get_xray_lines_near_energy(energy, width=0.2, only_lines=None):
"""Find xray lines near a specific energy, more specifically all xray lines
that satisfy only_lines and are within the given energy window width around
the passed energy.
Parameters
----------
energy : float
Energy to search near in keV
width : float
Window width in keV around energy in which to find nearby energies,
i.e. a value of 0.2 keV (the default) means to search +/- 0.1 keV.
only_lines :
If not None, only the given lines will be added (eg. ('a','Kb')).
Returns
-------
List of xray-lines sorted by energy difference to given energy.
"""
only_lines = _parse_only_lines(only_lines)
valid_lines = []
E_min, E_max = energy - width / 2.0, energy + width / 2.0
for element, el_props in elements_db.items():
# Not all elements in the DB have the keys, so catch KeyErrors
try:
lines = el_props["Atomic_properties"]["Xray_lines"]
except KeyError:
continue
for line, l_props in lines.items():
if only_lines and line not in only_lines:
continue
line_energy = l_props["energy (keV)"]
if E_min <= line_energy <= E_max:
# Store line in Element_Line format, and energy difference
valid_lines.append((element + "_" + line, abs(line_energy - energy)))
# Sort by energy difference, but return only the line names
return [line for line, _ in sorted(valid_lines, key=lambda x: x[1])]

@jlaehne
Copy link
Contributor

jlaehne commented May 10, 2024

But indeed, we should update the user guide to give working examples! Thanks for the catch.

By the way, the test datasets now reside in exspy.data.

@OliDG
Copy link

OliDG commented Jun 5, 2024

Hi ,

as a related problem, the "misc" module doesn't appear in the list while eXSpy is loaded and accessible. Is it a docstring issue?

image

@ericpre
Copy link
Member

ericpre commented Jun 5, 2024

This is designed to use internally and therefore not part of the public API. Do you think that they is a use case to make it part of the public API? If so, what would it be?

@OliDG
Copy link

OliDG commented Jun 10, 2024

oooh I see, I started to code a simple procedure to get an auto-detection of the elements present in my EDS maps to simplify my work (c.f. below),
I understand that you want to simplify the API for the public, but is there a list of all the internal API tools available somewhere? a developper documentation ? I found this function from older hyperspy documentation but that would be a pity to re-write something already existing...

image
0.39 kV: ['N_Ka', 'Sc_La', 'Ca_La', 'Ti_La']
0.52 kV: ['O_Ka', 'V_La', 'Cr_La', 'Ti_La']
0.93 kV: ['Cu_La', 'Ne_Kb', 'Zn_La', 'Ni_La', 'Ne_Ka']
1.49 kV: ['Al_Ka', 'Br_La', 'Al_Kb']
8.03 kV: ['Cu_Ka']

@ericpre
Copy link
Member

ericpre commented Jun 10, 2024

The main concern is the potential added maintenance burden if the elements database is part of the public API.
Are you referring to the elements database or the function? For the function, it should be find to make a submodule with these type of functions.

@OliDG
Copy link

OliDG commented Jun 10, 2024

The function
ex.misc.eds.utils.get_xray_lines_near_energy()
as it is now it seems that I need to read the source code to find what is available, the dir() only shows the public side of eXSpy.

dir(ex)
Out[149]: 
['__version__',
 'components',
 'data',
 'material',
 'models',
 'preferences',
 'signals']

@ericpre
Copy link
Member

ericpre commented Jun 10, 2024

Yes, this is expected, why should it lists what is not part of the public API?

@OliDG
Copy link

OliDG commented Jun 10, 2024

Sorry if I bother you. I am simply looking for a way to see what functions are already implemented.

@ericpre
Copy link
Member

ericpre commented Jun 10, 2024

If you want to know more about functionalities that is not public, you will need to search the source code. If you are interested in eds, it is only a few files.

@ericpre ericpre linked a pull request Jun 16, 2024 that will close this issue
7 tasks
@ericpre
Copy link
Member

ericpre commented Jun 16, 2024

This should be fixed in #59: some of the functionalities were removed from the public API when splitting from hyperspy but it does make sense to add it back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants