Skip to content

Commit

Permalink
add try except to emd Metadata viewer. Improve higher dimensional dat…
Browse files Browse the repository at this point in the history
…a logic
  • Loading branch information
ercius committed Nov 27, 2023
1 parent 97e495f commit 136c7ff
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions TemDataBrowser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def setup(self):
self.ui = self.imview = pg.ImageView(view=self.plt)
self.imview.ui.roiBtn.hide()
self.imview.ui.menuBtn.hide()

def is_file_supported(self, fname):
""" Tells the DataBrowser whether this plug-in would likely be able
to read the given file name
here we are using the file extension to make a guess
to read the given file name. Here we are using the file extension
to make a guess
"""
ext = Path(fname).suffix
return ext.lower() in ['.dm3', '.dm4', '.mrc', '.ali', '.rec', '.emd', '.ser']
Expand All @@ -80,13 +81,25 @@ def on_change_data_filename(self, fname):
""" A new file has been selected by the user, load and display it
"""
try:
is_stemtomo = False
with ncempy.io.emd.fileEMD(fname) as f0:
if 'stemtomo version' in f0.file_hdl['data'].attrs:
is_stemtomo = True

file = ncempy.read(fname)

# Remove singular dimensions
self.data = np.squeeze(file['data'])
if self.data.ndim == 4:

# Test for > 3D data and reduce if possible
if self.data.ndim == 4 and is_stemtomo:
print(f'Warning: only showing 1 image per tilt angle for STEMTomo7 data.')
self.data = self.data[:,0,:,:]
elif self.data.ndim == 4:
print(f'Warning: Reducing {self.data.ndim}-D data to 3-D.')
self.data = self.data[0,:,:,:]

print(file['pixelSize'][-1], file['pixelUnit'][-1])
elif self.data.ndim > 4:
print(f'{self.data.ndim}-D data files are not supported.')

xscale = file['pixelSize'][-2]
yscale = file['pixelSize'][-1]
Expand Down Expand Up @@ -262,9 +275,18 @@ def get_emd_metadata(path):
""" Reads important metadata from EMD Berkeley files."""
metaData = {}
with ncempy.io.emd.fileEMD(path) as emd0:
metaData.update(emd0.user.attrs)
metaData.update(emd0.microscope.attrs)
metaData.update(emd0.sample.attrs)
try:
metaData.update(emd0.user.attrs)
except AttributeError:
pass
try:
metaData.update(emd0.microscope.attrs)
except AttributeError:
pass
try:
metaData.update(emd0.sample.attrs)
except AttributeError:
pass
dims = emd0.get_emddims(emd0.list_emds[0])
dimX = dims[-1]
dimY = dims[-2]
Expand Down

0 comments on commit 136c7ff

Please sign in to comment.