def plotit(ax, aa, sect_df, sn): pfun.add_coast(ax) pfun.dar(ax) ax.axis(aa) ax.grid(True) x0 = sect_df.loc[sn,'x0']; x1 = sect_df.loc[sn,'x1'] y0 = sect_df.loc[sn,'y0']; y1 = sect_df.loc[sn,'y1'] xx = (x0+x1)/2; yy = (y0+y1)/2 if (xx > aa[0]) & (xx < aa[1]) & (yy > aa[2]) & (yy < aa[3]): ax.plot([x0,x1], [y0,y1], '-b', linewidth=3, alpha=.5) ax.text(xx, yy, sn, fontsize=12, color='r', fontweight='bold')
def P_carbon(in_dict): # START fig = plt.figure(figsize=figsize) ds = nc.Dataset(in_dict['fn']) vlims = in_dict['vlims'].copy() out_dict['vlims'] = vlims # PLOT CODE # panel 1 t_str = 'Surface TIC' ax = fig.add_subplot(121) vn = 'TIC' cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap='YlOrBr') fig.colorbar(cs) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') pfun.add_info(ax, in_dict['fn']) pfun.add_windstress_flower(ax, ds) # panel 2 t_str = 'Surface Alkalinity' ax = fig.add_subplot(122) vn = 'alkalinity' cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap='RdYlGn') fig.colorbar(cs) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') pfun.add_velocity_vectors(ax, ds, in_dict['fn']) # FINISH ds.close() if len(in_dict['fn_out']) > 0: plt.savefig(in_dict['fn_out']) plt.close() else: plt.show() return out_dict
def plotit(ax, aa, sect_df, sn): pfun.add_coast(ax) pfun.dar(ax) ax.axis(aa) ax.grid(True) x0 = sect_df.loc[sn, 'x0'] x1 = sect_df.loc[sn, 'x1'] y0 = sect_df.loc[sn, 'y0'] y1 = sect_df.loc[sn, 'y1'] xx = (x0 + x1) / 2 yy = (y0 + y1) / 2 if (xx > aa[0]) & (xx < aa[1]) & (yy > aa[2]) & (yy < aa[3]): ax.plot([x0, x1], [y0, y1], '-b', linewidth=3, alpha=.5) ax.text(xx, yy, sn, fontsize=12, color='r', fontweight='bold')
lmix_neap = np.log10(mmix_neap+1e-8) lmix_spring = np.log10(mmix_spring+1e-8) # PLOTTING plt.close('all') # MAPS OF MIXING per unit area fig = plt.figure(figsize=(18,8)) vmin = -6; vmax = -2 # full region ax = fig.add_subplot(131) cs = ax.pcolormesh(xp, yp, lmix[1:-1, 1:-1], vmin=vmin, vmax=vmax, cmap='rainbow') fig.colorbar(cs, ax=ax) pfun.dar(ax) pfun.add_coast(ax) ax.axis(aa) ax.set_title('$log_{10}[Average\ Mixing\ (psu^{2}\ m\ s^{-1})]$') ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') # close up of Puget Sound aa = [-123.25, -122, 47, 48.5] ax = fig.add_subplot(132) cs = ax.pcolormesh(xp, yp, lmix_neap[1:-1, 1:-1], vmin=vmin, vmax=vmax, cmap='rainbow') pfun.dar(ax) pfun.add_coast(ax) ax.axis(aa) ax.set_xlabel('Longitude') ax.set_title('Close-up of Puget Sound: NEAP')
plt.close('all') for add_stations in [True, False]: fig = plt.figure(figsize=(16,11)) # -------------- FULL MAP ----------------------------------------------- ax = fig.add_subplot(121) cs = ax.pcolormesh(lon[6:-6,6:],lat[6:-6,6:],v[6:-6,6:], cmap=cmap, vmin=vmin, vmax=vmax) nudge_alpha = .1 ax.pcolormesh(lon[:,:6],lat[:,:6],v[:,:6], cmap=cmap, vmin=vmin, vmax=vmax, alpha=nudge_alpha) ax.pcolormesh(lon[:6,:],lat[:6,:],v[:6,:], cmap=cmap, vmin=vmin, vmax=vmax, alpha=nudge_alpha) ax.pcolormesh(lon[-6:,:],lat[-6:,:],v[-6:,:], cmap=cmap, vmin=vmin, vmax=vmax, alpha=nudge_alpha) pfun.add_bathy_contours(ax, ds, txt=False) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) if add_stations: add_sta_loc(ax, moor_df, ctd_df, tide_df, do_leg=True) # Inset colorbar from mpl_toolkits.axes_grid1.inset_locator import inset_axes cbaxes = inset_axes(ax, width="4%", height="40%", loc='lower left', borderpad=3) cb = fig.colorbar(cs, cax=cbaxes, orientation='vertical') ax.text(.08, .53, r'SST $[^\circ C]$', transform=ax.transAxes) ax.text(.08, .03, dstr, size=fs2, transform=ax.transAxes, style='italic') ax.set_xticks([-130, -126, -122])
def draw_box(ax, x,y, s='-', c='k', w=3, a=1, t=''): ax.plot(x[:,0],y[:,0], linestyle=s, color=c, linewidth=w, alpha=a) ax.plot(x[:,-1],y[:,-1], linestyle=s, color=c, linewidth=w, alpha=a) ax.plot(x[0,:],y[0,:], linestyle=s, color=c, linewidth=w, alpha=a) ax.plot(x[-1,:],y[-1,:], linestyle=s, color=c, linewidth=w, alpha=a) ax.text(x[-1,-1]-1,y[-1,-1]-.5, t, fontweight='bold', color=c, horizontalalignment='right', verticalalignment='top') ax = plt.subplot2grid((1,3), (0,0), colspan=2) draw_box(ax, lon, lat, c='b', t='LiveOcean') draw_box(ax, lon2, lat2, c='g', t=('WRF d2\n(%0.1f km)' % (dx2_km))) draw_box(ax, lon3, lat3, c='orange', t=('WRF d3\n(%0.1f km)' % (dx3_km))) draw_box(ax, lon4, lat4, c='r', t=('WRF d4\n(%0.1f km)' % (dx4_km))) ax.set_title('(a) Grid extents') pfun.dar(ax) pfun.add_coast(ax, color='gray') ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.set_yticks([40, 45, 50]) ax = plt.subplot2grid((1,3), (0,2), colspan=1) al=.5 ax.plot(lon, lat, 'ob', markersize=2, alpha=al) ax.plot(lon2, lat2, 'sg', markersize=20, alpha=al) ax.plot(lon3, lat3, linestyle='', marker='o', color='orange', markersize=10, alpha=al) ax.plot(lon4, lat4, '*r', markersize=5, alpha=al) ax.axis([-123, -122.7, 47.55, 47.9]) ax.set_title('(b) Close up of grid spacing') pfun.dar(ax) pfun.add_coast(ax) ax.set_xlabel('Longitude')
counter = 0 for sn in sect_list: sn = sn.upper() ax1.text(dist[counter], qin[counter]+10, sn, rotation=45, fontsize=8) counter += 1 ax2.fill_between(dist, sout, y2=sin, color=lcol, alpha=.8) ax2.set_xlim(0,distmax) ax2.grid(True) ax2.set_xlabel('Distance from Mouth (km)', fontsize=fs) ax2.set_ylabel('$S_{in},\ S_{out}\ (psu)$', fontsize=fs) #ax2.legend() if lstr == 'JdF to South Sound': aa = [-125.5, -122, 46.7, 50.3] pfun.add_coast(ax3) pfun.dar(ax3) ax3.axis(aa) ax3.grid(True) plotit(ax3, sect_df, sect_list, lcol) # add rivers #%% get river info ri_fn = Gr['ri_dir'] + 'river_info.csv' df = pd.read_csv(ri_fn, index_col='rname') for rn in df.index: try: fn_tr = Gr['ri_dir'] + 'tracks/' + rn + '.csv' df_tr = pd.read_csv(fn_tr, index_col='ind') x = df_tr['lon'].values
def P_nest_plot(in_dict): # plots a field nested inside the corresponding HYCOM field # - currently only works for salt and temp - # START fig = plt.figure(figsize=figsize) ds = nc.Dataset(in_dict['fn']) vlims = in_dict['vlims'].copy() out_dict['vlims'] = vlims # PLOT CODE # ** choose the variable to plot ** which_var = 'temp' # need to get Ldir, which means unpacking gtagex fn = in_dict['fn'] gtagex = fn.split('/')[-3] gtx_list = gtagex.split('_') import Lfun Ldir = Lfun.Lstart(gtx_list[0], gtx_list[1]) # Get HYCOM field hyvar_dict = {'temp': 't3d', 'salt': 's3d'} hvar = hyvar_dict[which_var] f_string = fn.split('/')[-2] fnhy = (Ldir['LOo'] + Ldir['gtag'] + '/' + f_string + '/ocn/Data/' + hvar + '.nc') ds = nc.Dataset(fnhy) lon = ds.variables['lon'][:] lat = ds.variables['lat'][:] z = ds.variables['z'][:] # make sure zlev is in the HYCOM z zlev = zfun.find_nearest(z, in_dict['z_level']) nz = list(z).index(zlev) laym_hy = ds.variables[hvar + '_filt'][0, nz, :, :].squeeze() vlims = pfun.auto_lims(laym_hy) ds.close() aa = [lon.min(), lon.max(), lat.min(), lat.max()] # Get ROMS field ds = nc.Dataset(fn) zfull = pfun.get_zfull(ds, fn, 'rho') laym = pfun.get_laym(ds, zfull, ds['mask_rho'][:], which_var, zlev) # PLOTTING cmap = plt.get_cmap(name='gist_ncar') plt.close() fig, axes = plt.subplots(nrows=1, ncols=2, figsize=figsize, squeeze=False) # panel 1 ax = axes[0, 0] ax.set_title('HYCOM: z=' + str(zlev) + 'm, var=' + which_var) cs = ax.pcolormesh(lon, lat, laym_hy, vmin=vlims[0], vmax=vlims[1], cmap=cmap) ax.axis(aa) fig.colorbar(cs, ax=ax) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') # panel 2 ax = axes[0, 1] ax.set_title('HYCOM + ROMS') cs = ax.pcolormesh(lon, lat, laym_hy, vmin=vlims[0], vmax=vlims[1], cmap=cmap) ax.axis(aa) laymd = laym.data laymd[laym.mask] = 1e6 ax.pcolormesh(ds['lon_psi'][:], ds['lat_psi'][:], laymd[1:-1, 1:-1], vmin=vlims[0], vmax=vlims[1], cmap=cmap) fig.colorbar(cs, ax=ax) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) pfun.dar(ax) ax.set_xlabel('Longitude') # FINISH ds.close() if len(in_dict['fn_out']) > 0: plt.savefig(in_dict['fn_out']) plt.close() else: plt.show() return out_dict
def P_basic(in_dict): # This creates, and optionally saves, a basic plot of surface fields # from a ROMS history file. # INPUT a dict containing: # fn: text string with the full path name of the history file to plot # fn_out: text string with full path of output file name # in_dict: a tuple with optional information to pass to the plot # OUTPUT: either a screen image or a graphics file, and a dict of other # information such as axis limits. # START fig = plt.figure(figsize=figsize) ds = nc.Dataset(in_dict['fn']) vlims = in_dict['vlims'].copy() out_dict['vlims'] = vlims # PLOT CODE # panel 1 t_str = 'Surface Salinity' ax = fig.add_subplot(121) vn = 'salt' cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap='rainbow') fig.colorbar(cs) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.set_title(t_str) pfun.add_info(ax, in_dict['fn']) pfun.add_windstress_flower(ax, ds) # panel 2 t_str = 'Surface Temperature' ax = fig.add_subplot(122) vn = 'temp' cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap='bwr') fig.colorbar(cs) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') pfun.add_velocity_vectors(ax, ds, in_dict['fn']) # FINISH ds.close() if len(in_dict['fn_out']) > 0: plt.savefig(in_dict['fn_out']) plt.close() else: plt.show() return out_dict
def P_layer(in_dict): # START fig = plt.figure(figsize=figsize) ds = nc.Dataset(in_dict['fn']) vlims = in_dict['vlims'].copy() out_dict['vlims'] = vlims # PLOT CODE zfull = pfun.get_zfull(ds, in_dict['fn'], 'rho') # panel 1 t_str = 'Salinity' ax = fig.add_subplot(121) vn = 'salt' laym = pfun.get_laym(ds, zfull, ds['mask_rho'][:], vn, in_dict['z_level']) if len(vlims[vn]) == 0: vlims[vn] = pfun.auto_lims(laym) out_dict['vlims'][vn] = vlims[vn] cs = ax.pcolormesh(ds['lon_psi'][:], ds['lat_psi'][:], laym[1:-1, 1:-1], vmin=vlims[vn][0], vmax=vlims[vn][1], cmap='rainbow') cb = fig.colorbar(cs) cb.formatter.set_useOffset(False) cb.update_ticks() pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.set_title(t_str + ' on Z = ' + str(in_dict['z_level']) + ' m') pfun.add_info(ax, in_dict['fn']) pfun.add_windstress_flower(ax, ds) # panel 2 t_str = 'Temperature' ax = fig.add_subplot(122) vn = 'temp' laym = pfun.get_laym(ds, zfull, ds['mask_rho'][:], vn, in_dict['z_level']) if len(vlims[vn]) == 0: vlims[vn] = pfun.auto_lims(laym) out_dict['vlims'][vn] = vlims[vn] cs = ax.pcolormesh(ds['lon_psi'][:], ds['lat_psi'][:], laym[1:-1, 1:-1], vmin=vlims[vn][0], vmax=vlims[vn][1], cmap='bwr') cb = fig.colorbar(cs) cb.formatter.set_useOffset(False) cb.update_ticks() pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_xlabel('Longitude') ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') # FINISH ds.close() if len(in_dict['fn_out']) > 0: plt.savefig(in_dict['fn_out']) plt.close() else: plt.show() return out_dict
def P_bio(in_dict): # START ds = nc.Dataset(in_dict['fn']) vlims = in_dict['vlims'].copy() out_dict['vlims'] = vlims vn_list = ['NO3', 'phytoplankton', 'zooplankton', 'oxygen'] cmap_list = ['Oranges', 'Greens', 'BuPu', 'Spectral'] cmap_dict = dict(zip(vn_list, cmap_list)) NP = len(vn_list) if False: NR = np.maximum(1, np.ceil(np.sqrt(NP)).astype(int)) NC = np.ceil(np.sqrt(NP)).astype(int) figsize = (16, 16) else: NR = 1 NC = NP figsize = (23, 7) fig, axes = plt.subplots(nrows=NR, ncols=NC, figsize=figsize, squeeze=False) cc = 0 for vn in vn_list: ir = int(np.floor(cc / NC)) ic = int(cc - NC * ir) # PLOT CODE ax = axes[ir, ic] t_str = vn try: vlims[vn] except KeyError: vlims[vn] = () if vn == 'oxygen': cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap=cmap_dict[vn], slev=0) ax.text(.95, .04, 'BOTTOM', horizontalalignment='right', transform=ax.transAxes) else: cs, out_dict['vlims'][vn] = pfun.add_map_field(ax, ds, vn, vlims=vlims[vn], cmap=cmap_dict[vn]) fig.colorbar(cs, ax=ax) pfun.add_bathy_contours(ax, ds) pfun.add_coast(ax) ax.axis(pfun.get_aa(ds)) pfun.dar(ax) ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') if ir == NR - 1: ax.set_xlabel('Longitude') if ic == 0: ax.set_ylabel('Latitude') ax.set_title(t_str + ' (' + pfun.get_units(ds, vn) + ')') if cc == 0: pfun.add_info(ax, in_dict['fn']) cc += 1 # FINISH ds.close() if len(in_dict['fn_out']) > 0: plt.savefig(in_dict['fn_out']) plt.close() else: plt.show() return out_dict
np.abs(q_s[counter]), sn, rotation=45, fontsize=8) counter += 1 ax2.fill_between(dist, s_s, y2=s_f, color=lcol, alpha=.5) ax2.set_xlim(-5, distmax) ax2.set_ylim(21.5, 34) ax2.grid(True) ax2.set_xlabel('Distance from Mouth (km)', fontsize=fs) ax2.set_ylabel('Salinity', fontsize=fs) if do_plot_extras: aa = [-125.5, -122, 46.7, 50.4] pfun.add_coast(ax3) pfun.dar(ax3) ax3.axis(aa) ax3.set_title('Section Locations, and direction of deep inflow') for sn in sect_df.index: x0, x1, y0, y1, landward = sect_df.loc[sn, :] xx = (x0 + x1) / 2 yy = (y0 + y1) / 2 ax3.text(xx, yy, sn, rotation=45, fontsize=8) do_plot_extras = False # get the sign of q_s and plot the section locations with "inflow" direction # (defined as the direction of transport of the saltier water of the pair) qsign = np.sign(q_s) plotit(ax3, sect_df, sect_list, lcol, qsign)
ax2.text(sx, sy+.02, str(int(np.abs(F))), ha='center', va='center', size=ffs, weight='bold', color=cf, alpha=1) ax3.quiver(sx,sy, vq0, vq1, scale=scl, scale_units='height', linewidths=1, color=cq, alpha=aq) if sx < x00 or sy > y11: ax3.text(sx, sy+.04, str(int(np.abs(Q))), ha='center', va='center', size=ffs, weight='bold', color=cq, alpha=1) if sx > x00 and sy < y11: ax4.quiver(sx,sy, vq0, vq1, scale=scl, scale_units='height', linewidths=1, color=cq, alpha=aq) ax4.text(sx, sy+.02, str(int(np.abs(Q))), ha='center', va='center', size=ffs, weight='bold', color=cq, alpha=1) pfun.add_coast(ax1, color='gray') ax1.axis(aaS) pfun.dar(ax1) ax1.set_xticklabels([]) ax1.tick_params(labelsize=.8*fs) ax1.text(.95,.9,'(a)', size=fs, transform=ax1.transAxes, ha='right', weight='bold') ax1.set_ylabel('Latitude', size=.8*fs) ax1.set_xticks([-125, -124, -123, -122]) ax1.text(.05,.05,'Tidal energy Flux $[MW]$', size=.8*fs, transform=ax1.transAxes, weight='bold', color=cf) pfun.add_coast(ax2, color='gray') ax2.axis(aaP) pfun.dar(ax2) ax2.set_xticklabels([]) ax2.set_yticklabels([])