def contour_transition(da_transition: xr.DataArray, ax: mpl.axes.Axes, rcp: str): """Takes in DataArray for transition time from x to y months Omega Aragonite undersaturation, axes for the plot, and the simulation name, and makes a contour plot.""" crs = ccrs.Robinson(central_longitude=180) src = ccrs.PlateCarree() clevs = np.arange(0, 31, 5) lon = da_transition.xt_ocean.data lat = da_transition.yt_ocean.data im = ax.contourf(lon, lat, da_transition, cmap='plasma', levels=clevs, transform=src, robust=True) 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( 'Transition Time from 1-->6 Months Undersaturated (years)', fontsize=16) ax.add_feature(cfeature.LAND, zorder=10, facecolor='darkgray') ax.set_global() ax.set_title(rcp)
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 contour_emergence(da_emergence: xr.DataArray, m: int, ax: mpl.axes.Axes, rcp: str = None): """Takes in DataArray for time of emergence, axes for the plot, number of undersaturation months for recognized signal, and simulation name, and makes a contour plot.""" crs = ccrs.Robinson(central_longitude=180) src = ccrs.PlateCarree() clevs = np.arange(1950, 2101, 10) lon = da_emergence.xt_ocean.data lat = da_emergence.yt_ocean.data im = ax.contourf(lon, lat, da_emergence, cmap='plasma', levels=clevs, transform=src, robust=True) 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('Year of Emergence', fontsize=16) ax.add_feature(cfeature.LAND, zorder=10, facecolor='darkgray') ax.set_global() if m == 1: months = 'month' else: months = 'months' if rcp == None: ax.set_title(str(m) + ' ' + months + '/year', fontsize=16) else: ax.set_title(rcp + ' - ' + str(m) + ' ' + months + '/year', fontsize=16)