def slice_plot (data, grid, gtype='t', lon0=None, lat0=None, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, ctype='basic', title=None, date_string=None, fig_name=None): # Choose what the endpoints of the colourbar should do extend = get_extend(vmin=vmin, vmax=vmax) # Build the patches and get the bounds patches, values, loc0, hmin, hmax, zmin, zmax, vmin_tmp, vmax_tmp = slice_patches(data, grid, gtype=gtype, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax) # Update any colour bounds which aren't already set if vmin is None: vmin = vmin_tmp if vmax is None: vmax = vmax_tmp # Set colour map cmap, vmin, vmax = set_colours(values, ctype=ctype, vmin=vmin, vmax=vmax) # Figure out orientation and format slice location if lon0 is not None: h_axis = 'lat' loc_string = lon_label(loc0, 3) elif lat0 is not None: h_axis = 'lon' loc_string = lat_label(loc0, 3) # Set up the title if title is None: title = '' title += ' at ' + loc_string # Plot fig, ax = plt.subplots() # Add patches img = plot_slice_patches(ax, patches, values, hmin, hmax, zmin, zmax, vmin, vmax, cmap=cmap) # Make nice axis labels slice_axes(ax, h_axis=h_axis) # Add a colourbar plt.colorbar(img, extend=extend) # Add a title plt.title(title, fontsize=18) if date_string is not None: # Add the date in the bottom right corner plt.text(.99, .01, date_string, fontsize=14, ha='right', va='bottom', transform=fig.transFigure) finished_plot(fig, fig_name=fig_name)
def slice_plot (data, grid, gtype='t', lon0=None, lat0=None, point0=None, point1=None, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, contours=None, ctype='basic', title='', date_string=None, fig_name=None): # Choose what the endpoints of the colourbar should do extend = get_extend(vmin=vmin, vmax=vmax) # Build the patches and get the bounds if lon0 is not None or lat0 is not None: # Lat-lon slices # Get gridded data and axes just in case patches, values, loc0, hmin, hmax, zmin, zmax, vmin_tmp, vmax_tmp, data_grid, haxis, zaxis = slice_patches(data, grid, gtype=gtype, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_gridded=True) elif point0 is not None and point1 is not None: # Transect loc0 = None patches, values, hmin, hmax, zmin, zmax, vmin_tmp, vmax_tmp, data_grid, haxis, zaxis = transect_patches(data, grid, point0, point1, gtype=gtype, zmin=zmin, zmax=zmax, return_gridded=True) else: print 'Error (slice_plot): must specify either lon0, lat0, or point0 and point1' sys.exit() # Update any colour bounds which aren't already set if vmin is None: vmin = vmin_tmp if vmax is None: vmax = vmax_tmp # Plot make_slice_plot(patches, values, loc0, hmin, hmax, zmin, zmax, vmin, vmax, lon0=lon0, lat0=lat0, point0=point0, point1=point1, contours=contours, data_grid=data_grid, haxis=haxis, zaxis=zaxis, ctype=ctype, extend=extend, title=title, date_string=date_string, fig_name=fig_name)
def ts_slice_plot_diff (temp_1, temp_2, salt_1, salt_2, grid, lon0=None, lat0=None, point0=None, point1=None, hmin=None, hmax=None, zmin=None, zmax=None, tmin=None, tmax=None, smin=None, smax=None, tcontours=None, scontours=None, date_string=None, fig_name=None): # Choose what the endpoints of the colourbars should do extend = [get_extend(vmin=tmin, vmax=tmax), get_extend(vmin=smin, vmax=smax)] # Build the patches and temperature values for the first simulation # vmin and vmax don't matter, so just store them as temporary variables if lon0 is not None or lat0 is not None: # Lat-lon slices # Get gridded data and axes just in case patches, temp_values_1, loc0, hmin, hmax, zmin, zmax, tmp1, tmp2, left, right, below, above, temp_grid_1, haxis, zaxis = slice_patches(temp_1, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) # Get the temperature values for the second simulation on the same patches temp_values_2, tmp3, tmp4, temp_grid_2 = slice_values(temp_2, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0, return_gridded=True) # Get the salinity values for both simulations salt_values_1, tmp5, tmp6, salt_grid_1 = slice_values(salt_1, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0, return_gridded=True) salt_values_2, tmp7, tmp8, salt_grid_2 = slice_values(salt_2, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0, return_gridded=True) elif point0 is not None and point1 is not None: # Transect loc0 = None patches, temp_values_1, hmin, hmax, zmin, zmax, tmp1, tmp2, left, right, below, above, temp_grid_1, haxis, zaxis = transect_patches(temp_1, grid, point0, point1, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) temp_values_2, tmp3, tmp4, temp_grid_2 = transect_values(temp_2, grid, point0, point1, left, right, below, above, hmin, hmax, zmin, zmax, return_gridded=True) salt_values_1, tmp5, tmp6, salt_grid_1 = transect_values(salt_1, grid, point0, point1, left, right, below, above, hmin, hmax, zmin, zmax, return_gridded=True) salt_values_2, tmp7, tmp8, salt_grid_2 = transect_values(salt_2, grid, point0, point1, left, right, below, above, hmin, hmax, zmin, zmax, return_gridded=True) else: print 'Error (ts_slice_plot_diff): must specify either lon0, lat0, or point0 and point1' sys.exit() # Calculate the differences temp_values_diff = temp_values_2 - temp_values_1 salt_values_diff = salt_values_2 - salt_values_1 temp_grid = temp_grid_2 - temp_grid_1 salt_grid = salt_grid_2 - salt_grid_1 # Now figure out the colour bounds tmin_tmp, tmax_tmp = get_slice_minmax(np.reshape(temp_values_diff, left.shape), left, right, below, above, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_spatial=False) smin_tmp, smax_tmp = get_slice_minmax(np.reshape(salt_values_diff, left.shape), left, right, below, above, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_spatial=False) # Update any colour bounds which aren't already set if tmin is None: tmin = tmin_tmp if tmax is None: tmax = tmax_tmp if smin is None: smin = smin_tmp if smax is None: smax = smax_tmp # Plot make_ts_slice_plot(patches, temp_values_diff, salt_values_diff, loc0, hmin, hmax, zmin, zmax, tmin, tmax, smin, smax, lon0=lon0, lat0=lat0, point0=point0, point1=point1, tcontours=tcontours, scontours=scontours, temp_grid=temp_grid, salt_grid=salt_grid, haxis=haxis, zaxis=zaxis, extend=extend, diff=True, date_string=date_string, fig_name=fig_name)
def ts_slice_plot (temp, salt, grid, lon0=None, lat0=None, point0=None, point1=None, hmin=None, hmax=None, zmin=None, zmax=None, tmin=None, tmax=None, smin=None, smax=None, tcontours=None, scontours=None, date_string=None, fig_name=None): # Choose what the endpoints of the colourbars should do extend = [get_extend(vmin=tmin, vmax=tmax), get_extend(vmin=smin, vmax=smax)] # Build the temperature patches and get the bounds if lon0 is not None or lat0 is not None: # Lat-lon slices # Get gridded data and axes just in case patches, temp_values, loc0, hmin, hmax, zmin, zmax, tmin_tmp, tmax_tmp, left, right, below, above, temp_grid, haxis, zaxis = slice_patches(temp, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) # Get the salinity values on the same patches, and their colour bounds salt_values, smin_tmp, smax_tmp, salt_grid = slice_values(salt, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0, return_gridded=True) elif point0 is not None and point1 is not None: # Transect loc0 = None patches, temp_values, hmin, hmax, zmin, zmax, tmin_tmp, tmax_tmp, left, right, below, above, temp_grid, haxis, zaxis = transect_patches(temp, grid, point0, point1, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) salt_values, smin_tmp, smax_tmp, salt_grid = transect_values(salt, grid, point0, point1, left, right, below, above, hmin, hmax, zmin, zmax, return_gridded=True) else: print 'Error (ts_slice_plot): must specify either lon0, lat0, or point0 and point1' sys.exit() # Update any colour bounds which aren't already set if tmin is None: tmin = tmin_tmp if tmax is None: tmax = tmax_tmp if smin is None: smin = smin_tmp if smax is None: smax = smax_tmp # Make the plot make_ts_slice_plot(patches, temp_values, salt_values, loc0, hmin, hmax, zmin, zmax, tmin, tmax, smin, smax, lon0=lon0, lat0=lat0, point0=point0, point1=point1, tcontours=tcontours, scontours=scontours, temp_grid=temp_grid, salt_grid=salt_grid, haxis=haxis, zaxis=zaxis, extend=extend, date_string=date_string, fig_name=fig_name)
def slice_plot_diff (data_1, data_2, grid, gtype='t', lon0=None, lat0=None, point0=None, point1=None, hmin=None, hmax=None, zmin=None, zmax=None, vmin=None, vmax=None, contours=None, title='', date_string=None, fig_name=None): # Choose what the endpoints of the colourbar should do extend = get_extend(vmin=vmin, vmax=vmax) # Build the patches for the first array # vmin and vmax don't matter, so just store them as temporary variables # Then get the values for the second array on the same patches if lon0 is not None or lat0 is not None: # Lat-lon slices # Get gridded data and axes just in case patches, values_1, loc0, hmin, hmax, zmin, zmax, tmp1, tmp2, left, right, below, above, data_grid_1, haxis, zaxis = slice_patches(data_1, grid, gtype=gtype, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) values_2, tmp3, tmp4, data_grid_2 = slice_values(data_2, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0, return_gridded=True) elif point0 is not None and point1 is not None: # Transect loc0 = None patches, values_1, hmin, hmax, zmin, zmax, tmp1, tmp2, left, right, below, above, data_grid_1, haxis, zaxis = transect_patches(data_1, grid, point0, point1, gtype=gtype, zmin=zmin, zmax=zmax, return_bdry=True, return_gridded=True) values_2, tmp3, tmp4, data_grid_2 = transect_values(data_2, grid, point0, point1, left, right, below, above, hmin, hmax, zmin, zmax, gtype=gtype, return_gridded=True) else: print 'Error (slice_plot_diff): must specify either lon0, lat0, or point0 and point1' sys.exit() # Calculate the difference values_diff = values_2 - values_1 data_grid = data_grid_2 - data_grid_1 # Now figure out the colour bounds # Note we need to reshape the values array to be 2D again vmin_tmp, vmax_tmp = get_slice_minmax(np.reshape(values_diff, left.shape), left, right, below, above, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_spatial=False) # Update any colour bounds which aren't already set if vmin is None: vmin = vmin_tmp if vmax is None: vmax = vmax_tmp # Plot make_slice_plot(patches, values_diff, loc0, hmin, hmax, zmin, zmax, vmin, vmax, lon0=lon0, lat0=lat0, point0=point0, point1=point1, contours=contours, data_grid=data_grid, haxis=haxis, zaxis=zaxis, ctype='plusminus', extend=extend, title=title, date_string=date_string, fig_name=fig_name)
def ts_slice_plot (temp, salt, grid, lon0=None, lat0=None, hmin=None, hmax=None, zmin=None, zmax=None, tmin=None, tmax=None, smin=None, smax=None, date_string=None, fig_name=None): # Choose what the endpoints of the colourbars should do extend = [get_extend(vmin=tmin, vmax=tmax), get_extend(vmin=smin, vmax=smax)] # Build the temperature patches and get the bounds patches, temp_values, loc0, hmin, hmax, zmin, zmax, tmin_tmp, tmax_tmp, left, right, below, above = slice_patches(temp, grid, lon0=lon0, lat0=lat0, hmin=hmin, hmax=hmax, zmin=zmin, zmax=zmax, return_bdry=True) # Get the salinity values on the same patches, and their colour bounds salt_values, smin_tmp, smax_tmp = slice_values(salt, grid, left, right, below, above, hmin, hmax, zmin, zmax, lon0=lon0, lat0=lat0) # Update any colour bounds which aren't already set if tmin is None: tmin = tmin_tmp if tmax is None: tmax = tmax_tmp if smin is None: smin = smin_tmp if smax is None: smax = smax_tmp # Figure out orientation and format slice location if lon0 is not None: h_axis = 'lat' loc_string = lon_label(loc0, 3) elif lat0 is not None: h_axis = 'lon' loc_string = lat_label(loc0, 3) # Set panels fig, gs, cax_t, cax_s = set_panels('1x2C2') # Wrap some things up in lists for easier iteration values = [temp_values, salt_values] vmin = [tmin, smin] vmax = [tmax, smax] cax = [cax_t, cax_s] title = [r'Temperature ($^{\circ}$C)', 'Salinity (psu)'] for i in range(2): ax = plt.subplot(gs[0,i]) # Plot patches img = plot_slice_patches(ax, patches, values[i], hmin, hmax, zmin, zmax, vmin[i], vmax[i]) # Nice axes slice_axes(ax, h_axis=h_axis) if i == 1: # Don't need depth labels a second time ax.set_yticklabels([]) ax.set_ylabel('') # Add a colourbar and hide every second label so they're not squished cbar = plt.colorbar(img, cax=cax[i], extend=extend[i], orientation='horizontal') for label in cbar.ax.xaxis.get_ticklabels()[1::2]: label.set_visible(False) # Variable title plt.title(title[i], fontsize=18) if date_string is not None: # Add date to main title loc_string += ', ' + date_string # Main title plt.suptitle(loc_string, fontsize=20) finished_plot(fig, fig_name=fig_name)