Commit aaaaa209 by Martin Reinecke

### PEP8

parent df6b5347
Pipeline #17995 passed with stage
in 4 minutes and 54 seconds
 ... @@ -12,6 +12,7 @@ import os ... @@ -12,6 +12,7 @@ import os # - title # - title # - axis labels # - axis labels def _mollweide_helper(xsize): def _mollweide_helper(xsize): xsize = int(xsize) xsize = int(xsize) ysize = xsize//2 ysize = xsize//2 ... @@ -31,6 +32,7 @@ def _mollweide_helper(xsize): ... @@ -31,6 +32,7 @@ def _mollweide_helper(xsize): phi = np.where(phi < 0, phi+2*np.pi, phi) phi = np.where(phi < 0, phi+2*np.pi, phi) return res, mask, theta, phi return res, mask, theta, phi def _find_closest(A, target): def _find_closest(A, target): # A must be sorted # A must be sorted idx = A.searchsorted(target) idx = A.searchsorted(target) ... @@ -40,34 +42,36 @@ def _find_closest(A, target): ... @@ -40,34 +42,36 @@ def _find_closest(A, target): idx -= target - left < right - target idx -= target - left < right - target return idx return idx def _makeplot(name): def _makeplot(name): import matplotlib.pyplot as plt import matplotlib.pyplot as plt if name is None: if name is None: plt.show() plt.show() return return extension = os.path.splitext(name)[1] extension = os.path.splitext(name)[1] if extension==".pdf": if extension == ".pdf": plt.savefig(name) plt.savefig(name) plt.close() plt.close() elif extension==".png": elif extension == ".png": plt.savefig(name) plt.savefig(name) plt.close() plt.close() #elif extension==".html": # elif extension==".html": #import mpld3 # import mpld3 #mpld3.save_html(plt.gcf(),fileobj=name,no_extras=True) # mpld3.save_html(plt.gcf(),fileobj=name,no_extras=True) #import plotly.offline as py # import plotly.offline as py #import plotly.tools as tls # import plotly.tools as tls #plotly_fig = tls.mpl_to_plotly(plt.gcf()) # plotly_fig = tls.mpl_to_plotly(plt.gcf()) #py.plot(plotly_fig,filename=name) # py.plot(plotly_fig,filename=name) #py.plot_mpl(plt.gcf(),filename=name) # py.plot_mpl(plt.gcf(),filename=name) #import bokeh # import bokeh #bokeh.mpl.to_bokeh(plt.gcf()) # bokeh.mpl.to_bokeh(plt.gcf()) else: else: raise ValueError("file format not understood") raise ValueError("file format not understood") def _limit_xy(**kwargs): def _limit_xy(**kwargs): import matplotlib.pyplot as plt import matplotlib.pyplot as plt x1,x2,y1,y2 = plt.axis() x1, x2, y1, y2 = plt.axis() if (kwargs.get("xmin")) is not None: if (kwargs.get("xmin")) is not None: x1 = kwargs.get("xmin") x1 = kwargs.get("xmin") if (kwargs.get("xmax")) is not None: if (kwargs.get("xmax")) is not None: ... @@ -76,25 +80,26 @@ def _limit_xy(**kwargs): ... @@ -76,25 +80,26 @@ def _limit_xy(**kwargs): y1 = kwargs.get("ymin") y1 = kwargs.get("ymin") if (kwargs.get("ymax")) is not None: if (kwargs.get("ymax")) is not None: y2 = kwargs.get("ymax") y2 = kwargs.get("ymax") plt.axis((x1,x2,y1,y2)) plt.axis((x1, x2, y1, y2)) def plot(f,**kwargs): def plot(f, **kwargs): import matplotlib.pyplot as plt import matplotlib.pyplot as plt if not isinstance(f,Field): if not isinstance(f, Field): raise TypeError("incorrect data type") raise TypeError("incorrect data type") if len(f.domain)!=1: if len(f.domain) != 1: raise ValueError("input field must have exactly one domain") raise ValueError("input field must have exactly one domain") dom = f.domain[0] dom = f.domain[0] fig = plt.figure() fig = plt.figure() ax = fig.add_subplot(1,1,1) ax = fig.add_subplot(1, 1, 1) xsize,ysize = 6,6 xsize, ysize = 6, 6 if kwargs.get("xsize") is not None: if kwargs.get("xsize") is not None: xsize = kwargs.get("xsize") xsize = kwargs.get("xsize") if kwargs.get("ysize") is not None: if kwargs.get("ysize") is not None: ysize = kwargs.get("ysize") ysize = kwargs.get("ysize") fig.set_size_inches(xsize,ysize) fig.set_size_inches(xsize, ysize) if kwargs.get("title") is not None: if kwargs.get("title") is not None: ax.set_title(kwargs.get("title")) ax.set_title(kwargs.get("title")) ... @@ -102,31 +107,33 @@ def plot(f,**kwargs): ... @@ -102,31 +107,33 @@ def plot(f,**kwargs): ax.set_xlabel(kwargs.get("xlabel")) ax.set_xlabel(kwargs.get("xlabel")) if kwargs.get("ylabel") is not None: if kwargs.get("ylabel") is not None: ax.set_ylabel(kwargs.get("ylabel")) ax.set_ylabel(kwargs.get("ylabel")) cmap=plt.rcParams['image.cmap'] cmap = plt.rcParams['image.cmap'] if kwargs.get("colormap") is not None: if kwargs.get("colormap") is not None: cmap = kwargs.get("colormap") cmap = kwargs.get("colormap") if isinstance(dom, RGSpace): if isinstance(dom, RGSpace): if len(dom.shape)==1: if len(dom.shape) == 1: npoints = dom.shape[0] npoints = dom.shape[0] dist = dom.distances[0] dist = dom.distances[0] xcoord = np.arange(npoints,dtype=np.float64)*dist xcoord = np.arange(npoints, dtype=np.float64)*dist ycoord = f.val ycoord = f.val plt.plot(xcoord, ycoord) plt.plot(xcoord, ycoord) _limit_xy(**kwargs) _limit_xy(**kwargs) _makeplot(kwargs.get("name")) _makeplot(kwargs.get("name")) return return elif len(dom.shape)==2: elif len(dom.shape) == 2: nx = dom.shape[0] nx = dom.shape[0] ny = dom.shape[1] ny = dom.shape[1] dx = dom.distances[0] dx = dom.distances[0] dy = dom.distances[1] dy = dom.distances[1] xc = np.arange(nx,dtype=np.float64)*dx xc = np.arange(nx, dtype=np.float64)*dx yc = np.arange(ny,dtype=np.float64)*dy yc = np.arange(ny, dtype=np.float64)*dy im=ax.imshow(f.val,extent=[xc[0],xc[-1],yc[0],yc[-1]],vmin=kwargs.get("zmin"),vmax=kwargs.get("zmax"),cmap=cmap) im = ax.imshow(f.val, extent=[xc[0], xc[-1], yc[0], yc[-1]], #from mpl_toolkits.axes_grid1 import make_axes_locatable vmin=kwargs.get("zmin"), #divider = make_axes_locatable(ax) vmax=kwargs.get("zmax"), cmap=cmap) #cax = divider.append_axes("right", size="5%", pad=0.05) # from mpl_toolkits.axes_grid1 import make_axes_locatable #plt.colorbar(im,cax=cax) # divider = make_axes_locatable(ax) # cax = divider.append_axes("right", size="5%", pad=0.05) # plt.colorbar(im,cax=cax) plt.colorbar(im) plt.colorbar(im) _limit_xy(**kwargs) _limit_xy(**kwargs) _makeplot(kwargs.get("name")) _makeplot(kwargs.get("name")) ... @@ -152,7 +159,8 @@ def plot(f,**kwargs): ... @@ -152,7 +159,8 @@ def plot(f,**kwargs): base = pyHealpix.Healpix_Base(int(np.sqrt(f.val.size//12)), "RING") base = pyHealpix.Healpix_Base(int(np.sqrt(f.val.size//12)), "RING") res[mask] = f.val[base.ang2pix(ptg)] res[mask] = f.val[base.ang2pix(ptg)] plt.axis('off') plt.axis('off') plt.imshow(res,vmin=kwargs.get("zmin"),vmax=kwargs.get("zmax"),cmap=cmap) plt.imshow(res, vmin=kwargs.get("zmin"), vmax=kwargs.get("zmax"), cmap=cmap) plt.colorbar(orientation="horizontal") plt.colorbar(orientation="horizontal") _makeplot(kwargs.get("name")) _makeplot(kwargs.get("name")) return return ... @@ -168,7 +176,8 @@ def plot(f,**kwargs): ... @@ -168,7 +176,8 @@ def plot(f,**kwargs): res[mask] = f.val[ilat*dom.nlon + ilon] res[mask] = f.val[ilat*dom.nlon + ilon] plt.axis('off') plt.axis('off') plt.imshow(res,vmin=kwargs.get("zmin"),vmax=kwargs.get("zmax"),cmap=cmap) plt.imshow(res, vmin=kwargs.get("zmin"), vmax=kwargs.get("zmax"), cmap=cmap) plt.colorbar(orientation="horizontal") plt.colorbar(orientation="horizontal") _makeplot(kwargs.get("name")) _makeplot(kwargs.get("name")) return return ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!