pyTEMlib 0.2024.2.2__py2.py3-none-any.whl → 0.2024.8.4__py2.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.
- pyTEMlib/core_loss_widget.py +658 -0
- pyTEMlib/eds_tools.py +218 -167
- pyTEMlib/eels_dialog.py +13 -12
- pyTEMlib/eels_dialog_utilities.py +2 -3
- pyTEMlib/eels_tools.py +56 -71
- pyTEMlib/file_tools.py +7 -1
- pyTEMlib/image_tools.py +103 -27
- pyTEMlib/info_widget.py +301 -365
- pyTEMlib/low_loss_widget.py +176 -0
- pyTEMlib/version.py +2 -2
- pyTEMlib/xrpa_x_sections.py +140 -54
- {pyTEMlib-0.2024.2.2.dist-info → pyTEMlib-0.2024.8.4.dist-info}/METADATA +2 -3
- {pyTEMlib-0.2024.2.2.dist-info → pyTEMlib-0.2024.8.4.dist-info}/RECORD +17 -15
- {pyTEMlib-0.2024.2.2.dist-info → pyTEMlib-0.2024.8.4.dist-info}/WHEEL +1 -1
- {pyTEMlib-0.2024.2.2.dist-info → pyTEMlib-0.2024.8.4.dist-info}/entry_points.txt +0 -1
- {pyTEMlib-0.2024.2.2.dist-info → pyTEMlib-0.2024.8.4.dist-info}/LICENSE +0 -0
- {pyTEMlib-0.2024.2.2.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/version.py
CHANGED