Exemple #1
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
Exemple #2
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])
Exemple #3
0
plt.close('all')
fig = plt.figure(figsize=(17,9))
fs = 18 # fontsize

# map field
ax = fig.add_subplot(131)
lon = ds['lon_psi'][:]
lat = ds['lat_psi'][:]
v =ds[vn][0, -1, 1:-1, 1:-1]
fac=pinfo.fac_dict[vn]
vv = fac * v
vv[:, :6] = np.nan
vv[:6, :] = np.nan
cs = ax.pcolormesh(lon, lat, vv, vmin=vlims[0], vmax=vlims[1], cmap=cmap)
pfun.add_coast(ax)
ax.axis(pfun.get_aa(ds))
pfun.dar(ax)
ax.set_axis_off()
# add a box for the subplot
aa = [-123.5, -122.1, 47.03, 48.8]
pfun.draw_box(ax, aa, color='c', alpha=.5, linewidth=5, inset=.01)

ax.text(.95, .07, 'LiveOcean\nPHYTOPLANKTON\n'
    + datetime.strftime(T['tm'], '%m/%d/%Y'), fontsize=fs, color='k',
    transform=ax.transAxes, horizontalalignment='center',
    fontweight='bold')

# PS map
# map field
#ax =  plt.subplot2grid((3,3), (1,2), rowspan=2)
ax = fig.add_subplot(132)
    ds1.close()
    ds2.close()

if testing:
    # try plotting some results
    import matplotlib.pyplot as plt
    plt.close('all')
    ds = nc.Dataset(out_fn)
    plon = ds['lon_psi'][:]
    plat = ds['lat_psi'][:]
    mask = ds['mask_rho'][1:-1, 1:-1]
    pth = os.path.abspath('../../plotting/')
    if pth not in sys.path:
        sys.path.append(pth)
    import pfun
    aa = pfun.get_aa(ds)

    fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(12, 7))

    vn_list = ['salt', 'temp', 'AKs', 'u', 'v', 'w']

    rr = [0, 0, 0, 1, 1, 1]
    cc = [0, 1, 2, 0, 1, 2]

    ii = 0
    for vn in vn_list:
        ax = axes[rr[ii], cc[ii]]
        vv = ds[vn][0, -1, 1:-1, 1:-1].squeeze()
        vv[mask == 0] = np.nan
        cs = ax.pcolormesh(plon, plat, vv, cmap='rainbow')
        fig.colorbar(cs, ax=ax)
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
0
if False:
    item = Lfun.choose_item(indir0)
else:
    item = 'cas4_v2_lo6biom_2017.06.01_2017.07.01'
indir = indir0 + item + '/'
if False:
    infile = Lfun.choose_item(indir, tag='.nc')
    fn = indir + infile
else:
    fn = indir + 'svar_hourly.nc'

ds = nc.Dataset(fn)
xp = ds['lon_psi'][:]
yp = ds['lat_psi'][:]
ot = ds['ocean_time'][:]
aa = pfun.get_aa(ds)
mix = ds['mix'][:]
mask= ds['mask_rho'][:] # 1 on water, 0 on land
DA = ds['DA'][:] # cell horizontal area
x = ds['lon_rho'][:]
y = ds['lat_rho'][:]
ds.close()

days = (ot - ot[0])/86400.
mdays = Lfun.modtime_to_mdate_vec(ot)
mdt = mdates.num2date(mdays) # list of datetimes of data

# neap time limits: centered on 2017.06.16
ii0_neap = 24*14
ii1_neap = 24*17
mmix_neap = mix[ii0_neap:ii1_neap,:,:].mean(axis=0)