From 32c7d2ee52fe49aa3a979e890daab7b8f0f8e97b Mon Sep 17 00:00:00 2001 From: Peter Ercius Date: Wed, 18 Mar 2026 11:03:15 -0700 Subject: [PATCH 1/5] update gitignore --- .gitignore | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index de67f9e..e062686 100644 --- a/.gitignore +++ b/.gitignore @@ -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 From dbb7984b329b4d3586c7296542a55e9263aa5fd9 Mon Sep 17 00:00:00 2001 From: Peter Ercius Date: Wed, 18 Mar 2026 11:10:36 -0700 Subject: [PATCH 2/5] handle emd velox files in when testing for STEMTomo7 files --- TemDataBrowser/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TemDataBrowser/__init__.py b/TemDataBrowser/__init__.py index ed86258..2b14aa7 100644 --- a/TemDataBrowser/__init__.py +++ b/TemDataBrowser/__init__.py @@ -81,14 +81,17 @@ def on_change_data_filename(self, fname): """ A new file has been selected by the user, load and display it """ try: + is_stemtomo = False 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) From 01da9ce170d462ff6be3f6b34f5fb7b6989540cc Mon Sep 17 00:00:00 2001 From: Peter Ercius Date: Wed, 18 Mar 2026 11:12:26 -0700 Subject: [PATCH 3/5] fix issues with velox metadata reader --- TemDataBrowser/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TemDataBrowser/__init__.py b/TemDataBrowser/__init__.py index 2b14aa7..6c6bb02 100644 --- a/TemDataBrowser/__init__.py +++ b/TemDataBrowser/__init__.py @@ -313,12 +313,12 @@ def get_velox_metadata(path): import json metaData = {} with ncempy.io.emdVelox.fileEMDVelox(path) as f0: - dataGroup = emd_obj.list_data[0] + 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'] = [] From ca74e03491c0424f91b371d9d9465b018ff36a8f Mon Sep 17 00:00:00 2001 From: Peter Ercius Date: Wed, 18 Mar 2026 11:38:47 -0700 Subject: [PATCH 4/5] use getMetadata in new ncempy version --- TemDataBrowser/__init__.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/TemDataBrowser/__init__.py b/TemDataBrowser/__init__.py index 6c6bb02..7910904 100644 --- a/TemDataBrowser/__init__.py +++ b/TemDataBrowser/__init__.py @@ -82,6 +82,7 @@ def on_change_data_filename(self, fname): """ try: is_stemtomo = False + print(f'Loading {fname}...') if Path(fname).suffix.lower() == '.emd': # Check for special STEMTomo7 Berkeley EMD files try: @@ -230,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 @@ -313,6 +315,8 @@ def get_velox_metadata(path): import json metaData = {} with ncempy.io.emdVelox.fileEMDVelox(path) as f0: + if f0.list_data is None: + return metaData dataGroup = f0.list_data[0] dataset0 = dataGroup['Data'] @@ -402,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',): From a2da269eeceed26a8f6802a287a20bcba05b9beb Mon Sep 17 00:00:00 2001 From: Peter Ercius Date: Wed, 18 Mar 2026 11:43:43 -0700 Subject: [PATCH 5/5] bumpy python version support, bump TemDataBrowser version, bump ncempy minimum version --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4122801..7a8fcd6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"