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
pyTEMlib/info_widget.py
ADDED
|
@@ -0,0 +1,933 @@
|
|
|
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
|
+
from pyTEMlib.core_loss_widget import get_core_loss_sidebar, CoreLoss
|
|
15
|
+
from pyTEMlib.low_loss_widget import get_low_loss_sidebar, LowLoss
|
|
16
|
+
|
|
17
|
+
def get_image_sidebar() -> Any:
|
|
18
|
+
side_bar = ipywidgets.GridspecLayout(14, 3, width='auto', grid_gap="0px")
|
|
19
|
+
|
|
20
|
+
side_bar[0, :2] = ipywidgets.Dropdown(
|
|
21
|
+
options=[('None', 0)],
|
|
22
|
+
value=0,
|
|
23
|
+
description='Main Dataset:',
|
|
24
|
+
disabled=False)
|
|
25
|
+
row = 1
|
|
26
|
+
side_bar[row, :3] = ipywidgets.Button(description='Image Scale',
|
|
27
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
28
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
29
|
+
row += 1
|
|
30
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='x dim:', disabled=False, color='black',
|
|
31
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
32
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="nm", layout=ipywidgets.Layout(width='20px'))
|
|
33
|
+
row += 1
|
|
34
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='y dim:', disabled=False, color='black',
|
|
35
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
36
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="nm", layout=ipywidgets.Layout(width='20px'))
|
|
37
|
+
row += 1
|
|
38
|
+
|
|
39
|
+
side_bar[row, :3] = ipywidgets.Button(description='Microscope',
|
|
40
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
41
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
42
|
+
row += 1
|
|
43
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='Conv.Angle:', disabled=False, color='black',
|
|
44
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
45
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
|
|
46
|
+
row += 1
|
|
47
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Coll.Angle:', disabled=False, color='black',
|
|
48
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
49
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
|
|
50
|
+
row += 1
|
|
51
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Acc Voltage:', disabled=False, color='black',
|
|
52
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
53
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="keV", layout=ipywidgets.Layout(width='100px'))
|
|
54
|
+
|
|
55
|
+
row += 1
|
|
56
|
+
side_bar[row, :3] = ipywidgets.Button(description='Calibration',
|
|
57
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
58
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
59
|
+
row += 1
|
|
60
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Pixel_Time:', disabled=False, color='black',
|
|
61
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
62
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="μs", layout=ipywidgets.Layout(width='100px'))
|
|
63
|
+
row += 1
|
|
64
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='Screen Curr:', disabled=False, color='black',
|
|
65
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
66
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="pA", layout=ipywidgets.Layout(width='50px'))
|
|
67
|
+
row += 1
|
|
68
|
+
|
|
69
|
+
side_bar[row, 0] = ipywidgets.Button(description='FFT', disabled=True,
|
|
70
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
71
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
72
|
+
side_bar[row, 1] = ipywidgets.Button(description='LR-Decon', disabled=True,
|
|
73
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
74
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
75
|
+
side_bar[row, 2] = ipywidgets.Button(description='Find atoms', disabled=True,
|
|
76
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
77
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
78
|
+
|
|
79
|
+
row += 1
|
|
80
|
+
side_bar[row, :3] = ipywidgets.Button(description='Image Stack',
|
|
81
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
82
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
83
|
+
row += 1
|
|
84
|
+
side_bar[row, 0] = ipywidgets.Button(description='Rig Reg.', disabled=True,
|
|
85
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
86
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
87
|
+
side_bar[row, 1] = ipywidgets.Button(description='Demon', disabled=True,
|
|
88
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
89
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
90
|
+
side_bar[row, 2] = ipywidgets.Button(description='Sum', disabled=True,
|
|
91
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
92
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
93
|
+
|
|
94
|
+
side_bar[-2, 0].layout.display = "none"
|
|
95
|
+
for i in range(3):
|
|
96
|
+
side_bar[-1, i].layout.display = "none"
|
|
97
|
+
return side_bar
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_info_sidebar() -> Any:
|
|
101
|
+
side_bar = ipywidgets.GridspecLayout(18, 3, width='auto', grid_gap="0px")
|
|
102
|
+
|
|
103
|
+
side_bar[0, :2] = ipywidgets.Dropdown(
|
|
104
|
+
options=[('None', 0)],
|
|
105
|
+
value=0,
|
|
106
|
+
description='Main Dataset:',
|
|
107
|
+
disabled=False)
|
|
108
|
+
|
|
109
|
+
row = 1
|
|
110
|
+
side_bar[row, :3] = ipywidgets.Button(description='Energy Scale',
|
|
111
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
112
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
113
|
+
row += 1
|
|
114
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='Offset:', disabled=False, color='black',
|
|
115
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
116
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))
|
|
117
|
+
row += 1
|
|
118
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Dispersion:', disabled=False, color='black',
|
|
119
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
120
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="eV", layout=ipywidgets.Layout(width='20px'))
|
|
121
|
+
row += 1
|
|
122
|
+
side_bar[row, :3] = ipywidgets.Button(description='Microscope',
|
|
123
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
124
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
125
|
+
row += 1
|
|
126
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='Conv.Angle:', disabled=False, color='black',
|
|
127
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
128
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
|
|
129
|
+
row += 1
|
|
130
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Coll.Angle:', disabled=False, color='black',
|
|
131
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
132
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="mrad", layout=ipywidgets.Layout(width='100px'))
|
|
133
|
+
row += 1
|
|
134
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Acc Voltage:', disabled=False, color='black',
|
|
135
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
136
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="keV", layout=ipywidgets.Layout(width='100px'))
|
|
137
|
+
|
|
138
|
+
row += 1
|
|
139
|
+
side_bar[row, :3] = ipywidgets.Button(description='Calibration',
|
|
140
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
141
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
142
|
+
row += 1
|
|
143
|
+
side_bar[row, :2] = ipywidgets.Dropdown(
|
|
144
|
+
options=[('None', 0)],
|
|
145
|
+
value=0,
|
|
146
|
+
description='Reference:',
|
|
147
|
+
disabled=False)
|
|
148
|
+
side_bar[row, 2] = ipywidgets.ToggleButton(description='Probability',
|
|
149
|
+
disabled=False,
|
|
150
|
+
button_style='', # 'success', 'info', 'warning', 'danger' or ''
|
|
151
|
+
tooltip='Changes y-axis to probability if flux is given',
|
|
152
|
+
layout=ipywidgets.Layout(width='100px'))
|
|
153
|
+
row += 1
|
|
154
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Exp_Time:', disabled=False, color='black',
|
|
155
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
156
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="s", layout=ipywidgets.Layout(width='100px'))
|
|
157
|
+
row += 1
|
|
158
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=7.5, description='Flux:', disabled=False, color='black',
|
|
159
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
160
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="Mcounts", layout=ipywidgets.Layout(width='50px'))
|
|
161
|
+
row += 1
|
|
162
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Conversion:', disabled=False, color='black',
|
|
163
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
164
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="e⁻/counts", layout=ipywidgets.Layout(width='100px'))
|
|
165
|
+
row += 1
|
|
166
|
+
side_bar[row, :2] = ipywidgets.FloatText(value=0.1, description='Current:', disabled=False, color='black',
|
|
167
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
168
|
+
side_bar[row, 2] = ipywidgets.widgets.Label(value="pA", layout=ipywidgets.Layout(width='100px'))
|
|
169
|
+
|
|
170
|
+
row += 1
|
|
171
|
+
side_bar[row, 0] = ipywidgets.Button(description='Get Shift', disabled=True,
|
|
172
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
173
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
174
|
+
side_bar[row, 1] = ipywidgets.Button(description='Shift Spec', disabled=True,
|
|
175
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
176
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
177
|
+
side_bar[row, 2] = ipywidgets.Button(description='Res.Fct.', disabled=True,
|
|
178
|
+
layout=ipywidgets.Layout(width='auto'),
|
|
179
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
180
|
+
|
|
181
|
+
row += 1
|
|
182
|
+
side_bar[row, :3] = ipywidgets.Button(description='Spectrum Image',
|
|
183
|
+
layout=ipywidgets.Layout(width='auto', grid_area='header'),
|
|
184
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
185
|
+
|
|
186
|
+
row += 1
|
|
187
|
+
side_bar[row, :2] = ipywidgets.IntText(value=1, description='bin X:', disabled=False, color='black',
|
|
188
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
189
|
+
row += 1
|
|
190
|
+
side_bar[row, :2] = ipywidgets.IntText(value=1, description='bin X:', disabled=False, color='black',
|
|
191
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
192
|
+
|
|
193
|
+
for i in range(15, 18):
|
|
194
|
+
side_bar[i, 0].layout.display = "none"
|
|
195
|
+
return side_bar
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def get_file_widget_ui():
|
|
200
|
+
side_bar = ipywidgets.GridspecLayout(7, 3, height='500px', width='auto', grid_gap="0px")
|
|
201
|
+
row = 0
|
|
202
|
+
side_bar[row, :3] = ipywidgets.Dropdown(options=['None'], value='None', description='directory:', disabled=False,
|
|
203
|
+
button_style='', layout=ipywidgets.Layout(width='auto', grid_area='header'))
|
|
204
|
+
row += 1
|
|
205
|
+
side_bar[row, :3] = ipywidgets.Select(options=['.'], value='.', description='Select file:', disabled=False,
|
|
206
|
+
rows=10, layout=ipywidgets.Layout(width='auto'))
|
|
207
|
+
row += 1
|
|
208
|
+
side_bar[row, 0] = ipywidgets.Button(description='Select Main',
|
|
209
|
+
layout=ipywidgets.Layout(width='100px'),
|
|
210
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
211
|
+
side_bar[row, 1] = ipywidgets.Button(description='Add',
|
|
212
|
+
layout=ipywidgets.Layout(width='50px'),
|
|
213
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
214
|
+
side_bar[row, 2] = ipywidgets.Dropdown(options=['None'], value='None', description='loaded:', disabled=False,
|
|
215
|
+
button_style='')
|
|
216
|
+
|
|
217
|
+
row += 1
|
|
218
|
+
side_bar[row, :3] = ipywidgets.Select(options=['None'], value='None', description='Spectral:',
|
|
219
|
+
disabled=False, rows=3, layout=ipywidgets.Layout(width='auto'))
|
|
220
|
+
row += 1
|
|
221
|
+
side_bar[row, :3] = ipywidgets.Select(options=['Sum'], value='Sum', description='Images:',
|
|
222
|
+
disabled=False, rows=3, layout=ipywidgets.Layout(width='auto'))
|
|
223
|
+
row += 1
|
|
224
|
+
side_bar[row, :3] = ipywidgets.Select(options=['None'], value='None', description='Survey:',
|
|
225
|
+
disabled=False, rows=2, layout=ipywidgets.Layout(width='auto'))
|
|
226
|
+
for i in range(3, 6):
|
|
227
|
+
side_bar[i, 0].layout.display = "none"
|
|
228
|
+
|
|
229
|
+
row += 1
|
|
230
|
+
side_bar[row, 0] = ipywidgets.Button(description='Save',
|
|
231
|
+
layout=ipywidgets.Layout(width='100px'),
|
|
232
|
+
style=ipywidgets.ButtonStyle(button_color='lightblue'))
|
|
233
|
+
|
|
234
|
+
return side_bar
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class EELSBaseWidget(object):
|
|
238
|
+
|
|
239
|
+
def __init__(self, datasets, sidebar, tab_title=None):
|
|
240
|
+
|
|
241
|
+
self.datasets = datasets
|
|
242
|
+
self.dataset = None
|
|
243
|
+
self.save_path = False
|
|
244
|
+
self.dir_dictionary = {}
|
|
245
|
+
self.dir_list = ['.', '..']
|
|
246
|
+
self.display_list = ['.', '..']
|
|
247
|
+
self.dataset_list = ['None']
|
|
248
|
+
self.image_list = ['Sum']
|
|
249
|
+
self.dir_name = file_tools.get_last_path()
|
|
250
|
+
|
|
251
|
+
self.save_path = True
|
|
252
|
+
|
|
253
|
+
if not os.path.isdir(self.dir_name):
|
|
254
|
+
self.dir_name = '.'
|
|
255
|
+
|
|
256
|
+
self.get_directory(self.dir_name)
|
|
257
|
+
self.dir_list = ['.']
|
|
258
|
+
self.extensions = '*'
|
|
259
|
+
self.file_name = ''
|
|
260
|
+
self.datasets = {}
|
|
261
|
+
self.dataset = None
|
|
262
|
+
self.sd0 = 0
|
|
263
|
+
self.sds = 0
|
|
264
|
+
|
|
265
|
+
self.bin_x = 0
|
|
266
|
+
self.bin_y = 0
|
|
267
|
+
|
|
268
|
+
self.start_channel = -1
|
|
269
|
+
self.end_channel = -2
|
|
270
|
+
|
|
271
|
+
self.file_bar = get_file_widget_ui()
|
|
272
|
+
if isinstance(sidebar, dict):
|
|
273
|
+
tab = ipywidgets.Tab()
|
|
274
|
+
children = [self.file_bar]
|
|
275
|
+
titles = ['File']
|
|
276
|
+
for sidebar_key, sidebar_gui in sidebar.items():
|
|
277
|
+
children.append(sidebar_gui)
|
|
278
|
+
titles.append(sidebar_key)
|
|
279
|
+
tab.children = children
|
|
280
|
+
tab.titles = titles
|
|
281
|
+
elif not isinstance(sidebar, list):
|
|
282
|
+
tab = ipywidgets.Tab()
|
|
283
|
+
tab.children = [self.file_bar, sidebar]
|
|
284
|
+
tab.titles = ['File', 'Info']
|
|
285
|
+
else:
|
|
286
|
+
tab = sidebar
|
|
287
|
+
self.tab = tab
|
|
288
|
+
with plt.ioff():
|
|
289
|
+
self.figure = plt.figure()
|
|
290
|
+
|
|
291
|
+
self.figure.canvas.toolbar_position = 'right'
|
|
292
|
+
self.figure.canvas.toolbar_visible = True
|
|
293
|
+
|
|
294
|
+
self.start_cursor = ipywidgets.FloatText(value=0, description='Start:', disabled=False, color='black',
|
|
295
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
296
|
+
self.end_cursor = ipywidgets.FloatText(value=0, description='End:', disabled=False, color='black',
|
|
297
|
+
layout=ipywidgets.Layout(width='200px'))
|
|
298
|
+
self.panel = ipywidgets.VBox([ipywidgets.HBox([ipywidgets.Label('', layout=ipywidgets.Layout(width='100px')),
|
|
299
|
+
ipywidgets.Label('Cursor:'),
|
|
300
|
+
self.start_cursor, ipywidgets.Label('eV'),
|
|
301
|
+
self.end_cursor, ipywidgets.Label('eV')]),
|
|
302
|
+
self.figure.canvas])
|
|
303
|
+
|
|
304
|
+
self.app_layout = ipywidgets.AppLayout(
|
|
305
|
+
left_sidebar=tab,
|
|
306
|
+
center=self.panel,
|
|
307
|
+
footer=None, # message_bar,
|
|
308
|
+
pane_heights=[0, 10, 0],
|
|
309
|
+
pane_widths=[4, 10, 0],
|
|
310
|
+
)
|
|
311
|
+
# self.set_dataset()
|
|
312
|
+
self.change_y_scale = 1.0
|
|
313
|
+
self.x = 0
|
|
314
|
+
self.y = 0
|
|
315
|
+
self.bin_x = 1
|
|
316
|
+
self.bin_y = 1
|
|
317
|
+
self.count = 0
|
|
318
|
+
display(self.app_layout)
|
|
319
|
+
|
|
320
|
+
self.select_files = self.file_bar[1, 0]
|
|
321
|
+
self.path_choice = self.file_bar[0, 0]
|
|
322
|
+
self.set_file_options()
|
|
323
|
+
select_button = self.file_bar[2, 0]
|
|
324
|
+
add_button = self.file_bar[2, 1]
|
|
325
|
+
self.loaded_datasets = self.file_bar[2, 2]
|
|
326
|
+
self.select_files.observe(self.get_file_name, names='value')
|
|
327
|
+
self.path_choice.observe(self.set_dir, names='value')
|
|
328
|
+
|
|
329
|
+
select_button.on_click(self.select_main)
|
|
330
|
+
add_button.on_click(self.add_dataset)
|
|
331
|
+
self.loaded_datasets.observe(self.select_dataset, names='value')
|
|
332
|
+
self.file_bar[4, 0].observe(self.plot, names='value')
|
|
333
|
+
|
|
334
|
+
def set_image(self, key=None):
|
|
335
|
+
if self.file_bar[4, 0].value == 'Sum':
|
|
336
|
+
spec_dim = self.dataset.get_dimensions_by_type(sidpy.DimensionType.SPECTRAL)
|
|
337
|
+
if len(spec_dim) != 1:
|
|
338
|
+
raise ValueError('Only one spectral dimension')
|
|
339
|
+
|
|
340
|
+
channel_dim = self.dataset.get_dimensions_by_type(sidpy.DimensionType.CHANNEL)
|
|
341
|
+
|
|
342
|
+
if len(channel_dim) > 1:
|
|
343
|
+
raise ValueError('Maximal one channel dimension')
|
|
344
|
+
|
|
345
|
+
if len(channel_dim) > 0:
|
|
346
|
+
self.image = self.dataset.mean(axis=(spec_dim[0], channel_dim[0]))
|
|
347
|
+
else:
|
|
348
|
+
self.image = self.dataset.mean(axis=(spec_dim[0]))
|
|
349
|
+
else:
|
|
350
|
+
image_key = self.file_bar[4, 0].value.split(':')[0]
|
|
351
|
+
self.image = self.datasets[image_key]
|
|
352
|
+
|
|
353
|
+
def plot(self, scale=True):
|
|
354
|
+
self.figure.clear()
|
|
355
|
+
spec_dims = self.dataset.get_spectral_dims(return_axis=True)
|
|
356
|
+
if len(spec_dims)>0:
|
|
357
|
+
self.energy_scale = spec_dims[0]
|
|
358
|
+
if self.dataset.data_type.name == 'SPECTRUM':
|
|
359
|
+
self.axis = self.figure.subplots(ncols=1)
|
|
360
|
+
else:
|
|
361
|
+
self.plot_spectrum_image()
|
|
362
|
+
self.axis = self.axes[-1]
|
|
363
|
+
self.spectrum = self.get_spectrum()
|
|
364
|
+
self.plot_spectrum()
|
|
365
|
+
|
|
366
|
+
else:
|
|
367
|
+
self.axis = self.figure.subplots(ncols=1)
|
|
368
|
+
self.plot_image()
|
|
369
|
+
|
|
370
|
+
def plot_image(self):
|
|
371
|
+
# image_dims = self.dataset.get_image_dims()
|
|
372
|
+
image_dims = []
|
|
373
|
+
for dim, axis in self.dataset._axes.items():
|
|
374
|
+
if axis.dimension_type in [sidpy.DimensionType.SPATIAL, sidpy.DimensionType.RECIPROCAL]:
|
|
375
|
+
image_dims.append(dim)
|
|
376
|
+
self.img = self.axis.imshow(self.dataset, extent=self.dataset.get_extent(image_dims))
|
|
377
|
+
self.axis.set_xlabel(self.dataset.labels[image_dims[0]])
|
|
378
|
+
self.axis.set_ylabel(self.dataset.labels[image_dims[1]])
|
|
379
|
+
|
|
380
|
+
cbar = self.figure.colorbar(self.img)
|
|
381
|
+
cbar.set_label(self.dataset.data_descriptor)
|
|
382
|
+
|
|
383
|
+
self.axis.ticklabel_format(style='sci', scilimits=(-2, 3))
|
|
384
|
+
self.figure.tight_layout()
|
|
385
|
+
self.figure.canvas.draw_idle()
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def plot_spectrum(self):
|
|
389
|
+
self.axis.plot(self.energy_scale, self.spectrum, label='spectrum')
|
|
390
|
+
x_limit = self.axis.get_xlim()
|
|
391
|
+
y_limit = np.array(self.axis.get_ylim())
|
|
392
|
+
self.xlabel = self.datasets[self.key].labels[0]
|
|
393
|
+
self.ylabel = self.datasets[self.key].data_descriptor
|
|
394
|
+
self.axis.set_xlabel(self.datasets[self.key].labels[0])
|
|
395
|
+
self.axis.set_ylabel(self.datasets[self.key].data_descriptor)
|
|
396
|
+
self.axis.ticklabel_format(style='sci', scilimits=(-2, 4))
|
|
397
|
+
|
|
398
|
+
# if scale:
|
|
399
|
+
# self.axis.set_ylim(np.array(y_limit)*self.change_y_scale)
|
|
400
|
+
self.change_y_scale = 1.0
|
|
401
|
+
if self.y_scale != 1.:
|
|
402
|
+
self.axis.set_ylabel('scattering probability (ppm/eV)')
|
|
403
|
+
self.selector = matplotlib.widgets.SpanSelector(self.axis, self.line_select_callback,
|
|
404
|
+
direction="horizontal",
|
|
405
|
+
interactive=True,
|
|
406
|
+
props=dict(facecolor='blue', alpha=0.2))
|
|
407
|
+
self.axis.legend()
|
|
408
|
+
if self.dataset.data_type.name == 'SPECTRUM':
|
|
409
|
+
self.axis.set_title(self.dataset.title)
|
|
410
|
+
else:
|
|
411
|
+
self.axis.set_title(f'spectrum {self.x}, {self.y}')
|
|
412
|
+
self.figure.canvas.draw_idle()
|
|
413
|
+
|
|
414
|
+
def _update(self, ev=None):
|
|
415
|
+
if hasattr(self, 'axes'):
|
|
416
|
+
xlim = np.array(self.axes[1].get_xlim())
|
|
417
|
+
ylim = np.array(self.axes[1].get_ylim())
|
|
418
|
+
self.axes[1].clear()
|
|
419
|
+
self.axis = self.axes[-1]
|
|
420
|
+
else:
|
|
421
|
+
xlim = np.array(self.axis.get_xlim())
|
|
422
|
+
ylim = np.array(self.axis.get_ylim())
|
|
423
|
+
self.axis.clear()
|
|
424
|
+
self.get_spectrum()
|
|
425
|
+
if len(self.energy_scale) != self.spectrum.shape[0]:
|
|
426
|
+
self.spectrum = self.spectrum.T
|
|
427
|
+
self.axis.plot(self.energy_scale, self.spectrum.compute(), label='experiment')
|
|
428
|
+
|
|
429
|
+
self.axis.set_title(f'spectrum {self.x}, {self.y}')
|
|
430
|
+
self.figure.tight_layout()
|
|
431
|
+
self.selector = matplotlib.widgets.SpanSelector(self.axis, self.line_select_callback,
|
|
432
|
+
direction="horizontal",
|
|
433
|
+
interactive=True,
|
|
434
|
+
props=dict(facecolor='blue', alpha=0.2))
|
|
435
|
+
|
|
436
|
+
self.axis.set_xlim(xlim)
|
|
437
|
+
self.axis.set_ylim(ylim*self.change_y_scale)
|
|
438
|
+
self.axis.set_xlabel(self.xlabel)
|
|
439
|
+
self.axis.set_ylabel(self.ylabel)
|
|
440
|
+
self.change_y_scale = 1.0
|
|
441
|
+
self.figure.canvas.draw_idle()
|
|
442
|
+
|
|
443
|
+
def _onclick(self, event):
|
|
444
|
+
self.event = event
|
|
445
|
+
if event.inaxes in [self.axes[0]]:
|
|
446
|
+
x = int(event.xdata)
|
|
447
|
+
y = int(event.ydata)
|
|
448
|
+
|
|
449
|
+
x = int(x - self.rectangle[0])
|
|
450
|
+
y = int(y - self.rectangle[2])
|
|
451
|
+
|
|
452
|
+
if x >= 0 and y >= 0:
|
|
453
|
+
if x <= self.rectangle[1] and y <= self.rectangle[3]:
|
|
454
|
+
self.x = int(x / (self.rect.get_width() / self.bin_x))
|
|
455
|
+
self.y = int(y / (self.rect.get_height() / self.bin_y))
|
|
456
|
+
image_dims = self.dataset.get_image_dims()
|
|
457
|
+
|
|
458
|
+
if self.x + self.bin_x > self.dataset.shape[image_dims[0]]:
|
|
459
|
+
self.x = self.dataset.shape[image_dims[0]] - self.bin_x
|
|
460
|
+
if self.y + self.bin_y > self.dataset.shape[image_dims[1]]:
|
|
461
|
+
self.y = self.dataset.shape[image_dims[1]] - self.bin_y
|
|
462
|
+
|
|
463
|
+
self.rect.set_xy([self.x * self.rect.get_width() / self.bin_x + self.rectangle[0],
|
|
464
|
+
self.y * self.rect.get_height() / self.bin_y + self.rectangle[2]])
|
|
465
|
+
# self.get_spectrum()
|
|
466
|
+
self._update()
|
|
467
|
+
else:
|
|
468
|
+
if event.dblclick:
|
|
469
|
+
bottom = float(self.spectrum.min())
|
|
470
|
+
if bottom < 0:
|
|
471
|
+
bottom *= 1.02
|
|
472
|
+
else:
|
|
473
|
+
bottom *= 0.98
|
|
474
|
+
top = float(self.spectrum.max())
|
|
475
|
+
if top > 0:
|
|
476
|
+
top *= 1.02
|
|
477
|
+
else:
|
|
478
|
+
top *= 0.98
|
|
479
|
+
self.axis.set_ylim(bottom=bottom, top=top)
|
|
480
|
+
|
|
481
|
+
def get_spectrum(self):
|
|
482
|
+
if self.dataset.data_type.name == 'SPECTRUM':
|
|
483
|
+
self.spectrum = self.dataset.copy()
|
|
484
|
+
else:
|
|
485
|
+
image_dims = self.dataset.get_dimensions_by_type(sidpy.DimensionType.SPATIAL)
|
|
486
|
+
if self.x > self.dataset.shape[image_dims[0]] - self.bin_x:
|
|
487
|
+
self.x = self.dataset.shape[image_dims[0]] - self.bin_x
|
|
488
|
+
if self.y > self.dataset.shape[image_dims[1]] - self.bin_y:
|
|
489
|
+
self.y = self.dataset.shape[image_dims[1]] - self.bin_y
|
|
490
|
+
selection = []
|
|
491
|
+
self.axis.clear()
|
|
492
|
+
for dim, axis in self.dataset._axes.items():
|
|
493
|
+
if axis.dimension_type == sidpy.DimensionType.SPATIAL:
|
|
494
|
+
if dim == image_dims[0]:
|
|
495
|
+
selection.append(slice(self.x, self.x + self.bin_x))
|
|
496
|
+
else:
|
|
497
|
+
selection.append(slice(self.y, self.y + self.bin_y))
|
|
498
|
+
|
|
499
|
+
elif axis.dimension_type == sidpy.DimensionType.SPECTRAL:
|
|
500
|
+
selection.append(slice(None))
|
|
501
|
+
elif axis.dimension_type == sidpy.DimensionType.CHANNEL:
|
|
502
|
+
selection.append(slice(None))
|
|
503
|
+
else:
|
|
504
|
+
selection.append(slice(0, 1))
|
|
505
|
+
|
|
506
|
+
self.spectrum = self.dataset[tuple(selection)].mean(axis=tuple(image_dims))
|
|
507
|
+
|
|
508
|
+
self.spectrum *= self.y_scale
|
|
509
|
+
|
|
510
|
+
return self.spectrum.squeeze()
|
|
511
|
+
|
|
512
|
+
def plot_spectrum_image(self):
|
|
513
|
+
self.axes = self.figure.subplots(ncols=2)
|
|
514
|
+
self.axis = self.axes[-1]
|
|
515
|
+
|
|
516
|
+
self.set_image()
|
|
517
|
+
self.rect = matplotlib.patches.Rectangle((0, 0), self.bin_x, self.bin_y, linewidth=1, edgecolor='r',
|
|
518
|
+
facecolor='red', alpha=0.2)
|
|
519
|
+
image_dims = self.dataset.get_image_dims()
|
|
520
|
+
|
|
521
|
+
size_x = self.dataset.shape[image_dims[0]]
|
|
522
|
+
size_y = self.dataset.shape[image_dims[1]]
|
|
523
|
+
self.extent = [0, size_x, size_y, 0]
|
|
524
|
+
self.rectangle = [0, size_x, 0, size_y]
|
|
525
|
+
self.axes[0].imshow(self.image.T, extent=self.extent)
|
|
526
|
+
self.axes[0].set_aspect('equal')
|
|
527
|
+
self.axes[0].add_patch(self.rect)
|
|
528
|
+
self.cid = self.axes[0].figure.canvas.mpl_connect('button_press_event', self._onclick)
|
|
529
|
+
|
|
530
|
+
def line_select_callback(self, x_min, x_max):
|
|
531
|
+
self.start_cursor.value = np.round(x_min, 3)
|
|
532
|
+
self.end_cursor.value = np.round(x_max, 3)
|
|
533
|
+
|
|
534
|
+
energy_scale = self.dataset.get_spectral_dims(return_axis=True)[0]
|
|
535
|
+
self.start_channel = np.searchsorted(energy_scale, self.start_cursor.value)
|
|
536
|
+
self.end_channel = np.searchsorted(energy_scale, self.end_cursor.value)
|
|
537
|
+
|
|
538
|
+
def set_dataset(self, key=None):
|
|
539
|
+
|
|
540
|
+
if len(self.datasets) == 0:
|
|
541
|
+
data_set = sidpy.Dataset.from_array([0, 1], name='generic')
|
|
542
|
+
data_set.set_dimension(0, sidpy.Dimension([0, 1], 'energy_loss', units='channel', quantity='generic',
|
|
543
|
+
dimension_type='spectral'))
|
|
544
|
+
data_set.data_type = 'spectrum'
|
|
545
|
+
data_set.metadata = {'experiment': {'convergence_angle': 0,
|
|
546
|
+
'collection_angle': 0,
|
|
547
|
+
'acceleration_voltage': 0,
|
|
548
|
+
'exposure_time': 0}}
|
|
549
|
+
self.datasets = {'Nothing': data_set}
|
|
550
|
+
key = 'Nothing'
|
|
551
|
+
|
|
552
|
+
dataset_key = key
|
|
553
|
+
|
|
554
|
+
self.dataset_list = []
|
|
555
|
+
dataset_keys = []
|
|
556
|
+
for key in self.datasets.keys():
|
|
557
|
+
if isinstance(self.datasets[key], sidpy.Dataset):
|
|
558
|
+
self.dataset_list.append(f'{key}: {self.datasets[key].title}')
|
|
559
|
+
dataset_keys.append(key)
|
|
560
|
+
if dataset_key not in dataset_keys:
|
|
561
|
+
dataset_key = dataset_keys[0]
|
|
562
|
+
self.key = dataset_key
|
|
563
|
+
|
|
564
|
+
self.dataset = self.datasets[self.key]
|
|
565
|
+
|
|
566
|
+
spectral_dims = self.dataset.get_spectral_dims(return_axis=True)
|
|
567
|
+
if len(spectral_dims) >0:
|
|
568
|
+
self.energy_scale = spectral_dims[0]
|
|
569
|
+
self.y_scale = 1.0
|
|
570
|
+
self.change_y_scale = 1.0
|
|
571
|
+
self.x = 0
|
|
572
|
+
self.y = 0
|
|
573
|
+
self.bin_x = 1
|
|
574
|
+
self.bin_y = 1
|
|
575
|
+
self.count = 0
|
|
576
|
+
|
|
577
|
+
self.update_sidebars()
|
|
578
|
+
#self.update_sidebar()
|
|
579
|
+
self.plot()
|
|
580
|
+
|
|
581
|
+
def update_sidebars(self):
|
|
582
|
+
pass
|
|
583
|
+
|
|
584
|
+
def select_main(self, value=0):
|
|
585
|
+
self.sds +=1
|
|
586
|
+
self.datasets = {}
|
|
587
|
+
# self.loaded_datasets.options = self.dataset_list
|
|
588
|
+
|
|
589
|
+
self.datasets = file_tools.open_file(self.file_name)
|
|
590
|
+
file_tools.save_path(self.file_name)
|
|
591
|
+
self.dataset_list = []
|
|
592
|
+
self.image_list = ['Sum']
|
|
593
|
+
self.survey_list = ['None']
|
|
594
|
+
self.spectral_list = ['None']
|
|
595
|
+
for key in self.datasets.keys():
|
|
596
|
+
if isinstance(self.datasets[key], sidpy.Dataset):
|
|
597
|
+
self.dataset_list.append(f'{key}: {self.datasets[key].title}')
|
|
598
|
+
if 'SPECTR' in self.datasets[key].data_type.name:
|
|
599
|
+
self.spectral_list.append(f'{key}: {self.datasets[key].title}')
|
|
600
|
+
if 'IMAGE' == self.datasets[key].data_type.name:
|
|
601
|
+
if 'survey' in self.datasets[key].title.lower():
|
|
602
|
+
self.survey_list.append(f'{key}: {self.datasets[key].title}')
|
|
603
|
+
else:
|
|
604
|
+
self.image_list.append(f'{key}: {self.datasets[key].title}')
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
self.key = self.dataset_list[0].split(':')[0]
|
|
608
|
+
self.dataset = self.datasets[self.key]
|
|
609
|
+
|
|
610
|
+
self.selected_dataset = self.dataset
|
|
611
|
+
if len(self.image_list) > 0:
|
|
612
|
+
self.file_bar[4, 0].options = self.image_list
|
|
613
|
+
self.file_bar[5, 0].options = self.survey_list
|
|
614
|
+
self.file_bar[4, 0].layout.display = "flex"
|
|
615
|
+
self.file_bar[4, 0].value = self.image_list[0]
|
|
616
|
+
self.file_bar[5, 0].layout.display = "flex"
|
|
617
|
+
self.file_bar[5, 0].value = self.survey_list[0]
|
|
618
|
+
|
|
619
|
+
self.file_bar[3, 0].options = self.dataset_list
|
|
620
|
+
self.loaded_datasets.options = self.dataset_list
|
|
621
|
+
self.loaded_datasets.value = self.dataset_list[0]
|
|
622
|
+
|
|
623
|
+
def add_dataset(self, value=0):
|
|
624
|
+
key = file_tools.add_dataset_from_file(self.datasets, self.file_name, 'Channel')
|
|
625
|
+
self.dataset_list.append(f'{key}: {self.datasets[key].title}')
|
|
626
|
+
self.loaded_datasets.options = self.dataset_list
|
|
627
|
+
self.loaded_datasets.value = self.dataset_list[-1]
|
|
628
|
+
|
|
629
|
+
def get_directory(self, directory='.'):
|
|
630
|
+
self.dir_name = directory
|
|
631
|
+
self.dir_dictionary = {}
|
|
632
|
+
self.dir_list = []
|
|
633
|
+
self.dir_list = ['.', '..'] + os.listdir(directory)
|
|
634
|
+
|
|
635
|
+
def set_dir(self, value=0):
|
|
636
|
+
self.dir_name = self.path_choice.value
|
|
637
|
+
self.select_files.index = 0
|
|
638
|
+
self.set_file_options()
|
|
639
|
+
|
|
640
|
+
def select_dataset(self, value=0):
|
|
641
|
+
key = self.loaded_datasets.value.split(':')[0]
|
|
642
|
+
if key != 'None':
|
|
643
|
+
self.selected_dataset = self.datasets[key]
|
|
644
|
+
self.selected_key = key
|
|
645
|
+
self.key = key
|
|
646
|
+
self.datasets['_relationship'] = {'main_dataset': self.key}
|
|
647
|
+
|
|
648
|
+
self.set_dataset()
|
|
649
|
+
|
|
650
|
+
def set_file_options(self):
|
|
651
|
+
self.dir_name = os.path.abspath(os.path.join(self.dir_name, self.dir_list[self.select_files.index]))
|
|
652
|
+
dir_list = os.listdir(self.dir_name)
|
|
653
|
+
file_dict = file_tools.update_directory_list(self.dir_name)
|
|
654
|
+
|
|
655
|
+
sort = np.argsort(file_dict['directory_list'])
|
|
656
|
+
self.dir_list = ['.', '..']
|
|
657
|
+
self.display_list = ['.', '..']
|
|
658
|
+
for j in sort:
|
|
659
|
+
self.display_list.append(f" * {file_dict['directory_list'][j]}")
|
|
660
|
+
self.dir_list.append(file_dict['directory_list'][j])
|
|
661
|
+
|
|
662
|
+
sort = np.argsort(file_dict['display_file_list'])
|
|
663
|
+
|
|
664
|
+
for i, j in enumerate(sort):
|
|
665
|
+
if '--' in dir_list[j]:
|
|
666
|
+
self.display_list.append(f" {i:3} {file_dict['display_file_list'][j]}")
|
|
667
|
+
else:
|
|
668
|
+
self.display_list.append(f" {i:3} {file_dict['display_file_list'][j]}")
|
|
669
|
+
self.dir_list.append(file_dict['file_list'][j])
|
|
670
|
+
|
|
671
|
+
self.dir_label = os.path.split(self.dir_name)[-1] + ':'
|
|
672
|
+
self.select_files.options = self.display_list
|
|
673
|
+
|
|
674
|
+
path = self.dir_name
|
|
675
|
+
old_path = ' '
|
|
676
|
+
path_list = []
|
|
677
|
+
while path != old_path:
|
|
678
|
+
path_list.append(path)
|
|
679
|
+
old_path = path
|
|
680
|
+
path = os.path.split(path)[0]
|
|
681
|
+
self.path_choice.options = path_list
|
|
682
|
+
self.path_choice.value = path_list[0]
|
|
683
|
+
|
|
684
|
+
def get_file_name(self, b):
|
|
685
|
+
|
|
686
|
+
if os.path.isdir(os.path.join(self.dir_name, self.dir_list[self.select_files.index])):
|
|
687
|
+
self.set_file_options()
|
|
688
|
+
|
|
689
|
+
elif os.path.isfile(os.path.join(self.dir_name, self.dir_list[self.select_files.index])):
|
|
690
|
+
self.file_name = os.path.join(self.dir_name, self.dir_list[self.select_files.index])
|
|
691
|
+
|
|
692
|
+
class EELSWidget(EELSBaseWidget):
|
|
693
|
+
def __init__(self, datasets=None):
|
|
694
|
+
|
|
695
|
+
sidebar = {'Spec.': get_info_sidebar(),
|
|
696
|
+
'LowLoss': get_low_loss_sidebar(),
|
|
697
|
+
'CoreLoss': get_core_loss_sidebar()}
|
|
698
|
+
super().__init__(datasets, sidebar)
|
|
699
|
+
self.info_tab = sidebar['Spec.']
|
|
700
|
+
self.core_loss_tab = sidebar['CoreLoss']
|
|
701
|
+
self.low_loss_tab = sidebar['LowLoss']
|
|
702
|
+
super().set_dataset()
|
|
703
|
+
self.info = Info(self.info_tab, self)
|
|
704
|
+
self.low_loss = LowLoss(self.low_loss_tab, self)
|
|
705
|
+
self.core_loss = CoreLoss(self.core_loss_tab, self)
|
|
706
|
+
|
|
707
|
+
self.set_action()
|
|
708
|
+
|
|
709
|
+
def set_action(self):
|
|
710
|
+
self.tab.observe(self.tab_activated)
|
|
711
|
+
|
|
712
|
+
def tab_activated(self, val=0):
|
|
713
|
+
if isinstance(val.new, int):
|
|
714
|
+
self.tabval = val.new
|
|
715
|
+
self.update_sidebars()
|
|
716
|
+
if val.new == 1:
|
|
717
|
+
self.info.update_dataset()
|
|
718
|
+
elif val.new == 2:
|
|
719
|
+
self.low_loss.update_ll_dataset()
|
|
720
|
+
elif val.new == 3:
|
|
721
|
+
self.core_loss.update_cl_sidebar()
|
|
722
|
+
|
|
723
|
+
def update_sidebars(self):
|
|
724
|
+
if hasattr(self, 'info'):
|
|
725
|
+
self.info.update_sidebar()
|
|
726
|
+
#if hasattr(self, 'low_loss'):
|
|
727
|
+
# self.low_loss.update_ll_sidebar()
|
|
728
|
+
#if hasattr(self, 'core_loss'):
|
|
729
|
+
# self.core_loss.update_cl_sidebar()
|
|
730
|
+
|
|
731
|
+
class Info(object):
|
|
732
|
+
def __init__(self, sidebar=None, parent=None):
|
|
733
|
+
self.parent = parent
|
|
734
|
+
self.info_tab = sidebar
|
|
735
|
+
self.key = self.parent.key
|
|
736
|
+
self.update_sidebar()
|
|
737
|
+
self.set_action()
|
|
738
|
+
self.count =0
|
|
739
|
+
|
|
740
|
+
def set_energy_scale(self, value):
|
|
741
|
+
self.ens = 1
|
|
742
|
+
self.energy_scale = self.parent.datasets[self.key].get_spectral_dims(return_axis=True)[0]
|
|
743
|
+
dispersion = self.parent.datasets[self.key].get_dimension_slope(self.energy_scale)
|
|
744
|
+
self.ens = dispersion
|
|
745
|
+
self.energy_scale *= (self.info_tab[3, 0].value / dispersion)
|
|
746
|
+
self.energy_scale += (self.info_tab[2, 0].value - self.energy_scale[0])
|
|
747
|
+
self.parent.plot()
|
|
748
|
+
|
|
749
|
+
def set_y_scale(self, value):
|
|
750
|
+
self.count += 1
|
|
751
|
+
self.parent.change_y_scale = 1.0 / self.parent.y_scale
|
|
752
|
+
if self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] > 1e-12:
|
|
753
|
+
if self.info_tab[9, 2].value:
|
|
754
|
+
dispersion = self.parent.datasets[self.key].get_dimension_slope(self.energy_scale)
|
|
755
|
+
self.parent.y_scale = 1 / self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] * dispersion
|
|
756
|
+
self.parent.ylabel = 'scattering probability (ppm)'
|
|
757
|
+
else:
|
|
758
|
+
self.parent.y_scale = 1.0
|
|
759
|
+
self.parent.ylabel = 'intensity (counts)'
|
|
760
|
+
self.parent.change_y_scale *= self.parent.y_scale
|
|
761
|
+
self.parent._update()
|
|
762
|
+
|
|
763
|
+
def set_flux(self, value):
|
|
764
|
+
# self.parent.datasets[self.key].metadata['experiment']['exposure_time'] = self.info_tab[10, 0].value
|
|
765
|
+
if self.info_tab[9, 0].value == 'None':
|
|
766
|
+
self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] = 0.
|
|
767
|
+
else:
|
|
768
|
+
ll_key = self.info_tab[9, 0].value.split(':')[0]
|
|
769
|
+
self.parent.datasets['_relationship']['low_loss'] = ll_key
|
|
770
|
+
spectrum_dimensions = self.parent.dataset.get_spectral_dims()
|
|
771
|
+
|
|
772
|
+
number_of_pixels = 1
|
|
773
|
+
for index, dimension in enumerate(self.parent.dataset.shape):
|
|
774
|
+
if index not in spectrum_dimensions:
|
|
775
|
+
number_of_pixels *= dimension
|
|
776
|
+
if self.parent.datasets[ll_key].metadata['experiment']['exposure_time'] == 0.0:
|
|
777
|
+
if self.parent.datasets[ll_key].metadata['experiment']['single_exposure_time'] == 0.0:
|
|
778
|
+
return
|
|
779
|
+
else:
|
|
780
|
+
self.parent.datasets[ll_key].metadata['experiment']['exposure_time'] = (self.parent.datasets[ll_key].metadata['experiment']['single_exposure_time'] *
|
|
781
|
+
self.parent.datasets[ll_key].metadata['experiment']['number_of_frames'])
|
|
782
|
+
|
|
783
|
+
self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] = ((np.array(self.parent.datasets[ll_key])*1e-6).sum() /
|
|
784
|
+
self.parent.datasets[ll_key].metadata['experiment']['exposure_time'] /
|
|
785
|
+
number_of_pixels)
|
|
786
|
+
self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] *= self.parent.datasets[self.key].metadata['experiment']['exposure_time']
|
|
787
|
+
if 'SPECT' in self.parent.datasets[ll_key].data_type.name:
|
|
788
|
+
self.info_tab[14, 0].disabled = False
|
|
789
|
+
self.info_tab[11, 0].value = np.round(self.parent.datasets[self.key].metadata['experiment']['flux_ppm'], 2)
|
|
790
|
+
|
|
791
|
+
def set_microscope_parameter(self, value):
|
|
792
|
+
self.parent.datasets[self.key].metadata['experiment']['convergence_angle'] = self.info_tab[5, 0].value
|
|
793
|
+
self.parent.datasets[self.key].metadata['experiment']['collection_angle'] = self.info_tab[6, 0].value
|
|
794
|
+
self.parent.datasets[self.key].metadata['experiment']['acceleration_voltage'] = self.info_tab[7, 0].value*1000
|
|
795
|
+
|
|
796
|
+
def cursor2energy_scale(self, value):
|
|
797
|
+
self.energy_scale = self.parent.datasets[self.key].get_spectral_dims(return_axis=True)[0]
|
|
798
|
+
dispersion = (self.parent.end_cursor.value - self.parent.start_cursor.value) / (self.parent.end_channel - self.parent.start_channel)
|
|
799
|
+
|
|
800
|
+
self.energy_scale *= (self.info_tab[3, 0].value/dispersion)
|
|
801
|
+
|
|
802
|
+
offset = self.parent.start_cursor.value - self.parent.start_channel * dispersion
|
|
803
|
+
self.parent.energy_scale += (self.info_tab[2, 0].value-self.parent.energy_scale[0])
|
|
804
|
+
self.info_tab[2, 0].value = np.round(offset,4)
|
|
805
|
+
self.info_tab[3, 0].value = np.round(dispersion,4)
|
|
806
|
+
self.parent.plot()
|
|
807
|
+
|
|
808
|
+
def set_binning(self, value):
|
|
809
|
+
if 'SPECTRAL' in self.parent.dataset.data_type.name:
|
|
810
|
+
image_dims = self.parent.dataset.get_image_dims()
|
|
811
|
+
|
|
812
|
+
self.bin_x = int(self.info_tab[16, 0].value)
|
|
813
|
+
self.bin_y = int(self.info_tab[17, 0].value)
|
|
814
|
+
if self.bin_x < 1:
|
|
815
|
+
self.bin_x = 1
|
|
816
|
+
self.info_tab[16, 0].value = self.bin_x
|
|
817
|
+
if self.bin_y < 1:
|
|
818
|
+
self.bin_y = 1
|
|
819
|
+
self.info_tab[17, 0].value = self.bin_y
|
|
820
|
+
if self.bin_x > self.parent.dataset.shape[image_dims[0]]:
|
|
821
|
+
self.bin_x = self.parent.dataset.shape[image_dims[0]]
|
|
822
|
+
self.info_tab[16, 0].value = self.bin_x
|
|
823
|
+
if self.bin_y > self.parent.dataset.shape[image_dims[1]]:
|
|
824
|
+
self.bin_y = self.parent.dataset.shape[image_dims[1]]
|
|
825
|
+
self.info_tab[17, 0].value = self.bin_y
|
|
826
|
+
|
|
827
|
+
self.parent.datasets[self.key].metadata['experiment']['SI_bin_x'] = self.bin_x
|
|
828
|
+
self.parent.datasets[self.key].metadata['experiment']['SI_bin_y'] = self.bin_y
|
|
829
|
+
self.plot()
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
def update_sidebar(self):
|
|
834
|
+
spectrum_list = ['None']
|
|
835
|
+
reference_list = ['None']
|
|
836
|
+
data_list = []
|
|
837
|
+
self.key = self.parent.key
|
|
838
|
+
spectrum_data = False
|
|
839
|
+
for key in self.parent.datasets.keys():
|
|
840
|
+
if isinstance(self.parent.datasets[key], sidpy.Dataset):
|
|
841
|
+
if key[0] != '_' :
|
|
842
|
+
data_list.append(f'{key}: {self.parent.datasets[key].title}')
|
|
843
|
+
if 'SPECTR' in self.parent.datasets[key].data_type.name:
|
|
844
|
+
spectrum_data = True
|
|
845
|
+
spectrum_list.append(f'{key}: {self.parent.datasets[key].title}')
|
|
846
|
+
reference_list.append(f'{key}: {self.parent.datasets[key].title}')
|
|
847
|
+
self.info_tab[0, 0].options = spectrum_list
|
|
848
|
+
self.info_tab[9, 0].options = reference_list
|
|
849
|
+
|
|
850
|
+
if 'SPECTRUM' in self.parent.dataset.data_type.name:
|
|
851
|
+
for i in range(15, 18):
|
|
852
|
+
self.info_tab[i, 0].layout.display = "none"
|
|
853
|
+
else:
|
|
854
|
+
for i in range(15, 18):
|
|
855
|
+
self.info_tab[i, 0].layout.display = "flex"
|
|
856
|
+
|
|
857
|
+
if spectrum_data:
|
|
858
|
+
offset = self.parent.datasets[self.key].energy_loss[0]
|
|
859
|
+
dispersion = self.parent.datasets[self.key].energy_loss[1] - offset
|
|
860
|
+
|
|
861
|
+
# self.info_tab[0,0].value = dataset_index #f'{self.key}: {self.parent.datasets[self.key].title}'
|
|
862
|
+
self.info_tab[2, 0].value = np.round(offset, 3)
|
|
863
|
+
self.info_tab[3, 0].value = np.round(dispersion, 4)
|
|
864
|
+
self.info_tab[5, 0].value = np.round(self.parent.datasets[self.key].metadata['experiment']['convergence_angle'], 1)
|
|
865
|
+
self.info_tab[6, 0].value = np.round(self.parent.datasets[self.key].metadata['experiment']['collection_angle'], 1)
|
|
866
|
+
self.info_tab[7, 0].value = np.round(self.parent.datasets[self.key].metadata['experiment']['acceleration_voltage']/1000, 1)
|
|
867
|
+
self.info_tab[10, 0].value = np.round(self.parent.datasets[self.key].metadata['experiment']['exposure_time'], 4)
|
|
868
|
+
if 'flux_ppm' not in self.parent.datasets[self.key].metadata['experiment']:
|
|
869
|
+
self.parent.datasets[self.key].metadata['experiment']['flux_ppm'] = 0
|
|
870
|
+
self.info_tab[11, 0].value = self.parent.datasets[self.key].metadata['experiment']['flux_ppm']
|
|
871
|
+
if 'count_conversion' not in self.parent.datasets[self.key].metadata['experiment']:
|
|
872
|
+
self.parent.datasets[self.key].metadata['experiment']['count_conversion'] = 1
|
|
873
|
+
self.info_tab[12, 0].value = self.parent.datasets[self.key].metadata['experiment']['count_conversion']
|
|
874
|
+
if 'beam_current' not in self.parent.datasets[self.key].metadata['experiment']:
|
|
875
|
+
self.parent.datasets[self.key].metadata['experiment']['beam_current'] = 0
|
|
876
|
+
self.info_tab[13, 0].value = self.parent.datasets[self.key].metadata['experiment']['beam_current']
|
|
877
|
+
ll_key = 'None'
|
|
878
|
+
if '_relationship' in self.parent.datasets:
|
|
879
|
+
if 'low_loss' in self.parent.datasets['_relationship']:
|
|
880
|
+
ll_key = self.parent.datasets['_relationship']['low_loss']
|
|
881
|
+
ll_key = f'{ll_key}: {self.parent.datasets[ll_key].title}'
|
|
882
|
+
self.info_tab[9, 0].value = ll_key
|
|
883
|
+
|
|
884
|
+
def update_dataset(self, value=0):
|
|
885
|
+
key = self.info_tab[0, 0].value.split(':')[0]
|
|
886
|
+
self.parent.set_dataset(key)
|
|
887
|
+
|
|
888
|
+
def shift_low_loss(self, value=0):
|
|
889
|
+
if 'low_loss' in self.parent.datasets['_relationship']:
|
|
890
|
+
low_loss = self.parent.datasets[self.parent.datasets['_relationship']['low_loss']]
|
|
891
|
+
self.parent.datasets[self.parent.datasets['_relationship']['low_loss']] = eels_tools.align_zero_loss(low_loss)
|
|
892
|
+
|
|
893
|
+
if 'low_loss' in self.parent.datasets['_relationship']:
|
|
894
|
+
if 'zero_loss' in self.parent.datasets[self.parent.datasets['_relationship']['low_loss']].metadata:
|
|
895
|
+
if 'shifted' in self.parent.datasets[self.parent.datasets['_relationship']['low_loss']].metadata['zero_loss'].keys():
|
|
896
|
+
self.info_tab[14, 1].disabled = False
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
def shift_spectrum(self, value=0):
|
|
900
|
+
shifts = self.parent.dataset.shape
|
|
901
|
+
if 'low_loss' in self.parent.datasets['_relationship']:
|
|
902
|
+
if 'zero_loss' in self.parent.datasets[self.parent.datasets['_relationship']['low_loss']].metadata:
|
|
903
|
+
if 'shifted' in self.parent.datasets[self.parent.datasets['_relationship']['low_loss']].metadata['zero_loss'].keys():
|
|
904
|
+
shifts = self.parent.datasets[self.parent.datasets['_relationship']['low_loss']].metadata['zero_loss']['shifted']
|
|
905
|
+
shifts_new = shifts.copy()
|
|
906
|
+
if 'zero_loss' in self.parent.dataset.metadata:
|
|
907
|
+
if 'shifted' in self.parent.dataset.metadata['zero_loss'].keys():
|
|
908
|
+
shifts_new = shifts-self.parent.dataset.metadata['zero_loss']['shifted']
|
|
909
|
+
else:
|
|
910
|
+
self.parent.dataset.metadata['zero_loss'] = {}
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
self.parent.dataset = eels_tools.shift_energy(self.parent.dataset, shifts_new)
|
|
914
|
+
self.parent.dataset.metadata['zero_loss']['shifted'] = shifts
|
|
915
|
+
self.parent.plot()
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
def set_action(self):
|
|
919
|
+
self.info_tab[0, 0].observe(self.update_dataset, names='value')
|
|
920
|
+
self.info_tab[1, 0].on_click(self.cursor2energy_scale)
|
|
921
|
+
self.info_tab[2, 0].observe(self.set_energy_scale, names='value')
|
|
922
|
+
self.info_tab[3, 0].observe(self.set_energy_scale, names='value')
|
|
923
|
+
self.info_tab[5, 0].observe(self.set_microscope_parameter)
|
|
924
|
+
self.info_tab[6, 0].observe(self.set_microscope_parameter)
|
|
925
|
+
self.info_tab[7, 0].observe(self.set_microscope_parameter)
|
|
926
|
+
self.info_tab[9, 0].observe(self.set_flux, names='value')
|
|
927
|
+
self.info_tab[9, 2].observe(self.set_y_scale, names='value')
|
|
928
|
+
self.info_tab[10, 0].observe(self.set_flux)
|
|
929
|
+
self.info_tab[14, 0].on_click(self.shift_low_loss)
|
|
930
|
+
self.info_tab[14, 1].on_click(self.shift_spectrum)
|
|
931
|
+
|
|
932
|
+
self.info_tab[16, 0].observe(self.set_binning)
|
|
933
|
+
self.info_tab[17, 0].observe(self.set_binning)
|