pyTEMlib 0.2020.11.1__py3-none-any.whl → 0.2024.9.0__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.9.0.dist-info}/LICENSE +21 -21
  33. pyTEMlib-0.2024.9.0.dist-info/METADATA +92 -0
  34. pyTEMlib-0.2024.9.0.dist-info/RECORD +37 -0
  35. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.dist-info}/WHEEL +5 -5
  36. {pyTEMlib-0.2020.11.1.dist-info → pyTEMlib-0.2024.9.0.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.9.0.dist-info}/top_level.txt +0 -0
pyTEMlib/dm3_reader.py DELETED
@@ -1,613 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: iso-8859-1 -*-
3
- """
4
- Python class for reading GATAN DM3 (DigitalMicrograph) files
5
-
6
- will move to Scope Reader in pycroscopy
7
- """
8
- ################################################################################
9
- # Python class for reading GATAN DM3 (DigitalMicrograph) files
10
- # and extracting all metadata
11
- # --
12
- # tested on EELS spectra, spectrum images and single-image files and image-stacks
13
- # --
14
- # based on the DM3_Reader plug-in (v 1.3.4) for ImageJ by Greg Jefferis <jefferis@stanford.edu>
15
- # http://rsb.info.nih.gov/ij/plugins/DM3_Reader.html
16
- # --
17
- # Python adaptation: Pierre-Ivan Raynal <raynal@med.univ-tours.fr>
18
- # http://microscopies.med.univ-tours.fr/
19
- #
20
- # Extended for EELS support by Gerd Duscher, UTK 2012
21
- # Rewritten for integration of sidpy 2020
22
- #
23
- # Works for python 3
24
- #
25
- ################################################################################
26
- from __future__ import division, print_function, absolute_import, unicode_literals
27
-
28
- import struct
29
- import time
30
- import numpy
31
-
32
- import sys
33
- import numpy as np
34
- import os
35
-
36
- import sidpy
37
-
38
- version = '0.1beta'
39
-
40
- debugLevel = 0 # 0=none, 1-3=basic, 4-5=simple, 6-10 verbose
41
-
42
- if sys.version_info.major == 3:
43
- unicode = str
44
-
45
-
46
- # ### utility functions ###
47
-
48
- # ## binary data reading functions ###
49
-
50
-
51
- def read_long(f):
52
- """Read 4 bytes as integer in file f"""
53
- read_bytes = f.read(4)
54
- return struct.unpack('>l', read_bytes)[0]
55
-
56
-
57
- def read_64_long(f):
58
- read_bytes = f.read(8)
59
- return struct.unpack('>Q', read_bytes)[0]
60
-
61
-
62
- def read_short(f):
63
- """Read 2 bytes as integer in file f"""
64
- read_bytes = f.read(2)
65
- return struct.unpack('>h', read_bytes)[0]
66
-
67
-
68
- def read_byte(f):
69
- """Read 1 byte as integer in file f"""
70
- read_bytes = f.read(1)
71
- return struct.unpack('>b', read_bytes)[0]
72
-
73
-
74
- def read_bool(f):
75
- """Read 1 byte as boolean in file f"""
76
- read_val = read_byte(f)
77
- return read_val != 0
78
-
79
-
80
- def read_char(f):
81
- """Read 1 byte as char in file f"""
82
- read_bytes = f.read(1)
83
- return struct.unpack('c', read_bytes)[0]
84
-
85
-
86
- def read_string(f, length=1):
87
- """Read len bytes as a string in file f"""
88
- read_bytes = f.read(length)
89
- str_fmt = '>' + str(length) + 's'
90
- return struct.unpack(str_fmt, read_bytes)[0]
91
-
92
-
93
- def read_le_short(f):
94
- """Read 2 bytes as *little endian* integer in file f"""
95
- read_bytes = f.read(2)
96
- return struct.unpack('<h', read_bytes)[0]
97
-
98
-
99
- def read_le_long(f):
100
- """Read 4 bytes as *little endian* integer in file f"""
101
- read_bytes = f.read(4)
102
- return struct.unpack('<l', read_bytes)[0]
103
-
104
-
105
- def read_leu_short(f):
106
- """Read 2 bytes as *little endian* unsigned integer in file f"""
107
- read_bytes = f.read(2)
108
- return struct.unpack('<H', read_bytes)[0]
109
-
110
-
111
- def read_leu_long(f):
112
- """Read 4 bytes as *little endian* unsigned integer in file f"""
113
- read_bytes = f.read(4)
114
- return struct.unpack('<L', read_bytes)[0]
115
-
116
-
117
- def read_le_float(f):
118
- """Read 4 bytes as *little endian* float in file f"""
119
- read_bytes = f.read(4)
120
- return struct.unpack('<f', read_bytes)[0]
121
-
122
-
123
- def read_le_double(f):
124
- """Read 8 bytes as *little endian* double in file f"""
125
- read_bytes = f.read(8)
126
- return struct.unpack('<d', read_bytes)[0]
127
-
128
-
129
- # constants for encoded data types ##
130
- SHORT = 2
131
- LONG = 3
132
- USHORT = 4
133
- ULONG = 5
134
- FLOAT = 6
135
- DOUBLE = 7
136
- BOOLEAN = 8
137
- CHAR = 9
138
- OCTET = 10
139
- STRUCT = 15
140
- STRING = 18
141
- ARRAY = 20
142
-
143
- # - association data type <--> reading function
144
- readFunc = {
145
- SHORT: read_le_short,
146
- LONG: read_le_long,
147
- USHORT: read_leu_short,
148
- ULONG: read_leu_long,
149
- FLOAT: read_le_float,
150
- DOUBLE: read_le_double,
151
- BOOLEAN: read_bool,
152
- CHAR: read_char,
153
- OCTET: read_char, # difference with char???
154
- }
155
-
156
- # other constants ##
157
- IMGLIST = "root.ImageList."
158
- OBJLIST = "root.DocumentObjectList."
159
- MAXDEPTH = 64
160
-
161
-
162
- # END constants ##
163
-
164
- class DM3Reader(sidpy.Reader):
165
- debugLevel = -1
166
-
167
- """
168
- file_path: filepath to dm3 file.
169
-
170
- warn('This Reader will eventually be moved to the ScopeReaders package'
171
- '. Be prepared to change your import statements',
172
- FutureWarning)
173
- """
174
-
175
- def __init__(self, file_path, verbose=False):
176
- super().__init__(file_path)
177
-
178
- # initialize variables ##
179
- self.verbose = verbose
180
- self.__filename = file_path
181
- self.__chosen_image = -1
182
-
183
- # - open file for reading
184
- try:
185
- self.__f = open(self.__filename, 'rb')
186
- except FileNotFoundError:
187
- raise FileNotFoundError('File not found')
188
-
189
- # - create Tags repositories
190
- self.__stored_tags = {'DM': {}}
191
-
192
- # check if this is valid DM3 file
193
- is_dm = True
194
- # read header (first 3 4-byte int)
195
- # get version
196
- file_version = read_long(self.__f)
197
-
198
- # get indicated file size
199
- if file_version == 3:
200
- file_size = read_long(self.__f)
201
- elif file_version == 4:
202
- file_size = read_64_long(self.__f)
203
- else:
204
- is_dm = False
205
- # get byte-ordering
206
- le = read_long(self.__f)
207
- little_endian = (le == 1)
208
-
209
- if little_endian:
210
- self.endian_str = '>'
211
- else:
212
- self.endian_str = '<'
213
-
214
- # check file header, raise Exception if not DM3
215
- if not is_dm:
216
- raise TypeError("%s does not appear to be a DM3 or DM4 file." % os.path.split(self.__filename)[1])
217
- elif self.verbose:
218
- print("%s appears to be a DM3 file" % self.__filename)
219
- self.file_version = file_version
220
- self.file_size = file_size
221
-
222
- if self.verbose:
223
- print("Header info.:")
224
- print("- file version:", file_version)
225
- print("- le:", le)
226
- print("- file size:", file_size, "bytes")
227
-
228
- # don't read but close file
229
- self.__f.close()
230
-
231
- def read(self):
232
- try:
233
- self.__f = open(self.__filename, 'rb')
234
- except FileNotFoundError:
235
- raise FileNotFoundError('File not found')
236
-
237
- t1 = time.time()
238
- file_version = read_long(self.__f)
239
-
240
- # get indicated file size
241
- if file_version == 3:
242
- file_size = read_long(self.__f)
243
- elif file_version == 4:
244
- file_size = read_64_long(self.__f)
245
- else:
246
- is_dm = False
247
- # get byte-ordering
248
- le = read_long(self.__f)
249
- little_endian = (le == 1)
250
-
251
- if little_endian:
252
- self.endian_str = '>'
253
- else:
254
- self.endian_str = '<'
255
-
256
- # ... then read it
257
-
258
- self.__stored_tags = {'DM': {'file_version': file_version, 'file_size': file_size}}
259
-
260
- self.__read_tag_group(self.__stored_tags)
261
-
262
- if self.verbose:
263
- print("-- %s Tags read --" % len(self.__stored_tags))
264
-
265
- if self.verbose:
266
- t2 = time.time()
267
- print("| parse DM3 file: %.3g s" % (t2 - t1))
268
-
269
- path, file_name = os.path.split(self.__filename)
270
- basename, extension = os.path.splitext(file_name)
271
-
272
- dataset = sidpy.Dataset.from_array(self.data_cube, name=basename)
273
- self.__stored_tags['DM']['chosen_image'] = self.__chosen_image
274
- dataset.original_metadata = self.get_tags()
275
-
276
- dataset.quantity = 'intensity'
277
- dataset.units = 'counts'
278
-
279
- self.set_dimensions(dataset)
280
- self.set_data_type(dataset)
281
-
282
- dataset.title = basename
283
- dataset.modality = 'generic'
284
- dataset.source = 'DM3Reader'
285
- dataset.original_metadata['DM']['full_file_name'] = self.__filename
286
-
287
- return dataset
288
-
289
- def set_data_type(self, dataset):
290
- spectral_dim = False
291
- # print(dataset._axes)
292
- for dim, axis in dataset._axes.items():
293
- if axis.dimension_type == sidpy.DimensionTypes.SPECTRAL:
294
- spectral_dim = True
295
-
296
- dataset.data_type = 'unknown'
297
- if 'ImageTags' in dataset.original_metadata['ImageList'][str(self.__chosen_image)]:
298
- image_tags = dataset.original_metadata['ImageList'][str(self.__chosen_image)]['ImageTags']
299
- if 'SI' in image_tags:
300
- if len(dataset.shape) == 3:
301
- dataset.data_type = sidpy.DataTypes.SPECTRAL_IMAGE
302
- else:
303
- if spectral_dim:
304
- dataset.data_type = sidpy.DataTypes.SPECTRAL_IMAGE # 'linescan'
305
- else:
306
- dataset.data_type = sidpy.DataTypes.IMAGE
307
- dataset.metadata['image_type'] = 'survey image'
308
-
309
- if dataset.data_type == sidpy.DataTypes.UNKNOWN:
310
- if len(dataset.shape) > 3:
311
- raise NotImplementedError('Data_type not implemented yet')
312
- elif len(dataset.shape) == 3:
313
- if spectral_dim:
314
- dataset.data_type = sidpy.DataTypes.SPECTRAL_IMAGE
315
- else:
316
- dataset.data_type = 'image_stack'
317
- elif len(dataset.shape) == 2:
318
- if spectral_dim:
319
- dataset.data_type = sidpy.DataTypes.SPECTRAL_IMAGE
320
- else:
321
- dataset.data_type = 'image'
322
- elif len(dataset.shape) == 1:
323
- if spectral_dim:
324
- dataset.data_type = sidpy.DataTypes.SPECTRUM
325
- else:
326
- dataset.data_type = sidpy.DataTypes.LINE_PLOT
327
-
328
- def set_dimensions(self, dataset):
329
- dimensions_dict = dataset.original_metadata['ImageList'][str(self.__chosen_image)]['ImageData']['Calibrations'][
330
- 'Dimension']
331
-
332
- reciprocal_name = 'u'
333
- spatial_name = 'x'
334
-
335
- for dim, dimension_tags in dimensions_dict.items():
336
- # Fix annoying scale of spectrum_images in Zeiss and SEM images
337
- if dimension_tags['Units'] == '�m':
338
- dimension_tags['Units'] = 'nm'
339
- dimension_tags['Scale'] *= 1000.0
340
-
341
- if dimension_tags['Units'].strip() == '':
342
- units = 'counts'
343
- else:
344
- units = dimension_tags['Units']
345
-
346
- values = (np.arange(dataset.shape[int(dim)]) - dimension_tags['Origin']) * dimension_tags['Scale']
347
-
348
- if 'eV' == units:
349
- dataset.set_dimension(int(dim), sidpy.Dimension(values, name='energy_loss', units=units,
350
- quantity='energy-loss',
351
- dimension_type=sidpy.DimensionTypes.SPECTRAL))
352
- elif 'eV' in units:
353
- dataset.set_dimension(int(dim), sidpy.Dimension(values, name='energy', units=units,
354
- quantity='energy',
355
- dimension_type=sidpy.DimensionTypes.SPECTRAL))
356
- elif '1/' in units or units in ['mrad', 'rad']:
357
- dataset.set_dimension(int(dim), sidpy.Dimension(values, name=reciprocal_name, units=units,
358
- quantity='reciprocal distance',
359
- dimension_type=sidpy.DimensionTypes.RECIPROCAL))
360
- reciprocal_name = chr(ord(reciprocal_name) + 1)
361
- else:
362
- units = 'counts'
363
- dataset.set_dimension(int(dim), sidpy.Dimension(values, name=spatial_name, units=units,
364
- quantity='distance',
365
- dimension_type=sidpy.DimensionTypes.SPATIAL))
366
- spatial_name = chr(ord(spatial_name) + 1)
367
-
368
- # utility functions
369
-
370
- def __read_tag_group(self, tags):
371
-
372
- g_sorted = read_byte(self.__f)
373
- # is the group open?
374
- opened = read_byte(self.__f)
375
- # number of Tags
376
- if self.file_version == 3:
377
- n_tags = read_long(self.__f)
378
- else:
379
- n_tags = read_64_long(self.__f)
380
-
381
- # read Tags
382
- for i in range(n_tags):
383
- data = read_byte(self.__f)
384
- is_data = (data == 21)
385
-
386
- len_tag_label = read_short(self.__f)
387
-
388
- if len_tag_label > 0:
389
- tag_label = self.__f.read(len_tag_label).decode('latin-1')
390
- else:
391
- tag_label = '0'
392
- for key in tags:
393
- if key.isdigit():
394
- tag_label = str(int(key) + 1)
395
- if is_data:
396
- value = self.__read_any_data()
397
- tags[tag_label] = value
398
- else:
399
- tags[tag_label] = {}
400
- self.__read_tag_group(tags[tag_label])
401
- return 1
402
-
403
- def __encoded_type_size(self, et):
404
- # returns the size in bytes of the data type
405
- if et == 0:
406
- width = 0
407
- elif et in (BOOLEAN, CHAR, OCTET):
408
- width = 1
409
- elif et in (SHORT, USHORT):
410
- width = 2
411
- elif et in (LONG, ULONG, FLOAT):
412
- width = 4
413
- elif et == DOUBLE:
414
- width = 8
415
- else:
416
- # returns -1 for unrecognised types
417
- width = -1
418
- return width
419
-
420
- def __read_any_data(self):
421
- if self.file_version == 4:
422
- tag_byte_length = struct.unpack_from('>Q', self.__f.read(8))[0]
423
- # DM4 specifies this property as always big endian
424
-
425
- delim = read_string(self.__f, 4)
426
- if delim != b"%%%%":
427
- raise Exception(hex(self.__f.tell()) + ": Tag Type delimiter not %%%%")
428
- if self.file_version == 4:
429
- n_in_tag = read_64_long(self.__f)
430
- else:
431
- n_in_tag = read_long(self.__f)
432
- # higher level function dispatching to handling data types to other functions
433
- # - get Type category (short, long, array...)
434
- if self.file_version == 4:
435
- encoded_type = read_64_long(self.__f)
436
- else:
437
- encoded_type = read_long(self.__f)
438
- # - calc size of encoded_type
439
- et_size = self.__encoded_type_size(encoded_type)
440
- if et_size > 0:
441
- data = self.__read_native_data(encoded_type, et_size)
442
- elif encoded_type == STRING:
443
- string_size = read_long(self.__f)
444
- data = self.__read_string_data(string_size)
445
- elif encoded_type == STRUCT:
446
- struct_types = self.__read_struct_types()
447
- data = self.__read_struct_data(struct_types)
448
- elif encoded_type == ARRAY:
449
- array_types = self.__read_array_types()
450
- data = self.__read_array_data(array_types)
451
- else:
452
- raise Exception("rAnD, " + hex(self.__f.tell()) + ": Can't understand encoded type")
453
- return data
454
-
455
- def __read_native_data(self, encoded_type, et_size):
456
- # reads ordinary data types
457
- if encoded_type in readFunc.keys():
458
- val = readFunc[encoded_type](self.__f)
459
- else:
460
- raise Exception("rND, " + hex(self.__f.tell()) + ": Unknown data type " + str(encoded_type))
461
- return val
462
-
463
- def __read_string_data(self, string_size):
464
- # reads string data
465
- if string_size <= 0:
466
- r_string = ""
467
- else:
468
- # !!! *Unicode* string (UTF-16)... convert to Python unicode str
469
- r_string = read_string(self.__f, string_size)
470
- r_string = str(r_string, "utf_16_le")
471
- return r_string
472
-
473
- def __read_array_types(self):
474
- # determines the data types in an array data type
475
- array_type = read_long(self.__f)
476
- item_types = []
477
- if array_type == STRUCT:
478
- item_types = self.__read_struct_types()
479
- elif array_type == ARRAY:
480
- item_types = self.__read_array_types()
481
- else:
482
- item_types.append(array_type)
483
- return item_types
484
-
485
- def __read_array_data(self, array_types):
486
- # reads array data
487
- array_size = read_long(self.__f)
488
- item_size = 0
489
- encoded_type = 0
490
- for i in range(len(array_types)):
491
- encoded_type = int(array_types[i])
492
- et_size = self.__encoded_type_size(encoded_type)
493
- item_size += et_size
494
- buf_size = array_size * item_size
495
-
496
- if len(array_types) == 1 and encoded_type == USHORT \
497
- and array_size < 256:
498
- # treat as string
499
- val = self.__read_string_data(buf_size)
500
- else:
501
- # treat as binary data
502
- # - store data size and offset as tags
503
- val = self.__f.read(buf_size)
504
- return val
505
-
506
- def __read_struct_types(self):
507
- # analyses data types in a struct
508
- if self.file_version == 4:
509
- struct_name_length = read_64_long(self.__f)
510
- n_fields = read_64_long(self.__f)
511
- else:
512
- struct_name_length = read_long(self.__f)
513
- n_fields = read_long(self.__f)
514
-
515
- field_types = []
516
- name_length = 0
517
- for i in range(n_fields):
518
- if self.file_version == 4:
519
- name_length = read_64_long(self.__f)
520
- field_type = read_64_long(self.__f)
521
- else:
522
- name_length = read_long(self.__f)
523
- field_type = read_long(self.__f)
524
- field_types.append(field_type)
525
- return field_types
526
-
527
- def __read_struct_data(self, struct_types):
528
- # reads struct data based on type info in structType
529
- data = []
530
- for i in range(len(struct_types)):
531
- encoded_type = struct_types[i]
532
- et_size = self.__encoded_type_size(encoded_type)
533
- # get data
534
- data.append(self.__read_native_data(encoded_type, et_size))
535
- return data
536
-
537
- # ## END utility functions ###
538
-
539
- def get_filename(self):
540
- return self.__filename
541
-
542
- filename = property(get_filename)
543
-
544
- def get_tags(self):
545
- return self.__stored_tags
546
-
547
- tags = property(get_tags)
548
-
549
- def get_raw(self):
550
- """Extracts data as np array"""
551
-
552
- # DataTypes for image data <--> PIL decoders
553
- data_types = {
554
- 1: '<u2', # 2 byte integer signed ("short")
555
- 2: '<f4', # 4 byte real (IEEE 754)
556
- 3: '<c8', # 8 byte complex (real, imaginary)
557
- 4: '', # ?
558
- # 4 byte packed complex (see below)
559
- 5: (numpy.int16, {'real': (numpy.int8, 0), 'imaginary': (numpy.int8, 1)}),
560
- 6: '<u1', # 1 byte integer unsigned ("byte")
561
- 7: '<i4', # 4 byte integer signed ("long")
562
- # I do not have any dm3 file with this format to test it.
563
- 8: '', # rgb view, 4 bytes/pixel, unused, red, green, blue?
564
- 9: '<i1', # byte integer signed
565
- 10: '<u2', # 2 byte integer unsigned
566
- 11: '<u4', # 4 byte integer unsigned
567
- 12: '<f8', # 8 byte real
568
- 13: '<c16', # byte complex
569
- 14: 'bool', # 1 byte binary (ie 0 or 1)
570
- # Packed RGB. It must be a recent addition to the format because it does
571
- # not appear in http://www.microscopy.cen.dtu.dk/~cbb/info/dmformat/
572
- 23: (numpy.float32,
573
- {'R': ('<u1', 0), 'G': ('<u1', 1), 'B': ('<u1', 2), 'A': ('<u1', 3)}),
574
- }
575
-
576
- # find main image
577
- for key in self.__stored_tags['ImageList']:
578
-
579
- if key.isdigit():
580
- if 'ImageData' in self.__stored_tags['ImageList'][key]:
581
- if 'Data' in self.__stored_tags['ImageList'][key]['ImageData'] \
582
- and 'DataType' in self.__stored_tags['ImageList'][key]['ImageData'] \
583
- and 'Dimensions' in self.__stored_tags['ImageList'][key]['ImageData']:
584
- if int(key) > self.__chosen_image:
585
- self.__chosen_image = int(key)
586
- if self.__chosen_image < 0:
587
- raise IOError('Did not find data in file')
588
-
589
- # get relevant Tags
590
- byte_data = self.__stored_tags['ImageList'][str(self.__chosen_image)]['ImageData']['Data']
591
- data_type = self.__stored_tags['ImageList'][str(self.__chosen_image)]['ImageData']['DataType']
592
- dimensions = self.__stored_tags['ImageList'][str(self.__chosen_image)]['ImageData']['Dimensions']
593
-
594
- # get shape from Dimensions
595
- shape = []
596
- for dim in dimensions:
597
- shape.append(dimensions[dim])
598
-
599
- # get data_type and reformat into numpy array
600
- dt = data_types[data_type]
601
- if dt == '':
602
- raise TypeError('The datatype is not supported')
603
- else:
604
- raw_data = numpy.frombuffer(byte_data, dtype=dt, count=numpy.cumprod(shape)[-1]).reshape(shape, order='F')
605
- # delete byte data in dictionary
606
- self.__stored_tags['ImageList'][str(self.__chosen_image)]['ImageData']['Data'] = 'read'
607
- return raw_data
608
-
609
- data_cube = property(get_raw)
610
-
611
-
612
- if __name__ == '__main__':
613
- pass # print "DM3lib v.%s"%version
pyTEMlib/edges_db.py DELETED
@@ -1,76 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Copyright © 2007 Francisco Javier de la Peña
3
- #
4
- # This file is part of EELSLab.
5
- #
6
- # EELSLab is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # EELSLab is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with EELSLab; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
- # USA
20
-
21
-
22
- import csv
23
- import os
24
-
25
- from pyTEMlib.config_dir import config_path
26
-
27
-
28
- file_path = os.path.join(config_path, 'edges_db.csv')
29
- #print file_path
30
- f = open(file_path, 'r')
31
- reader = csv.reader(f)
32
- edges_dict = {}
33
- for row in reader:
34
- twin_subshell = None
35
- element, subshell = row[0].split('.')
36
- Z = row[1]
37
- if (element in edges_dict) is not True :
38
- edges_dict[element]={}
39
- edges_dict[element]['subshells'] = {}
40
- edges_dict[element]['Z'] = Z
41
- if row[3] is not '':
42
- if subshell == "L3":
43
- twin_subshell = "L2"
44
- factor = 0.5
45
- if subshell == "M3":
46
- twin_subshell = "M2"
47
- factor = 0.5
48
- if subshell == "M5":
49
- twin_subshell = "M4"
50
- factor = 4/6.
51
- if subshell == "N3":
52
- twin_subshell = "N2"
53
- factor = 2/4.
54
- if subshell == "N5":
55
- twin_subshell = "N4"
56
- factor = 4/6.
57
- if subshell == "N7":
58
- twin_subshell = "N6"
59
- factor = 6/8.
60
- if subshell == "O5":
61
- twin_subshell = "O4"
62
- factor = 4/6.
63
-
64
- edges_dict[element]['subshells'][subshell] = {}
65
- edges_dict[element]['subshells'][subshell]['onset_energy'] = float(row[2])
66
- edges_dict[element]['subshells'][subshell]['filename'] = row[0]
67
- edges_dict[element]['subshells'][subshell]['relevance'] = row[4]
68
- edges_dict[element]['subshells'][subshell]['factor'] = 1
69
-
70
- if twin_subshell is not None :
71
- edges_dict[element]['subshells'][twin_subshell] = {}
72
- edges_dict[element]['subshells'][twin_subshell]['onset_energy'] = \
73
- float(row[3])
74
- edges_dict[element]['subshells'][twin_subshell]['filename'] = row[0]
75
- edges_dict[element]['subshells'][twin_subshell]['relevance'] = row[4]
76
- edges_dict[element]['subshells'][twin_subshell]['factor'] = factor