pyTEMlib 0.2020.11.1__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.
- pyTEMlib/__init__.py +11 -11
- pyTEMlib/animation.py +631 -0
- pyTEMlib/atom_tools.py +240 -245
- pyTEMlib/config_dir.py +57 -33
- pyTEMlib/core_loss_widget.py +658 -0
- pyTEMlib/crystal_tools.py +1255 -0
- pyTEMlib/diffraction_plot.py +756 -0
- pyTEMlib/dynamic_scattering.py +293 -0
- pyTEMlib/eds_tools.py +609 -0
- pyTEMlib/eels_dialog.py +749 -491
- pyTEMlib/{interactive_eels.py → eels_dialog_utilities.py} +1199 -1177
- pyTEMlib/eels_tools.py +2031 -1698
- pyTEMlib/file_tools.py +1276 -560
- pyTEMlib/file_tools_qt.py +193 -0
- pyTEMlib/graph_tools.py +1166 -450
- pyTEMlib/graph_viz.py +449 -0
- pyTEMlib/image_dialog.py +158 -0
- pyTEMlib/image_dlg.py +146 -232
- pyTEMlib/image_tools.py +1399 -1028
- pyTEMlib/info_widget.py +933 -0
- pyTEMlib/interactive_image.py +1 -226
- pyTEMlib/kinematic_scattering.py +1196 -0
- pyTEMlib/low_loss_widget.py +176 -0
- pyTEMlib/microscope.py +61 -81
- pyTEMlib/peak_dialog.py +1047 -410
- pyTEMlib/peak_dlg.py +286 -242
- pyTEMlib/probe_tools.py +653 -207
- pyTEMlib/sidpy_tools.py +153 -136
- pyTEMlib/simulation_tools.py +104 -87
- pyTEMlib/version.py +6 -3
- pyTEMlib/xrpa_x_sections.py +20972 -0
- {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/LICENSE +21 -21
- pyTEMlib-0.2024.8.4.dist-info/METADATA +93 -0
- pyTEMlib-0.2024.8.4.dist-info/RECORD +37 -0
- {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/WHEEL +6 -5
- {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/entry_points.txt +0 -1
- pyTEMlib/KinsCat.py +0 -2758
- pyTEMlib/__version__.py +0 -2
- pyTEMlib/data/TEMlibrc +0 -68
- pyTEMlib/data/edges_db.csv +0 -189
- pyTEMlib/data/edges_db.pkl +0 -0
- pyTEMlib/data/fparam.txt +0 -103
- pyTEMlib/data/microscopes.csv +0 -7
- pyTEMlib/data/microscopes.xml +0 -167
- pyTEMlib/data/path.txt +0 -1
- pyTEMlib/defaults_parser.py +0 -90
- pyTEMlib/dm3_reader.py +0 -613
- pyTEMlib/edges_db.py +0 -76
- pyTEMlib/eels_dlg.py +0 -224
- pyTEMlib/hdf_utils.py +0 -483
- pyTEMlib/image_tools1.py +0 -2194
- pyTEMlib/info_dialog.py +0 -237
- pyTEMlib/info_dlg.py +0 -202
- pyTEMlib/nion_reader.py +0 -297
- pyTEMlib/nsi_reader.py +0 -170
- pyTEMlib/structure_tools.py +0 -316
- pyTEMlib/test.py +0 -2072
- pyTEMlib-0.2020.11.1.dist-info/METADATA +0 -20
- pyTEMlib-0.2020.11.1.dist-info/RECORD +0 -45
- {pyTEMlib-0.2020.11.1.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,81 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Read microscope CSV file
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
self.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
tem
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
exec('self.%s = self.microscopes[\'%s\'][\'%s\']' % (key, microscope_name, key))
|
|
63
|
-
self.name = microscope_name
|
|
64
|
-
|
|
65
|
-
def __repr__(self):
|
|
66
|
-
info = '''
|
|
67
|
-
Microscope parameters:
|
|
68
|
-
-----------------------------
|
|
69
|
-
|
|
70
|
-
Microscope: %s
|
|
71
|
-
Convergence angle: %1.2f mrad
|
|
72
|
-
Collection angle: %1.2f mrad
|
|
73
|
-
Beam energy: %1.2E eV
|
|
74
|
-
pppc: %1.2f
|
|
75
|
-
Correlation factor: %1.2f
|
|
76
|
-
''' % (self.name, self.alpha, self.beta, self.E0,
|
|
77
|
-
self.pppc, self.correlation_factor)
|
|
78
|
-
return info
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
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()
|