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.

Files changed (60) hide show
  1. pyTEMlib/__init__.py +11 -11
  2. pyTEMlib/animation.py +631 -0
  3. pyTEMlib/atom_tools.py +240 -245
  4. pyTEMlib/config_dir.py +57 -33
  5. pyTEMlib/core_loss_widget.py +658 -0
  6. pyTEMlib/crystal_tools.py +1255 -0
  7. pyTEMlib/diffraction_plot.py +756 -0
  8. pyTEMlib/dynamic_scattering.py +293 -0
  9. pyTEMlib/eds_tools.py +609 -0
  10. pyTEMlib/eels_dialog.py +749 -491
  11. pyTEMlib/{interactive_eels.py → eels_dialog_utilities.py} +1199 -1177
  12. pyTEMlib/eels_tools.py +2031 -1698
  13. pyTEMlib/file_tools.py +1276 -560
  14. pyTEMlib/file_tools_qt.py +193 -0
  15. pyTEMlib/graph_tools.py +1166 -450
  16. pyTEMlib/graph_viz.py +449 -0
  17. pyTEMlib/image_dialog.py +158 -0
  18. pyTEMlib/image_dlg.py +146 -232
  19. pyTEMlib/image_tools.py +1399 -1028
  20. pyTEMlib/info_widget.py +933 -0
  21. pyTEMlib/interactive_image.py +1 -226
  22. pyTEMlib/kinematic_scattering.py +1196 -0
  23. pyTEMlib/low_loss_widget.py +176 -0
  24. pyTEMlib/microscope.py +61 -81
  25. pyTEMlib/peak_dialog.py +1047 -410
  26. pyTEMlib/peak_dlg.py +286 -242
  27. pyTEMlib/probe_tools.py +653 -207
  28. pyTEMlib/sidpy_tools.py +153 -136
  29. pyTEMlib/simulation_tools.py +104 -87
  30. pyTEMlib/version.py +6 -3
  31. pyTEMlib/xrpa_x_sections.py +20972 -0
  32. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/LICENSE +21 -21
  33. pyTEMlib-0.2024.8.4.dist-info/METADATA +93 -0
  34. pyTEMlib-0.2024.8.4.dist-info/RECORD +37 -0
  35. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/WHEEL +6 -5
  36. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/entry_points.txt +0 -1
  37. pyTEMlib/KinsCat.py +0 -2758
  38. pyTEMlib/__version__.py +0 -2
  39. pyTEMlib/data/TEMlibrc +0 -68
  40. pyTEMlib/data/edges_db.csv +0 -189
  41. pyTEMlib/data/edges_db.pkl +0 -0
  42. pyTEMlib/data/fparam.txt +0 -103
  43. pyTEMlib/data/microscopes.csv +0 -7
  44. pyTEMlib/data/microscopes.xml +0 -167
  45. pyTEMlib/data/path.txt +0 -1
  46. pyTEMlib/defaults_parser.py +0 -90
  47. pyTEMlib/dm3_reader.py +0 -613
  48. pyTEMlib/edges_db.py +0 -76
  49. pyTEMlib/eels_dlg.py +0 -224
  50. pyTEMlib/hdf_utils.py +0 -483
  51. pyTEMlib/image_tools1.py +0 -2194
  52. pyTEMlib/info_dialog.py +0 -237
  53. pyTEMlib/info_dlg.py +0 -202
  54. pyTEMlib/nion_reader.py +0 -297
  55. pyTEMlib/nsi_reader.py +0 -170
  56. pyTEMlib/structure_tools.py +0 -316
  57. pyTEMlib/test.py +0 -2072
  58. pyTEMlib-0.2020.11.1.dist-info/METADATA +0 -20
  59. pyTEMlib-0.2020.11.1.dist-info/RECORD +0 -45
  60. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.8.4.dist-info}/top_level.txt +0 -0
pyTEMlib/atom_tools.py CHANGED
@@ -1,245 +1,240 @@
1
- """
2
- All atom detection is done here
3
-
4
- Everything is in unit of pixel!!
5
- """
6
- # All atom detection is done here
7
- # Everything is in unit of pixel!!
8
- #
9
-
10
- import numpy as np
11
-
12
- from skimage.feature import peak_local_max
13
- from sklearn.cluster import KMeans
14
- from scipy.spatial import cKDTree
15
- import scipy.optimize as optimization
16
-
17
- from .probe_tools import *
18
- from .file_tools import *
19
-
20
-
21
- def find_atoms(image, tags):
22
- """
23
- Find atoms
24
-
25
- Not changed to sidpy dataset yet.
26
- """
27
- image = image - image.min()
28
- image = image / image.max()
29
-
30
- if 'sigma_min' not in tags:
31
- tags['sigma_min'] = 0.1
32
- if 'resolution' not in tags:
33
- tags['resolution'] = 0.1
34
-
35
- if 'ROIsize' not in tags:
36
- tags['ROIsize'] = 100.
37
-
38
- res = tags['resolution'] / tags['pixel_size'] # * tags['ROIsize']/100.
39
- print('res', res)
40
- coordinates = peak_local_max(image, min_distance=int(res / 2), threshold_rel=tags['sigma_min'], exclude_border=True)
41
- print('coor', len(coordinates))
42
- """
43
- peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1,
44
- exclude_border=True, indices=True, num_peaks=np.inf,
45
- footprint=None, labels=None):
46
-
47
- Find peaks in an image, and return them as coordinates or a boolean array.
48
- Peaks are the local maxima in a region of `2 * min_distance + 1
49
-
50
- (i.e. peaks are separated by at least `min_distance`).
51
- NOTE: If peaks are flat (i.e. multiple adjacent pixels have identical
52
- intensities), the coordinates of all such pixels are returned.
53
- """
54
-
55
- # We calculate the radius in pixel of a round area in which atoms are evaluated
56
- sc = tags['pixel_size']
57
- r = tags['resolution'] / sc * tags['ROIsize'] / 100. / 2.
58
- tags['radius'] = r
59
-
60
- #######################################
61
- # Now we determine intensity #
62
- #######################################
63
-
64
- ###############
65
- # Make a circular mask for integration of atom intensity
66
- ################
67
- rr = int(r + 0.5)
68
- mask = np.zeros((2 * rr + 1, 2 * rr + 1))
69
-
70
- for i in range(2 * rr + 1):
71
- for j in range(2 * rr + 1):
72
- if (i - rr) ** 2 + (j - rr) ** 2 < rr ** 2 + 0.1:
73
- mask[i, j] = 1
74
-
75
- ###
76
- # Determine pixel position and intensity of all atoms
77
- ###
78
- atoms = []
79
- for i in range(len(coordinates)):
80
- x, y = coordinates[i]
81
-
82
- if rr < x < image.shape[1] - rr and rr < y < image.shape[0] - rr:
83
- area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
84
- arr = area * mask
85
- atoms.append((x, y, rr, arr.sum(), arr.max()))
86
-
87
- print(' Detected ', len(atoms), ' atoms')
88
- atoms.sort()
89
- return atoms
90
-
91
-
92
- def atoms_clustering(atoms, mid_atoms, number_of_clusters=3, nearest_neighbours=7):
93
- """
94
- KMeans clustering of atoms according to nearest neighbour distances
95
-
96
- Input:
97
- atoms: (nx2) numpy array or list of floats with atom positions
98
- mid-atoms: list of indices of atoms not at rim
99
- Optional:
100
- number_of_clusters: number of output clusters (default=3)
101
- nearest_neighbours: number of nearest neighbours to be considered (default=7)
102
- """
103
- # get distances
104
- nn_tree = cKDTree(np.array(atoms)[:, 0:2])
105
-
106
- distances, indices = nn_tree.query(np.array(mid_atoms)[:, 0:2], nearest_neighbours)
107
-
108
- # Clustering
109
- k_means = KMeans(n_clusters=number_of_clusters, random_state=0) # Fixing the RNG in kmeans
110
- k_means.fit(distances)
111
- clusters = k_means.predict(distances)
112
- return clusters, distances, indices
113
-
114
-
115
- def gauss_difference(params, area):
116
- """
117
- difference between Gaussian and area in image
118
-
119
- used in atom_refine function
120
- """
121
- gauss = make_gauss(area.shape[0], area.shape[1], width=params[0], x0=params[1], y0=params[2], intensity=params[3])
122
- return (area - gauss).flatten()
123
-
124
-
125
- def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
126
- """
127
- fits a Gaussian in a blob
128
- """
129
- rr = int(radius + 0.5) # atom radius
130
- print('using radius ', rr, 'pixels')
131
-
132
- pixels = np.linspace(0, 2 * rr, 2 * rr + 1) - rr
133
- x, y = np.meshgrid(pixels, pixels)
134
- mask = (x ** 2 + y ** 2) < rr ** 2
135
-
136
- guess = [rr * 2, 0.0, 0.0, 1]
137
-
138
- sym = {'number_of_atoms': len(atoms)}
139
-
140
- volume = []
141
- position = []
142
- intensities = []
143
- maximum_area = []
144
- new_atoms = []
145
- gauss_width = []
146
- gauss_amplitude = []
147
- gauss_intensity = []
148
- if QT_available:
149
- progress = pyTEMlib.sidpy_tools.ProgressDialog("Refine Atom Positions", len(atoms))
150
-
151
- done = 0
152
- for i in range(len(atoms)):
153
- if QT_available:
154
- progress.set_value(i)
155
-
156
- else:
157
- if done < int((i + 1) / len(atoms) * 50):
158
- done = int((i + 1) / len(atoms) * 50)
159
- sys.stdout.write('\r')
160
- # progress output :
161
- sys.stdout.write("[%-50s] %d%%" % ('=' * done, 2 * done))
162
- sys.stdout.flush()
163
-
164
- x, y = atoms[i][0:2]
165
- x = int(x)
166
- y = int(y)
167
-
168
- area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
169
-
170
- append = False
171
-
172
- if (x - rr) < 0 or y - rr < 0 or x + rr + 1 > image.shape[0] or y + rr + 1 > image.shape[1]:
173
- position.append(-1)
174
- intensities.append(0)
175
- maximum_area.append(0)
176
- else:
177
- position.append(1)
178
- intensities.append((area * mask).sum())
179
- maximum_area.append((area * mask).max())
180
-
181
- if max_int > 0:
182
- if area.sum() < max_int:
183
- if area.sum() > min_int:
184
- append = True
185
- elif area.sum() > min_int:
186
- append = True
187
-
188
- pout = [0, 0, 0, 0]
189
- if append:
190
- if (x - rr) < 0 or y - rr < 0 or x + rr + 1 > image.shape[0] or y + rr + 1 > image.shape[1]:
191
- pass
192
- else:
193
- [pout, _] = optimization.leastsq(gauss_difference, np.array(guess), args=area)
194
-
195
- if (abs(pout[1]) > max_dist) or (abs(pout[2]) > max_dist):
196
- pout = [0, 0, 0, 0]
197
-
198
- volume.append(2 * np.pi * pout[3] * pout[0] * pout[0])
199
-
200
- new_atoms.append([x + pout[1], y + pout[2]]) # ,pout[0], volume)) #,pout[3]))
201
- if all(v == 0 for v in pout):
202
- gauss_intensity.append(0.)
203
- else:
204
- gauss = make_gauss(area.shape[0], area.shape[1], width=pout[0], x0=pout[1], y0=pout[2], intensity=pout[3])
205
- gauss_intensity.append((gauss * mask).sum())
206
- gauss_width.append(pout[0])
207
- gauss_amplitude.append(pout[3])
208
- if QT_available:
209
- progress.close()
210
-
211
- sym['inside'] = position
212
- sym['intensity_area'] = intensities
213
- sym['maximum_area'] = maximum_area
214
- sym['atoms'] = new_atoms
215
- sym['gauss_width'] = gauss_width
216
- sym['gauss_amplitude'] = gauss_amplitude
217
- sym['gauss_intensity'] = gauss_intensity
218
- sym['gauss_volume'] = volume
219
-
220
- return sym
221
-
222
-
223
- def intensity_area(image, atoms, radius=3):
224
- """
225
- Intensity of atoms
226
-
227
- Intensity of atoms in an image within a disk of radius
228
- """
229
-
230
- rr = int(radius + 0.5) # atom radius
231
- print('using radius ', rr, 'pixels')
232
-
233
- pixels = np.linspace(0, 2 * rr, 2 * rr + 1) - rr
234
- x, y = np.meshgrid(pixels, pixels)
235
- mask = (x ** 2 + y ** 2) < rr ** 2
236
- intensities = []
237
- for i in range(len(atoms)):
238
- x = int(atoms[i][1])
239
- y = int(atoms[i][0])
240
- area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
241
- if area.shape == mask.shape:
242
- intensities.append((area * mask).sum())
243
- else:
244
- intensities.append(-1)
245
- return intensities
1
+ """ Atom detection
2
+
3
+ All atom detection is done here
4
+ Everything is in unit of pixel!!
5
+
6
+ Author: Gerd Duscher
7
+
8
+ part of pyTEMlib
9
+
10
+ a pycroscopy package
11
+ """
12
+
13
+ import numpy as np
14
+ import sys
15
+
16
+ # from skimage.feature import peak_local_max
17
+ from skimage.feature import blob_log
18
+
19
+ from sklearn.cluster import KMeans
20
+ from scipy.spatial import cKDTree
21
+ import scipy.optimize as optimization
22
+
23
+ import pyTEMlib.probe_tools as probe_tools
24
+ import pyTEMlib.file_tools as ft
25
+ import sidpy
26
+ from tqdm.auto import trange
27
+
28
+
29
+ def find_atoms(image, atom_size=0.1, threshold=0.):
30
+ """ Find atoms is a simple wrapper for blob_log in skimage.feature
31
+
32
+ Parameters
33
+ ----------
34
+ image: sidpy.Dataset
35
+ the image to find atoms
36
+ atom_size: float
37
+ visible size of atom blob diameter in nm gives minimal distance between found blobs
38
+ threshold: float
39
+ threshold for blob finder; (usually between 0.001 and 1.0) for threshold <= 0 we use the RMS contrast
40
+
41
+ Returns
42
+ -------
43
+ atoms: numpy array(Nx3)
44
+ atoms positions and radius of blob
45
+ """
46
+
47
+ if not isinstance(image, sidpy.Dataset):
48
+ raise TypeError('We need a sidpy.Dataset')
49
+ if image.data_type.name != 'IMAGE':
50
+ raise TypeError('We need sidpy.Dataset of sidpy.Datatype: IMAGE')
51
+ if not isinstance(atom_size, (float, int)):
52
+ raise TypeError('atom_size parameter has to be a number')
53
+ if not isinstance(threshold, float):
54
+ raise TypeError('threshold parameter has to be a float number')
55
+
56
+ scale_x = ft.get_slope(image.dim_0)
57
+ im = np.array(image-image.min())
58
+ im = im/im.max()
59
+ if threshold <= 0.:
60
+ threshold = np.std(im)
61
+ atoms = blob_log(im, max_sigma=atom_size/scale_x, threshold=threshold)
62
+
63
+ return atoms
64
+
65
+
66
+ def atoms_clustering(atoms, mid_atoms, number_of_clusters=3, nearest_neighbours=7):
67
+ """ A wrapper for sklearn.cluster kmeans clustering of atoms.
68
+
69
+ Parameters
70
+ ----------
71
+ atoms: list or np.array (Nx2)
72
+ list of all atoms
73
+ mid_atoms: list or np.array (Nx2)
74
+ atoms to be evaluated
75
+ number_of_clusters: int
76
+ number of clusters to sort (ini=3)
77
+ nearest_neighbours: int
78
+ number of nearest neighbours evaluated
79
+
80
+ Returns
81
+ -------
82
+ clusters, distances, indices: numpy arrays
83
+ """
84
+
85
+ # get distances
86
+ nn_tree = cKDTree(np.array(atoms)[:, 0:2])
87
+
88
+ distances, indices = nn_tree.query(np.array(mid_atoms)[:, 0:2], nearest_neighbours)
89
+
90
+ # Clustering
91
+ k_means = KMeans(n_clusters=number_of_clusters, random_state=0) # Fixing the RNG in kmeans
92
+ k_means.fit(distances)
93
+ clusters = k_means.predict(distances)
94
+
95
+ return clusters, distances, indices
96
+
97
+
98
+ def gauss_difference(params, area):
99
+ """
100
+ Difference between part of an image and a Gaussian
101
+ This function is used int he atom refine function of pyTEMlib
102
+
103
+ Parameters
104
+ ----------
105
+ params: list
106
+ list of Gaussian parameters [width, position_x, position_y, intensity]
107
+ area: numpy array
108
+ 2D matrix = part of an image
109
+
110
+ Returns
111
+ -------
112
+ numpy array: flattened array of difference
113
+
114
+ """
115
+ gauss = probe_tools.make_gauss(area.shape[0], area.shape[1], width=params[0], x0=params[1], y0=params[2],
116
+ intensity=params[3])
117
+ return (area - gauss).flatten()
118
+
119
+
120
+ def atom_refine(image, atoms, radius, max_int=0, min_int=0, max_dist=4):
121
+ """Fits a Gaussian in a blob of an image
122
+
123
+ Parameters
124
+ ----------
125
+ image: np.array or sidpy Dataset
126
+ atoms: list or np.array
127
+ positions of atoms
128
+ radius: float
129
+ radius of circular mask to define fitting of Gaussian
130
+ max_int: float
131
+ optional - maximum intensity to be considered for fitting (to exclude contaminated areas for example)
132
+ min_int: float
133
+ optional - minimum intensity to be considered for fitting (to exclude contaminated holes for example)
134
+ max_dist: float
135
+ optional - maximum distance of movement of Gaussian during fitting
136
+
137
+ Returns
138
+ -------
139
+ sym: dict
140
+ dictionary containing new atom positions and other output such as intensity of the fitted Gaussian
141
+ """
142
+ rr = int(radius + 0.5) # atom radius
143
+ print('using radius ', rr, 'pixels')
144
+
145
+ pixels = np.linspace(0, 2 * rr, 2 * rr + 1) - rr
146
+ x, y = np.meshgrid(pixels, pixels)
147
+ mask = (x ** 2 + y ** 2) < rr ** 2
148
+
149
+ guess = [rr * 2, 0.0, 0.0, 1]
150
+
151
+ sym = {'number_of_atoms': len(atoms)}
152
+
153
+ volume = []
154
+ position = []
155
+ intensities = []
156
+ maximum_area = []
157
+ new_atoms = []
158
+ gauss_width = []
159
+ gauss_amplitude = []
160
+ gauss_intensity = []
161
+
162
+ for i in trange(len(atoms)):
163
+ x, y = atoms[i][0:2]
164
+ x = int(x)
165
+ y = int(y)
166
+
167
+ area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
168
+
169
+ append = False
170
+
171
+ if (x - rr) < 0 or y - rr < 0 or x + rr + 1 > image.shape[0] or y + rr + 1 > image.shape[1]: # atom not found
172
+ position.append(-1)
173
+ intensities.append(-1.)
174
+ maximum_area.append(-1.)
175
+ else: # atom found
176
+ position.append(1)
177
+ intensities.append((area * mask).sum())
178
+ maximum_area.append((area * mask).max())
179
+
180
+ if max_int > 0:
181
+ if area.sum() < max_int:
182
+ if area.sum() > min_int:
183
+ append = True
184
+ elif area.sum() > min_int:
185
+ append = True
186
+
187
+ pout = [0, 0, 0, 0]
188
+ if append:
189
+ if (x - rr) < 0 or y - rr < 0 or x + rr + 1 > image.shape[0] or y + rr + 1 > image.shape[1]:
190
+ pass
191
+ else:
192
+ [pout, _] = optimization.leastsq(gauss_difference, guess, args=area)
193
+
194
+ if (abs(pout[1]) > max_dist) or (abs(pout[2]) > max_dist):
195
+ pout = [0, 0, 0, 0]
196
+
197
+ volume.append(2 * np.pi * pout[3] * pout[0] * pout[0])
198
+
199
+ new_atoms.append([x + pout[1], y + pout[2]]) # ,pout[0], volume)) #,pout[3]))
200
+ if all(v == 0 for v in pout):
201
+ gauss_intensity.append(0.)
202
+ else:
203
+ gauss = probe_tools.make_gauss(area.shape[0], area.shape[1], width=pout[0], x0=pout[1], y0=pout[2],
204
+ intensity=pout[3])
205
+ gauss_intensity.append((gauss * mask).sum())
206
+ gauss_width.append(pout[0])
207
+ gauss_amplitude.append(pout[3])
208
+
209
+ sym['inside'] = position
210
+ sym['intensity_area'] = intensities
211
+ sym['maximum_area'] = maximum_area
212
+ sym['atoms'] = new_atoms
213
+ sym['gauss_width'] = gauss_width
214
+ sym['gauss_amplitude'] = gauss_amplitude
215
+ sym['gauss_intensity'] = gauss_intensity
216
+ sym['gauss_volume'] = volume
217
+
218
+ return sym
219
+
220
+
221
+ def intensity_area(image, atoms, radius):
222
+ """
223
+ integrated intensity of atoms in an image with a mask around each atom of radius radius
224
+ """
225
+ rr = int(radius + 0.5) # atom radius
226
+ print('using radius ', rr, 'pixels')
227
+
228
+ pixels = np.linspace(0, 2 * rr, 2 * rr + 1) - rr
229
+ x, y = np.meshgrid(pixels, pixels)
230
+ mask = np.array((x ** 2 + y ** 2) < rr ** 2)
231
+ intensities = []
232
+ for i in range(len(atoms)):
233
+ x = int(atoms[i][1])
234
+ y = int(atoms[i][0])
235
+ area = image[x - rr:x + rr + 1, y - rr:y + rr + 1]
236
+ if area.shape == mask.shape:
237
+ intensities.append((area * mask).sum())
238
+ else:
239
+ intensities.append(-1)
240
+ return intensities
pyTEMlib/config_dir.py CHANGED
@@ -1,33 +1,57 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Provides access to the configuration directory of pyTEMlib
4
- """
5
-
6
- # Gleaned from
7
- # Copyright © 2007 Francisco Javier de la Peña
8
- # file of EELSLab.
9
- #
10
-
11
- import os
12
- import shutil
13
-
14
- config_files = ['TEMlibrc', 'microscopes.csv', 'edges_db.csv', 'edges_db.pkl', 'fparam.txt']
15
- data_path = os.sep.join([os.path.dirname(__file__), 'data'])
16
-
17
- if os.name == 'posix':
18
- config_path = os.path.join(os.path.expanduser('~'), '.TEMlib')
19
- os_name = 'posix'
20
- elif os.name in ['nt', 'dos']:
21
- config_path = os.path.join(os.path.expanduser('~'), '.TEMlib')
22
- os_name = 'windows'
23
- else:
24
- config_path = '.'
25
- if os.path.isdir(config_path) is False:
26
- # messages.information("Creating config directory: %s" % config_path)
27
- os.mkdir(config_path)
28
-
29
- for file in config_files:
30
- templates_file = os.path.join(data_path, file)
31
- config_file = os.path.join(config_path, file)
32
- if os.path.isfile(config_file) is False:
33
- shutil.copy(templates_file, config_file)
1
+ # -*- coding: utf-8 -*-
2
+ # part of pyTEMlib
3
+ # 2022/08 Changed this to be hopefully compatible with conda-forge
4
+ #
5
+ #
6
+ """
7
+ config_dir: setup of directory ~/.pyTEMlib for custom sources and database
8
+ """
9
+ import os
10
+
11
+ # import wget
12
+ if os.name == 'posix':
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
+ else:
19
+ config_path = '.'
20
+
21
+ if os.path.isdir(config_path) is False:
22
+ # messages.information("Creating config directory: %s" % config_path)
23
+ os.mkdir(config_path)
24
+
25
+ lines = ['Microscope,E0,alpha,beta,pppc,correlation_factor,VOA_conv,EELS_b1,EELS_b2,EELS_b100,MADF_offset,MADF_slope,'
26
+ 'HADF_offset,HADF_slope,BF_offset,BF_slope',
27
+ 'Libra 200,2.00E+05,10,15,1,1,6241509.647,0.0634,0.0634,0.0634,0,0,0,0,0,0',
28
+ 'UltraSTEM 60,6.00E+04,30,50,1,1,1.79E+07,0.2,0.45,0.9,0.001383,4.04E-06,0,0,0,0',
29
+ 'UltraSTEM 100,1.00E+05,30,50,1,1,6.24E+06,0.45,1,2,0,0,0,0,0,0',
30
+ 'UltraSTEM 200,2.00E+05,30,50,1,1,6.24E+06,0.45,1,2,0,0,0,0,0,0']
31
+
32
+ config_file = os.path.join(config_path, 'microscopes.csv')
33
+ if os.path.isfile(config_file) is False: # Do not overwrite users microscopy files
34
+ with open(config_file, 'w') as f:
35
+ 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
+ """