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.
- pyTEMlib/__init__.py +11 -11
- pyTEMlib/animation.py +631 -0
- pyTEMlib/atom_tools.py +240 -222
- pyTEMlib/config_dir.py +57 -29
- 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 -486
- pyTEMlib/{interactive_eels.py → eels_dialog_utilities.py} +1199 -1524
- pyTEMlib/eels_tools.py +2031 -1731
- pyTEMlib/file_tools.py +1276 -491
- 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 -0
- pyTEMlib/image_tools.py +1399 -956
- pyTEMlib/info_widget.py +933 -0
- pyTEMlib/interactive_image.py +1 -0
- pyTEMlib/kinematic_scattering.py +1196 -0
- pyTEMlib/low_loss_widget.py +176 -0
- pyTEMlib/microscope.py +61 -78
- pyTEMlib/peak_dialog.py +1047 -350
- pyTEMlib/peak_dlg.py +286 -248
- pyTEMlib/probe_tools.py +653 -202
- pyTEMlib/sidpy_tools.py +153 -129
- pyTEMlib/simulation_tools.py +104 -87
- pyTEMlib/version.py +6 -3
- pyTEMlib/xrpa_x_sections.py +20972 -0
- {pyTEMlib-0.2020.11.0.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.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/WHEEL +6 -5
- {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/entry_points.txt +0 -1
- pyTEMlib/KinsCat.py +0 -2685
- 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 -86
- pyTEMlib/dm3_reader.py +0 -609
- pyTEMlib/edges_db.py +0 -76
- pyTEMlib/eels_dlg.py +0 -240
- pyTEMlib/hdf_utils.py +0 -481
- pyTEMlib/image_tools1.py +0 -2194
- pyTEMlib/info_dialog.py +0 -227
- pyTEMlib/info_dlg.py +0 -205
- pyTEMlib/nion_reader.py +0 -293
- pyTEMlib/nsi_reader.py +0 -165
- pyTEMlib/structure_tools.py +0 -316
- pyTEMlib-0.2020.11.0.dist-info/METADATA +0 -20
- pyTEMlib-0.2020.11.0.dist-info/RECORD +0 -42
- {pyTEMlib-0.2020.11.0.dist-info → pyTEMlib-0.2024.8.4.dist-info}/top_level.txt +0 -0
pyTEMlib/sidpy_tools.py
CHANGED
|
@@ -1,129 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
import numpy as np
|
|
3
|
-
import sidpy
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
self.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
42
|
-
self.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
"""utility functions for sidpy; will move to sidpy"""
|
|
2
|
+
import numpy as np
|
|
3
|
+
import sidpy
|
|
4
|
+
import h5py
|
|
5
|
+
import pyNSID
|
|
6
|
+
import os
|
|
7
|
+
import ipywidgets as widgets
|
|
8
|
+
from IPython.display import display
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChooseDataset(object):
|
|
13
|
+
"""Widget to select dataset object """
|
|
14
|
+
|
|
15
|
+
def __init__(self, input_object, show_dialog=True):
|
|
16
|
+
if isinstance(input_object, sidpy.Dataset):
|
|
17
|
+
if isinstance(input_object.h5_dataset, h5py.Dataset):
|
|
18
|
+
self.current_channel = input_object.h5_dataset.parent
|
|
19
|
+
elif isinstance(input_object, h5py.Group):
|
|
20
|
+
self.current_channel = input_object
|
|
21
|
+
elif isinstance(input_object, h5py.Dataset):
|
|
22
|
+
self.current_channel = input_object.parent
|
|
23
|
+
else:
|
|
24
|
+
raise ValueError('Need hdf5 group or sidpy Dataset to determine image choices')
|
|
25
|
+
self.dataset_names = []
|
|
26
|
+
self.dataset_list = []
|
|
27
|
+
self.dataset_type = None
|
|
28
|
+
self.dataset = None
|
|
29
|
+
self.reader = pyNSID.NSIDReader(self.current_channel.file.filename)
|
|
30
|
+
|
|
31
|
+
self.get_dataset_list()
|
|
32
|
+
self.select_image = widgets.Dropdown(options=self.dataset_names,
|
|
33
|
+
value=self.dataset_names[0],
|
|
34
|
+
description='select dataset:',
|
|
35
|
+
disabled=False,
|
|
36
|
+
button_style='')
|
|
37
|
+
if show_dialog:
|
|
38
|
+
display(self.select_image)
|
|
39
|
+
|
|
40
|
+
self.select_image.observe(self.set_dataset, names='value')
|
|
41
|
+
self.set_dataset(0)
|
|
42
|
+
self.select_image.index = (len(self.dataset_names) - 1)
|
|
43
|
+
|
|
44
|
+
def get_dataset_list(self):
|
|
45
|
+
""" Get by Log number sorted list of datasets"""
|
|
46
|
+
datasets = self.reader.read()
|
|
47
|
+
order = []
|
|
48
|
+
for dset in datasets:
|
|
49
|
+
if self.dataset_type is None or dset.data_type == self.data_type:
|
|
50
|
+
if 'Log' in dset.title:
|
|
51
|
+
position = dset.title.find('Log_') + 4
|
|
52
|
+
order.append(int(dset.title[position:position + 3])+1)
|
|
53
|
+
else:
|
|
54
|
+
order.append(0)
|
|
55
|
+
for index in np.argsort(order):
|
|
56
|
+
dset = datasets[index]
|
|
57
|
+
self.dataset_names.append('/'.join(dset.title.replace('-', '_').split('/')[-1:]))
|
|
58
|
+
self.dataset_list.append(dset)
|
|
59
|
+
|
|
60
|
+
def set_dataset(self, b):
|
|
61
|
+
index = self.select_image.index
|
|
62
|
+
self.dataset = self.dataset_list[index]
|
|
63
|
+
# Find
|
|
64
|
+
self.dataset.title = self.dataset.title.split('/')[-1]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get_dimensions_by_order(dims_in, dataset):
|
|
68
|
+
"""get dimension
|
|
69
|
+
|
|
70
|
+
Parameters
|
|
71
|
+
----------
|
|
72
|
+
dims_in: int or list of int
|
|
73
|
+
the dimensions by numerical order
|
|
74
|
+
dataset: sidpy.Dataset
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
dims_out: list of dimensions
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
if isinstance(dims_in, int):
|
|
82
|
+
dims_in = [dims_in]
|
|
83
|
+
dims_out = []
|
|
84
|
+
for item in dims_in:
|
|
85
|
+
if isinstance(item, int):
|
|
86
|
+
if item in dataset._axes:
|
|
87
|
+
dims_out.append([item, dataset._axes[item]])
|
|
88
|
+
return dims_out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def get_dimensions_by_type(dims_in, dataset):
|
|
92
|
+
""" get dimension by dimension_type name
|
|
93
|
+
|
|
94
|
+
Parameters
|
|
95
|
+
----------
|
|
96
|
+
dims_in: dimension_type or list of dimension_types
|
|
97
|
+
the dimensions by numerical order
|
|
98
|
+
dataset: sidpy.Dataset
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
dims_out: list of dimensions
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
if isinstance(dims_in, (str, sidpy.DimensionType)):
|
|
106
|
+
dims_in = [dims_in]
|
|
107
|
+
for i in range(len(dims_in)):
|
|
108
|
+
if isinstance(dims_in[i], str):
|
|
109
|
+
dims_in[i] = sidpy.DimensionType[dims_in[i].upper()]
|
|
110
|
+
dims_out = []
|
|
111
|
+
for dim, axis in dataset._axes.items():
|
|
112
|
+
if axis.dimension_type in dims_in:
|
|
113
|
+
dims_out.append([dim, dataset._axes[dim]])
|
|
114
|
+
return dims_out
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def make_dummy_dataset(value_type):
|
|
118
|
+
"""Make a dummy sidpy.Dataset """
|
|
119
|
+
|
|
120
|
+
assert isinstance(value_type, sidpy.DataType)
|
|
121
|
+
if type == sidpy.DataType.SPECTRUM:
|
|
122
|
+
dataset = sidpy.Dataset.from_array(np.arange(100))
|
|
123
|
+
dataset.data_type = 'spectrum'
|
|
124
|
+
dataset.units = 'counts'
|
|
125
|
+
dataset.quantity = 'intensity'
|
|
126
|
+
|
|
127
|
+
dataset.set_dimension(0, sidpy.Dimension(np.arange(dataset.shape[0]) + 70, name='energy_scale'))
|
|
128
|
+
dataset.dim_0.dimension_type = 'spectral'
|
|
129
|
+
dataset.dim_0.units = 'eV'
|
|
130
|
+
dataset.dim_0.quantity = 'energy loss'
|
|
131
|
+
else:
|
|
132
|
+
raise NotImplementedError('not implemented')
|
|
133
|
+
return dataset
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def plot(dataset):
|
|
137
|
+
dataset.plot()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_image_dims(dataset):
|
|
141
|
+
"""Get all spatial dimensions"""
|
|
142
|
+
|
|
143
|
+
image_dims = []
|
|
144
|
+
for dim, axis in dataset._axes.items():
|
|
145
|
+
if axis.dimension_type == sidpy.DimensionType.SPATIAL:
|
|
146
|
+
image_dims.append(dim)
|
|
147
|
+
return image_dims
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_extent(dataset):
|
|
151
|
+
"""get extent to plot with matplotlib"""
|
|
152
|
+
image_dims = get_image_dims(dataset)
|
|
153
|
+
return dataset.get_extent(image_dims)
|
pyTEMlib/simulation_tools.py
CHANGED
|
@@ -1,87 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
print(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
""" dft simulations tools
|
|
2
|
+
|
|
3
|
+
Part of pyTEMlib
|
|
4
|
+
by Gerd Duscher
|
|
5
|
+
created 10/29/2020
|
|
6
|
+
|
|
7
|
+
Supports the conversion of DFT data to simulated EELS spectra
|
|
8
|
+
|
|
9
|
+
- exciting_get_spectra: importing dielectric function from the exciting program
|
|
10
|
+
- final_state_broadening: apply final state broadening to loss-spectra
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
from lxml import etree
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def exciting_get_spectra(file):
|
|
18
|
+
"""get EELS spectra from exciting calculation"""
|
|
19
|
+
|
|
20
|
+
tags = {'data': {}}
|
|
21
|
+
|
|
22
|
+
tree = etree.ElementTree(file=file)
|
|
23
|
+
root = tree.getroot()
|
|
24
|
+
|
|
25
|
+
data = tags['data']
|
|
26
|
+
|
|
27
|
+
if root.tag in ['loss', 'dielectric']:
|
|
28
|
+
print(' reading ', root.tag, ' function from file ', file)
|
|
29
|
+
# print(root[0].tag, root[0].text)
|
|
30
|
+
map_def = root[0]
|
|
31
|
+
i = 0
|
|
32
|
+
v = {}
|
|
33
|
+
for child_of_root in map_def:
|
|
34
|
+
data[child_of_root.tag] = child_of_root.attrib
|
|
35
|
+
v[child_of_root.tag] = []
|
|
36
|
+
i += 1
|
|
37
|
+
|
|
38
|
+
for elem in tree.iter(tag='map'):
|
|
39
|
+
m_dict = elem.attrib
|
|
40
|
+
for key in m_dict:
|
|
41
|
+
v[key].append(float(m_dict[key]))
|
|
42
|
+
|
|
43
|
+
for key in data:
|
|
44
|
+
data[key]['data'] = np.array(v[key])
|
|
45
|
+
data['type'] = root.tag+' function'
|
|
46
|
+
return tags
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def final_state_broadening(x, y, start, instrument):
|
|
50
|
+
"""Final state smearing of ELNES edges
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
x: numpy array
|
|
55
|
+
x or energy loss axis of density of states
|
|
56
|
+
y: numpy array
|
|
57
|
+
y or intensity axis of density of states
|
|
58
|
+
start: float
|
|
59
|
+
start energy of edge
|
|
60
|
+
instrument: float
|
|
61
|
+
instrument broadening
|
|
62
|
+
|
|
63
|
+
Return
|
|
64
|
+
------
|
|
65
|
+
out_data: numpy array
|
|
66
|
+
smeared intensity according to final state and instrument broadening
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
# Getting the smearing
|
|
70
|
+
a_i = 107.25*5
|
|
71
|
+
b_i = 0.04688*2.
|
|
72
|
+
x = np.array(x)-start
|
|
73
|
+
zero = int(-x[0]/(x[1]-x[0]))+1
|
|
74
|
+
smear_i = x*0.0
|
|
75
|
+
smear_i[zero:-1] = (a_i/x[zero:-1]**2)+b_i*np.sqrt(x[zero:-1])
|
|
76
|
+
h_bar = 6.58e-16 # h/2pi
|
|
77
|
+
pre = 1.0
|
|
78
|
+
m = 6.58e-31
|
|
79
|
+
smear = x*0.0
|
|
80
|
+
smear[zero:-1] = pre*(h_bar/(smear_i[zero:-1]*0.000000001))*np.sqrt((2*x[zero:-1]*1.6E-19)/m)
|
|
81
|
+
|
|
82
|
+
def lorentzian(xx, pp):
|
|
83
|
+
yy = ((0.5 * pp[1]/3.14)/((xx-pp[0])**2 + ((pp[1]/2)**2)))
|
|
84
|
+
return yy/sum(yy)
|
|
85
|
+
|
|
86
|
+
p = [0, instrument]
|
|
87
|
+
in_data = y.copy()
|
|
88
|
+
out_data = np.array(y)*0.0
|
|
89
|
+
for i in range(zero+5, len(x)):
|
|
90
|
+
p[0] = x[i]
|
|
91
|
+
p[1] = smear[i]/1.0
|
|
92
|
+
lor = lorentzian(x+1e-9, p)
|
|
93
|
+
out_data[i] = sum(in_data*lor)
|
|
94
|
+
if np.isnan(out_data[i]):
|
|
95
|
+
out_data[i] = 0.0
|
|
96
|
+
|
|
97
|
+
p[1] = instrument
|
|
98
|
+
in_data = out_data.copy()
|
|
99
|
+
for i in range(zero-5, len(x)):
|
|
100
|
+
p[0] = x[i]
|
|
101
|
+
lor = lorentzian(x+1e-9, p)
|
|
102
|
+
out_data[i] = sum(in_data*lor)
|
|
103
|
+
# print(out_data[i],in_data[i], lor[i],in_data[i-1], lor[i-1], )
|
|
104
|
+
return out_data
|
pyTEMlib/version.py
CHANGED