TemDataBrowser 1.1__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.
- {temdatabrowser-1.1 → temdatabrowser-1.2}/.github/workflows/publish-to-pypi.yml +3 -0
- {temdatabrowser-1.1/TemDataBrowser.egg-info → temdatabrowser-1.2}/PKG-INFO +1 -1
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser/__init__.py +48 -201
- {temdatabrowser-1.1 → temdatabrowser-1.2/TemDataBrowser.egg-info}/PKG-INFO +1 -1
- {temdatabrowser-1.1 → temdatabrowser-1.2}/pyproject.toml +1 -1
- {temdatabrowser-1.1 → temdatabrowser-1.2}/.gitignore +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/README.md +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser/images/TemDataBrowser_window.png +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser.egg-info/SOURCES.txt +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser.egg-info/dependency_links.txt +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser.egg-info/entry_points.txt +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser.egg-info/requires.txt +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/TemDataBrowser.egg-info/top_level.txt +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/run_TemDataBrowser.py +0 -0
- {temdatabrowser-1.1 → temdatabrowser-1.2}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
from importlib.metadata import version
|
|
3
2
|
from pathlib import Path
|
|
4
|
-
|
|
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
|
|
@@ -163,106 +161,26 @@ class TemMetadataView(DataBrowserView):
|
|
|
163
161
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
164
162
|
def get_dm_metadata(fname):
|
|
165
163
|
""" Reads important metadata from DM files"""
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
# Only keep the most useful tags as meta data
|
|
169
|
-
for kk, ii in dm1.allTags.items():
|
|
170
|
-
# Most useful starting tags
|
|
171
|
-
prefix1 = 'ImageList.{}.ImageTags.'.format(dm1.numObjects)
|
|
172
|
-
prefix2 = 'ImageList.{}.ImageData.'.format(dm1.numObjects)
|
|
173
|
-
pos1 = kk.find(prefix1)
|
|
174
|
-
pos2 = kk.find(prefix2)
|
|
175
|
-
if pos1 > -1:
|
|
176
|
-
sub = kk[pos1 + len(prefix1):]
|
|
177
|
-
metaData[sub] = ii
|
|
178
|
-
elif pos2 > -1:
|
|
179
|
-
sub = kk[pos2 + len(prefix2):]
|
|
180
|
-
metaData[sub] = ii
|
|
181
|
-
|
|
182
|
-
# Remove unneeded keys
|
|
183
|
-
for jj in list(metaData):
|
|
184
|
-
if jj.find('frame sequence') > -1:
|
|
185
|
-
del metaData[jj]
|
|
186
|
-
elif jj.find('Private') > -1:
|
|
187
|
-
del metaData[jj]
|
|
188
|
-
elif jj.find('Reference Images') > -1:
|
|
189
|
-
del metaData[jj]
|
|
190
|
-
elif jj.find('Frame.Intensity') > -1:
|
|
191
|
-
del metaData[jj]
|
|
192
|
-
elif jj.find('Area.Transform') > -1:
|
|
193
|
-
del metaData[jj]
|
|
194
|
-
elif jj.find('Parameters.Objects') > -1:
|
|
195
|
-
del metaData[jj]
|
|
196
|
-
elif jj.find('Device.Parameters') > -1:
|
|
197
|
-
del metaData[jj]
|
|
198
|
-
|
|
199
|
-
# Store the X and Y pixel size, offset and unit
|
|
200
|
-
try:
|
|
201
|
-
metaData['PhysicalSizeX'] = metaData['Calibrations.Dimension.1.Scale']
|
|
202
|
-
metaData['PhysicalSizeXOrigin'] = metaData['Calibrations.Dimension.1.Origin']
|
|
203
|
-
metaData['PhysicalSizeXUnit'] = metaData['Calibrations.Dimension.1.Units']
|
|
204
|
-
metaData['PhysicalSizeY'] = metaData['Calibrations.Dimension.2.Scale']
|
|
205
|
-
metaData['PhysicalSizeYOrigin'] = metaData['Calibrations.Dimension.2.Origin']
|
|
206
|
-
metaData['PhysicalSizeYUnit'] = metaData['Calibrations.Dimension.2.Units']
|
|
207
|
-
except:
|
|
208
|
-
metaData['PhysicalSizeX'] = 1
|
|
209
|
-
metaData['PhysicalSizeXOrigin'] = 0
|
|
210
|
-
metaData['PhysicalSizeXUnit'] = ''
|
|
211
|
-
metaData['PhysicalSizeY'] = 1
|
|
212
|
-
metaData['PhysicalSizeYOrigin'] = 0
|
|
213
|
-
metaData['PhysicalSizeYUnit'] = ''
|
|
164
|
+
with ncempy.io.dm.fileDM(fname) as f:
|
|
165
|
+
meta_data = f.getMetadata(index=0)
|
|
214
166
|
|
|
215
|
-
return
|
|
167
|
+
return meta_data
|
|
216
168
|
|
|
217
169
|
@staticmethod
|
|
218
170
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
219
171
|
def get_mrc_metadata(path):
|
|
220
172
|
""" Reads important metadata from MRC and related files."""
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
# Open file and parse the header
|
|
224
|
-
with ncempy.io.mrc.fileMRC(path) as mrc1:
|
|
225
|
-
pass
|
|
226
|
-
|
|
227
|
-
# Save most useful metaData
|
|
228
|
-
metaData['axisOrientations'] = mrc1.axisOrientations # meta data information from the mrc header
|
|
229
|
-
metaData['cellAngles'] = mrc1.cellAngles
|
|
230
|
-
|
|
231
|
-
if hasattr(mrc1, 'FEIinfo'):
|
|
232
|
-
# add in the special FEIinfo if it exists
|
|
233
|
-
try:
|
|
234
|
-
if isinstance(mrc1.FEIinfo, dict):
|
|
235
|
-
metaData.update(mrc1.FEIinfo)
|
|
236
|
-
except TypeError:
|
|
237
|
-
pass
|
|
238
|
-
|
|
239
|
-
# Store the X and Y pixel size, offset and unit
|
|
240
|
-
# Test for bad pixel sizes which happens often
|
|
241
|
-
if mrc1.voxelSize[2] > 0:
|
|
242
|
-
metaData['PhysicalSizeX'] = mrc1.voxelSize[2] * 1e-10 # change Angstroms to meters
|
|
243
|
-
metaData['PhysicalSizeXOrigin'] = 0
|
|
244
|
-
metaData['PhysicalSizeXUnit'] = 'm'
|
|
245
|
-
else:
|
|
246
|
-
metaData['PhysicalSizeX'] = 1
|
|
247
|
-
metaData['PhysicalSizeXOrigin'] = 0
|
|
248
|
-
metaData['PhysicalSizeXUnit'] = ''
|
|
249
|
-
if mrc1.voxelSize[1] > 0:
|
|
250
|
-
metaData['PhysicalSizeY'] = mrc1.voxelSize[1] * 1e-10 # change Angstroms to meters
|
|
251
|
-
metaData['PhysicalSizeYOrigin'] = 0
|
|
252
|
-
metaData['PhysicalSizeYUnit'] = 'm'
|
|
253
|
-
else:
|
|
254
|
-
metaData['PhysicalSizeY'] = 1
|
|
255
|
-
metaData['PhysicalSizeYOrigin'] = 0
|
|
256
|
-
metaData['PhysicalSizeYUnit'] = ''
|
|
257
|
-
|
|
258
|
-
metaData['FileName'] = path
|
|
173
|
+
with ncempy.io.mrc.fileMRC(path) as f:
|
|
174
|
+
meta_data = f.getMetadata()
|
|
259
175
|
|
|
176
|
+
# Read tilt angles from .rawtlt file if it exists
|
|
260
177
|
rawtltName = Path(path).with_suffix('.rawtlt')
|
|
261
178
|
if rawtltName.exists():
|
|
262
179
|
with open(rawtltName, 'r') as f1:
|
|
263
|
-
tilts = map(float, f1)
|
|
264
|
-
|
|
265
|
-
|
|
180
|
+
tilts = list(map(float, f1))
|
|
181
|
+
meta_data['tilt angles'] = tilts
|
|
182
|
+
|
|
183
|
+
# Read FEI parameters from .txt file if it exists
|
|
266
184
|
FEIparameters = Path(path).with_suffix('.txt')
|
|
267
185
|
if FEIparameters.exists():
|
|
268
186
|
with open(FEIparameters, 'r') as f2:
|
|
@@ -274,116 +192,49 @@ class TemMetadataView(DataBrowserView):
|
|
|
274
192
|
pp2[ll[0]] = float(ll[1])
|
|
275
193
|
except:
|
|
276
194
|
pass # skip lines with no data
|
|
277
|
-
|
|
195
|
+
meta_data.update(pp2)
|
|
278
196
|
|
|
279
|
-
return
|
|
197
|
+
return meta_data
|
|
280
198
|
|
|
281
199
|
@staticmethod
|
|
282
200
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
283
201
|
def get_emd_metadata(path):
|
|
284
202
|
""" Reads important metadata from EMD Berkeley files."""
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
metaData.update(emd0.user.attrs)
|
|
289
|
-
except AttributeError:
|
|
290
|
-
pass
|
|
291
|
-
try:
|
|
292
|
-
metaData.update(emd0.microscope.attrs)
|
|
293
|
-
except AttributeError:
|
|
294
|
-
pass
|
|
295
|
-
try:
|
|
296
|
-
metaData.update(emd0.sample.attrs)
|
|
297
|
-
except AttributeError:
|
|
298
|
-
pass
|
|
299
|
-
dims = emd0.get_emddims(emd0.list_emds[0])
|
|
300
|
-
dimX = dims[-1]
|
|
301
|
-
dimY = dims[-2]
|
|
302
|
-
metaData['PhysicalSizeX'] = dimX[0][1] - dimX[0][0]
|
|
303
|
-
metaData['PhysicalSizeXOrigin'] = dimX[0][0]
|
|
304
|
-
metaData['PhysicalSizeXUnit'] = dimX[2].replace('_', '')
|
|
305
|
-
metaData['PhysicalSizeY'] = dimY[0][1] - dimY[0][0]
|
|
306
|
-
metaData['PhysicalSizeYOrigin'] = dimY[0][0]
|
|
307
|
-
metaData['PhysicalSizeYUnit'] = dimY[2].replace('_', '')
|
|
308
|
-
return metaData
|
|
309
|
-
|
|
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
|
|
310
206
|
|
|
311
207
|
@staticmethod
|
|
312
208
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
313
209
|
def get_velox_metadata(path):
|
|
314
210
|
""" Reads important metadata from Velox EMD files."""
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
dataGroup = f0.list_data[0]
|
|
321
|
-
dataset0 = dataGroup['Data']
|
|
322
|
-
|
|
323
|
-
# Convert JSON metadata to dict
|
|
324
|
-
mData = f0.list_data[0]['Metadata'][:, 0]
|
|
325
|
-
validMetaDataIndex = np.where(mData > 0) # find valid metadata
|
|
326
|
-
mData = mData[validMetaDataIndex].tostring() # change to string
|
|
327
|
-
mDataS = json.loads(mData.decode('utf-8', 'ignore')) # load UTF-8 string as JSON and output dict
|
|
328
|
-
metaData['pixel sizes'] = []
|
|
329
|
-
metaData['pixel units'] = []
|
|
330
|
-
try:
|
|
331
|
-
# Store the X and Y pixel size, offset and unit
|
|
332
|
-
metaData['PhysicalSizeX'] = float(mDataS['BinaryResult']['PixelSize']['width'])
|
|
333
|
-
metaData['PhysicalSizeXOrigin'] = float(mDataS['BinaryResult']['Offset']['x'])
|
|
334
|
-
metaData['PhysicalSizeXUnit'] = mDataS['BinaryResult']['PixelUnitX']
|
|
335
|
-
metaData['PhysicalSizeY'] = float(mDataS['BinaryResult']['PixelSize']['height'])
|
|
336
|
-
metaData['PhysicalSizeYOrigin'] = float(mDataS['BinaryResult']['Offset']['y'])
|
|
337
|
-
metaData['PhysicalSizeYUnit'] = mDataS['BinaryResult']['PixelUnitY']
|
|
338
|
-
except:
|
|
339
|
-
metaData['PhysicalSizeX'] = 1
|
|
340
|
-
metaData['PhysicalSizeXOrigin'] = 0
|
|
341
|
-
metaData['PhysicalSizeXUnit'] = ''
|
|
342
|
-
metaData['PhysicalSizeY'] = 1
|
|
343
|
-
metaData['PhysicalSizeYOrigin'] = 0
|
|
344
|
-
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
|
|
345
216
|
|
|
346
|
-
metaData.update(mDataS)
|
|
347
|
-
|
|
348
|
-
metaData['shape'] = dataset0.shape
|
|
349
|
-
return metaData
|
|
350
|
-
|
|
351
217
|
@staticmethod
|
|
352
218
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
353
|
-
def get_ser_metadata(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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)
|
|
361
227
|
|
|
362
|
-
|
|
228
|
+
# Get the header information
|
|
229
|
+
meta_data.update(f.head)
|
|
363
230
|
|
|
364
231
|
# Clean the dictionary
|
|
365
|
-
for k, v in
|
|
232
|
+
for k, v in meta_data.items():
|
|
366
233
|
if isinstance(v, bytes):
|
|
367
|
-
|
|
234
|
+
meta_data[k] = v.decode('UTF8')
|
|
368
235
|
|
|
369
|
-
|
|
370
|
-
try:
|
|
371
|
-
metaData['PhysicalSizeX'] = metaData['Calibration'][0]['CalibrationDelta']
|
|
372
|
-
metaData['PhysicalSizeXOrigin'] = metaData['Calibration'][0]['CalibrationOffset']
|
|
373
|
-
metaData['PhysicalSizeXUnit'] = 'm' # always meters
|
|
374
|
-
metaData['PhysicalSizeY'] = metaData['Calibration'][1]['CalibrationDelta']
|
|
375
|
-
metaData['PhysicalSizeYOrigin'] = metaData['Calibration'][1]['CalibrationOffset']
|
|
376
|
-
metaData['PhysicalSizeYUnit'] = 'm' # always meters
|
|
377
|
-
except:
|
|
378
|
-
metaData['PhysicalSizeX'] = 1
|
|
379
|
-
metaData['PhysicalSizeXOrigin'] = 0
|
|
380
|
-
metaData['PhysicalSizeXUnit'] = ''
|
|
381
|
-
metaData['PhysicalSizeY'] = 1
|
|
382
|
-
metaData['PhysicalSizeYOrigin'] = 0
|
|
383
|
-
metaData['PhysicalSizeYUnit'] = ''
|
|
236
|
+
return meta_data
|
|
384
237
|
|
|
385
|
-
return metaData
|
|
386
|
-
|
|
387
238
|
@staticmethod
|
|
388
239
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
389
240
|
def get_emi_metadata(fname):
|
|
@@ -392,13 +243,12 @@ class TemMetadataView(DataBrowserView):
|
|
|
392
243
|
@staticmethod
|
|
393
244
|
@functools.lru_cache(maxsize=10, typed=False)
|
|
394
245
|
def get_img_metadata(fname):
|
|
395
|
-
print(fname)
|
|
396
246
|
with ncempy.io.smv.fileSMV(fname) as f0:
|
|
397
|
-
|
|
398
|
-
return
|
|
399
|
-
|
|
247
|
+
meta_data = f0.getMetadata()
|
|
248
|
+
return meta_data
|
|
249
|
+
|
|
400
250
|
def on_change_data_filename(self, fname):
|
|
401
|
-
ext = Path(fname).suffix
|
|
251
|
+
ext = Path(fname).suffix.lower()
|
|
402
252
|
|
|
403
253
|
meta_data = {'file name': str(fname)}
|
|
404
254
|
if ext in ('.dm3', '.dm4'):
|
|
@@ -406,17 +256,14 @@ class TemMetadataView(DataBrowserView):
|
|
|
406
256
|
elif ext in ('.mrc', '.rec', '.ali'):
|
|
407
257
|
meta_data = self.get_mrc_metadata(fname)
|
|
408
258
|
elif ext in ('.emd',):
|
|
409
|
-
try:
|
|
410
|
-
|
|
411
|
-
# if not then it throws a NoEmdDataSets error
|
|
412
|
-
with ncempy.io.emd.fileEMD(fname) as f0:
|
|
413
|
-
meta_data = f0.getMetadata(0)
|
|
259
|
+
try:
|
|
260
|
+
meta_data = self.get_emd_metadata(fname)
|
|
414
261
|
except ncempy.io.emd.NoEmdDataSets:
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
262
|
+
velox_meta = self.get_velox_metadata(fname)
|
|
263
|
+
if velox_meta is not None:
|
|
264
|
+
meta_data = velox_meta
|
|
265
|
+
else:
|
|
266
|
+
meta_data = {'file name': str(fname), 'error': 'No EMD datasets found'}
|
|
420
267
|
elif ext in ('.ser',):
|
|
421
268
|
meta_data = self.get_ser_metadata(fname)
|
|
422
269
|
elif ext in ('.emi',):
|
|
@@ -432,7 +279,7 @@ class TemMetadataView(DataBrowserView):
|
|
|
432
279
|
|
|
433
280
|
def is_file_supported(self, fname):
|
|
434
281
|
ext = Path(fname).suffix
|
|
435
|
-
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')
|
|
436
283
|
|
|
437
284
|
def open_file():
|
|
438
285
|
"""Start the graphical user interface from inside a python interpreter."""
|
|
@@ -9,7 +9,7 @@ description = "Graphical user interface to view transmission electron microscopy
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
dependencies = ["numpy","pyqtgraph","ScopeFoundry>=1.5","ncempy>=1.15","scipy","imageio>2.17"]
|
|
12
|
-
version = "1.
|
|
12
|
+
version = "1.2"
|
|
13
13
|
|
|
14
14
|
[project.scripts]
|
|
15
15
|
TemDataBrowser = "TemDataBrowser:open_file"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|