pyTEMlib 0.2020.11.0__py3-none-any.whl → 0.2024.8.4__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 (59) hide show
  1. pyTEMlib/__init__.py +11 -11
  2. pyTEMlib/animation.py +631 -0
  3. pyTEMlib/atom_tools.py +240 -222
  4. pyTEMlib/config_dir.py +57 -29
  5. pyTEMlib/core_loss_widget.py +658 -0
  6. pyTEMlib/crystal_tools.py +1255 -0
  7. pyTEMlib/diffraction_plot.py +756 -0
  8. pyTEMlib/dynamic_scattering.py +293 -0
  9. pyTEMlib/eds_tools.py +609 -0
  10. pyTEMlib/eels_dialog.py +749 -486
  11. pyTEMlib/{interactive_eels.py → eels_dialog_utilities.py} +1199 -1524
  12. pyTEMlib/eels_tools.py +2031 -1731
  13. pyTEMlib/file_tools.py +1276 -491
  14. pyTEMlib/file_tools_qt.py +193 -0
  15. pyTEMlib/graph_tools.py +1166 -450
  16. pyTEMlib/graph_viz.py +449 -0
  17. pyTEMlib/image_dialog.py +158 -0
  18. pyTEMlib/image_dlg.py +146 -0
  19. pyTEMlib/image_tools.py +1399 -956
  20. pyTEMlib/info_widget.py +933 -0
  21. pyTEMlib/interactive_image.py +1 -0
  22. pyTEMlib/kinematic_scattering.py +1196 -0
  23. pyTEMlib/low_loss_widget.py +176 -0
  24. pyTEMlib/microscope.py +61 -78
  25. pyTEMlib/peak_dialog.py +1047 -350
  26. pyTEMlib/peak_dlg.py +286 -248
  27. pyTEMlib/probe_tools.py +653 -202
  28. pyTEMlib/sidpy_tools.py +153 -129
  29. pyTEMlib/simulation_tools.py +104 -87
  30. pyTEMlib/version.py +6 -3
  31. pyTEMlib/xrpa_x_sections.py +20972 -0
  32. {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/LICENSE +21 -21
  33. pyTEMlib-0.2024.8.4.dist-info/METADATA +93 -0
  34. pyTEMlib-0.2024.8.4.dist-info/RECORD +37 -0
  35. {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/WHEEL +6 -5
  36. {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/entry_points.txt +0 -1
  37. pyTEMlib/KinsCat.py +0 -2685
  38. pyTEMlib/__version__.py +0 -2
  39. pyTEMlib/data/TEMlibrc +0 -68
  40. pyTEMlib/data/edges_db.csv +0 -189
  41. pyTEMlib/data/edges_db.pkl +0 -0
  42. pyTEMlib/data/fparam.txt +0 -103
  43. pyTEMlib/data/microscopes.csv +0 -7
  44. pyTEMlib/data/microscopes.xml +0 -167
  45. pyTEMlib/data/path.txt +0 -1
  46. pyTEMlib/defaults_parser.py +0 -86
  47. pyTEMlib/dm3_reader.py +0 -609
  48. pyTEMlib/edges_db.py +0 -76
  49. pyTEMlib/eels_dlg.py +0 -240
  50. pyTEMlib/hdf_utils.py +0 -481
  51. pyTEMlib/image_tools1.py +0 -2194
  52. pyTEMlib/info_dialog.py +0 -227
  53. pyTEMlib/info_dlg.py +0 -205
  54. pyTEMlib/nion_reader.py +0 -293
  55. pyTEMlib/nsi_reader.py +0 -165
  56. pyTEMlib/structure_tools.py +0 -316
  57. pyTEMlib-0.2020.11.0.dist-info/METADATA +0 -20
  58. pyTEMlib-0.2020.11.0.dist-info/RECORD +0 -42
  59. {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,176 @@
1
+ from typing import Any
2
+
3
+ import numpy as np
4
+ import os
5
+ import ipywidgets
6
+ import matplotlib.pylab as plt
7
+ import matplotlib
8
+ from IPython.display import display
9
+
10
+ import sidpy
11
+ # from pyTEMlib.microscope import microscope
12
+ from pyTEMlib import file_tools
13
+ from pyTEMlib import eels_tools
14
+
15
+
16
+ def get_low_loss_sidebar() -> Any:
17
+ side_bar = ipywidgets.GridspecLayout(9, 3, width='auto', grid_gap="0px")
18
+
19
+ side_bar[0, :2] = ipywidgets.Dropdown(
20
+ options=[('None', 0)],
21
+ value=0,
22
+ description='Main Dataset:',
23
+ disabled=False)
24
+
25
+ row = 1
26
+
27
+ side_bar[row, :3] = ipywidgets.Button(description='Resolution Function',
28
+ layout=ipywidgets.Layout(width='auto', grid_area='header'),
29
+ style=ipywidgets.ButtonStyle(button_color='lightblue'))
30
+ row += 1
31
+ side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='fit width:', disabled=False, color='black',
32
+ layout=ipywidgets.Layout(width='200px'))
33
+ side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='100px'))
34
+ row +=1
35
+ side_bar[row, 0] = ipywidgets.widgets.Label(value="thickness", layout=ipywidgets.Layout(width='100px'))
36
+ side_bar[row, 1] = ipywidgets.widgets.Label(value="", layout=ipywidgets.Layout(width='100px'))
37
+ side_bar[row, 2] = ipywidgets.widgets.Label(value="* iMFP", layout=ipywidgets.Layout(width='100px'))
38
+ row +=1
39
+ side_bar[row, 0] = ipywidgets.ToggleButton(description='Plot Res.Fct.',
40
+ disabled=False,
41
+ button_style='', # 'success', 'info', 'warning', 'danger' or ''
42
+ tooltip='Plots resolution function on right',
43
+ layout=ipywidgets.Layout(width='100px'))
44
+
45
+ side_bar[row, 2] = ipywidgets.ToggleButton(description='Probability',
46
+ disabled=False,
47
+ button_style='', # 'success', 'info', 'warning', 'danger' or ''
48
+ tooltip='Changes y-axis to probability if flux is given',
49
+ layout=ipywidgets.Layout(width='100px'))
50
+
51
+
52
+ row += 1
53
+ side_bar[row, :3] = ipywidgets.Button(description='Drude',
54
+ layout=ipywidgets.Layout(width='auto', grid_area='header'),
55
+ style=ipywidgets.ButtonStyle(button_color='lightblue'))
56
+ row += 1
57
+ side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Start Fit:', disabled=False, color='black',
58
+ layout=ipywidgets.Layout(width='200px'))
59
+ side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='100px'))
60
+ row += 1
61
+ side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='End Fit:', disabled=False, color='black',
62
+ layout=ipywidgets.Layout(width='200px'))
63
+ side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='50px'))
64
+ row +=1
65
+ side_bar[row, 0] = ipywidgets.ToggleButton(description='Plot Drude',
66
+ disabled=False,
67
+ button_style='', # 'success', 'info', 'warning', 'danger' or ''
68
+ tooltip='Plots resolution function on right',
69
+ layout=ipywidgets.Layout(width='100px'))
70
+
71
+ side_bar[row, 2] = ipywidgets.ToggleButton(description='Plot Diel.Fct.',
72
+ disabled=False,
73
+ button_style='', # 'success', 'info', 'warning', 'danger' or ''
74
+ tooltip='Changes y-axis to probability if flux is given',
75
+ layout=ipywidgets.Layout(width='100px'))
76
+
77
+
78
+ return side_bar
79
+
80
+ class LowLoss(object):
81
+ def __init__(self, sidebar=None, parent=None):
82
+ self.parent = parent
83
+ self.dataset = parent.dataset
84
+ self.low_loss_tab = sidebar
85
+ self.set_ll_action()
86
+ self.update_ll_sidebar()
87
+
88
+ def update_ll_sidebar(self):
89
+ spectrum_list = ['None']
90
+ for index, key in enumerate(self.parent.datasets.keys()):
91
+ if isinstance(self.parent.datasets[key], sidpy.Dataset):
92
+ if 'SPECTR' in self.parent.datasets[key].data_type.name:
93
+ energy_offset = self.parent.datasets[key].get_spectral_dims(return_axis=True)[0][0]
94
+ if energy_offset < 0:
95
+ spectrum_list.append(f'{key}: {self.parent.datasets[key].title}')
96
+
97
+ self.low_loss_tab[0, 0].options = spectrum_list
98
+
99
+ def get_resolution_function(self, value):
100
+ self.low_loss_tab[4, 0].value = False
101
+ zero_loss_fit_width=self.low_loss_tab[2, 0].value
102
+ self.parent.datasets['resolution_functions'] = eels_tools.get_resolution_functions(self.parent.dataset,
103
+ startFitEnergy=-zero_loss_fit_width,
104
+ endFitEnergy=zero_loss_fit_width)
105
+ if 'low_loss' not in self.dataset.metadata:
106
+ self.dataset.metadata['zero_loss'] = {}
107
+ self.dataset.metadata['zero_loss'].update(self.parent.datasets['resolution_functions'].metadata['zero_loss'])
108
+ self.low_loss_tab[4, 0].value = True
109
+ self.low_loss_tab[3, 1].value = f"{np.log(self.parent.dataset.sum()/self.parent.datasets['resolution_functions'].sum())}"
110
+
111
+
112
+
113
+ def set_ll_action(self):
114
+ self.low_loss_tab[0, 0].observe(self.update_ll_dataset)
115
+ #self.low_loss_tab[1, 0].on_click(self.fix_energy_scale)
116
+ #self.low_loss_tab[2, 0].observe(self.set_energy_scale, names='value')
117
+ #self.low_loss_tab[3, 0].observe(self.set_energy_scale, names='value')
118
+ self.low_loss_tab[1, 0].on_click(self.get_resolution_function)
119
+ self.low_loss_tab[4, 2].observe(self.parent.info.set_y_scale, names='value')
120
+ self.low_loss_tab[4, 0].observe(self._update, names='value')
121
+
122
+ def _update(self, ev=0):
123
+ self.parent._update(ev)
124
+
125
+ if self.low_loss_tab[4, 0].value:
126
+ if 'resolution_functions' in self.parent.datasets:
127
+ resolution_function = self.get_additional_spectrum('resolution_functions')
128
+ self.parent.axis.plot(self.parent.energy_scale, resolution_function, label='resolution_function')
129
+ self.parent.axis.plot(self.parent.energy_scale,
130
+ self.parent.spectrum -resolution_function, label='difference')
131
+
132
+ self.parent.axis.legend()
133
+
134
+ def get_additional_spectrum(self, key):
135
+ if key not in self.parent.datasets.keys():
136
+ return
137
+
138
+ if self.parent.datasets[key].data_type == sidpy.DataType.SPECTRUM:
139
+ self.spectrum = self.parent.datasets[key].copy()
140
+ else:
141
+ image_dims = self.parent.datasets[key].get_dimensions_by_type(sidpy.DimensionType.SPATIAL)
142
+ selection = []
143
+ for dim, axis in self.parent.datasets[key]._axes.items():
144
+ # print(dim, axis.dimension_type)
145
+ if axis.dimension_type == sidpy.DimensionType.SPATIAL:
146
+ if dim == image_dims[0]:
147
+ selection.append(slice(self.x, self.x + self.bin_x))
148
+ else:
149
+ selection.append(slice(self.y, self.y + self.bin_y))
150
+
151
+ elif axis.dimension_type == sidpy.DimensionType.SPECTRAL:
152
+ selection.append(slice(None))
153
+ elif axis.dimension_type == sidpy.DimensionType.CHANNEL:
154
+ selection.append(slice(None))
155
+ else:
156
+ selection.append(slice(0, 1))
157
+
158
+ self.spectrum = self.parent.datasets[key][tuple(selection)].mean(axis=tuple(image_dims))
159
+
160
+ self.spectrum *= self.parent.y_scale
161
+
162
+ return self.spectrum.squeeze()
163
+
164
+ def update_ll_dataset(self, value=0):
165
+ self.ll_key = self.low_loss_tab[0, 0].value.split(':')[0]
166
+ self.parent.set_dataset(self.ll_key)
167
+ self.dataset = self.parent.dataset
168
+
169
+
170
+ def set_binning(self, value):
171
+ if 'SPECTRAL' in self.dataset.data_type.name:
172
+ bin_x = self.info_tab[15, 0].value
173
+ bin_y = self.info_tab[16, 0].value
174
+ self.dataset.view.set_bin([bin_x, bin_y])
175
+ self.datasets[self.key].metadata['experiment']['SI_bin_x'] = bin_x
176
+ self.datasets[self.key].metadata['experiment']['SI_bin_y'] = bin_y
pyTEMlib/microscope.py CHANGED
@@ -1,78 +1,61 @@
1
- # -*- coding: cp1252 -*-
2
- #################################################################
3
- # Read microscope CSV file
4
- # Original by EELSLab Author: Francisco Javier de la Pe�a
5
- # Made more flexible for load microscopes with csv.DictReader
6
- # for pyTEMLib by Gerd
7
- # copyright 2012, Gerd Duscher
8
- ################################################################
9
-
10
- import csv
11
- import os.path
12
-
13
- from pyTEMlib.config_dir import config_path
14
- from pyTEMlib.defaults_parser import defaults
15
-
16
- microscopes_file = os.path.join(config_path, 'microscopes.csv')
17
-
18
-
19
- class Microscope(object):
20
- microscopes = {}
21
- name = None
22
- E0 = None
23
- alpha = None
24
- beta = None
25
- pppc = None
26
- correlation_factor = None
27
-
28
- def __init__(self):
29
- self.load_microscopes()
30
-
31
- defaults.microscope = defaults.microscope.replace('.', ' ')
32
- self.set_microscope(defaults.microscope)
33
-
34
- def load_microscopes(self):
35
- f = open(microscopes_file, 'r')
36
-
37
- labels = f.readline().strip().split(',')
38
- # print labels
39
- csv_read = csv.DictReader(f, labels, delimiter=",")
40
-
41
- for line in csv_read:
42
- tem = line['Microscope']
43
- self.microscopes[tem] = line
44
- for i in self.microscopes[tem]:
45
- if i != 'Microscope':
46
- self.microscopes[tem][i] = float(self.microscopes[tem][i])
47
-
48
- f.close()
49
-
50
- def get_available_microscope_names(self):
51
- tem = []
52
- for scope in self.microscopes.keys():
53
- tem.append(scope)
54
- return tem
55
-
56
- def set_microscope(self, microscope_name):
57
-
58
- for key in self.microscopes[microscope_name]:
59
- exec('self.%s = self.microscopes[\'%s\'][\'%s\']' % (key, microscope_name, key))
60
- self.name = microscope_name
61
-
62
- def __repr__(self):
63
- info = '''
64
- Microscope parameters:
65
- -----------------------------
66
-
67
- Microscope: %s
68
- Convergence angle: %1.2f mrad
69
- Collection angle: %1.2f mrad
70
- Beam energy: %1.2E eV
71
- pppc: %1.2f
72
- Correlation factor: %1.2f
73
- ''' % (self.name, self.alpha, self.beta, self.E0,
74
- self.pppc, self.correlation_factor)
75
- return info
76
-
77
-
78
- microscope = Microscope()
1
+ """ default microscope parameters from config file
2
+
3
+ Read microscope CSV file
4
+
5
+ for pyTEMLib by Gerd
6
+
7
+ copyright 2012, Gerd Duscher
8
+ updated 2021
9
+ """
10
+ # -*- coding: utf-8 -*-
11
+
12
+ import csv
13
+ import os.path
14
+
15
+ from pyTEMlib.config_dir import config_path
16
+ microscopes_file = os.path.join(config_path, 'microscopes.csv')
17
+
18
+
19
+
20
+ class Microscope(object):
21
+ """Class to read configuration file and provide microscope information"""
22
+ microscopes = {}
23
+ name = None
24
+ E0 = None
25
+ alpha = None
26
+ beta = None
27
+ pppc = None
28
+ correlation_factor = None
29
+
30
+ def __init__(self):
31
+ self.load_microscopes()
32
+ default_tem = self.microscopes[list(self.microscopes.keys())[0]]
33
+ self.set_microscope(default_tem['Microscope'])
34
+
35
+ def load_microscopes(self):
36
+ f = open(microscopes_file, 'r')
37
+
38
+ labels = f.readline().strip().split(',')
39
+ # print labels
40
+ csv_read = csv.DictReader(f, labels, delimiter=",")
41
+
42
+ for line in csv_read:
43
+ tem = line['Microscope']
44
+ self.microscopes[tem] = line
45
+ for i in self.microscopes[tem]:
46
+ if i != 'Microscope':
47
+ self.microscopes[tem][i] = float(self.microscopes[tem][i])
48
+ f.close()
49
+
50
+ def get_available_microscope_names(self):
51
+ tem = []
52
+ for scope in self.microscopes.keys():
53
+ tem.append(scope)
54
+ return tem
55
+
56
+ def set_microscope(self, microscope_name):
57
+ if microscope_name in self.microscopes:
58
+ self.name = microscope_name
59
+
60
+
61
+ microscope = Microscope()