pyTEMlib 0.2025.4.1__py3-none-any.whl → 0.2025.9.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyTEMlib might be problematic. Click here for more details.

Files changed (94) hide show
  1. build/lib/pyTEMlib/__init__.py +33 -0
  2. build/lib/pyTEMlib/animation.py +640 -0
  3. build/lib/pyTEMlib/atom_tools.py +238 -0
  4. build/lib/pyTEMlib/config_dir.py +31 -0
  5. build/lib/pyTEMlib/crystal_tools.py +1219 -0
  6. build/lib/pyTEMlib/diffraction_plot.py +756 -0
  7. build/lib/pyTEMlib/dynamic_scattering.py +293 -0
  8. build/lib/pyTEMlib/eds_tools.py +826 -0
  9. build/lib/pyTEMlib/eds_xsections.py +432 -0
  10. build/lib/pyTEMlib/eels_tools/__init__.py +44 -0
  11. build/lib/pyTEMlib/eels_tools/core_loss_tools.py +751 -0
  12. build/lib/pyTEMlib/eels_tools/eels_database.py +134 -0
  13. build/lib/pyTEMlib/eels_tools/low_loss_tools.py +655 -0
  14. build/lib/pyTEMlib/eels_tools/peak_fit_tools.py +175 -0
  15. build/lib/pyTEMlib/eels_tools/zero_loss_tools.py +264 -0
  16. build/lib/pyTEMlib/file_reader.py +274 -0
  17. build/lib/pyTEMlib/file_tools.py +811 -0
  18. build/lib/pyTEMlib/get_bote_salvat.py +69 -0
  19. build/lib/pyTEMlib/graph_tools.py +1153 -0
  20. build/lib/pyTEMlib/graph_viz.py +599 -0
  21. build/lib/pyTEMlib/image/__init__.py +37 -0
  22. build/lib/pyTEMlib/image/image_atoms.py +270 -0
  23. build/lib/pyTEMlib/image/image_clean.py +197 -0
  24. build/lib/pyTEMlib/image/image_distortion.py +299 -0
  25. build/lib/pyTEMlib/image/image_fft.py +277 -0
  26. build/lib/pyTEMlib/image/image_graph.py +926 -0
  27. build/lib/pyTEMlib/image/image_registration.py +316 -0
  28. build/lib/pyTEMlib/image/image_utilities.py +309 -0
  29. build/lib/pyTEMlib/image/image_window.py +421 -0
  30. build/lib/pyTEMlib/image_tools.py +699 -0
  31. build/lib/pyTEMlib/interactive_image.py +1 -0
  32. build/lib/pyTEMlib/kinematic_scattering.py +1196 -0
  33. build/lib/pyTEMlib/microscope.py +61 -0
  34. build/lib/pyTEMlib/probe_tools.py +906 -0
  35. build/lib/pyTEMlib/sidpy_tools.py +153 -0
  36. build/lib/pyTEMlib/simulation_tools.py +104 -0
  37. build/lib/pyTEMlib/test.py +437 -0
  38. build/lib/pyTEMlib/utilities.py +314 -0
  39. build/lib/pyTEMlib/version.py +5 -0
  40. build/lib/pyTEMlib/xrpa_x_sections.py +20976 -0
  41. pyTEMlib/__init__.py +25 -3
  42. pyTEMlib/animation.py +31 -22
  43. pyTEMlib/atom_tools.py +29 -34
  44. pyTEMlib/config_dir.py +2 -28
  45. pyTEMlib/crystal_tools.py +129 -165
  46. pyTEMlib/eds_tools.py +559 -342
  47. pyTEMlib/eds_xsections.py +432 -0
  48. pyTEMlib/eels_tools/__init__.py +44 -0
  49. pyTEMlib/eels_tools/core_loss_tools.py +751 -0
  50. pyTEMlib/eels_tools/eels_database.py +134 -0
  51. pyTEMlib/eels_tools/low_loss_tools.py +655 -0
  52. pyTEMlib/eels_tools/peak_fit_tools.py +175 -0
  53. pyTEMlib/eels_tools/zero_loss_tools.py +264 -0
  54. pyTEMlib/file_reader.py +274 -0
  55. pyTEMlib/file_tools.py +260 -1130
  56. pyTEMlib/get_bote_salvat.py +69 -0
  57. pyTEMlib/graph_tools.py +101 -174
  58. pyTEMlib/graph_viz.py +150 -0
  59. pyTEMlib/image/__init__.py +37 -0
  60. pyTEMlib/image/image_atoms.py +270 -0
  61. pyTEMlib/image/image_clean.py +197 -0
  62. pyTEMlib/image/image_distortion.py +299 -0
  63. pyTEMlib/image/image_fft.py +277 -0
  64. pyTEMlib/image/image_graph.py +926 -0
  65. pyTEMlib/image/image_registration.py +316 -0
  66. pyTEMlib/image/image_utilities.py +309 -0
  67. pyTEMlib/image/image_window.py +421 -0
  68. pyTEMlib/image_tools.py +154 -915
  69. pyTEMlib/kinematic_scattering.py +1 -1
  70. pyTEMlib/probe_tools.py +1 -1
  71. pyTEMlib/test.py +437 -0
  72. pyTEMlib/utilities.py +314 -0
  73. pyTEMlib/version.py +2 -3
  74. pyTEMlib/xrpa_x_sections.py +14 -10
  75. {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/METADATA +13 -16
  76. pytemlib-0.2025.9.1.dist-info/RECORD +86 -0
  77. {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/WHEEL +1 -1
  78. pytemlib-0.2025.9.1.dist-info/top_level.txt +6 -0
  79. pyTEMlib/core_loss_widget.py +0 -721
  80. pyTEMlib/eels_dialog.py +0 -754
  81. pyTEMlib/eels_dialog_utilities.py +0 -1199
  82. pyTEMlib/eels_tools.py +0 -2359
  83. pyTEMlib/file_tools_qt.py +0 -193
  84. pyTEMlib/image_dialog.py +0 -158
  85. pyTEMlib/image_dlg.py +0 -146
  86. pyTEMlib/info_widget.py +0 -1086
  87. pyTEMlib/info_widget3.py +0 -1120
  88. pyTEMlib/low_loss_widget.py +0 -479
  89. pyTEMlib/peak_dialog.py +0 -1129
  90. pyTEMlib/peak_dlg.py +0 -286
  91. pytemlib-0.2025.4.1.dist-info/RECORD +0 -38
  92. pytemlib-0.2025.4.1.dist-info/top_level.txt +0 -1
  93. {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/entry_points.txt +0 -0
  94. {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,134 @@
1
+ """
2
+ eels_tools
3
+ Model based quantification of electron energy-loss data
4
+ Copyright by Gerd Duscher
5
+
6
+ """
7
+ import numpy as np
8
+ import requests
9
+
10
+
11
+
12
+ ##########################
13
+ # EELS Database
14
+ ##########################
15
+
16
+
17
+ def read_msa(msa_string):
18
+ """read msa formated file"""
19
+ parameters = {}
20
+ y = []
21
+ x = []
22
+ # Read the keywords
23
+ data_section = False
24
+ msa_lines = msa_string.split('\n')
25
+
26
+ for line in msa_lines:
27
+ if data_section is False:
28
+ if len(line) > 0:
29
+ if line[0] == "#":
30
+ try:
31
+ key, value = line.split(': ')
32
+ value = value.strip()
33
+ except ValueError:
34
+ key = line
35
+ value = None
36
+ key = key.strip('#').strip()
37
+
38
+ if key != 'SPECTRUM':
39
+ parameters[key] = value
40
+ else:
41
+ data_section = True
42
+ else:
43
+ # Read the data
44
+
45
+ if len(line) > 0 and line[0] != "#" and line.strip():
46
+ if parameters['DATATYPE'] == 'XY':
47
+ xy = line.replace(',', ' ').strip().split()
48
+ y.append(float(xy[1]))
49
+ x.append(float(xy[0]))
50
+ elif parameters['DATATYPE'] == 'Y':
51
+ print('y')
52
+ data = [
53
+ float(i) for i in line.replace(',', ' ').strip().split()]
54
+ y.extend(data)
55
+ parameters['data'] = np.array(y)
56
+ if 'XPERCHAN' in parameters:
57
+ parameters['XPERCHAN'] = str(parameters['XPERCHAN']).split(' ', maxsplit=1)[0]
58
+ parameters['OFFSET'] = str(parameters['OFFSET']).split(' ', maxsplit=1)[0]
59
+ dispersion = float(parameters['XPERCHAN']) # eV per channel
60
+ offset = float(parameters['OFFSET']) # eV offset
61
+ parameters['energy_scale'] = np.arange(len(y)) * dispersion + offset
62
+ return parameters
63
+
64
+
65
+ def get_spectrum_eels_db(formula=None, edge=None, title=None, element=None):
66
+ """
67
+ get spectra from EELS database
68
+ chemical formula and edge is accepted.
69
+ Could expose more of the search parameters
70
+ """
71
+ valid_edges = ['K', 'L1', 'L2,3', 'M2,3', 'M4,5', 'N2,3', 'N4,5', 'O2,3', 'O4,5']
72
+ if edge is not None and edge not in valid_edges:
73
+ print('edge should be a in ', valid_edges)
74
+
75
+ spectrum_type = None
76
+ author = None
77
+ min_energy = None
78
+ max_energy = None
79
+ resolution = None
80
+ min_energy_compare = "gt"
81
+ max_energy_compare = "lt"
82
+ resolution_compare = "lt"
83
+ max_n = -1
84
+ monochromated = None
85
+ order = None
86
+ order_direction = "ASC"
87
+ verify_certificate = True
88
+ # Verify arguments
89
+
90
+ if spectrum_type is not None and spectrum_type not in {'coreloss', 'lowloss', 'zeroloss', 'xrayabs'}:
91
+ raise ValueError("spectrum_type must be one of \'coreloss\', \'lowloss\', "
92
+ "\'zeroloss\', \'xrayabs\'.")
93
+ # valid_edges = ['K', 'L1', 'L2,3', 'M2,3', 'M4,5', 'N2,3', 'N4,5', 'O2,3', 'O4,5']
94
+
95
+ params = {
96
+ "type": spectrum_type,
97
+ "title": title,
98
+ "author": author,
99
+ "edge": edge,
100
+ "min_energy": min_energy,
101
+ "max_energy": max_energy,
102
+ "resolution": resolution,
103
+ "resolution_compare": resolution_compare,
104
+ "monochromated": monochromated,
105
+ "formula": formula,
106
+ 'element': element,
107
+ "min_energy_compare": min_energy_compare,
108
+ "max_energy_compare": max_energy_compare,
109
+ "per_page": max_n,
110
+ "order": order,
111
+ "order_direction": order_direction,
112
+ }
113
+
114
+ request = requests.get('http://api.eelsdb.eu/spectra', params=params, verify=True, timeout=10)
115
+ # spectra = []
116
+ jsons = request.json()
117
+ if "message" in jsons:
118
+ # Invalid query, EELSdb raises error.
119
+ raise IOError(
120
+ f"Please report the following error to the HyperSpy developers: ",
121
+ f"{jsons['message']}")
122
+ reference_spectra = {}
123
+ for json_spectrum in jsons:
124
+ download_link = json_spectrum['download_link']
125
+ # print(download_link)
126
+ msa_string = requests.get(download_link, verify=verify_certificate, timeout=10).text
127
+ # print(msa_string[:100])
128
+ parameters = read_msa(msa_string)
129
+ if 'XPERCHAN' in parameters:
130
+ reference_spectra[parameters['TITLE']] = parameters
131
+ print(parameters['TITLE'])
132
+ print(f'found {len(reference_spectra.keys())} spectra in EELS database)')
133
+
134
+ return reference_spectra