TemDataBrowser 1.0.6__tar.gz → 1.2__tar.gz

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.
@@ -2,6 +2,9 @@ name: Publish Python distribution to Pypi and testpypi
2
2
 
3
3
  on: push
4
4
 
5
+ env:
6
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
7
+
5
8
  jobs:
6
9
  build:
7
10
  name: Build distribution
@@ -0,0 +1,91 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # C extensions
8
+ *.c
9
+ *.o
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ pip-wheel-metadata/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Unit test / coverage reports
37
+ htmlcov/
38
+ .tox/
39
+ .nox/
40
+ .coverage
41
+ .coverage.*
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+ *.cover
46
+ *.py,cover
47
+ .hypothesis/
48
+ .pytest_cache/
49
+
50
+ # Jupyter Notebook
51
+ .ipynb_checkpoints
52
+ *.ipynb
53
+
54
+ # IPython
55
+ profile_default/
56
+ ipython_config.py
57
+
58
+ # pyenv
59
+ .python-version
60
+
61
+ # Virtual environments
62
+ venv/
63
+ ENV/
64
+ env/
65
+ .venv
66
+ env.bak/
67
+ venv.bak/
68
+
69
+ # IDEs and editors
70
+ .vscode/
71
+ .idea/
72
+ *.swp
73
+ *.swo
74
+ *~
75
+ .DS_Store
76
+ *.sublime-project
77
+ *.sublime-workspace
78
+
79
+ # mypy
80
+ .mypy_cache/
81
+ .dmypy.json
82
+ dmypy.json
83
+
84
+ # Environment variables
85
+ .env
86
+ .env.local
87
+ .env.*.local
88
+
89
+ # OS
90
+ Thumbs.db
91
+ .DS_Store
@@ -1,14 +1,14 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: TemDataBrowser
3
- Version: 1.0.6
3
+ Version: 1.2
4
4
  Summary: Graphical user interface to view transmission electron microscopy data.
5
5
  Author-email: Peter Ercius <percius@lbl.gov>
6
- Requires-Python: >=3.8
6
+ Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: numpy
9
9
  Requires-Dist: pyqtgraph
10
10
  Requires-Dist: ScopeFoundry>=1.5
11
- Requires-Dist: ncempy
11
+ Requires-Dist: ncempy>=1.15
12
12
  Requires-Dist: scipy
13
13
  Requires-Dist: imageio>2.17
14
14
 
@@ -1,7 +1,7 @@
1
- #from __future__ import division, print_function, absolute_import
2
-
1
+ from importlib.metadata import version
3
2
  from pathlib import Path
4
- from collections import OrderedDict
3
+
4
+ __version__ = version("TemDataBrowser")
5
5
  import functools
6
6
 
7
7
  from ScopeFoundry import BaseApp
@@ -10,8 +10,6 @@ from ScopeFoundry.data_browser import DataBrowser, DataBrowserView
10
10
  from qtpy import QtCore, QtWidgets, QtGui
11
11
  import pyqtgraph as pg
12
12
  import numpy as np
13
- from ScopeFoundry.logged_quantity import LQCollection
14
- import argparse
15
13
 
16
14
  import imageio.v3 as iio
17
15
  import ncempy
@@ -81,14 +79,18 @@ class TemView(DataBrowserView):
81
79
  """ A new file has been selected by the user, load and display it
82
80
  """
83
81
  try:
82
+ is_stemtomo = False
83
+ print(f'Loading {fname}...')
84
84
  if Path(fname).suffix.lower() == '.emd':
85
85
  # Check for special STEMTomo7 Berkeley EMD files
86
- is_stemtomo = False
87
- if Path(fname).suffix.lower() == '.emd':
86
+ try:
88
87
  with ncempy.io.emd.fileEMD(fname) as f0:
89
88
  if 'data' in f0.file_hdl:
90
89
  if 'stemtomo version' in f0.file_hdl['data'].attrs:
91
90
  is_stemtomo = True
91
+ except ncempy.io.emd.NoEmdDataSets:
92
+ # Velox files throw this error, they are not Berkeley EMD files
93
+ is_stemtomo = False
92
94
 
93
95
  file = ncempy.read(fname)
94
96
 
@@ -159,105 +161,26 @@ class TemMetadataView(DataBrowserView):
159
161
  @functools.lru_cache(maxsize=10, typed=False)
160
162
  def get_dm_metadata(fname):
161
163
  """ Reads important metadata from DM files"""
162
- metaData = {}
163
- with ncempy.io.dm.fileDM(fname, on_memory=True) as dm1:
164
- # Only keep the most useful tags as meta data
165
- for kk, ii in dm1.allTags.items():
166
- # Most useful starting tags
167
- prefix1 = 'ImageList.{}.ImageTags.'.format(dm1.numObjects)
168
- prefix2 = 'ImageList.{}.ImageData.'.format(dm1.numObjects)
169
- pos1 = kk.find(prefix1)
170
- pos2 = kk.find(prefix2)
171
- if pos1 > -1:
172
- sub = kk[pos1 + len(prefix1):]
173
- metaData[sub] = ii
174
- elif pos2 > -1:
175
- sub = kk[pos2 + len(prefix2):]
176
- metaData[sub] = ii
177
-
178
- # Remove unneeded keys
179
- for jj in list(metaData):
180
- if jj.find('frame sequence') > -1:
181
- del metaData[jj]
182
- elif jj.find('Private') > -1:
183
- del metaData[jj]
184
- elif jj.find('Reference Images') > -1:
185
- del metaData[jj]
186
- elif jj.find('Frame.Intensity') > -1:
187
- del metaData[jj]
188
- elif jj.find('Area.Transform') > -1:
189
- del metaData[jj]
190
- elif jj.find('Parameters.Objects') > -1:
191
- del metaData[jj]
192
- elif jj.find('Device.Parameters') > -1:
193
- del metaData[jj]
164
+ with ncempy.io.dm.fileDM(fname) as f:
165
+ meta_data = f.getMetadata(index=0)
194
166
 
195
- # Store the X and Y pixel size, offset and unit
196
- try:
197
- metaData['PhysicalSizeX'] = metaData['Calibrations.Dimension.1.Scale']
198
- metaData['PhysicalSizeXOrigin'] = metaData['Calibrations.Dimension.1.Origin']
199
- metaData['PhysicalSizeXUnit'] = metaData['Calibrations.Dimension.1.Units']
200
- metaData['PhysicalSizeY'] = metaData['Calibrations.Dimension.2.Scale']
201
- metaData['PhysicalSizeYOrigin'] = metaData['Calibrations.Dimension.2.Origin']
202
- metaData['PhysicalSizeYUnit'] = metaData['Calibrations.Dimension.2.Units']
203
- except:
204
- metaData['PhysicalSizeX'] = 1
205
- metaData['PhysicalSizeXOrigin'] = 0
206
- metaData['PhysicalSizeXUnit'] = ''
207
- metaData['PhysicalSizeY'] = 1
208
- metaData['PhysicalSizeYOrigin'] = 0
209
- metaData['PhysicalSizeYUnit'] = ''
210
-
211
- return metaData
167
+ return meta_data
212
168
 
213
169
  @staticmethod
214
170
  @functools.lru_cache(maxsize=10, typed=False)
215
171
  def get_mrc_metadata(path):
216
172
  """ Reads important metadata from MRC and related files."""
217
- metaData = {}
218
-
219
- # Open file and parse the header
220
- with ncempy.io.mrc.fileMRC(path) as mrc1:
221
- pass
222
-
223
- # Save most useful metaData
224
- metaData['axisOrientations'] = mrc1.axisOrientations # meta data information from the mrc header
225
- metaData['cellAngles'] = mrc1.cellAngles
226
-
227
- if hasattr(mrc1, 'FEIinfo'):
228
- # add in the special FEIinfo if it exists
229
- try:
230
- metaData.update(mrc1.FEIinfo)
231
- except TypeError:
232
- pass
233
-
234
- # Store the X and Y pixel size, offset and unit
235
- # Test for bad pixel sizes which happens often
236
- if mrc1.voxelSize[2] > 0:
237
- metaData['PhysicalSizeX'] = mrc1.voxelSize[2] * 1e-10 # change Angstroms to meters
238
- metaData['PhysicalSizeXOrigin'] = 0
239
- metaData['PhysicalSizeXUnit'] = 'm'
240
- else:
241
- metaData['PhysicalSizeX'] = 1
242
- metaData['PhysicalSizeXOrigin'] = 0
243
- metaData['PhysicalSizeXUnit'] = ''
244
- if mrc1.voxelSize[1] > 0:
245
- metaData['PhysicalSizeY'] = mrc1.voxelSize[1] * 1e-10 # change Angstroms to meters
246
- metaData['PhysicalSizeYOrigin'] = 0
247
- metaData['PhysicalSizeYUnit'] = 'm'
248
- else:
249
- metaData['PhysicalSizeY'] = 1
250
- metaData['PhysicalSizeYOrigin'] = 0
251
- metaData['PhysicalSizeYUnit'] = ''
252
-
253
- metaData['FileName'] = path
173
+ with ncempy.io.mrc.fileMRC(path) as f:
174
+ meta_data = f.getMetadata()
254
175
 
176
+ # Read tilt angles from .rawtlt file if it exists
255
177
  rawtltName = Path(path).with_suffix('.rawtlt')
256
178
  if rawtltName.exists():
257
179
  with open(rawtltName, 'r') as f1:
258
- tilts = map(float, f1)
259
- metaData['tilt angles'] = tilts
260
-
180
+ tilts = list(map(float, f1))
181
+ meta_data['tilt angles'] = tilts
182
+
183
+ # Read FEI parameters from .txt file if it exists
261
184
  FEIparameters = Path(path).with_suffix('.txt')
262
185
  if FEIparameters.exists():
263
186
  with open(FEIparameters, 'r') as f2:
@@ -269,114 +192,49 @@ class TemMetadataView(DataBrowserView):
269
192
  pp2[ll[0]] = float(ll[1])
270
193
  except:
271
194
  pass # skip lines with no data
272
- metaData.update(pp2)
195
+ meta_data.update(pp2)
273
196
 
274
- return metaData
197
+ return meta_data
275
198
 
276
199
  @staticmethod
277
200
  @functools.lru_cache(maxsize=10, typed=False)
278
201
  def get_emd_metadata(path):
279
202
  """ Reads important metadata from EMD Berkeley files."""
280
- metaData = {}
281
- with ncempy.io.emd.fileEMD(path) as emd0:
282
- try:
283
- metaData.update(emd0.user.attrs)
284
- except AttributeError:
285
- pass
286
- try:
287
- metaData.update(emd0.microscope.attrs)
288
- except AttributeError:
289
- pass
290
- try:
291
- metaData.update(emd0.sample.attrs)
292
- except AttributeError:
293
- pass
294
- dims = emd0.get_emddims(emd0.list_emds[0])
295
- dimX = dims[-1]
296
- dimY = dims[-2]
297
- metaData['PhysicalSizeX'] = dimX[0][1] - dimX[0][0]
298
- metaData['PhysicalSizeXOrigin'] = dimX[0][0]
299
- metaData['PhysicalSizeXUnit'] = dimX[2].replace('_', '')
300
- metaData['PhysicalSizeY'] = dimY[0][1] - dimY[0][0]
301
- metaData['PhysicalSizeYOrigin'] = dimY[0][0]
302
- metaData['PhysicalSizeYUnit'] = dimY[2].replace('_', '')
303
- return metaData
304
-
203
+ with ncempy.io.emd.fileEMD(path) as f:
204
+ meta_data = f.getMetadata(0) # 0 = index into f.list_data
205
+ return meta_data
305
206
 
306
207
  @staticmethod
307
208
  @functools.lru_cache(maxsize=10, typed=False)
308
209
  def get_velox_metadata(path):
309
210
  """ Reads important metadata from Velox EMD files."""
310
- import json
311
- metaData = {}
312
- with ncempy.io.emdVelox.fileEMDVelox(path) as f0:
313
- dataGroup = emd_obj.list_data[0]
314
- dataset0 = dataGroup['Data']
315
-
316
- # Convert JSON metadata to dict
317
- mData = emd_obj.list_data[0]['Metadata'][:, 0]
318
- validMetaDataIndex = npwhere(mData > 0) # find valid metadata
319
- mData = mData[validMetaDataIndex].tostring() # change to string
320
- mDataS = json.loads(mData.decode('utf-8', 'ignore')) # load UTF-8 string as JSON and output dict
321
- metaData['pixel sizes'] = []
322
- metaData['pixel units'] = []
323
- try:
324
- # Store the X and Y pixel size, offset and unit
325
- metaData['PhysicalSizeX'] = float(mDataS['BinaryResult']['PixelSize']['width'])
326
- metaData['PhysicalSizeXOrigin'] = float(mDataS['BinaryResult']['Offset']['x'])
327
- metaData['PhysicalSizeXUnit'] = mDataS['BinaryResult']['PixelUnitX']
328
- metaData['PhysicalSizeY'] = float(mDataS['BinaryResult']['PixelSize']['height'])
329
- metaData['PhysicalSizeYOrigin'] = float(mDataS['BinaryResult']['Offset']['y'])
330
- metaData['PhysicalSizeYUnit'] = mDataS['BinaryResult']['PixelUnitY']
331
- except:
332
- metaData['PhysicalSizeX'] = 1
333
- metaData['PhysicalSizeXOrigin'] = 0
334
- metaData['PhysicalSizeXUnit'] = ''
335
- metaData['PhysicalSizeY'] = 1
336
- metaData['PhysicalSizeYOrigin'] = 0
337
- metaData['PhysicalSizeYUnit'] = ''
211
+ with ncempy.io.emdVelox.fileEMDVelox(path) as f:
212
+ if f.list_data is None:
213
+ return None
214
+ meta_data = f.getMetadata(0) # 0 = index into f.list_data
215
+ return meta_data
338
216
 
339
- metaData.update(mDataS)
340
-
341
- metaData['shape'] = dataset0.shape
342
- return metaData
343
-
344
217
  @staticmethod
345
218
  @functools.lru_cache(maxsize=10, typed=False)
346
- def get_ser_metadata(fname):
347
- metaData = {}
348
- with ncempy.io.ser.fileSER(fname) as ser1:
349
- data, metaData = ser1.getDataset(0) # have to get 1 image and its meta data
350
-
351
- # Add extra meta data from the EMI file if it exists
352
- if ser1._emi is not None:
353
- metaData.update(ser1._emi)
219
+ def get_ser_metadata(path):
220
+ with ncempy.io.ser.fileSER(path) as f:
221
+ # Returns global metadata for the whole file
222
+ meta_data = f.getMetadata()
223
+
224
+ # Get additional metadata from the first dataset
225
+ _, extra_metadata = f.getDataset(0)
226
+ meta_data.update(extra_metadata)
354
227
 
355
- metaData.update(ser1.head) # some header data for the ser file
228
+ # Get the header information
229
+ meta_data.update(f.head)
356
230
 
357
231
  # Clean the dictionary
358
- for k, v in metaData.items():
232
+ for k, v in meta_data.items():
359
233
  if isinstance(v, bytes):
360
- metaData[k] = v.decode('UTF8')
234
+ meta_data[k] = v.decode('UTF8')
361
235
 
362
- # Store the X and Y pixel size, offset and unit
363
- try:
364
- metaData['PhysicalSizeX'] = metaData['Calibration'][0]['CalibrationDelta']
365
- metaData['PhysicalSizeXOrigin'] = metaData['Calibration'][0]['CalibrationOffset']
366
- metaData['PhysicalSizeXUnit'] = 'm' # always meters
367
- metaData['PhysicalSizeY'] = metaData['Calibration'][1]['CalibrationDelta']
368
- metaData['PhysicalSizeYOrigin'] = metaData['Calibration'][1]['CalibrationOffset']
369
- metaData['PhysicalSizeYUnit'] = 'm' # always meters
370
- except:
371
- metaData['PhysicalSizeX'] = 1
372
- metaData['PhysicalSizeXOrigin'] = 0
373
- metaData['PhysicalSizeXUnit'] = ''
374
- metaData['PhysicalSizeY'] = 1
375
- metaData['PhysicalSizeYOrigin'] = 0
376
- metaData['PhysicalSizeYUnit'] = ''
236
+ return meta_data
377
237
 
378
- return metaData
379
-
380
238
  @staticmethod
381
239
  @functools.lru_cache(maxsize=10, typed=False)
382
240
  def get_emi_metadata(fname):
@@ -385,13 +243,12 @@ class TemMetadataView(DataBrowserView):
385
243
  @staticmethod
386
244
  @functools.lru_cache(maxsize=10, typed=False)
387
245
  def get_img_metadata(fname):
388
- print(fname)
389
246
  with ncempy.io.smv.fileSMV(fname) as f0:
390
- md = f0.header_info
391
- return md
392
-
247
+ meta_data = f0.getMetadata()
248
+ return meta_data
249
+
393
250
  def on_change_data_filename(self, fname):
394
- ext = Path(fname).suffix
251
+ ext = Path(fname).suffix.lower()
395
252
 
396
253
  meta_data = {'file name': str(fname)}
397
254
  if ext in ('.dm3', '.dm4'):
@@ -399,11 +256,14 @@ class TemMetadataView(DataBrowserView):
399
256
  elif ext in ('.mrc', '.rec', '.ali'):
400
257
  meta_data = self.get_mrc_metadata(fname)
401
258
  elif ext in ('.emd',):
402
- with ncempy.io.emd.fileEMD(fname) as emd0:
403
- if len(emd0.list_emds) > 0:
404
- meta_data = self.get_emd_metadata(fname)
259
+ try:
260
+ meta_data = self.get_emd_metadata(fname)
261
+ except ncempy.io.emd.NoEmdDataSets:
262
+ velox_meta = self.get_velox_metadata(fname)
263
+ if velox_meta is not None:
264
+ meta_data = velox_meta
405
265
  else:
406
- meta_data = self.get_velox_metadata(fname)
266
+ meta_data = {'file name': str(fname), 'error': 'No EMD datasets found'}
407
267
  elif ext in ('.ser',):
408
268
  meta_data = self.get_ser_metadata(fname)
409
269
  elif ext in ('.emi',):
@@ -419,7 +279,7 @@ class TemMetadataView(DataBrowserView):
419
279
 
420
280
  def is_file_supported(self, fname):
421
281
  ext = Path(fname).suffix
422
- return ext.lower() in ('.dm3', '.dm4', '.mrc', '.ali', '.rec', '.ser', '.emi', '.img')
282
+ return ext.lower() in ('.dm3', '.dm4', '.mrc', '.ali', '.rec', '.ser', '.emi', '.img', '.emd')
423
283
 
424
284
  def open_file():
425
285
  """Start the graphical user interface from inside a python interpreter."""
@@ -1,14 +1,14 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: TemDataBrowser
3
- Version: 1.0.6
3
+ Version: 1.2
4
4
  Summary: Graphical user interface to view transmission electron microscopy data.
5
5
  Author-email: Peter Ercius <percius@lbl.gov>
6
- Requires-Python: >=3.8
6
+ Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: numpy
9
9
  Requires-Dist: pyqtgraph
10
10
  Requires-Dist: ScopeFoundry>=1.5
11
- Requires-Dist: ncempy
11
+ Requires-Dist: ncempy>=1.15
12
12
  Requires-Dist: scipy
13
13
  Requires-Dist: imageio>2.17
14
14
 
@@ -1,6 +1,6 @@
1
1
  numpy
2
2
  pyqtgraph
3
3
  ScopeFoundry>=1.5
4
- ncempy
4
+ ncempy>=1.15
5
5
  scipy
6
6
  imageio>2.17
@@ -7,9 +7,9 @@ name = "TemDataBrowser"
7
7
  authors = [{name = "Peter Ercius", email="percius@lbl.gov"}]
8
8
  description = "Graphical user interface to view transmission electron microscopy data."
9
9
  readme = "README.md"
10
- requires-python = ">=3.8"
11
- dependencies = ["numpy","pyqtgraph","ScopeFoundry>=1.5","ncempy","scipy","imageio>2.17"]
12
- version = "1.0.6"
10
+ requires-python = ">=3.10"
11
+ dependencies = ["numpy","pyqtgraph","ScopeFoundry>=1.5","ncempy>=1.15","scipy","imageio>2.17"]
12
+ version = "1.2"
13
13
 
14
14
  [project.scripts]
15
15
  TemDataBrowser = "TemDataBrowser:open_file"
@@ -1,3 +0,0 @@
1
- dist
2
- .ipynb_checkpoints
3
- *.egg-info
File without changes
File without changes