From d590ac9a104dca132a26847cb4c831cfb884e291 Mon Sep 17 00:00:00 2001 From: Jan Caron <j.caron@fz-juelich.de> Date: Thu, 5 Dec 2019 19:15:30 +0100 Subject: [PATCH] plottools: removed old unreachable code! --- pyramid/plottools.py | 102 ++----------------------------------------- 1 file changed, 3 insertions(+), 99 deletions(-) diff --git a/pyramid/plottools.py b/pyramid/plottools.py index 1edb76c..4bbfda2 100644 --- a/pyramid/plottools.py +++ b/pyramid/plottools.py @@ -378,7 +378,7 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True # TODO: Look at https://docs.enthought.com/mayavi/mayavi/tips.html and implement! from mayavi import mlab if figsize is None: - figsize = FIGSIZE_DEFAULT + figsize = FIGSIZE_DEFAULT if axis is None: _log.debug('axis is None') fig = plt.figure(figsize=figsize, dpi=dpi) @@ -391,7 +391,7 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True # (needs screen resolution, hardcode now, later: https://github.com/rr-/screeninfo): # IF resolution of mayavi image is smaller than screen resolution: tmpdir = tempfile.mkdtemp() - temp_path = 'temp.png'#TODO:os.path.join(tmpdir, 'temp.png') + temp_path = os.path.join(tmpdir, 'temp.png') print('Temp file created') try: mlab.savefig(temp_path, magnification=mag) @@ -401,7 +401,7 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True except Exception as e: raise e finally: - #TODO:os.remove(temp_path) + os.remove(temp_path) os.rmdir(tmpdir) # In both cases, log mappable shape and do the rest: if close_3d: @@ -413,102 +413,6 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True return format_axis(axis, **kwargs) - - - - - - - - if dim_uv is None: - dim_uv = self.dim[1:] - axis.imshow(imgmap, extent=[0, dim_uv[0], 0, dim_uv[1]], origin='upper') - kwargs.setdefault('scalebar', False) - kwargs.setdefault('hideaxes', True) - # TODO: RETURN AXIS AND FORMAT AFTER! kwargs are for quiverplot (do some defaults here, - # TODO not adding stuff like colorbars!!!!)!!!! - return plottools.format_axis(axis, **kwargs) - - - - # OLD - res = tuple((int(i * dpi) for i in figsize)) - print(f'res: {res}') - self.plot_quiver3d(figsize=res, labels=False, orientation=False, mode='arrow') - if mag > 1: # Use temp files: - tmpdir = tempfile.mkdtemp() - temp_path = 'temp.png'#TODO:os.path.join(tmpdir, 'temp.png') - print('Temp file created') - try: - mlab.savefig(temp_path, magnification=mag) # size=(10, 10), - print('SAVED! now load?') - imgmap = np.asarray(Image.open(temp_path)) - print('LOADED!') - except Exception as e: - raise e - finally: - #TODO:os.remove(temp_path) - os.rmdir(tmpdir) - else: # Use screenshot (returns array WITH alpha!): - # TODO: saving images does NOT give alpha -> set bgcolor there and remove alpha here! - imgmap = mlab.screenshot(mode='rgba', antialiased=True) - self._log.info(f'mappable shape: {imgmap.shape[:2]} (res.: {res})') - if imgmap.shape[0] < res[0] or imgmap.shape[1] < res[1]: - import warnings - warnings.warn(f'Shape of created image {imgmap.shape[:2]} is smaller than the ' - +'calculated resolution {res} for at least one axis. This might lead ' - +'to distorted images. Try other values for dpi, figsize or a ' - +'monitor with larger resolution!') - mlab.close(mlab.gcf()) - if dim_uv is None: - dim_uv = self.dim[1:] - axis.imshow(imgmap, extent=[0, dim_uv[0], 0, dim_uv[1]], origin='upper') - kwargs.setdefault('scalebar', False) - kwargs.setdefault('hideaxes', True) - return plottools.format_axis(axis, **kwargs) - - - -# # OLD -# res = tuple((int(i * dpi) for i in figsize)) -# print(f'res: {res}') -# self.plot_quiver3d(figsize=res, labels=False, orientation=False, mode='arrow') -# if mag > 1: # Use temp files: -# tmpdir = tempfile.mkdtemp() -# temp_path = 'temp.png'#TODO:os.path.join(tmpdir, 'temp.png') -# print('Temp file created') -# try: -# mlab.savefig(temp_path, magnification=mag) # size=(10, 10), -# print('SAVED! now load?') -# imgmap = np.asarray(Image.open(temp_path)) -# print('LOADED!') -# except Exception as e: -# raise e -# finally: -# #TODO:os.remove(temp_path) -# os.rmdir(tmpdir) -# else: # Use screenshot (returns array WITH alpha!): -# # TODO: saving images does NOT give alpha -> set bgcolor there and remove alpha here! -# imgmap = mlab.screenshot(mode='rgba', antialiased=True) -# self._log.info(f'mappable shape: {imgmap.shape[:2]} (res.: {res})') -# if imgmap.shape[0] < res[0] or imgmap.shape[1] < res[1]: -# import warnings -# warnings.warn(f'Shape of created image {imgmap.shape[:2]} is smaller than the ' -# +'calculated resolution {res} for at least one axis. This might lead ' -# +'to distorted images. Try other values for dpi, figsize or a ' -# +'monitor with larger resolution!') -# mlab.close(mlab.gcf()) -# if dim_uv is None: -# dim_uv = self.dim[1:] -# axis.imshow(imgmap, extent=[0, dim_uv[0], 0, dim_uv[1]], origin='upper') -# kwargs.setdefault('scalebar', False) -# kwargs.setdefault('hideaxes', True) -# return plottools.format_axis(axis, **kwargs) - - - - - # TODO: Florians way of shifting axes labels (should already be in somewhere): # for i in [1, 3]: # axs[i].yaxis.set_label_position('right') -- GitLab