Skip to content

Commit

Permalink
Merge pull request #144 from pycroscopy/test_visualizer
Browse files Browse the repository at this point in the history
fixed list of list bug in sidpy string_utiles
  • Loading branch information
gduscher authored Jan 7, 2022
2 parents d2fce31 + 7b658c9 commit 23c306b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions sidpy/sid/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def view_original_metadata(self):
if isinstance(self.original_metadata, dict):
print_nested_dict(self.original_metadata)

def plot(self, verbose=False, **kwargs):
def plot(self, verbose=False, figure=None, **kwargs):
"""
Plots the dataset according to the
- shape of the sidpy Dataset,
Expand Down Expand Up @@ -497,35 +497,35 @@ def plot(self, verbose=False, **kwargs):
if len(self.shape) == 1:
if verbose:
print('1D dataset')
self.view = CurveVisualizer(self, **kwargs)
plt.show()
self.view = CurveVisualizer(self, figure=figure, **kwargs)
# plt.show()
elif len(self.shape) == 2:
# this can be an image or a set of line_plots
if verbose:
print('2D dataset')
if self.data_type == DataType.IMAGE:
self.view = ImageVisualizer(self, **kwargs)
plt.show()
self.view = ImageVisualizer(self, figure=figure, **kwargs)
# plt.show()
elif self.data_type.value <= DataType['LINE_PLOT'].value:
# self.data_type in ['spectrum_family', 'line_family', 'line_plot_family', 'spectra']:
self.view = CurveVisualizer(self, **kwargs)
plt.show()
self.view = CurveVisualizer(self, figure=figure, **kwargs)
# plt.show()
else:
raise NotImplementedError('Datasets with data_type {} cannot be plotted, yet.'.format(self.data_type))
elif len(self.shape) == 3:
if verbose:
print('3D dataset')
if self.data_type == DataType.IMAGE:
self.view = ImageVisualizer(self, **kwargs)
plt.show()
self.view = ImageVisualizer(self, figure=figure, **kwargs)
# plt.show()
elif self.data_type == DataType.IMAGE_MAP:
pass
elif self.data_type == DataType.IMAGE_STACK:
self.view = ImageStackVisualizer(self, **kwargs)
plt.show()
self.view = ImageStackVisualizer(self, figure=figure, **kwargs)
# plt.show()
elif self.data_type == DataType.SPECTRAL_IMAGE:
self.view = SpectralImageVisualizer(self, **kwargs)
plt.show()
self.view = SpectralImageVisualizer(self, figure=figure, **kwargs)
# plt.show()
else:
raise NotImplementedError('Datasets with data_type {} cannot be plotted, yet.'.format(self.data_type))
elif len(self.shape) == 4:
Expand All @@ -537,13 +537,13 @@ def plot(self, verbose=False, **kwargs):
elif self.data_type == DataType.IMAGE_MAP:
pass
elif self.data_type == DataType.IMAGE_STACK:
self.view = ImageStackVisualizer(self, **kwargs)
self.view = ImageStackVisualizer(self, figure=figure, **kwargs)
plt.show()
elif self.data_type == DataType.SPECTRAL_IMAGE:
self.view = SpectralImageVisualizer(self, **kwargs)
self.view = SpectralImageVisualizer(self, figure=figure, **kwargs)
plt.show()
elif self.data_type == DataType.IMAGE_4D:
self.view = FourDimImageVisualizer(self, **kwargs)
self.view = FourDimImageVisualizer(self, figure=figure, **kwargs)
plt.show()
if verbose:
print('4D dataset')
Expand All @@ -553,7 +553,7 @@ def plot(self, verbose=False, **kwargs):
raise NotImplementedError('Datasets with data_type {} cannot be plotted, yet.'.format(self.data_type))
return self.view.fig

def set_thumbnail(self, thumbnail_size=128):
def set_thumbnail(self, figure=None, thumbnail_size=128):
"""
Creates a thumbnail which is stored in thumbnail attribute of sidpy Dataset
Thumbnail data is saved to Thumbnail group of associated h5_file if it exists
Expand All @@ -571,7 +571,7 @@ def set_thumbnail(self, thumbnail_size=128):
import imageio
# Thumbnail configurations for matplotlib
kwargs = {'figsize': (1,1), 'colorbar': False, 'set_title': False}
view = self.plot(**kwargs)
view = self.plot(figure=figure, **kwargs)
for axis in view.axes:
axis.set_axis_off()

Expand All @@ -581,7 +581,6 @@ def set_thumbnail(self, thumbnail_size=128):

# Writing thumbnail to h5_file if it exists
if self.h5_dataset is not None:

if 'Thumbnail' not in self.h5_dataset.file:
thumb_group = self.h5_dataset.file.create_group("Thumbnail")
else:
Expand Down

0 comments on commit 23c306b

Please sign in to comment.