예제 #1
0
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')
예제 #2
0
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')
예제 #4
0
lmix = np.log10(mmix+1e-8)
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')
예제 #5
0
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])
    ax.set_yticks([42, 44, 46, 48, 50, 52])
예제 #6
0
    # create interpolant
    upi = intp.interp2d(lonr_s[0, :], latr_s[:, 0], upd[t, :])
    vpi = intp.interp2d(lonr_s[0, :], latr_s[:, 0], vpd[t, :])
    uai = intp.interp2d(lonr_s[0, :], latr_s[:, 0], uad[t, :])
    vai = intp.interp2d(lonr_s[0, :], latr_s[:, 0], vad[t, :])

    rs = np.ma.masked_where(maskr == 0, dens)
    p = ax0.pcolormesh(lonr,
                       latr,
                       rs,
                       vmin=-vmax,
                       vmax=vmax,
                       cmap='RdYlBu_r',
                       alpha=1.0)
    ax0.axis(a_ll)
    pfun.dar(ax0)
    ax0.set_xlabel('Longitude', fontweight='bold')
    ax0.set_ylabel('Latitude', fontweight='bold')
    ax0.set_title(ax0_title, fontweight='bold')
    cbar = plt.colorbar(p, orientation='horizontal', pad=0.1)
    cbar.ax.set_xlabel(r'$kg/m^{3}$')

    if t == 0:
        # create regular grid
        aaa = ax0.axis()
        daax = aaa[1] - aaa[0]
        daay = aaa[3] - aaa[2]
        axrat = np.cos(np.deg2rad(aaa[2])) * daax / daay
        x = np.linspace(aaa[0], aaa[1], int(round(nngrid * axrat)))
        y = np.linspace(aaa[2], aaa[3], nngrid)
        xx, yy = np.meshgrid(x, y)
    ax1.axis(aa1)
    ax1.grid(True)
    ax1.set_ylabel('Transport $[1000\ m^{3}s^{-1}]$')
    ax1.set_title(season.title() + ' ' + year_str)

    ax1.fill([aa2[0], aa2[1], aa2[1], aa2[0], aa2[0]],
             [aa2[2], aa2[2], aa2[3], aa2[3], aa2[2]],
             'orange',
             alpha=.3)

    ax2.axis(aa2)
    ax2.grid(True)
    ax2.set_ylabel('Transport $[1000\ m^{3}s^{-1}]$')

    pfun.add_coast(ax3, color='gray')
    pfun.dar(ax3)
    ax3.axis(aa3)
    ax3.set_xticks([])
    ax3.set_yticks([])
    # just do these things once
    for sn in sect_df.index:
        x0, x1, y0, y1, landward = sect_df.loc[sn, :]
        ax3.text(x1,
                 y1,
                 sn,
                 fontsize=.6 * fs,
                 color='k',
                 va='center',
                 ha='center',
                 rotation=45,
                 style='italic',
예제 #8
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
        y = df_tr['lat'].values
예제 #9
0
             linestyle='None')
    #ax1.plot(lon0[:nt:24,tma],lat0[:nt:24,tma],'-k',alpha=0.2,linewidth=0.5)
    ax1.set_title('Plan view', fontweight='bold')

    ax2 = fig.add_subplot(1, 3, 3)
    a_lz = [lonr.min() + lpad, 1.2, -60, 5]
    p = ax2.pcolormesh(lonr[:NZ, :],
                       zr[:, midlat, :].squeeze(),
                       crosssalt,
                       vmin=0,
                       vmax=30,
                       cmap=cmap,
                       alpha=1.0)
    plt.colorbar(p)
    ax2.axis(a_lz)
    pfun.dar(ax2)
    ax2.set_aspect(1 / 80)
    ax2.set_xlabel('Longitude', fontweight='bold')
    ax2.set_ylabel('z (m)', fontweight='bold')
    #plot particles
    #ax2.plot(lon,z,'og',alpha=0.3)
    ax2.plot(lon1,
             z1,
             marker='o',
             color='black',
             markerfacecolor='magenta',
             alpha=1.0,
             linestyle='None')
    #ax2.plot(lon0[:nt:24,tma],z0[:nt:24,tma],'-k',alpha=0.2,linewidth=0.5)
    ax2.set_title('Cross shelf section', fontweight='bold')
예제 #10
0
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
예제 #11
0
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
예제 #12
0
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
예제 #13
0
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
        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([])
    ax2.tick_params(labelsize=.8*fs)
    ax2.text(.95,.9,'(b)', size=fs, transform=ax2.transAxes, ha='right', weight='bold')