def test_simple_figure(): @kamodofy(units='kg', hidden_args=['ions']) def f_N(x_N): return x_N**2 kamodo = Kamodo(f_N=f_N,verbose=True) kamodo.plot(f_N=dict(x_N=np.linspace(-4, 3, 30)))
def test_unavailable_4d_plot_type(): def g(x=np.array([1]), y=np.array([1]), z=np.array([1]), t=np.array([1])): return x**2 + y**2 + z**2 + t**2 kamodo = Kamodo(g=g, verbose=True) with pytest.raises(KeyError): kamodo.plot('g')
def get_plot(self, var, colorscale="Viridis"): ''' Return a plotly figure object for the available plot types set in set_plot().. colorscale = Viridis [default], Cividis, or Rainbow ''' #Set some text strings txtbot = "Model: BATSRUS, Run: " + str(self.runname) + ", " + str( self.gridSize) + " cells, minimum dx=" + str(self.gridMinDx) txtbar = var + " [" + self.variables[var]['units'] + "]" # Get values from interpolation already computed result = self.variables[var]['interpolator'] r = np.sqrt( np.square(self.newgrid[:, 0]) + np.square(self.newgrid[:, 1]) + np.square(self.newgrid[:, 2])) cmin = np.amin(result[(r[:] > 2.999)]) cmax = np.amax(result[(r[:] > 2.999)]) if self.plottype == "XY": txttop = "Z=" + str(self.plots[self.plottype] ['cutV']) + " slice, Time = " + self.filetime xint = self.newx yint = self.newy # Reshape interpolated values into 2D result2 = np.reshape(result, (self.nY, self.nX)) def plot_XY(xint=xint, yint=yint): return result2 plotXY = Kamodo(plot_XY=plot_XY) fig = plotXY.plot(plot_XY=dict()) fig.update_xaxes(title_text="", scaleanchor='y') fig.update_yaxes(title_text="Y [RE]") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar), hovertemplate= "X: %{x:.2f}<br>Y: %{y:.2f}<br><b> %{z:.4f}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) fig.update_layout(title_text=txttop, annotations=[ dict(text="X [RE]", x=0.5, y=-0.10, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ]) if self.plots[self.plottype]['cutV'] == 0.: fig.update_layout(shapes=[ dict(type="circle", xref="x", yref="y", x0=-3, y0=-3, x1=3, y1=3, fillcolor="black", line_color="black"), dict(type="circle", xref="x", yref="y", x0=-1, y0=-1, x1=1, y1=1, fillcolor="black", line_color="white"), dict(type="path", path=self.ellipse_arc(N=30), fillcolor="white", line_color="white") ]) return fig if self.plottype == "XZ": txttop = "Y=" + str(self.plots[self.plottype] ['cutV']) + " slice, Time = " + self.filetime xint = self.newx zint = self.newz # Reshape interpolated values into 2D result2 = np.reshape(result, (self.nX, self.nZ)) def plot_XZ(xint=xint, zint=zint): return result2 plotXZ = Kamodo(plot_XZ=plot_XZ) fig = plotXZ.plot(plot_XZ=dict()) fig.update_xaxes(title_text="", scaleanchor='y') fig.update_yaxes(title_text="Z [RE]") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar), hovertemplate= "X: %{x:.2f}<br>Z: %{y:.2f}<br><b> %{z:.4f}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) fig.update_layout(title_text=txttop, annotations=[ dict(text="X [RE]", x=0.5, y=-0.10, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ]) if self.plots[self.plottype]['cutV'] == 0.: fig.update_layout(shapes=[ dict(type="circle", xref="x", yref="y", x0=-3, y0=-3, x1=3, y1=3, fillcolor="black", line_color="black"), dict(type="circle", xref="x", yref="y", x0=-1, y0=-1, x1=1, y1=1, fillcolor="black", line_color="white"), dict(type="path", path=self.ellipse_arc(N=30), fillcolor="white", line_color="white") ]) return fig if self.plottype == "YZ": txttop = "X=" + str(self.plots[self.plottype] ['cutV']) + " slice, Time = " + self.filetime yint = self.newy zint = self.newz # Reshape interpolated values into 2D result2 = np.reshape(result, (self.nY, self.nZ)) def plot_YZ(yint=yint, zint=zint): return result2 plotYZ = Kamodo(plot_YZ=plot_YZ) fig = plotYZ.plot(plot_YZ=dict()) fig.update_xaxes(title_text="", scaleanchor='y') fig.update_yaxes(title_text="Z [RE]") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar), hovertemplate= "Y: %{x:.2f}<br>Z: %{y:.2f}<br><b> %{z:.4f}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) fig.update_layout(title_text=txttop, annotations=[ dict(text="Y [RE]", x=0.5, y=-0.10, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ]) if self.plots[self.plottype]['cutV'] == 0.: fig.update_layout(shapes=[ dict(type="circle", xref="x", yref="y", x0=-3, y0=-3, x1=3, y1=3, fillcolor="black", line_color="black"), dict(type="circle", xref="x", yref="y", x0=-1, y0=-1, x1=1, y1=1, fillcolor="white", line_color="white"), #dict(type="path", path= self.ellipse_arc(N=30), fillcolor="white", line_color="white") ]) return fig if self.plottype == "XYZ": Nplot = 0 txttop = "3D Plot, Time = " + self.filetime # Plot 'XY' is assumed to be part of the 3D plot pt = 'XY' # Get values from interpolation already computed result = self.plots[pt][var] newgrid = self.plots[pt]['newgrid'] r = np.sqrt( np.square(newgrid[:, 0]) + np.square(newgrid[:, 1]) + np.square(newgrid[:, 2])) cmin = np.amin(result[(r[:] > 2.999)]) cmax = np.amax(result[(r[:] > 2.999)]) xint = self.plots[pt]['newx'] yint = self.plots[pt]['newy'] zint = self.plots[pt]['newz'] # Reshape interpolated values into 3D result2 = np.reshape(result, (self.plots[pt]['nY'], self.plots[pt]['nX'], self.plots[pt]['nZ'])) def plot_XY(xint=xint, yint=yint, zint=zint): return result2 plotXY = Kamodo(plot_XY=plot_XY) fig = plotXY.plot(plot_XY=dict()) Nplot = Nplot + 1 if ('XZ' in self.plots): pt = 'XZ' # Get values from interpolation already computed result = self.plots[pt][var] newgrid = self.plots[pt]['newgrid'] r = np.sqrt( np.square(newgrid[:, 0]) + np.square(newgrid[:, 1]) + np.square(newgrid[:, 2])) cmin = min(cmin, np.amin(result[(r[:] > 2.999)])) cmax = max(cmax, np.amax(result[(r[:] > 2.999)])) xint = self.plots[pt]['newx'] yint = self.plots[pt]['newy'] zint = self.plots[pt]['newz'] # Reshape interpolated values into 3D result2 = np.reshape( result, (self.plots[pt]['nY'], self.plots[pt]['nX'], self.plots[pt]['nZ'])) def plot_XZ(xint=xint, yint=yint, zint=zint): return result2 plotXZ = Kamodo(plot_XZ=plot_XZ) figXZ = plotXZ.plot(plot_XZ=dict()) fig.add_surface(showscale=False) fig.data[Nplot].surfacecolor = figXZ.data[0].surfacecolor fig.data[Nplot].x = figXZ.data[0].x fig.data[Nplot].y = figXZ.data[0].y fig.data[Nplot].z = figXZ.data[0].z Nplot = Nplot + 1 if ('YZ' in self.plots): pt = 'YZ' # Get values from interpolation already computed result = self.plots[pt][var] newgrid = self.plots[pt]['newgrid'] r = np.sqrt( np.square(newgrid[:, 0]) + np.square(newgrid[:, 1]) + np.square(newgrid[:, 2])) cmin = min(cmin, np.amin(result[(r[:] > 2.999)])) cmax = max(cmax, np.amax(result[(r[:] > 2.999)])) xint = self.plots[pt]['newx'] yint = self.plots[pt]['newy'] zint = self.plots[pt]['newz'] # Reshape interpolated values into 3D result2 = np.reshape( result, (self.plots[pt]['nY'], self.plots[pt]['nX'], self.plots[pt]['nZ'])) def plot_YZ(xint=xint, yint=yint, zint=zint): return result2 plotYZ = Kamodo(plot_YZ=plot_YZ) figYZ = plotYZ.plot(plot_YZ=dict()) fig.add_surface(showscale=False) fig.data[Nplot].surfacecolor = figYZ.data[0].surfacecolor fig.data[Nplot].x = figYZ.data[0].x fig.data[Nplot].y = figYZ.data[0].y fig.data[Nplot].z = figYZ.data[0].z Nplot = Nplot + 1 # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "RdBu": fig.update_traces(colorscale="RdBu") elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( colorbar=dict(title=txtbar), cmin=cmin, cmax=cmax, hovertemplate= "X: %{x:.2f}<br>Y: %{y:.2f}<br>Z: %{z:.2f}<extra></extra>") fig.update_layout(scene_aspectmode='data', title_text=txttop, scene=dict(xaxis=dict(title="X [RE]"), yaxis=dict(title="Y [RE]"), zaxis=dict(title="Z [RE]")), annotations=[ dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=-0.08, y=-0.05, ax=0, ay=0, xanchor="left", xref="paper", yref="paper") ], margin=dict(l=0, b=30, t=30)) # Add in plot axis for reference #fig.add_scatter3d() #fig.data[Nplot].x = [-20., 0., 20., 0., 0., 0., 0., 0., 0., 0., 0.] #fig.data[Nplot].y = [ 0., 0., 0., 0., -20., 0., 20., 0., 0., 0., 0.] #fig.data[Nplot].z = [ 0., 0., 0., 0., 0., 0., 0., 0., -20., 0., 20.] #fig.data[Nplot].name = 'Axis' #fig.data[Nplot].marker = dict(size=3, color='white', opacity=0.8) #fig.data[Nplot].line = dict(color='white', width=4) #fig.data[Nplot].hoverinfo='skip' #Nplot = Nplot +1 # Add in R=3 sphere dataXYZ = pd.read_csv( 'http://vmr.engin.umich.edu/dbg/sphereXYZ.csv') dataIJK = pd.read_csv( 'http://vmr.engin.umich.edu/dbg/sphereIJK.csv') fig.add_mesh3d() fig.data[Nplot].x = dataXYZ['x'] * 3. fig.data[Nplot].y = dataXYZ['y'] * 3. fig.data[Nplot].z = dataXYZ['z'] * 3. fig.data[Nplot].i = dataIJK['i'] fig.data[Nplot].j = dataIJK['j'] fig.data[Nplot].k = dataIJK['k'] fig.data[Nplot].facecolor = dataIJK['c'] fig.data[Nplot].flatshading = True fig.data[Nplot].name = 'R=3 sphere' fig.data[Nplot].hovertemplate = "R=3 sphere<extra></extra>" Nplot = Nplot + 1 return fig print("ERROR, unknown plottype =", plottype, ", exiting without definition of figure.") return
def test_multiple_traces(): kamodo = Kamodo(f='x', g='x**2') kamodo.plot( f=dict(x=np.linspace(-1, 1, 10)), g=dict(x=np.linspace(-5, 5, 10)))
def get_plot(self, var, plottype, runname, colorscale="BlueRed", sym="T"): ''' Return a plotly figure object for the plottype requested. var, plottype, and runname are required variables. colorscale = BlueRed [default], Viridis, Cividis, or Rainbow sym = T [default] for symetric colorscale around 0 ''' if plottype.count('2D-') > 0: x = np.linspace(-.65, .65, 130) y = np.linspace(-.65, .65, 130) xx, yy = np.meshgrid(np.array(x), np.array(y)) if plottype == "2D-N": loctxt = "Northern" llat = 180. - np.arcsin( np.sqrt(xx * xx + yy * yy)) * 180. / np.pi if plottype == "2D-S": loctxt = "Southern" llat = np.arcsin(np.sqrt(xx * xx + yy * yy)) * 180. / np.pi llon = 180. - (90. + np.arctan(xx / yy) * 180. / np.pi) llon[yy < 0.] += 180. grid = np.ndarray(shape=(np.size(np.reshape(xx, -1)), 2), dtype=np.float32) grid[:, 0] = np.reshape(llat, -1) grid[:, 1] = np.reshape(llon, -1) units = self.variables[var]['units'] test = self.variables[var]['interpolator'](grid) result = np.reshape(test, (y.shape[0], x.shape[0])) if sym == "T": cmax = np.max(np.absolute(self.variables[var]['data'])) #cmax = np.max(np.absolute(result)) cmin = -cmax else: cmax = np.max(self.variables[var]['data']) #cmax = np.max(result) cmin = np.min(self.variables[var]['data']) time = self.Date.strftime("%Y/%m/%d %H:%M:%S UT") def plot_var(y=y, x=x): return result plotvar = Kamodo(plot_var=plot_var) fig = plotvar.plot(plot_var=dict()) fig.update_xaxes(nticks=7, title_text="", scaleanchor='y', autorange="reversed") fig.update_yaxes(nticks=7, title_text="") txtbar = var + " [" + units + "]" txtbot = "Model: SWMF-IE, Run: " + runname if colorscale == "BlueRed": fig.update_traces( colorscale="RdBu", reversescale=True, ) elif colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) else: fig.update_traces(colorscale=colorscale) fig.update_traces( zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar), hovertemplate=loctxt + " Hemisphere<br>X: %{y:.2f}<br>Y: %{x:.2f}<br><b>" + var + ": %{z:.4g}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) c80 = np.sin(((90. - 80.) / 90.) * np.pi / 2.) c70 = np.sin(((90. - 70.) / 90.) * np.pi / 2.) c60 = np.sin(((90. - 60.) / 90.) * np.pi / 2.) c50 = np.sin(((90. - 50.) / 90.) * np.pi / 2.) c50d = c50 / np.sqrt(2.) fig.update_layout(title=dict(text=loctxt + " Hemisphere, Time = " + time, yref="container", yanchor="top", y=0.95), title_font_size=16, shapes=[ dict(type="circle", xref="x", yref="y", x0=-c80, y0=-c80, x1=c80, y1=c80, line=dict(color="black", width=1, dash="dash")), dict(type="circle", xref="x", yref="y", x0=-c70, y0=-c70, x1=c70, y1=c70, line=dict(color="black", width=1)), dict(type="circle", xref="x", yref="y", x0=-c60, y0=-c60, x1=c60, y1=c60, line=dict(color="black", width=1, dash="dash")), dict(type="circle", xref="x", yref="y", x0=-c50, y0=-c50, x1=c50, y1=c50, line=dict(color="black", width=1)), dict(type="line", xref="x", yref="y", x0=-c50, y0=0., x1=c50, y1=0., line=dict(color="black", width=1)), dict(type="line", xref="x", yref="y", x0=0., y0=-c50, x1=0., y1=c50, line=dict(color="black", width=1)), dict(type="line", xref="x", yref="y", x0=-c50d, y0=-c50d, x1=c50d, y1=c50d, line=dict(color="black", width=1)), dict(type="line", xref="x", yref="y", x0=-c50d, y0=c50d, x1=c50d, y1=-c50d, line=dict(color="black", width=1)) ], annotations=[ dict(text="Y [RE]", x=0.5, y=-0.11, showarrow=False, xref="paper", yref="paper", font=dict(size=12)), dict(text="X [RE]", x=-0.19, y=0.5, showarrow=False, xref="paper", yref="paper", font=dict(size=12), textangle=-90), dict(text="midnight", x=0.5, y=0.0, showarrow=False, xref="paper", yref="paper", font=dict(size=10)), dict(text="noon", x=0.5, y=1.0, showarrow=False, xref="paper", yref="paper", font=dict(size=10)), dict(text="dawn", x=1.0, y=0.5, showarrow=False, textangle=90, xref="paper", yref="paper", font=dict(size=10)), dict(text="dusk", x=0.0, y=0.5, showarrow=False, textangle=-90, xref="paper", yref="paper", font=dict(size=10)), dict(text=txtbot, x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper", font=dict(size=16, family="sans serif", color="#000000")) ], height=375, width=500, margin=dict(t=45, r=140)) return fig if self.plottype == "3D": return print('Error, no valid plottype was given.') return
def plot2D(kamodo_object, varname, plottype, t, lon, lat, h=-1): '''Use Kamodo's native plotting to generate 2D plot. Possible plot types are LonLat, LatH, LonH, TimeLat, TimeLon, and TimeH. If the variable depends on 4 dimensions, h should be given. If a LonLat plot is requested, then the function expects a single value (integer, float, float32, or float64) for t and h (if h is given). In this case, lon and lat should be 1D arrays or flat lists. If the variable depends on height, then a value or array should be given for h. ''' #initialize new kamodo object plot_kamodo = Kamodo() #first, determine if kamodo function is griddified or not, and function units gridified = (varname[-3:] == 'ijk') units = kamodo_object.variables[varname]['units'] xvec = kamodo_object.variables[varname]['xvec'] #next, determine vertical dependency of variable coord_list = list(xvec.keys()) if len(coord_list) == 4: vert = coord_list[-1] #height, ilev, ilev1, or milev (always last) else: vert = 'none' if 'H' in plottype: raise AttributeError(f'Cannot produce {plottype} plot for a variable '+\ f'that does not depend on height.\n{varname}: {xvec}\n') #convert inputs to arrays t = convert_to_array(t) lon = convert_to_array(lon) lat = convert_to_array(lat) h = convert_to_array(h) #create printing message for heading of plot #print(varname, plottype, units, gridified, vert) if t.shape[0] == 1: t_message = f'Time slice at {t[0]:.3f} hrs. ' else: t_message = '' if lon.shape[0] == 1: lon_message = f'Longitude slice at {lon[0]:.3f} deg. ' else: lon_message = '' if lat.shape[0] == 1: lat_message = f'Latitude slice at {lat[0]:.3f} deg. ' else: lat_message = '' if vert == 'none': h_message = '' elif h.shape[0] > 1: h_message = '' else: if vert in ['ilev', 'ilev1', 'milev']: h_message = f'Pressure level slice at {h[0]}.' elif vert == 'height': h_message = f'Height slice at {h[0]:.3f} km.' elif vert == 'radius': h_message = f'Radius slice at {h[0]:.7f} R_E.' print(t_message + lon_message + lat_message + h_message) #create 2D kamodo function for plotting desired plottype with given function if gridified: #logic for plotting with gridified functions #LonLat plots if plottype == 'LonLat': arg_units = { coord_list[1]: xvec[coord_list[1]], coord_list[2]: xvec[coord_list[2]] } #e.g. {'lon':'deg','lat':'deg'} #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, height=h) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) if vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, radius=h) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, ilev=h) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, ilev1=h) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, milev=h) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(mlat=lat, mlon=lon)) elif vert == 'none': if coord_list[ 1] == 'Elon': #for ctipe 3D variables that depend on Elon and Elat @kamodofy(units=units, arg_units=arg_units) @partial(time=t) def pfunc(time, Elon, Elat): return getattr(kamodo_object, varname)(time=time, Elon=Elon, Elat=Elat) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(Elat=lat, Elon=lon)) else: @kamodofy(units=units, arg_units=arg_units) @partial(time=t) def pfunc(time, lon, lat): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(lat=lat, lon=lon)) #TimeLon plots elif plottype == 'TimeLon': arg_units = { 'time': 'hr', coord_list[1]: xvec[coord_list[1]] } #'lon':'deg' #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, height=h) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, radius=h) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, ilev=h) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, ilev1=h) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlat=lat, milev=h) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, mlon=lon)) elif vert == 'none': if coord_list[ 1] == 'Elon': #for ctipe 3D variables that depend on Elon and Elat @kamodofy(units=units, arg_units=arg_units) @partial(Elat=lat) def pfunc(time, Elon, Elat): return getattr(kamodo_object, varname)(time=time, Elon=Elon, Elat=Elat) plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, Elon=lon)) else: @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat) def pfunc(time, lon, lat): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat) plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, lon=lon)) #TimeLat plots elif plottype == 'TimeLat': arg_units = { 'time': 'hr', coord_list[2]: xvec[coord_list[2]] } #'lat':'deg' #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, height=h) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, radius=h) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, ilev=h) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, ilev1=h) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlon=lon, milev=h) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, mlat=lat)) elif vert == 'none': if coord_list[ 1] == 'Elon': #for ctipe 3D variables that depend on Elon and Elat @kamodofy(units=units, arg_units=arg_units) @partial(Elon=lon) def pfunc(time, Elon, Elat): return getattr(kamodo_object, varname)(time=time, Elon=Elon, Elat=Elat) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, Elat=lat)) else: @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon) def pfunc(time, lon, lat): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, lat=lat)) #TimeH plots elif plottype == 'TimeH': #accounting for differing vertical dependencies arg_units = { 'time': 'hr', coord_list[-1]: xvec[coord_list[-1]] } #'time':'hr', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlon=lon, mlat=lat) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.') #LonH plots elif plottype == 'LonH': #accounting for differing vertical dependencies arg_units = { coord_list[1]: xvec[coord_list[1]], coord_list[-1]: xvec[coord_list[-1]] } #'lon':'deg', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, mlat=lat) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(mlon=lon, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.') #LatH plots elif plottype == 'LatH': #accounting for differing vertical dependencies arg_units = { coord_list[2]: xvec[coord_list[2]], coord_list[-1]: xvec[coord_list[-1]] } #'lat':'deg', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, height): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, height=height) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, radius): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, radius=radius) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, ilev): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev=ilev) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, ilev1): return getattr(kamodo_object, varname)(time=time, lon=lon, lat=lat, ilev1=ilev1) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, mlon=lon) def pfunc(time, mlon, mlat, milev): return getattr(kamodo_object, varname)(time=time, mlon=mlon, mlat=mlat, milev=milev) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(mlat=lat, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.') else: #logic for plotting with not gridified function----------------------------------------------------- #LonLat plots if plottype == 'LonLat': arg_units = { coord_list[1]: xvec[coord_list[1]], coord_list[2]: xvec[coord_list[2]] } #{'lon':'deg','lat':'deg'} #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, height=h) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (lon.shape[0], lat.shape[0])) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, radius=h) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (lon.shape[0], lat.shape[0])) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, ilev=h) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (lon.shape[0], lat.shape[0])) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, ilev1=h) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (lon.shape[0], lat.shape[0])) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, milev=h) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (mlon.shape[0], mlat.shape[0])) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(mlat=lat, mlon=lon)) elif vert == 'none': if coord_list[1] == 'Elon': @kamodofy(units=units, arg_units=arg_units) @partial(time=t) def pfunc(time, Elon, Elat): data = grid3D(kamodo_object, varname, time, Elon, Elat) return reshape(data, (Elon.shape[0], Elat.shape[0])) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(Elat=lat, Elon=lon)) else: @kamodofy(units=units, arg_units=arg_units) @partial(time=t) def pfunc(time, lon, lat): data = grid3D(kamodo_object, varname, time, lon, lat) return reshape(data, (lon.shape[0], lat.shape[0])) plot_kamodo['LonLat'] = pfunc return plot_kamodo.plot(LonLat=dict(lat=lat, lon=lon)) #TimeLon plots #####reshape command has reverse order b/c plots looked wrong for CTIPe elif plottype == 'TimeLon': arg_units = { 'time': 'hr', coord_list[1]: xvec[coord_list[1]] } #'lon':'deg' #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, height=h) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (lon.shape[0], time.shape[0])).T elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, radius=h) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (lon.shape[0], time.shape[0])).T elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, ilev=h) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (lon.shape[0], time.shape[0])).T elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat, ilev1=h) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (lon.shape[0], time.shape[0])).T elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlat=lat, milev=h) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (mlon.shape[0], time.shape[0])).T plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, mlon=lon)) elif vert == 'none': if coord_list[1] == 'Elon': @kamodofy(units=units, arg_units=arg_units) @partial(Elat=lat) def pfunc(time, Elon, Elat): data = grid3D(kamodo_object, varname, time, Elon, Elat) return reshape(data, (Elon.shape[0], time.shape[0])) plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, Elon=lon)) else: @kamodofy(units=units, arg_units=arg_units) @partial(lat=lat) def pfunc(time, lon, lat): data = grid3D(kamodo_object, varname, time, lon, lat) return reshape(data, (lon.shape[0], time.shape[0])) plot_kamodo['TimeLon'] = pfunc return plot_kamodo.plot(TimeLon=dict(time=t, lon=lon)) #TimeLat plots elif plottype == 'TimeLat': arg_units = { 'time': 'hr', coord_list[2]: xvec[coord_list[2]] } #'lat':'deg' #accounting for differing vertical dependencies if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, height=h) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (time.shape[0], lat.shape[0])) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, radius=h) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (time.shape[0], lat.shape[0])) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, ilev=h) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (time.shape[0], lat.shape[0])) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, ilev1=h) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (time.shape[0], lat.shape[0])) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlon=lon, milev=h) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (time.shape[0], mlat.shape[0])) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, mlat=lat)) elif vert == 'none': if coord_list[1] == 'Elon': @kamodofy(units=units, arg_units=arg_units) @partial(Elon=lon) def pfunc(time, Elon, Elat): data = grid3D(kamodo_object, varname, time, Elon, Elat) return reshape(data, (time.shape[0], Elat.shape[0])) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, Elat=lat)) else: @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon) def pfunc(time, lon, lat): data = grid3D(kamodo_object, varname, time, lon, lat) return reshape(data, (time.shape[0], lat.shape[0])) plot_kamodo['TimeLat'] = pfunc return plot_kamodo.plot(TimeLat=dict(time=t, lat=lat)) #TimeH plots elif plottype == 'TimeH': #accounting for differing vertical dependencies arg_units = { 'time': 'hr', coord_list[-1]: xvec[coord_list[-1]] } #'time':'hr', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (time.shape[0], height.shape[0])) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (time.shape[0], radius.shape[0])) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (time.shape[0], ilev.shape[0])) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(lon=lon, lat=lat) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (time.shape[0], ilev1.shape[0])) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(mlon=lon, mlat=lat) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (time.shape[0], milev.shape[0])) plot_kamodo['TimeH'] = pfunc return plot_kamodo.plot(TimeH=dict(time=t, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.') #LonH plots elif plottype == 'LonH': #accounting for differing vertical dependencies arg_units = { coord_list[1]: xvec[coord_list[1]], coord_list[-1]: xvec[coord_list[-1]] } #'lon':'deg', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (lon.shape[0], height.shape[0])) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (lon.shape[0], radius.shape[0])) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (lon.shape[0], ilev.shape[0])) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lat=lat) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (lon.shape[0], ilev1.shape[0])) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(lon=lon, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, mlat=lat) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (mlon.shape[0], milev.shape[0])) plot_kamodo['LonH'] = pfunc return plot_kamodo.plot(LonH=dict(mlon=lon, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.') #LatH plots elif plottype == 'LatH': #accounting for differing vertical dependencies arg_units = { coord_list[2]: xvec[coord_list[2]], coord_list[-1]: xvec[coord_list[-1]] } #'lat':'deg', 'height':'km' if vert == 'height': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, height): data = grid4D(kamodo_object, varname, time, lon, lat, height) return reshape(data, (lat.shape[0], height.shape[0])) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, height=h)) elif vert == 'radius': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, radius): data = grid4D(kamodo_object, varname, time, lon, lat, radius) return reshape(data, (lat.shape[0], radius.shape[0])) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, radius=h)) elif vert == 'ilev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, ilev): data = grid4D(kamodo_object, varname, time, lon, lat, ilev) return reshape(data, (lat.shape[0], ilev.shape[0])) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, ilev=h)) elif vert == 'ilev1': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, lon=lon) def pfunc(time, lon, lat, ilev1): data = grid4D(kamodo_object, varname, time, lon, lat, ilev1) return reshape(data, (lat.shape[0], ilev1.shape[0])) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(lat=lat, ilev1=h)) elif vert == 'milev': @kamodofy(units=units, arg_units=arg_units) @partial(time=t, mlon=lon) def pfunc(time, mlon, mlat, milev): data = grid4D(kamodo_object, varname, time, mlon, mlat, milev) return reshape(data, (mlat.shape[0], milev.shape[0])) plot_kamodo['LatH'] = pfunc return plot_kamodo.plot(LatH=dict(mlat=lat, milev=h)) elif vert == 'none': raise AttributeError('Variable does not depend on height.')
def heatplot2D(xint, yint, plot_flip, nx, ny, result, datascale, kamodo_plot, xlabel, ylabel, colorscale, txtbar, xformat, yformat, zformat, xunit, yunit, txttop, txtbot, ellipse=False): '''Generate a 2D heat plot for the given data''' xrange = {'min': xint.min(), 'max': xint.max(), 'n': len(xint)} yrange = {'min': yint.min(), 'max': yint.max(), 'n': len(yint)} if plot_flip: result2 = np.reshape(result, (nx, ny)) # Reshape interpolated values into 2D else: result2 = np.reshape(result, (ny, nx)) #some plots need this if nx == ny: result2 = result2.T #fix weird behavior when nx=ny if datascale == "linear": def plot_XY(xint=xint, yint=yint): return result2 if datascale == "log": def plot_XY(xint=xint, yint=yint): return np.log(result2) plotXY = Kamodo(plot_XY=plot_XY) #func_name = func fig = plotXY.plot(plot_XY=dict()) if kamodo_plot == 'XY': fig.update_xaxes(title_text='', scaleanchor='y') # label included in annotations if kamodo_plot == 'XZ' or kamodo_plot == 'YZ' or kamodo_plot == 'TY' or kamodo_plot == 'TZ': fig.update_xaxes(title_text='', scaleanchor=None) fig.update_yaxes(title_text=ylabel) # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [0.25, 'rgb(0,255,255)'], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "BlueRed": fig.update_traces(colorscale="RdBu", reversescale=True) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces(ncontours=201, colorbar=dict(title=txtbar,tickformat=zformat), hovertemplate="X: %{x:"+xformat+"}<br>Y: %{y:"+yformat+\ "}<br><b> %{z:"+zformat+"}</b><extra></extra>", contours=dict(coloring="fill", showlines=False) ) #set aspect ratio #if xunit == yunit: #real if xunit == 'deg': if xrange['max'] - xrange['min'] > yrange['max'] - yrange['min']: aspectratio = dict(x=np.asarray([ 2., (xrange['max'] - xrange['min']) / np.asarray([1.e-5, (yrange['max'] - yrange['min'])]).max() ]).min(), y=1) else: aspectratio = dict( x=1, y=np.asarray([ 1.5, (yrange['max'] - yrange['min']) / np.asarray([1.e-5, (xrange['max'] - xrange['min'])]).max() ]).min()) if yunit == 'km': aspectratio = dict(x=2, y=1) aspectmode = 'manual' else: aspectratio = dict(x=1.5, y=1) aspectmode = 'cube' width = 180 + 300 * aspectratio['x'] height = 90 + 300 * aspectratio['y'] fig.update_layout(autosize=False, height=height, width=width, scene=dict(aspectmode=aspectmode), margin=dict(t=45, b=45, l=40, r=140), title=dict(text=txttop), annotations=[ dict(text=xlabel, x=0.5, y=-0.12, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.1, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ]) if 'Lat' in xlabel or 'Lon' in xlabel: fig.update_layout(xaxis=dict(tickmode='linear', tick0=0, dtick=30)) if 'Lat' in ylabel or 'Lon' in ylabel: fig.update_layout(yaxis=dict(tickmode='linear', tick0=0, dtick=30)) if ellipse == True: fig.update_layout(shapes=[ dict(type="circle", xref="x", yref="y", x0=-3, y0=-3, x1=3, y1=3, fillcolor="black", line_color="black"), dict(type="circle", xref="x", yref="y", x0=-1, y0=-1, x1=1, y1=1, fillcolor="black", line_color="white"), dict(type="path", path=ellipse_arc(N=30), fillcolor="white", line_color="white") ]) return fig
def get_plot(self, var, colorscale="Viridis", style="linear"): ''' Return a plotly figure object for the available plot types set in set_plot().. colorscale = Viridis [default], Cividis, BlueRed or Rainbow ''' #Set some text strings txtbot = "Model: TIEGCM, Run: " + str(self.runname) + ", " + str( self.gridSize) + " cells, minimum dx=" + str(self.gridMinDx) if style == "linear": txtbar = var + " [" + self.variables[var]['units'] + "]" if style == "log": txtbar = "log(" + var + ") [" + self.variables[var]['units'] + "]" print("before interpolation") # Get values from interpolation already computed tic = time.perf_counter() if (self.newgrid[:, 1] ).max() < 50: # IP or height is column 1 (CTIPe_singletime: 0) # result=self[var](self.newgrid[:,0].ravel(),self.newgrid[:,1].ravel(),self.newgrid[:,2].ravel(),self.newgrid[:,3].ravel()) result = self[var](self.newt, self.newx, self.newy, self.newz) else: self.varname = var # once we have a gridify'd version we can use this # result=vert_interp(self.newt,self.newx,self.newy,self.newz) # have to use np.vectorize'd version result = self.vert_interp(self, self.newgrid[:, 0].ravel(), self.newgrid[:, 1].ravel(), self.newgrid[:, 2].ravel(), self.newgrid[:, 3].ravel()) toc = time.perf_counter() print(f"Time for computing interpolations: {toc - tic:0.4f} seconds") print("result.shape after interpolation: ", result.shape) if self.plottype == "LonLat" or self.plottype == "LonLatH": txttop = self.plots[ self.plottype]['cut'] + " " + self.cutunit + "=" + str( self.plots[self.plottype] ['cutV']) + " slice, Time = " + self.filetime tint = self.newt xint = self.newz yint = self.newy zint = self.newx # print("tint:",tint) # print("xint:",xint) # print("yint:",yint) # print("zint:",zint) xunit = self.zunit yunit = self.yunit xrange = dict(min=xint.min(), max=xint.max(), n=len(xint)) yrange = dict(min=yint.min(), max=yint.max(), n=len(yint)) # Reshape interpolated values into 2D print("result shape: ", result.shape) result2 = np.reshape(result, (self.nY, self.nZ)) print("result2 shape: ", result2.shape) # print(result2) if style == "linear": def plot_XY(xint=xint, yint=yint): return result2 if style == "log": def plot_XY(xint=xint, yint=yint): return np.log(result2) plotXY = Kamodo(plot_XY=plot_XY) fig = plotXY.plot(plot_XY=dict()) fig.update_xaxes(title_text="", scaleanchor='y') fig.update_yaxes(title_text="Lat [deg]") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "BlueRed": fig.update_traces( colorscale="RdBu", reversescale=True, ) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( # zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar, tickformat='.4g'), hovertemplate= "X: %{x:.2f}<br>Y: %{y:.2f}<br><b> %{z:.4g}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) if xunit == yunit: # real aspect ratio if xrange['max'] - xrange['min'] > yrange['max'] - yrange[ 'min']: aspectratio = dict(x=np.asarray([ 4., (xrange['max'] - xrange['min']) / np.asarray([1.e-5, (yrange['max'] - yrange['min'])]).max() ]).min(), y=1) else: aspectratio = dict( x=1, y=np.asarray([ 4, (yrange['max'] - yrange['min']) / np.asarray( [1.e-5, (xrange['max'] - xrange['min'])]).max() ]).min()) else: aspectratio = dict(x=1.25, y=1) width = 180 + 300 * aspectratio['x'] height = 90 + 300 * aspectratio['y'] fig.update_layout(autosize=False, height=height, width=width, margin=dict(t=45, b=45, l=40, r=140), title=dict(text=txttop), annotations=[ dict(text="Lon [deg]", x=0.5, y=-0.10, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ], xaxis=dict(tickmode='linear', tick0=0, dtick=30), yaxis=dict(tickmode='linear', tick0=0, dtick=30)) return fig if self.plottype == "LonIP" or self.plottype == "LonH": xint = self.newz yint = self.newx / self.xfactor xunit = self.zunit yunit = self.xunit xrange = dict(min=xint.min(), max=xint.max(), n=len(xint)) yrange = dict(min=yint.min(), max=yint.max(), n=len(yint)) # Reshape interpolated values into 2D result2 = np.reshape(result, (self.nX, self.nZ)) # def plot_XZ(xint = xint, yint = yint): # return result2 print(style) if style == "linear": def plot_XZ(xint=xint, yint=yint): return result2 if style == "log": def plot_XZ(xint=xint, yint=yint): return np.log(result2) plotXZ = Kamodo(plot_XZ=plot_XZ) fig = plotXZ.plot(plot_XZ=dict()) # fig.update_xaxes(title_text="",scaleanchor='y') fig.update_xaxes(title_text="") vert_coord = self.xname vert_unit = self.xunit vert_format = self.xformat txttop = self.cut + " " + self.cutunit + "=" + str(self.plots[ self.plottype]['cutV']) + " slice, Time = " + self.filetime fig.update_yaxes(title_text=vert_coord + " " + vert_unit, tickformat=".4g") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "BlueRed": fig.update_traces( colorscale="RdBu", reversescale=True, ) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") else: fig.update_traces(colorscale="Viridis") fig.update_traces( # zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar, tickformat='.4g'), hovertemplate="Lon: %{x:.2f}<br>" + vert_coord + ": %{y:" + vert_format + "}<br><b> %{z:.4g}</b><extra></extra>", # hovertemplate="Lon: %{x:.2f}<br>"+vert_coord+": %{y:.2f}<br><b> %{z:.4g}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) if xunit == yunit: # real aspect ratio if xrange['max'] - xrange['min'] > yrange['max'] - yrange[ 'min']: aspectratio = dict(x=np.asarray([ 4., (xrange['max'] - xrange['min']) / np.asarray([1.e-5, (yrange['max'] - yrange['min'])]).max() ]).min(), y=1) else: aspectratio = dict( x=1, y=np.asarray([ 4, (yrange['max'] - yrange['min']) / np.asarray( [1.e-5, (xrange['max'] - xrange['min'])]).max() ]).min()) else: aspectratio = dict(x=1.25, y=1) width = 180 + 300 * aspectratio['x'] height = 90 + 300 * aspectratio['y'] fig.update_layout(autosize=False, height=height, width=width, margin=dict(t=45, b=45, l=40, r=140), title_text=txttop, annotations=[ dict(text="Lon [deg]", x=0.5, y=-0.10, showarrow=False, xref="paper", yref="paper", font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-65, yshift=-42, xref="paper", yref="paper") ]) return fig if self.plottype == "LatIP" or self.plottype == "LatH": xint = self.newy yint = self.newx / self.xfactor txttop = self.cut + " " + self.cutunit + "=" + str(self.plots[ self.plottype]['cutV']) + " slice, Time = " + self.filetime xunit = self.yunit yunit = self.xunit vert_coord = self.xname vert_format = self.xformat xrange = dict(min=xint.min(), max=xint.max(), n=len(xint)) yrange = dict(min=yint.min(), max=yint.max(), n=len(yint)) # Reshape interpolated values into 2D # result2=np.transpose(np.reshape(result,(self.nY,self.nX))) result2 = np.reshape(result, (self.nX, self.nY)) if style == "linear": def plot_XY(xint=xint, yint=yint): return result2 if style == "log": def plot_XY(xint=xint, yint=yint): return np.log(result2) plotXY = Kamodo(plot_XY=plot_XY) fig = plotXY.plot(plot_XY=dict()) # fig.update_xaxes(title_text="",scaleanchor='y') fig.update_xaxes(title_text="") fig.update_yaxes(title_text=vert_coord + " " + yunit, tickformat=".4g") # Choose colorscale if colorscale == "Rainbow": fig.update_traces( colorscale=[[0.00, 'rgb(0,0,255)'], [ 0.25, 'rgb(0,255,255)' ], [0.50, 'rgb(0,255,0)'], [0.75, 'rgb(255,255,0)'], [1.00, 'rgb(255,0,0)']]) elif colorscale == "Cividis": fig.update_traces(colorscale="Cividis") elif colorscale == "BlueRed": fig.update_traces( colorscale="RdBu", reversescale=True, ) else: fig.update_traces(colorscale="Viridis") fig.update_traces( # zmin=cmin, zmax=cmax, ncontours=201, colorbar=dict(title=txtbar, tickformat='.4g'), hovertemplate="Lat: %{x:.2f}<br>" + vert_coord + ": %{y:" + vert_format + "}<br><b> %{z:.4g}</b><extra></extra>", # hovertemplate="Lat: %{x:.2f}<br>"+vert_coord+": %{y:.2f}<br><b> %{z:.4g}</b><extra></extra>", contours=dict(coloring="fill", showlines=False)) if xunit == yunit: # real aspect ratio if xrange['max'] - xrange['min'] > yrange['max'] - yrange[ 'min']: aspectratio = dict(x=np.asarray([ 4., (xrange['max'] - xrange['min']) / np.asarray([1.e-5, (yrange['max'] - yrange['min'])]).max() ]).min(), y=1) if aspectratio['x'] > 2: aspectratio_x = aspectratio['x'] aspectratio = dict(x=2., y=aspectratio['y'] * 2. / aspectratio_x) else: aspectratio = dict( x=1, y=np.asarray([ 4, (yrange['max'] - yrange['min']) / np.asarray( [1.e-5, (xrange['max'] - xrange['min'])]).max() ]).min()) else: aspectratio = dict(x=1.25, y=1) width = 180 + 300 * aspectratio['x'] height = 90 + 300 * aspectratio['y'] fig.update_layout(autosize=False, height=height, width=width, margin=dict(t=45, b=45, l=40, r=140), title_text=txttop, annotations=[ dict(text="Lat [deg]", x=0.5, y=0.0, showarrow=False, xref="paper", yref="paper", yshift=-32, font=dict(size=14)), dict(text=txtbot, font=dict(size=16, family="sans serif", color="#000000"), x=0.0, y=0.0, ax=0, ay=0, xanchor="left", xshift=-45, yshift=-42, xref="paper", yref="paper") ]) return fig print("ERROR, unknown plottype =", plottype, ", exiting without definition of figure.") return