pyTEMlib 0.2025.4.1__py3-none-any.whl → 0.2025.9.1__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.
- build/lib/pyTEMlib/__init__.py +33 -0
- build/lib/pyTEMlib/animation.py +640 -0
- build/lib/pyTEMlib/atom_tools.py +238 -0
- build/lib/pyTEMlib/config_dir.py +31 -0
- build/lib/pyTEMlib/crystal_tools.py +1219 -0
- build/lib/pyTEMlib/diffraction_plot.py +756 -0
- build/lib/pyTEMlib/dynamic_scattering.py +293 -0
- build/lib/pyTEMlib/eds_tools.py +826 -0
- build/lib/pyTEMlib/eds_xsections.py +432 -0
- build/lib/pyTEMlib/eels_tools/__init__.py +44 -0
- build/lib/pyTEMlib/eels_tools/core_loss_tools.py +751 -0
- build/lib/pyTEMlib/eels_tools/eels_database.py +134 -0
- build/lib/pyTEMlib/eels_tools/low_loss_tools.py +655 -0
- build/lib/pyTEMlib/eels_tools/peak_fit_tools.py +175 -0
- build/lib/pyTEMlib/eels_tools/zero_loss_tools.py +264 -0
- build/lib/pyTEMlib/file_reader.py +274 -0
- build/lib/pyTEMlib/file_tools.py +811 -0
- build/lib/pyTEMlib/get_bote_salvat.py +69 -0
- build/lib/pyTEMlib/graph_tools.py +1153 -0
- build/lib/pyTEMlib/graph_viz.py +599 -0
- build/lib/pyTEMlib/image/__init__.py +37 -0
- build/lib/pyTEMlib/image/image_atoms.py +270 -0
- build/lib/pyTEMlib/image/image_clean.py +197 -0
- build/lib/pyTEMlib/image/image_distortion.py +299 -0
- build/lib/pyTEMlib/image/image_fft.py +277 -0
- build/lib/pyTEMlib/image/image_graph.py +926 -0
- build/lib/pyTEMlib/image/image_registration.py +316 -0
- build/lib/pyTEMlib/image/image_utilities.py +309 -0
- build/lib/pyTEMlib/image/image_window.py +421 -0
- build/lib/pyTEMlib/image_tools.py +699 -0
- build/lib/pyTEMlib/interactive_image.py +1 -0
- build/lib/pyTEMlib/kinematic_scattering.py +1196 -0
- build/lib/pyTEMlib/microscope.py +61 -0
- build/lib/pyTEMlib/probe_tools.py +906 -0
- build/lib/pyTEMlib/sidpy_tools.py +153 -0
- build/lib/pyTEMlib/simulation_tools.py +104 -0
- build/lib/pyTEMlib/test.py +437 -0
- build/lib/pyTEMlib/utilities.py +314 -0
- build/lib/pyTEMlib/version.py +5 -0
- build/lib/pyTEMlib/xrpa_x_sections.py +20976 -0
- pyTEMlib/__init__.py +25 -3
- pyTEMlib/animation.py +31 -22
- pyTEMlib/atom_tools.py +29 -34
- pyTEMlib/config_dir.py +2 -28
- pyTEMlib/crystal_tools.py +129 -165
- pyTEMlib/eds_tools.py +559 -342
- pyTEMlib/eds_xsections.py +432 -0
- pyTEMlib/eels_tools/__init__.py +44 -0
- pyTEMlib/eels_tools/core_loss_tools.py +751 -0
- pyTEMlib/eels_tools/eels_database.py +134 -0
- pyTEMlib/eels_tools/low_loss_tools.py +655 -0
- pyTEMlib/eels_tools/peak_fit_tools.py +175 -0
- pyTEMlib/eels_tools/zero_loss_tools.py +264 -0
- pyTEMlib/file_reader.py +274 -0
- pyTEMlib/file_tools.py +260 -1130
- pyTEMlib/get_bote_salvat.py +69 -0
- pyTEMlib/graph_tools.py +101 -174
- pyTEMlib/graph_viz.py +150 -0
- pyTEMlib/image/__init__.py +37 -0
- pyTEMlib/image/image_atoms.py +270 -0
- pyTEMlib/image/image_clean.py +197 -0
- pyTEMlib/image/image_distortion.py +299 -0
- pyTEMlib/image/image_fft.py +277 -0
- pyTEMlib/image/image_graph.py +926 -0
- pyTEMlib/image/image_registration.py +316 -0
- pyTEMlib/image/image_utilities.py +309 -0
- pyTEMlib/image/image_window.py +421 -0
- pyTEMlib/image_tools.py +154 -915
- pyTEMlib/kinematic_scattering.py +1 -1
- pyTEMlib/probe_tools.py +1 -1
- pyTEMlib/test.py +437 -0
- pyTEMlib/utilities.py +314 -0
- pyTEMlib/version.py +2 -3
- pyTEMlib/xrpa_x_sections.py +14 -10
- {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/METADATA +13 -16
- pytemlib-0.2025.9.1.dist-info/RECORD +86 -0
- {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/WHEEL +1 -1
- pytemlib-0.2025.9.1.dist-info/top_level.txt +6 -0
- pyTEMlib/core_loss_widget.py +0 -721
- pyTEMlib/eels_dialog.py +0 -754
- pyTEMlib/eels_dialog_utilities.py +0 -1199
- pyTEMlib/eels_tools.py +0 -2359
- pyTEMlib/file_tools_qt.py +0 -193
- pyTEMlib/image_dialog.py +0 -158
- pyTEMlib/image_dlg.py +0 -146
- pyTEMlib/info_widget.py +0 -1086
- pyTEMlib/info_widget3.py +0 -1120
- pyTEMlib/low_loss_widget.py +0 -479
- pyTEMlib/peak_dialog.py +0 -1129
- pyTEMlib/peak_dlg.py +0 -286
- pytemlib-0.2025.4.1.dist-info/RECORD +0 -38
- pytemlib-0.2025.4.1.dist-info/top_level.txt +0 -1
- {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/entry_points.txt +0 -0
- {pytemlib-0.2025.4.1.dist-info → pytemlib-0.2025.9.1.dist-info}/licenses/LICENSE +0 -0
pyTEMlib/__init__.py
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""
|
|
3
|
+
PyTEMlib
|
|
4
|
+
--------
|
|
5
|
+
A Python package for analyzing and processing transmission electron microscopy (TEM) data.
|
|
6
|
+
This package provides tools for data quantification through a model-based approach,
|
|
7
|
+
including functionalities for imaging, spectra analysis, and data visualization.
|
|
8
|
+
|
|
9
|
+
The package is part of the pycrosccopy ecosystem and the dataformat is based on sidpy,
|
|
10
|
+
the fileformat is based on pyNSDI.
|
|
3
11
|
Created on Sat Jan 19 10:07:35 2019
|
|
12
|
+
Update on Sun Jul 20 2025
|
|
4
13
|
|
|
5
14
|
@author: gduscher
|
|
6
15
|
"""
|
|
7
|
-
from .version import
|
|
16
|
+
from .version import __version__
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
from . import file_tools
|
|
19
|
+
from . import image_tools
|
|
20
|
+
from .image import image_atoms as atom_tools
|
|
21
|
+
from . import graph_tools
|
|
22
|
+
from . import probe_tools
|
|
23
|
+
from . import eels_tools
|
|
24
|
+
from . import eds_tools
|
|
25
|
+
from . import crystal_tools
|
|
26
|
+
from . import kinematic_scattering
|
|
27
|
+
from . import dynamic_scattering
|
|
28
|
+
from .config_dir import config_path
|
|
10
29
|
|
|
11
|
-
|
|
30
|
+
__all__ = ['__version__', 'file_tools', 'image_tools', 'atom_tools',
|
|
31
|
+
'graph_tools', 'probe_tools', 'eels_tools', 'eds_tools',
|
|
32
|
+
'crystal_tools', 'kinematic_scattering', 'dynamic_scattering', 'config_path']
|
|
33
|
+
__author__ = 'Gerd Duscher'
|
pyTEMlib/animation.py
CHANGED
|
@@ -8,7 +8,7 @@ revision: 01/11/2021
|
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
import matplotlib.pyplot as plt
|
|
11
|
-
|
|
11
|
+
from matplotlib import patches
|
|
12
12
|
|
|
13
13
|
from ipywidgets import widgets
|
|
14
14
|
from IPython.display import display
|
|
@@ -50,8 +50,8 @@ def geometric_ray_diagram(focal_length=1., magnification=False):
|
|
|
50
50
|
ax.add_patch(ellipse)
|
|
51
51
|
ax.plot([1.5, -1.5], [0, 0], '--', color='black')
|
|
52
52
|
ax.plot([0, 0], [u, -v], '--', color='black')
|
|
53
|
-
single_prop =
|
|
54
|
-
double_prop =
|
|
53
|
+
single_prop = {"arrowstyle": '->', "shrinkA": 0, "shrinkB": 0}
|
|
54
|
+
double_prop = {"arrowstyle": "<->", "shrinkA": 0, "shrinkB": 0}
|
|
55
55
|
|
|
56
56
|
if magnification:
|
|
57
57
|
ax.annotate("", xy=(-x, u), xytext=(x, u), arrowprops=single_prop)
|
|
@@ -120,14 +120,16 @@ def add_lens(z, f, diam, lens_labels):
|
|
|
120
120
|
def add_aperture(z, diam, radius, lens_labels):
|
|
121
121
|
"""add aperture to propagate beam plot"""
|
|
122
122
|
|
|
123
|
-
ww, tw, rad = diam / 10.0, diam / 3.0, diam / 2.0
|
|
123
|
+
# ww, tw, rad = diam / 10.0, diam / 3.0, diam / 2.0
|
|
124
|
+
rad = diam / 2
|
|
124
125
|
radius = radius / 2
|
|
125
126
|
plt.plot([z, z], [-rad, -radius], 'k', linewidth=2)
|
|
126
127
|
plt.plot([z, z], [rad, radius], 'k', linewidth=2)
|
|
127
128
|
plt.text(z, -rad - 2.0, lens_labels, fontsize=12)
|
|
128
129
|
|
|
129
130
|
|
|
130
|
-
def propagate_beam(source_position, numerical_aperture, number_of_rays,
|
|
131
|
+
def propagate_beam(source_position, numerical_aperture, number_of_rays,
|
|
132
|
+
lens_positions, focal_lengths,
|
|
131
133
|
lens_labels='', color='b'):
|
|
132
134
|
"""geometrical propagation of light rays from given source
|
|
133
135
|
|
|
@@ -242,33 +244,35 @@ def deficient_holz_line(exact_bragg=False, shift=False, laue_zone=1, color='blac
|
|
|
242
244
|
k_0[1] += shift_y
|
|
243
245
|
|
|
244
246
|
# Ewald Sphere
|
|
245
|
-
ewald_sphere = patches.Circle((k_0[0], k_0[1]), radius=np.linalg.norm(k_0),
|
|
247
|
+
ewald_sphere = patches.Circle((k_0[0], k_0[1]), radius=np.linalg.norm(k_0),
|
|
248
|
+
clip_on=False, zorder=10, linewidth=1,
|
|
246
249
|
edgecolor=color, fill=False)
|
|
247
250
|
plt.gca().add_artist(ewald_sphere)
|
|
248
251
|
|
|
249
|
-
plt.gca().arrow(g[-1] + .1 / d / 4, 1 / d / 2, 0, 1 / d / 2, head_width=0.03,
|
|
250
|
-
length_includes_head=True)
|
|
251
|
-
plt.gca().arrow(g[-1] + .1 / d / 4, 1 / d / 2, 0, -1 / d / 2, head_width=0.03,
|
|
252
|
-
length_includes_head=True)
|
|
253
|
-
plt.gca().annotate("$|g_{HOLZ}|$", xytext=(g[-1] + .1 / d / 3, 1 / d / 3),
|
|
254
|
-
|
|
255
|
-
# k_0
|
|
252
|
+
plt.gca().arrow(g[-1] + .1 / d / 4, 1 / d / 2, 0, 1 / d / 2, head_width=0.03,
|
|
253
|
+
head_length=0.04, fc='k', ec='k', length_includes_head=True)
|
|
254
|
+
plt.gca().arrow(g[-1] + .1 / d / 4, 1 / d / 2, 0, -1 / d / 2, head_width=0.03,
|
|
255
|
+
head_length=0.04, fc='k', ec='k', length_includes_head=True)
|
|
256
|
+
plt.gca().annotate("$|g_{HOLZ}|$", xytext=(g[-1] + .1 / d / 3, 1 / d / 3),
|
|
257
|
+
xy=(g[-1] + 1 / d / 3, 1 / d / 3))
|
|
256
258
|
plt.scatter(k_0[0], k_0[1])
|
|
257
|
-
plt.gca().arrow(k_0[0], k_0[1], -k_0[0] + shift_x, -k_0[1] + shift_y, head_width=0.03,
|
|
258
|
-
ec=color, length_includes_head=True)
|
|
259
|
+
plt.gca().arrow(k_0[0], k_0[1], -k_0[0] + shift_x, -k_0[1] + shift_y, head_width=0.03,
|
|
260
|
+
head_length=0.04, fc=color, ec=color, length_includes_head=True)
|
|
259
261
|
plt.gca().annotate("K$_0$", xytext=(k_0[0] / 2, k_0[1] / 3), xy=(k_0[0] / 2, k_0[1] / 2))
|
|
260
262
|
|
|
261
263
|
# K_d Bragg of HOLZ reflection
|
|
262
|
-
plt.gca().arrow(k_0[0], k_0[1], -k_0[0] + g_d[0] + shift_x, -k_0[1] + g_d[1] + s_g + shift_y,
|
|
263
|
-
head_length=0.04, fc=color,
|
|
264
|
-
|
|
265
|
-
plt.gca().annotate("K$_d$", xytext=(k_0[0] + (g_d[0] - k_0[0]) / 2, k_0[1] / 2),
|
|
264
|
+
plt.gca().arrow(k_0[0], k_0[1], -k_0[0] + g_d[0] + shift_x, -k_0[1] + g_d[1] + s_g + shift_y,
|
|
265
|
+
head_width=0.03, head_length=0.04, fc=color, ec=color,
|
|
266
|
+
length_includes_head=True)
|
|
267
|
+
plt.gca().annotate("K$_d$", xytext=(k_0[0] + (g_d[0] - k_0[0]) / 2, k_0[1] / 2),
|
|
268
|
+
xy=(6.5 / d / 2, k_0[1] / 2))
|
|
266
269
|
|
|
267
270
|
# s_g excitation Error of HOLZ reflection
|
|
268
271
|
if s_g > 0:
|
|
269
272
|
plt.gca().arrow(g_d[0], g_d[1], 0, s_g, head_width=0.03, head_length=0.04, fc='k',
|
|
270
273
|
ec='k', length_includes_head=True)
|
|
271
|
-
plt.gca().annotate("s$_g$", xytext=(g_d[0] * 1.01, g_d[1] + s_g / 3),
|
|
274
|
+
plt.gca().annotate("s$_g$", xytext=(g_d[0] * 1.01, g_d[1] + s_g / 3),
|
|
275
|
+
xy=(g_d[0] * 1.01, g_d[1] + s_g / 3))
|
|
272
276
|
|
|
273
277
|
# Bragg angle
|
|
274
278
|
g_sg = g_d
|
|
@@ -311,6 +315,7 @@ def deficient_holz_line(exact_bragg=False, shift=False, laue_zone=1, color='blac
|
|
|
311
315
|
|
|
312
316
|
|
|
313
317
|
def deficient_kikuchi_line(s_g=0., color_b='black'):
|
|
318
|
+
"""Draw the deficient Kikuchi line in the plot."""
|
|
314
319
|
k_len = 1 / ks.get_wavelength(20)
|
|
315
320
|
d = 2 # lattice parameter in nm
|
|
316
321
|
|
|
@@ -391,7 +396,7 @@ def deficient_kikuchi_line(s_g=0., color_b='black'):
|
|
|
391
396
|
plt.gca().set_xlim(-.2, 1.03)
|
|
392
397
|
|
|
393
398
|
|
|
394
|
-
class InteractiveAberration(
|
|
399
|
+
class InteractiveAberration():
|
|
395
400
|
"""
|
|
396
401
|
### Interactive explanation of aberrations
|
|
397
402
|
|
|
@@ -423,6 +428,7 @@ class InteractiveAberration(object):
|
|
|
423
428
|
# self.cid = self.figure.canvas.mpl_connect('button_press_event', self.onclick)
|
|
424
429
|
|
|
425
430
|
def on_button_clicked(self, b):
|
|
431
|
+
"""Handle button click events to update the analysis options"""
|
|
426
432
|
# print(b['owner'].description)
|
|
427
433
|
selection = b['owner'].description
|
|
428
434
|
if selection in self.analysis:
|
|
@@ -432,6 +438,7 @@ class InteractiveAberration(object):
|
|
|
432
438
|
self.update()
|
|
433
439
|
|
|
434
440
|
def update(self):
|
|
441
|
+
"""Update the plot based on the selected analysis options"""
|
|
435
442
|
ax = self.ax
|
|
436
443
|
ax.clear()
|
|
437
444
|
selection = self.analysis
|
|
@@ -519,7 +526,7 @@ class InteractiveAberration(object):
|
|
|
519
526
|
plt.gca().add_patch(aberration2)
|
|
520
527
|
|
|
521
528
|
|
|
522
|
-
class InteractiveRonchigramMagnification(
|
|
529
|
+
class InteractiveRonchigramMagnification():
|
|
523
530
|
"""
|
|
524
531
|
### Interactive explanation of magnification
|
|
525
532
|
|
|
@@ -551,6 +558,7 @@ class InteractiveRonchigramMagnification(object):
|
|
|
551
558
|
# self.cid = self.figure.canvas.mpl_connect('button_press_event', self.onclick)
|
|
552
559
|
|
|
553
560
|
def on_button_clicked(self, b):
|
|
561
|
+
"""Handle button click events"""
|
|
554
562
|
# print(b['owner'].description)
|
|
555
563
|
selection = b['owner'].description
|
|
556
564
|
if selection in self.analysis:
|
|
@@ -560,6 +568,7 @@ class InteractiveRonchigramMagnification(object):
|
|
|
560
568
|
self.update()
|
|
561
569
|
|
|
562
570
|
def update(self):
|
|
571
|
+
"""Update the plot based on the selected analysis options"""
|
|
563
572
|
ax = self.ax
|
|
564
573
|
ax.clear()
|
|
565
574
|
selection = self.analysis
|
pyTEMlib/atom_tools.py
CHANGED
|
@@ -12,20 +12,16 @@ a pycroscopy package
|
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
|
-
import sys
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import skimage.feature
|
|
17
|
+
import sklearn.cluster
|
|
18
|
+
import scipy.spatial
|
|
19
|
+
import scipy.optimize
|
|
19
20
|
|
|
20
|
-
from sklearn.cluster import KMeans
|
|
21
|
-
from scipy.spatial import cKDTree
|
|
22
|
-
import scipy.optimize as optimization
|
|
23
|
-
|
|
24
|
-
import pyTEMlib.probe_tools as probe_tools
|
|
25
|
-
import pyTEMlib.file_tools as ft
|
|
26
|
-
import sidpy
|
|
27
21
|
from tqdm.auto import trange
|
|
28
22
|
|
|
23
|
+
import sidpy
|
|
24
|
+
import pyTEMlib
|
|
29
25
|
|
|
30
26
|
def find_atoms(image, atom_size=0.1, threshold=0.):
|
|
31
27
|
""" Find atoms is a simple wrapper for blob_log in skimage.feature
|
|
@@ -37,7 +33,8 @@ def find_atoms(image, atom_size=0.1, threshold=0.):
|
|
|
37
33
|
atom_size: float
|
|
38
34
|
visible size of atom blob diameter in nm gives minimal distance between found blobs
|
|
39
35
|
threshold: float
|
|
40
|
-
threshold for blob finder; (usually between 0.001 and 1.0)
|
|
36
|
+
threshold for blob finder; (usually between 0.001 and 1.0)
|
|
37
|
+
for threshold <= 0 we use the RMS contrast
|
|
41
38
|
|
|
42
39
|
Returns
|
|
43
40
|
-------
|
|
@@ -59,10 +56,7 @@ def find_atoms(image, atom_size=0.1, threshold=0.):
|
|
|
59
56
|
im = im/im.max()
|
|
60
57
|
if threshold <= 0.:
|
|
61
58
|
threshold = np.std(im)
|
|
62
|
-
atoms = blob_log(im, max_sigma=atom_size/scale_x, threshold=threshold)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
atoms = skimage.feature.blob_log(im, max_sigma=atom_size/scale_x, threshold=threshold)
|
|
66
60
|
return atoms
|
|
67
61
|
|
|
68
62
|
|
|
@@ -86,12 +80,12 @@ def atoms_clustering(atoms, mid_atoms, number_of_clusters=3, nearest_neighbours=
|
|
|
86
80
|
"""
|
|
87
81
|
|
|
88
82
|
# get distances
|
|
89
|
-
nn_tree =
|
|
83
|
+
nn_tree = scipy.spatial.KDTree(np.array(atoms)[:, 0:2])
|
|
90
84
|
|
|
91
85
|
distances, indices = nn_tree.query(np.array(mid_atoms)[:, 0:2], nearest_neighbours)
|
|
92
86
|
|
|
93
|
-
# Clustering
|
|
94
|
-
k_means = KMeans(n_clusters=number_of_clusters, random_state=0)
|
|
87
|
+
# Clustering with fixed RNG in kmeans
|
|
88
|
+
k_means = sklearn.cluster.KMeans(n_clusters=number_of_clusters, random_state=0)
|
|
95
89
|
k_means.fit(distances)
|
|
96
90
|
clusters = k_means.predict(distances)
|
|
97
91
|
|
|
@@ -115,8 +109,9 @@ def gauss_difference(params, area):
|
|
|
115
109
|
numpy array: flattened array of difference
|
|
116
110
|
|
|
117
111
|
"""
|
|
118
|
-
gauss = probe_tools.make_gauss(area.shape[0], area.shape[1],
|
|
119
|
-
|
|
112
|
+
gauss = pyTEMlib.probe_tools.make_gauss(area.shape[0], area.shape[1],
|
|
113
|
+
width=params[0], x0=params[1],
|
|
114
|
+
y0=params[2], intensity=params[3])
|
|
120
115
|
return (area - gauss).flatten()
|
|
121
116
|
|
|
122
117
|
|
|
@@ -131,19 +126,20 @@ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
|
|
|
131
126
|
radius: float
|
|
132
127
|
radius of circular mask to define fitting of Gaussian
|
|
133
128
|
max_int: float
|
|
134
|
-
optional - maximum intensity to be considered for fitting
|
|
129
|
+
optional - maximum intensity to be considered for fitting
|
|
130
|
+
(to exclude contaminated areas for example)
|
|
135
131
|
min_int: float
|
|
136
|
-
optional - minimum intensity to be considered for fitting
|
|
132
|
+
optional - minimum intensity to be considered for fitting
|
|
133
|
+
(to exclude contaminated holes for example)
|
|
137
134
|
max_dist: float
|
|
138
135
|
optional - maximum distance of movement of Gaussian during fitting
|
|
139
136
|
|
|
140
137
|
Returns
|
|
141
138
|
-------
|
|
142
139
|
sym: dict
|
|
143
|
-
dictionary containing new atom positions and other output
|
|
140
|
+
dictionary containing new atom positions and other output
|
|
144
141
|
"""
|
|
145
142
|
rr = int(radius + 0.5) # atom radius
|
|
146
|
-
print('using radius ', rr, 'pixels')
|
|
147
143
|
|
|
148
144
|
pixels = np.linspace(0, 2 * rr, 2 * rr + 1) - rr
|
|
149
145
|
x, y = np.meshgrid(pixels, pixels)
|
|
@@ -162,7 +158,7 @@ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
|
|
|
162
158
|
gauss_amplitude = []
|
|
163
159
|
gauss_intensity = []
|
|
164
160
|
|
|
165
|
-
for i in
|
|
161
|
+
for i in range(len(atoms)):
|
|
166
162
|
x, y = atoms[i][0:2]
|
|
167
163
|
x = int(x)
|
|
168
164
|
y = int(y)
|
|
@@ -171,7 +167,7 @@ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
|
|
|
171
167
|
|
|
172
168
|
append = False
|
|
173
169
|
|
|
174
|
-
if
|
|
170
|
+
if x-rr < 0 or y-rr < 0 or x+rr+1 > image.shape[0] or y+rr+1 > image.shape[1]:
|
|
175
171
|
position.append(-1)
|
|
176
172
|
intensities.append(-1.)
|
|
177
173
|
maximum_area.append(-1.)
|
|
@@ -189,11 +185,10 @@ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
|
|
|
189
185
|
|
|
190
186
|
pout = [0, 0, 0, 0]
|
|
191
187
|
if append:
|
|
192
|
-
if
|
|
188
|
+
if x-rr < 0 or y-rr < 0 or x+rr+1 > image.shape[0] or y+rr+1 > image.shape[1]:
|
|
193
189
|
pass
|
|
194
190
|
else:
|
|
195
|
-
[pout, _] =
|
|
196
|
-
|
|
191
|
+
[pout, _] = scipy.optimize.leastsq(gauss_difference, guess, args=area)
|
|
197
192
|
if (abs(pout[1]) > max_dist) or (abs(pout[2]) > max_dist):
|
|
198
193
|
pout = [0, 0, 0, 0]
|
|
199
194
|
|
|
@@ -203,8 +198,8 @@ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
|
|
|
203
198
|
if all(v == 0 for v in pout):
|
|
204
199
|
gauss_intensity.append(0.)
|
|
205
200
|
else:
|
|
206
|
-
gauss = probe_tools.make_gauss(area.shape[0], area.shape[1], width=pout[0],
|
|
207
|
-
|
|
201
|
+
gauss = pyTEMlib.probe_tools.make_gauss(area.shape[0], area.shape[1], width=pout[0],
|
|
202
|
+
x0=pout[1], y0=pout[2], intensity=pout[3])
|
|
208
203
|
gauss_intensity.append((gauss * mask).sum())
|
|
209
204
|
gauss_width.append(pout[0])
|
|
210
205
|
gauss_amplitude.append(pout[3])
|
|
@@ -232,9 +227,9 @@ def intensity_area(image, atoms, radius):
|
|
|
232
227
|
x, y = np.meshgrid(pixels, pixels)
|
|
233
228
|
mask = np.array((x ** 2 + y ** 2) < rr ** 2)
|
|
234
229
|
intensities = []
|
|
235
|
-
for
|
|
236
|
-
x = int(
|
|
237
|
-
y = int(
|
|
230
|
+
for atom in atoms:
|
|
231
|
+
x = int(atom[1])
|
|
232
|
+
y = int(atom[0])
|
|
238
233
|
area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
|
|
239
234
|
if area.shape == mask.shape:
|
|
240
235
|
intensities.append((area * mask).sum())
|
pyTEMlib/config_dir.py
CHANGED
|
@@ -9,12 +9,8 @@ config_dir: setup of directory ~/.pyTEMlib for custom sources and database
|
|
|
9
9
|
import os
|
|
10
10
|
|
|
11
11
|
# import wget
|
|
12
|
-
if os.name
|
|
12
|
+
if os.name in ['nt', 'dos', 'posix']:
|
|
13
13
|
config_path = os.path.join(os.path.expanduser('~'), '.pyTEMlib')
|
|
14
|
-
os_name = 'posix'
|
|
15
|
-
elif os.name in ['nt', 'dos']:
|
|
16
|
-
config_path = os.path.join(os.path.expanduser('~'), '.pyTEMlib')
|
|
17
|
-
os_name = 'windows'
|
|
18
14
|
else:
|
|
19
15
|
config_path = '.'
|
|
20
16
|
|
|
@@ -31,27 +27,5 @@ lines = ['Microscope,E0,alpha,beta,pppc,correlation_factor,VOA_conv,EELS_b1,EELS
|
|
|
31
27
|
|
|
32
28
|
config_file = os.path.join(config_path, 'microscopes.csv')
|
|
33
29
|
if os.path.isfile(config_file) is False: # Do not overwrite users microscopy files
|
|
34
|
-
with open(config_file, 'w') as f:
|
|
30
|
+
with open(config_file, 'w', encoding='utf-8') as f:
|
|
35
31
|
f.write('\n'.join(lines))
|
|
36
|
-
|
|
37
|
-
"""
|
|
38
|
-
import pickle
|
|
39
|
-
from pkg_resources import resource_filename
|
|
40
|
-
|
|
41
|
-
data_path = resource_filename(__name__, 'data')
|
|
42
|
-
pkl_file = open(data_path + '/old/edges_db.pkl', 'rb')
|
|
43
|
-
x_sections = pickle.load(pkl_file)
|
|
44
|
-
pkl_file.close()
|
|
45
|
-
for key in range(80, 83):
|
|
46
|
-
print(f'\'{key}\': ', x_sections[str(key)], ',')
|
|
47
|
-
|
|
48
|
-
# config_file = os.path.join(config_path, 'edges_db.pkl')
|
|
49
|
-
ref = importlib_resources.files('pyTEMlib') / 'data/edges_db.pkl'
|
|
50
|
-
with importlib_resources.as_file(ref) as templates_file:
|
|
51
|
-
if os.path.isfile(config_file) is False:
|
|
52
|
-
try:
|
|
53
|
-
shutil.copy(templates_file, config_file)
|
|
54
|
-
except FileNotFoundError:
|
|
55
|
-
pass
|
|
56
|
-
# wget('https://github.com/pycroscopy/pyTEMlib/tree/main/pyTEMlib/data/'+file)
|
|
57
|
-
"""
|