def contour_temp(ds: xr.core.dataset.Dataset, in_year: int, ax: mpl.axes.Axes, title: str, central_longitude: int = 0) -> mpl.axes.Axes: """Takes in a Dataset for Temperature, and creates a contour plot for the data for the given year. Adds a darkgrey landmask, grindlines, coastlines, a title, and a colorbar to the plot.""" clevs = np.arange(260, 320, 10) # Can also choose to define colormap colors = ['blue', 'green', 'yellow', 'orange', 'red'] crs = ccrs.PlateCarree(central_longitude=central_longitude) # Specify variables X = ds['xt_ocean'] Y = ds['yt_ocean'] # Already grouped by year Z = ds['temp'].sel(year=in_year).squeeze() Z, X = add_cyclic_point(Z, coord=X) # can also use cmap='plasma','inferno',etc... im = ax.contourf(X, Y, Z, levels=clevs, transform=crs) if ax == plt.gcf().get_axes()[0]: cbar = plt.colorbar(im, ax=plt.gcf().get_axes(), orientation='horizontal', fraction=0.05, pad=0.05) cbar.set_label('Temeprature ($^\circ\,K$)', fontsize=18) # Zoom in on a region # ax.set_extent([x0,x1,y0,y1]) # Add land mask, gridlines, coastlines, and title ax.add_feature(cfeature.LAND, zorder=10, facecolor='darkgray') ax.gridlines() ax.coastlines() ax.set_title(title + " " + str(in_year), fontsize=18, loc='center') return ax
def contour_oa(ds: xr.core.dataset.Dataset, in_year: int, ax: mpl.axes.Axes, title: str, central_longitude: int = 0) -> mpl.axes.Axes: """Takes in a Dataset for Omega Aragonite, and creates a contour plot for the data for the given year. Adds a darkgrey landmask, grindlines, coastlines, a title, and a colorbar to the plot.""" clevs = np.array([0, 1, 2, 3, 4]) # Can also choose to define colormap # colors = ['red', 'orange', 'yellow','green','blue'] crs = ccrs.PlateCarree(central_longitude=central_longitude) # Specify variables X = ds['XT_OCEAN'] Y = ds['YT_OCEAN'] # Already grouped by year Z = ds['OMEGA_ARAG'].sel(year=in_year).squeeze() Z, X = add_cyclic_point(Z, coord=X) im = ax.contourf(X, Y, Z, clevs, transform=crs) if ax == plt.gcf().get_axes()[0]: cbar = plt.colorbar(im, ax=plt.gcf().get_axes(), orientation='horizontal', fraction=0.05, pad=0.05) cbar.set_label('$\Omega$ Aragonite', fontsize=18) # Zoom in on a region # ax.set_extent([x0,x1,y0,y1]) # Add land mask, gridlines, coastlines, and title ax.add_feature(cfeature.LAND, zorder=10, facecolor='darkgray') ax.gridlines() ax.coastlines() ax.set_title(title + " " + str(in_year), fontsize=18, loc='center') return ax
def southern_ocean_axes_setup( ax: matplotlib.axes.Axes, fig: matplotlib.figure.Figure, add_gridlines: bool = True, ) -> None: """ This function sets up the subplot so that it is a cartopy map of the southern ocean. returns void as the ax and figure objects are pointers not data. Args: ax (matplotlib.axes.Axes): The axis object to add the map to. fig (matplotlib.figure.Figure): The figure object for the figure in general. add_gridlines (bool): whether or not to add gridlines to the plot. """ carree = ccrs.PlateCarree() ax.set_extent([-180, 180, -90, -30], carree) fig.subplots_adjust(bottom=0.05, top=0.95, left=0.04, right=0.95, wspace=0.02) def plot_boundary() -> None: """ Makes SO plot boundary into a nice circle of the right size. """ theta = np.linspace(0, 2 * np.pi, 100) center, radius = [0.5, 0.5], 0.45 verts = np.vstack([np.sin(theta), np.cos(theta)]).T circle = mpath.Path(verts * radius + center) ax.set_boundary(circle, transform=ax.transAxes) plot_boundary() # add coastlines and gridlines ax.coastlines(resolution="50m", linewidth=0.3) if add_gridlines: ax.gridlines(linewidth=0.5) # Add 2000m isobath (or whatever the max depth is). @jit(cache=True) # significant performance enhancement. def find_isobath(tmp_bathymetry: np.ndarray, crit_depth=cst.MAX_DEPTH) -> List[list]: """ Find isobath. Args: tmp_bathymetry (np.ndarray): Bathymetry np array. crit_depth ([type], optional): Critical depth. Defaults to cst.MAX_DEPTH. Returns: List[list]: List of index pairs. """ isobath_index_list = [] shape_bathymetry = np.shape(tmp_bathymetry) for i in range(0, shape_bathymetry[0] - 1): for j in range(0, shape_bathymetry[1] - 1): if tmp_bathymetry[i, j] >= crit_depth: if tmp_bathymetry[i - 1, j] < crit_depth: isobath_index_list.append([i, j]) if tmp_bathymetry[i, j - 1] < crit_depth: isobath_index_list.append([i, j]) if tmp_bathymetry[i + 1, j] < crit_depth: isobath_index_list.append([i, j]) if tmp_bathymetry[i, j + 1] < crit_depth: isobath_index_list.append([i, j]) return isobath_index_list i_list = find_isobath( xr.open_dataset(cst.SALT_FILE)[cst.DEPTH_NAME].values, crit_depth=cst.MAX_DEPTH, ) index_npa: np.ndarray = np.array(i_list) lons = xr.open_dataset(cst.SALT_FILE)[cst.X_COORD].values[index_npa[:, 1]] lats = xr.open_dataset(cst.SALT_FILE)[cst.Y_COORD].values[index_npa[:, 0]] ax.plot(lons, lats, ",", markersize=0.4, color="grey", transform=ccrs.Geodetic())