Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 90 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
dist
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.so

# C extensions
*.c
*.o

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Jupyter Notebook
.ipynb_checkpoints
*.egg-info
*.ipynb

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# Virtual environments
venv/
ENV/
env/
.venv
env.bak/
venv.bak/

# IDEs and editors
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
*.sublime-project
*.sublime-workspace

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Environment variables
.env
.env.local
.env.*.local

# OS
Thumbs.db
.DS_Store
35 changes: 24 additions & 11 deletions TemDataBrowser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ def on_change_data_filename(self, fname):
""" A new file has been selected by the user, load and display it
"""
try:
is_stemtomo = False
print(f'Loading {fname}...')
if Path(fname).suffix.lower() == '.emd':
# Check for special STEMTomo7 Berkeley EMD files
is_stemtomo = False
if Path(fname).suffix.lower() == '.emd':
try:
with ncempy.io.emd.fileEMD(fname) as f0:
if 'data' in f0.file_hdl:
if 'stemtomo version' in f0.file_hdl['data'].attrs:
is_stemtomo = True
except ncempy.io.emd.NoEmdDataSets:
# Velox files throw this error, they are not Berkeley EMD files
is_stemtomo = False

file = ncempy.read(fname)

Expand Down Expand Up @@ -227,7 +231,8 @@ def get_mrc_metadata(path):
if hasattr(mrc1, 'FEIinfo'):
# add in the special FEIinfo if it exists
try:
metaData.update(mrc1.FEIinfo)
if isinstance(mrc1.FEIinfo, dict):
metaData.update(mrc1.FEIinfo)
except TypeError:
pass

Expand Down Expand Up @@ -310,12 +315,14 @@ def get_velox_metadata(path):
import json
metaData = {}
with ncempy.io.emdVelox.fileEMDVelox(path) as f0:
dataGroup = emd_obj.list_data[0]
if f0.list_data is None:
return metaData
dataGroup = f0.list_data[0]
dataset0 = dataGroup['Data']

# Convert JSON metadata to dict
mData = emd_obj.list_data[0]['Metadata'][:, 0]
validMetaDataIndex = npwhere(mData > 0) # find valid metadata
mData = f0.list_data[0]['Metadata'][:, 0]
validMetaDataIndex = np.where(mData > 0) # find valid metadata
mData = mData[validMetaDataIndex].tostring() # change to string
mDataS = json.loads(mData.decode('utf-8', 'ignore')) # load UTF-8 string as JSON and output dict
metaData['pixel sizes'] = []
Expand Down Expand Up @@ -399,11 +406,17 @@ def on_change_data_filename(self, fname):
elif ext in ('.mrc', '.rec', '.ali'):
meta_data = self.get_mrc_metadata(fname)
elif ext in ('.emd',):
with ncempy.io.emd.fileEMD(fname) as emd0:
if len(emd0.list_emds) > 0:
meta_data = self.get_emd_metadata(fname)
else:
meta_data = self.get_velox_metadata(fname)
try:
# Parse the file to see if any EMD datasets exist
# if not then it throws a NoEmdDataSets error
with ncempy.io.emd.fileEMD(fname) as f0:
meta_data = f0.getMetadata(0)
except ncempy.io.emd.NoEmdDataSets:
with ncempy.io.emdVelox.fileEMDVelox(fname) as f0:
if f0.list_data is not None:
meta_data = f0.getMetadata(0)
else:
meta_data = {'file name': str(fname), 'error': 'No EMD datasets found'}
elif ext in ('.ser',):
meta_data = self.get_ser_metadata(fname)
elif ext in ('.emi',):
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ name = "TemDataBrowser"
authors = [{name = "Peter Ercius", email="percius@lbl.gov"}]
description = "Graphical user interface to view transmission electron microscopy data."
readme = "README.md"
requires-python = ">=3.8"
dependencies = ["numpy","pyqtgraph","ScopeFoundry>=1.5","ncempy","scipy","imageio>2.17"]
version = "1.0.6"
requires-python = ">=3.10"
dependencies = ["numpy","pyqtgraph","ScopeFoundry>=1.5","ncempy>=1.15","scipy","imageio>2.17"]
version = "1.1"

[project.scripts]
TemDataBrowser = "TemDataBrowser:open_file"
Loading