예제 #1
0
def plot_cb(geofil,fil,xstart,xend,ystart,yend,zs,ze,meanax,
        savfil=None,perc=99):
    X,Y,P = extract_cb_terms(geofil,fil,xstart,xend,ystart,yend,zs,ze,meanax)
    cmax = np.nanpercentile(np.absolute(P),perc)
    fig,axc = plt.subplots(1,3,sharex=True,sharey=True,figsize=(10, 3))
    ti = ['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)','(j)']
    lab = [ r'$(\bar{h}\hat{u})_{\tilde{x}}$',
            r'$(\bar{h}\hat{v})_{\tilde{y}}$',
            r'$(\bar{h}\hat{\varpi})_{\tilde{b}}$']

    for i in range(P.shape[-1]):
        ax = axc.ravel()[i]
        im = m6plot((X,Y,P[:,:,i]),ax,vmax=cmax,vmin=-cmax,#ptype='imshow',
                txt=lab[i], ylim=(-2500,0),cmap='RdBu_r',cbar=False)

        xdegtokm(ax,0.5*(ystart+yend))
        if i == 0:
            ax.set_ylabel('z (m)')
        #ax.set_ylim(-1500,0)

    fig.tight_layout()
    cb = fig.colorbar(im, ax=axc.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()

    if savfil:
        plt.savefig(savfil+'.eps', dpi=300, facecolor='w', edgecolor='w',
                    format='eps', transparent=False, bbox_inches='tight')
    else:
        im = m6plot((X,Y,np.sum(P,axis=2)),vmax=cmax,vmin=-cmax,cmap='RdBu_r')
        plt.show()
def plot_momx(geofil,
              fil,
              xstart,
              xend,
              ystart,
              yend,
              zs,
              ze,
              meanax,
              savfil=None,
              alreadysaved=False):
    X, Y, P = extract_momx_terms(geofil, fil, xstart, xend, ystart, yend, zs,
                                 ze, meanax, alreadysaved)
    cmax = np.nanmax(np.absolute(P))
    fig = plt.figure(figsize=(12, 9))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [
        r'$\overline{(f+\zeta)v-(KE)_{\tilde{x}}}$',
        r'$-\overline{\varpi u_{\tilde{b}}}$', r'$-\overline{m_{\tilde{x}}}$',
        r'$\overline{X^H}$', r'$\overline{X^V}$'
    ]

    for i in range(P.shape[-1]):
        ax = plt.subplot(5, 2, i + 1)
        im = m6plot((X, Y, P[:, :, i]),
                    ax,
                    vmax=cmax,
                    vmin=-cmax,
                    txt=lab[i],
                    ylim=(-2500, 0),
                    cmap='RdBu_r')
        if i % 2:
            ax.set_yticklabels([])
        else:
            ax.set_ylabel('z (m)')

        if i > 2:
            xdegtokm(ax, 0.5 * (ystart + yend))

        else:
            ax.set_xticklabels([])

    if savfil:
        plt.savefig(savfil + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        im = m6plot((X, Y, np.sum(P, axis=2)), Zmax=cmax, cmap='RdBu_r')
        plt.show()
예제 #3
0
def plot_nt(geofil,vgeofil,fil,fil2,xstart,xend,ystart,yend,zs,ze,meanax,
        cmaxscalefactor = 1, savfil=None):
    X,Y,P,lr = extract_northward_transport(geofil,vgeofil,fil,fil2,xstart,xend,ystart,yend,zs,ze,meanax)
    cmax = np.nanmax(np.absolute(P))*cmaxscalefactor
    fig,ax = plt.subplots(1,2,sharey=True,figsize=(4,4))#,figsize=(8, 4))
    ti = [r'$\int_{-D}^{0} (vdx) dz$ $(m^3s^{-1}) \forall v>0$',
            r'$\int_{-D}^{0} (vdx) dz$ $(m^3s^{-1}) \forall v<0$']
    for i in range(P.shape[-1]):
        im = m6plot((X,Y,P[:,:,i]),ax[i],vmax=cmax,vmin=-cmax,ptype='imshow',
                cmap='RdBu_r',cbar=False)
        cs = ax[i].contour(X,Y,P[:,:,i],
                colors='k',levels=[-4,-3,3,4])
        cs.clabel(inline=True,fmt="%.3f")

        ax[i].plot(-np.nanmean(lr,axis=1),Y,lw=2,color='k')
        ax[i].grid(True)
        xdegtokm(ax[i],0.5*(ystart+yend))
    ax[0].set_ylabel(r'y ($^{\circ}$)')
    fig.tight_layout()
    cb = fig.colorbar(im,ax=[ax[0],ax[1]])
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()

#    ax[2].plot(np.nansum(P[:,:,0],axis=1)/1e3,Y,lw=2,label='North',color='r')
#    ax[2].plot(np.nansum(-P[:,:,1],axis=1)/1e3,Y,lw=2,label='South',color='b')
#    ax[2].set_xlabel('EB transport ($10^3 m^3s^{-1}$)')
#    #ax.text(0.1,0.05,r'$\int_{D}^{0} \int_{EB}^{} v dx dz$ ($m^3s^{-1}$)',transform=ax.transAxes)
#    ax[2].grid(True)
#    plt.legend(loc='best')

#    ax = plt.subplot(1,4,1)
#    ax.plot(np.nanmean(lr,axis=1),Y,lw=2,color='k')
#    ax.set_xlabel(r'$L_R$ (km)')
#    plt.ylabel(r'$y (^{\circ}$)')
#    ax.grid(True)
#    plt.tight_layout()
    
    if savfil:
        plt.savefig(savfil+'.eps', dpi=300, facecolor='w',
                    format='eps', transparent=True, bbox_inches='tight')
    else:
        return fig
def get_pveddy_coeffs(geofil,
                      vgeofil,
                      fil,
                      fil2,
                      xstart,
                      xend,
                      ystart,
                      yend,
                      zs=0,
                      ze=None,
                      z=np.linspace(-3000, 0, 100),
                      percx=0,
                      percy=0):

    fhgeo = dset(geofil)
    fhvgeo = dset(vgeofil)
    fh = mfdset(fil)
    fh2 = mfdset(fil2)
    db = fhvgeo.variables['g'][:]
    fhvgeo.close()
    dbi = np.append(db, 0)
    zi = fh.variables['zi'][:]
    zl = fh.variables['zl'][:]
    dbl = np.diff(zi) * 9.8 / 1031
    dt = fh.variables['average_DT'][:]
    dt = dt[:, np.newaxis, np.newaxis, np.newaxis]

    sl, dimq = rdp1.getslice(fh,
                             xstart,
                             xend,
                             ystart,
                             yend,
                             xhxq='xq',
                             yhyq='yq')
    xs = sl[3].start
    xe = sl[3].stop
    ys = sl[2].start
    ye = sl[2].stop
    zs = sl[1].start
    ze = sl[1].stop
    slmx = np.s_[:, :, sl[2], (sl[3].start - 1):sl[3].stop]
    slpx = np.s_[:, :, sl[2], (sl[3].start + 1):sl[3].stop]
    slmxpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1),
                   (sl[3].start - 1):sl[3].stop]
    slpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1), sl[3]]
    sl2d = sl[2:]
    slmx2d = slmx[2:]
    slpx2d = slpx[2:]

    dxbu = fhgeo.variables['dxBu'][sl2d]
    dxcv = fhgeo.variables['dxCv'][sl2d]
    e = (fh2.variables['e'][slpy] * dt).sum(axis=0, keepdims=True) / dt.sum(
        axis=0, keepdims=True)
    e = np.concatenate((e, e[:, :, :, -1:]), axis=3)
    eatq = 0.25 * (e[:, :, :-1, :-1] + e[:, :, 1:, 1:] + e[:, :, 1:, :-1] +
                   e[:, :, :-1, 1:])

    (_, _, _, q, _, _) = pv2.extract_twapv_terms(geofil,
                                                 vgeofil,
                                                 fil,
                                                 fil2,
                                                 xs - 1,
                                                 xe,
                                                 ys,
                                                 ye,
                                                 zs,
                                                 ze,
                                                 meanax=(0, ),
                                                 fil3=None,
                                                 calledfromgeteddycoeffs=True)
    (_, _, _, _, qbud,
     _) = pv2.extract_twapv_terms(geofil,
                                  vgeofil,
                                  fil,
                                  fil2,
                                  xs,
                                  xe,
                                  ys,
                                  ye,
                                  zs,
                                  ze,
                                  meanax=(0, ),
                                  fil3=None,
                                  calledfromgeteddycoeffs=True)
    fd = qbud[:, :, :, :, 12]
    q[np.isnan(q)] = 0
    qx = np.diff(q, axis=3) / dxcv
    qx = np.concatenate((qx, qx[:, :, :, -1:]), axis=3)
    qxx = np.diff(qx, axis=3) / dxbu

    fdaz = getvaratzc(fd.astype(np.float32), z.astype(np.float32),
                      eatq.astype(np.float32))
    qxxaz = getvaratzc(qxx.astype(np.float32), z.astype(np.float32),
                       eatq.astype(np.float32))

    qxxazm = np.apply_over_axes(np.nanmean, qxxaz, (0, 2))
    fdazm = np.apply_over_axes(np.nanmean, fdaz, (0, 2))

    fig, ax = plt.subplots(1, 2, sharex=True, sharey=True, figsize=(12, 3))
    cmax = np.fabs(np.nanpercentile(qxxazm, (1, 99))).max()
    im = ax[0].pcolormesh(dimq[3],
                          z,
                          qxxazm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    cb = fig.colorbar(im, ax=ax[0])
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    cmax = np.fabs(np.nanpercentile(fdazm, (1, 99))).max()
    im = ax[1].pcolormesh(dimq[3],
                          z,
                          fdazm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    cb = fig.colorbar(im, ax=ax[1])
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    for axc in ax:
        xdegtokm(axc, 0.5 * (ystart + yend))
        axc.set_xlabel('x (km)')
        axc.grid()
    ax[0].set_ylabel('z (m)')

    fig2, ax = plt.subplots(1, 1, sharey=True)
    ax.linfit(qxx, fd, percx=percx, percy=percy)
    ax.set_xlabel('qxx')
    ax.set_ylabel('grad fd')
    ax.grid()

    return fig, fig2
def get_heddy_coeffs(geofil,
                     vgeofil,
                     fil,
                     fil2,
                     xstart,
                     xend,
                     ystart,
                     yend,
                     zs=0,
                     ze=None,
                     z=np.linspace(-3000, 0, 100),
                     percx=0,
                     percy=0):

    fhgeo = dset(geofil)
    fhvgeo = dset(vgeofil)
    fh = mfdset(fil)
    fh2 = mfdset(fil2)
    db = fhvgeo.variables['g'][:]
    fhvgeo.close()
    dbi = np.append(db, 0)
    zi = fh.variables['zi'][:]
    zl = fh.variables['zl'][:]
    dbl = np.diff(zi) * 9.8 / 1031
    dt = fh.variables['average_DT'][:]
    dt = dt[:, np.newaxis, np.newaxis, np.newaxis]

    sl, dimv = rdp1.getslice(fh, xstart, xend, ystart, yend, yhyq='yq')
    slmx = np.s_[:, :, sl[2], (sl[3].start - 1):sl[3].stop]
    slpx = np.s_[:, :, sl[2], (sl[3].start + 1):sl[3].stop]
    slmxpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1),
                   (sl[3].start - 1):sl[3].stop]
    slpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1), sl[3]]
    sl2d = sl[2:]
    slmx2d = slmx[2:]
    slpx2d = slpx[2:]

    dxbu = fhgeo.variables['dxBu'][slmx2d]
    dxcv = fhgeo.variables['dxCv'][sl2d]

    v, _ = pv.getvtwa(fhgeo, fh, fh2, slmx)
    vx = np.diff(v, axis=3) / dxbu
    vxx = np.diff(vx, axis=3) / dxcv
    e = (fh2.variables['e'][slpy] * dt).sum(axis=0, keepdims=True) / dt.sum(
        axis=0, keepdims=True)
    eatv = 0.5 * (e[:, :, :-1, :] + e[:, :, 1:, :])
    vxx = getvaratzc(vxx.astype(np.float32), z.astype(np.float32),
                     eatv.astype(np.float32))

    e = fh2.variables['e'][slmxpy]
    eatvmx = 0.5 * (e[:, :, :-1, :] + e[:, :, 1:, :])
    vaz = getvaratzc(v.astype(np.float32), z.astype(np.float32),
                     eatvmx.astype(np.float32))
    vazx = np.diff(vaz, axis=3) / dxbu
    vazxx = np.diff(vazx, axis=3) / dxcv

    x, y, P, _, _ = py.extract_twamomy_terms(geofil, vgeofil, fil, fil2,
                                             xstart, xend, ystart, yend, zs,
                                             ze, (0, ))
    uv = P[:, :, :, :, 5]

    vvalid = vaz[:, :, :, 1:-1]

    vazm = np.apply_over_axes(np.nanmean, vvalid, (0, 2))
    vxxm = np.apply_over_axes(np.nanmean, vxx, (0, 2))
    vazxxm = np.apply_over_axes(np.nanmean, vazxx, (0, 2))
    uvm = np.apply_over_axes(np.nanmean, uv, (0, 2))

    fig, ax = plt.subplots(1, 4, sharex=True, sharey=True, figsize=(12, 3))
    cmax = np.fabs(np.percentile(vxxm, (1, 99))).max()
    im = ax[0].pcolormesh(dimv[3],
                          z,
                          vxxm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    fig.colorbar(im, ax=ax[0])
    cmax = np.fabs(np.percentile(vazxxm, (1, 99))).max()
    im = ax[1].pcolormesh(dimv[3],
                          z,
                          vazxxm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    fig.colorbar(im, ax=ax[1])
    cmax = np.fabs(np.percentile(vvalid, (0.5, 99.5))).max()
    im = ax[2].pcolormesh(dimv[3],
                          z,
                          vazm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    fig.colorbar(im, ax=ax[2])
    cmax = np.fabs(np.percentile(uvm, (0.5, 99.5))).max()
    im = ax[3].pcolormesh(dimv[3],
                          z,
                          uvm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    cb = fig.colorbar(im, ax=ax[3])
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    for axc in ax:
        xdegtokm(axc, 0.5 * (ystart + yend))
        axc.set_xlabel('x (km)')
        axc.grid()
    ax[0].set_ylabel('z (m)')

    fig2, ax = plt.subplots(1, 2, sharey=True)
    ax[0].linfit(vvalid, uv, percx=percx, percy=percy)
    ax[0].set_xlabel('v (m/s)')
    ax[0].set_ylabel('RS div (m/s2)')
    ax[0].grid()

    ax[1].linfit(vxx, uv, percx=percx, percy=percy)
    ax[1].set_xlabel('vxx (1/ms)')
    ax[1].grid()

    return fig, fig2
def get_heddy_coeffs_fromflx(geofil,
                             vgeofil,
                             fil,
                             fil2,
                             xstart,
                             xend,
                             ystart,
                             yend,
                             zs=0,
                             ze=None,
                             z=np.linspace(-3000, 0, 100),
                             perc=5,
                             htol=1e-3):

    fhgeo = dset(geofil)
    fhvgeo = dset(vgeofil)
    fh = mfdset(fil)
    fh2 = mfdset(fil2)
    db = fhvgeo.variables['g'][:]
    fhvgeo.close()
    dbi = np.append(db, 0)
    zi = fh.variables['zi'][:]
    zl = fh.variables['zl'][:]
    dbl = np.diff(zi) * 9.8 / 1031
    dt = fh.variables['average_DT'][:]
    dt = dt[:, np.newaxis, np.newaxis, np.newaxis]

    sl, dimv = rdp1.getslice(fh, xstart, xend, ystart, yend, yhyq='yq')
    slmx = np.s_[:, :, sl[2], (sl[3].start - 1):sl[3].stop]
    slpx = np.s_[:, :, sl[2], (sl[3].start + 1):sl[3].stop]
    slmxpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1),
                   (sl[3].start - 1):sl[3].stop]
    slpy = np.s_[:, :, sl[2].start:(sl[2].stop + 1), sl[3]]
    slmpy = np.s_[:, :, (sl[2].start - 1):(sl[2].stop + 1), sl[3]]
    sl2d = sl[2:]
    slmx2d = slmx[2:]
    slpx2d = slpx[2:]
    slpy2d = slpy[2:]

    dxbu = fhgeo.variables['dxBu'][slmx2d]
    dybu = fhgeo.variables['dyBu'][slmx2d]
    dxcv = fhgeo.variables['dxCv'][sl2d]
    dycv = fhgeo.variables['dyCv'][sl2d]
    dxt = fhgeo.variables['dxT'][slpy2d]
    dyt = fhgeo.variables['dyT'][slpy2d]

    v, _ = pv.getvtwa(fhgeo, fh, fh2, slmx)
    vx = np.diff(v, axis=3) / dxbu
    vx = vx[:, :, :, 1:]
    e = (fh2.variables['e'][slpy] * dt).sum(axis=0, keepdims=True) / dt.sum(
        axis=0, keepdims=True)
    eatv = 0.5 * (e[:, :, :-1, :] + e[:, :, 1:, :])

    e = fh2.variables['e'][slmxpy]
    eatvmx = 0.5 * (e[:, :, :-1, :] + e[:, :, 1:, :])

    vh = (fh.variables['vh_masked'][sl] * dt).sum(axis=0,
                                                  keepdims=True) / np.sum(dt)
    h_cv = (fh.variables['h_Cv'][sl] * dt).sum(axis=0,
                                               keepdims=True) / np.sum(dt)
    h_cv[h_cv < htol] = np.nan
    sig = h_cv / dbl[:, np.newaxis, np.newaxis]
    h_vm = h_cv
    vtwa = vh / h_cv / dxcv
    vhforxdiff = (fh.variables['vh_masked'][slmx] * dt).sum(
        axis=0, keepdims=True) / np.sum(dt)
    h_cvforxdiff = (fh.variables['h_Cv'][slmx] * dt).sum(
        axis=0, keepdims=True) / np.sum(dt)
    h_cvforxdiff[h_cvforxdiff < htol] = np.nan
    vtwaforxdiff = vhforxdiff / h_cvforxdiff
    vtwaforxdiff = np.concatenate((vtwaforxdiff, vtwaforxdiff[:, :, :, -1:]),
                                  axis=3)
    vtwax = np.diff(vtwaforxdiff, axis=3) / dxbu / dybu
    vtwax = 0.5 * (vtwax[:, :, :, :-1] + vtwax[:, :, :, 1:])
    uh = (fh.variables['uh_masked'][slmxpy] * dt).filled(0).sum(
        axis=0, keepdims=True) / np.sum(dt)
    hum = 0.25 * (uh[:, :, :-1, :-1] + uh[:, :, :-1, 1:] + uh[:, :, 1:, :-1] +
                  uh[:, :, 1:, 1:]) / dycv
    huvxphvvym = (fh.variables['twa_huvxpt'][sl] * dt +
                  fh.variables['twa_hvvymt'][sl] * dt).sum(
                      axis=0, keepdims=True) / np.sum(dt)
    hvv = (fh.variables['hvv_Cv'][slmpy] * dt).sum(axis=0,
                                                   keepdims=True) / np.sum(dt)
    hvvym = np.diff(hvv, axis=2) / dxt / dyt
    hvvym = 0.5 * (hvvym[:, :, :-1, :] + hvvym[:, :, 1:, :])
    huvxm = -(huvxphvvym + hvvym)
    advx = hum * vtwax / h_vm
    humx = np.diff(np.nan_to_num(uh), axis=3) / dxt / dyt
    humx = 0.5 * (humx[:, :, :-1, :] + humx[:, :, 1:, :])
    xdivep1 = -huvxm / h_vm
    xdivep2 = advx
    xdivep3 = vtwa * humx / h_vm
    xdivep = (xdivep1 + xdivep2 + xdivep3)

    xdivep *= sig
    uv = sint.cumtrapz(
        xdivep[:, :, :, ::-1], dx=-dxbu[:, 1:-1], axis=3,
        initial=0)[:, :, :, ::-1] / sig

    uvm = np.apply_over_axes(np.nanmean, uv, (0, 2))
    vxm = np.apply_over_axes(np.nanmean, vx, (0, 2))
    uvm = getvaratzc(uvm.astype(np.float32), z.astype(np.float32),
                     eatv.astype(np.float32))
    vxm = getvaratzc(vxm.astype(np.float32), z.astype(np.float32),
                     eatv.astype(np.float32))

    fig, ax = plt.subplots(1, 2, sharex=True, sharey=True, figsize=(12, 3))
    cmax = np.fabs(np.percentile(uvm, (1, 99))).max()
    im = ax[0].pcolormesh(dimv[3],
                          z,
                          uvm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    cmax = np.fabs(np.percentile(vxm, (1, 99))).max()
    im = ax[1].pcolormesh(dimv[3],
                          z,
                          vxm.squeeze(),
                          vmax=cmax,
                          vmin=-cmax,
                          cmap='RdBu_r')
    for axc in ax:
        xdegtokm(axc, 0.5 * (ystart + yend))
        axc.set_xlabel('x (km)')
        axc.grid()
    ax[0].set_ylabel('z (m)')

    fig2, ax = plt.subplots(1, 1, sharey=True)
    ax.linfit(vx, uv)
    ax.set_xlabel('v_x (m/s)')
    ax.set_ylabel('RS (m2/s2)')
    ax.grid()

    return fig, fig2
예제 #7
0
def plot_twamomy(geofil,
                 vgeofil,
                 fil,
                 fil2,
                 xstart,
                 xend,
                 ystart,
                 yend,
                 zs,
                 ze,
                 meanax,
                 fil3=None,
                 cmaxpercfactor=1,
                 cmaxpercfactorforep=1,
                 plotterms=[3, 4, 5, 6, 7, 8],
                 swashperc=1,
                 savfil=None,
                 savfilep=None,
                 alreadysaved=False):
    X, Y, P, Pep, swash, em = extract_twamomy_terms(geofil,
                                                    vgeofil,
                                                    fil,
                                                    fil2,
                                                    xstart,
                                                    xend,
                                                    ystart,
                                                    yend,
                                                    zs,
                                                    ze,
                                                    meanax,
                                                    alreadysaved=alreadysaved,
                                                    fil3=fil3)
    P = np.ma.masked_array(P, mask=np.isnan(P)).squeeze()
    cmax = np.nanpercentile(P, [cmaxpercfactor, 100 - cmaxpercfactor])
    cmax = np.max(np.fabs(cmax))
    fig, ax = plt.subplots(np.int8(np.ceil(len(plotterms) / 2)),
                           2,
                           sharex=True,
                           sharey=True,
                           figsize=(10, 5.5))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [
        r'$-\hat{u}\hat{v}_{\tilde{x}}$',
        r'$-\hat{v}\hat{v}_{\tilde{y}}$',
        r'$-\hat{\varpi}\hat{v}_{\tilde{b}}$',
        r'$-f\hat{u}$',
        r'$-\overline{m_{\tilde{y}}}$',
        r"""$-\frac{1}{\overline{h}}(\overline{h}\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{x}}$""",
        #r"""$-\frac{1}{\overline{h}}(\overline{h}\widehat{v^{\prime \prime}v^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{y}}$""",
        r"""$-\frac{1}{\overline{h}}(\overline{h}\widehat{v^{\prime \prime}v^{\prime \prime}})_{\tilde{y}}$""",
        #r"""$-\frac{1}{\overline{h}}(\overline{h}\widehat{v^{\prime \prime}\varpi ^{\prime \prime}} + \overline{\zeta^\prime m_{\tilde{y}}^\prime})_{\tilde{b}}$""",
        r"""$-\frac{1}{\overline{\zeta_{\tilde{b}}}}(\overline{\zeta^\prime m_{\tilde{y}}^\prime})_{\tilde{b}}$""",
        r'$\widehat{Y^H}$',
        r'$\widehat{Y^V}$'
    ]

    for i, p in enumerate(plotterms):
        axc = ax.ravel()[i]
        im = m6plot((X, Y, P[:, :, p]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=lab[p],
                    ylim=(-2000, 0),
                    cmap='RdBu_r',
                    cbar=False)
        if fil3:
            cs = axc.contour(X,
                             Y,
                             swash,
                             np.array([swashperc]),
                             colors='grey',
                             linewidths=4)
        cs = axc.contour(X,
                         Y,
                         P[:, :, p],
                         levels=[-2e-6, -1e-6, 1e-6, 2e-6],
                         colors='k',
                         linestyles='dashed')
        cs.clabel(inline=True, fmt="%.0e")
        cs1 = axc.plot(X, em[::4, :].T, 'k')

        if i % 2 == 0:
            axc.set_ylabel('z (m)')
        if i > np.size(ax) - 3:
            xdegtokm(axc, 0.5 * (ystart + yend))

    fig.tight_layout()
    cb = fig.colorbar(im, ax=ax.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    if savfil:
        plt.savefig(savfil + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    im = m6plot((X, Y, np.sum(P, axis=2)),
                vmax=cmax,
                vmin=-cmax,
                ptype='imshow',
                cmap='RdBu_r',
                ylim=(-2500, 0))
    if savfil:
        plt.savefig(savfil + 'res.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    Pep = np.ma.masked_array(Pep, mask=np.isnan(Pep)).squeeze()
    cmax = np.nanpercentile(Pep,
                            [cmaxpercfactorforep, 100 - cmaxpercfactorforep])
    cmax = np.max(np.fabs(cmax))

    lab = [
        r'$-\frac{(\overline{huv})_{\tilde{x}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{hu})_{\tilde{x}}}{\overline{h}}$',
        r'$-\frac{(\overline{hvv})_{\tilde{y}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{hv})_{\tilde{y}}}{\overline{h}}$',
        r"""-$\frac{1}{2\overline{h}}\overline{\zeta ^{\prime 2}}_{\tilde{y}}$""",
        r'$-\frac{(\overline{hv\varpi})_{\tilde{b}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{h\varpi})_{\tilde{b}}}{\overline{h}}$',
        r"""$-\frac{(\overline{\zeta^\prime m_{\tilde{y}}^\prime})_{\tilde{b}}}{\overline{h}}$"""
    ]

    fig, ax = plt.subplots(np.int8(np.ceil(Pep.shape[-1] / 2)),
                           2,
                           sharex=True,
                           sharey=True,
                           figsize=(12, 9))
    for i in range(Pep.shape[-1]):
        axc = ax.ravel()[i]
        im = m6plot((X, Y, Pep[:, :, i]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=lab[i],
                    cmap='RdBu_r',
                    ylim=(-2500, 0),
                    cbar=False)
        if fil3:
            cs = axc.contour(X,
                             Y,
                             swash,
                             np.array([swashperc]),
                             colors='grey',
                             linewidths=4)
        cs = axc.contour(X,
                         Y,
                         P[:, :, p],
                         levels=[-2e-6, -1e-6, 1e-6, 2e-6],
                         colors='k')
        cs.clabel(inline=True, fmt="%.0e")
        if i % 2 == 0:
            axc.set_ylabel('z (m)')

        if i > np.size(ax) - 3:
            xdegtokm(axc, 0.5 * (ystart + yend))

    fig.tight_layout()
    cb = fig.colorbar(im, ax=ax.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()

    if savfilep:
        plt.savefig(savfilep + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()
예제 #8
0
def plot_forcing(fil, fil2=None):
    y = np.linspace(10, 60, 100)
    sflat = 20
    nflat = 40

    T = np.zeros(y.shape)
    Tnorth = 10
    Tsouth = 20
    T[y >= sflat] = (Tsouth - Tnorth) / (sflat - nflat) * (y[y >= sflat] -
                                                           nflat) + Tnorth
    T[y < sflat] = Tsouth
    T[y > nflat] = Tnorth

    rho0 = 1031
    drhodt = -0.2
    rho = rho0 + drhodt * T

    gs = gridspec.GridSpec(2, 3, width_ratios=[1, 4, 1], height_ratios=[1, 4])
    fig = plt.figure(figsize=(9, 4))
    #ax = fig.add_subplot(121)
    ax = plt.subplot(gs[1])
    ax.plot(y, T, 'k', lw=1)
    #    ax.set_ylabel('T ($^{\circ}$C)')
    ax.set_xlabel('y ($^{\circ}$N)')
    ax.set_ylim(8, 22)
    ax.grid(True)
    ax.xaxis.tick_top()
    ax.xaxis.set_label_position("top")

    ax2 = ax.twinx()
    ax2.set_ylabel(r"""$\rho (kgm^{-3})$""")
    ax2.set_ylim(ax.get_ylim())
    yticks = ax.get_yticks()
    ax2.set_yticks(yticks[::2])
    yticks = rho0 + drhodt * yticks[::2]
    ax2.set_yticklabels(['{}'.format(i) for i in yticks])

    z = np.linspace(0, 3000)
    dabyss = 1500
    Tabyss = 5
    Tz = (Tabyss - Tsouth) / dabyss * z + Tsouth
    Tz[z > dabyss] = Tabyss

    #ax = fig.add_subplot(122)
    ax = plt.subplot(gs[3])
    ax.plot(Tz, z, 'k', lw=1)
    ax.set_xlabel('T ($^{\circ}$C)')
    ax.set_ylabel('z (m)')
    ax.set_xlim(4, 21)
    ax.grid(True)
    ax.invert_yaxis()
    #    ax.yaxis.tick_right()
    #    ax.yaxis.set_label_position("right")

    #    ax2 = ax.twiny()
    #    ax2.set_xlabel(r"""$\rho (kgm^{-3})$""")
    #    ax2.set_xlim(ax.get_xlim())
    #    xticks = ax.get_xticks()
    #    ax2.set_xticks(xticks[::2])
    #    xticks = rho0 + drhodt*xticks[::2]
    #    ax2.set_xticklabels(['{}'.format(i) for i in xticks])

    with mfdset(fil) as fh, mfdset(fil2) as fh2:
        geofil = 'ocean_geometry.nc'
        vgeofil = 'Vertical_coordinate.nc'
        domain = Domain.Domain2(geofil,
                                vgeofil,
                                -0.5,
                                0,
                                10,
                                60,
                                ls=0,
                                le=None)
        e = gv('e', domain, 'hi', fh).read_array()
        ax = plt.subplot(gs[4])
        ax.plot(domain.lath[e.plot_slice[2, 0]:e.plot_slice[2, 1]],
                np.mean(e.values, axis=(0, 3)).T[:, ::2],
                'k',
                lw=1)
        ax.plot(domain.lath[e.plot_slice[2, 0]:e.plot_slice[2, 1]],
                np.mean(e.values, axis=(0, 3)).T[:, -1],
                'k',
                lw=1)
        ax.set_yticklabels('')
        ax.set_xlabel('y ($^{\circ}$N)')
        ax.axvline(x=38.5, color='k')
        ax.grid()
        swash = gv('islayerdeep', domain, 'ql', fh2,
                   plot_loc='hl').xsm().ysm().read_array(
                       extend_kwargs=dict(method='mirror'),
                       tmean=False).move_to('ul').move_to('hl')
        swash0 = fh2.variables['islayerdeep'][-1, 0, 0, 320]
        swash = (-swash + swash0) * (100 / swash0)
        z = np.linspace(-3000, 0)
        swash = swash.toz(z, e=e)
        ax.contour(swash.dom.lath[e.plot_slice[2, 0]:e.plot_slice[2, 1]],
                   z,
                   np.nanmean(swash.values, axis=(0, 3)),
                   levels=[1],
                   colors='r')

        domain = Domain.Domain2(geofil,
                                vgeofil,
                                -0.5,
                                0,
                                38,
                                39,
                                ls=0,
                                le=None)
        ax = plt.subplot(gs[5])
        e = gv('e', domain, 'hi', fh).read_array()
        ax.plot(domain.lonh[e.plot_slice[3, 0]:e.plot_slice[3, 1]],
                np.mean(e.values, axis=(0, 2)).T[:, ::2],
                'k',
                lw=1)
        ax.plot(domain.lonh[e.plot_slice[3, 0]:e.plot_slice[3, 1]],
                np.mean(e.values, axis=(0, 2)).T[:, -1],
                'k',
                lw=1)
        ax.set_yticklabels('')
        ax.set_xlabel('x ($^{\circ}$)')

        swash = gv('islayerdeep', domain, 'ql', fh2,
                   plot_loc='hl').xsm().ysm().read_array(
                       tmean=False).move_to('ul').move_to('hl')
        swash0 = fh2.variables['islayerdeep'][-1, 0, 0, 320]
        swash = (-swash + swash0) * (100 / swash0)
        z = np.linspace(-3000, 0)
        swash = swash.toz(z, e=e)

        ax.contour(swash.dom.lonh[swash.plot_slice[3, 0]:swash.plot_slice[3,
                                                                          1]],
                   z,
                   np.nanmean(swash.values, axis=(0, 2)),
                   levels=[1],
                   colors='r')
        xdegtokm(ax, (38 + 39) / 2)
        ax.grid()
        #swash.plot('nanmean',(0,2),zcoord=True,e=e,z=np.linspace(-3000,0),cbar=True,ax=ax)
    return fig
예제 #9
0
def plot_twamomy(geofil,
                 vgeofil,
                 fil,
                 fil2,
                 xstart,
                 xend,
                 ystart,
                 yend,
                 zs,
                 ze,
                 meanax,
                 cmaxscalefactor=1,
                 cmaxscalefactorforep=1,
                 savfil=None,
                 savfilep=None,
                 alreadysaved=False):
    X, Y, P, Pep = extract_twamomy_terms(geofil, vgeofil, fil, fil2, xstart,
                                         xend, ystart, yend, zs, ze, meanax,
                                         alreadysaved)
    cmax = np.nanmax(np.absolute(P)) * cmaxscalefactor
    fig = plt.figure(figsize=(12, 9))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [
        r'$-\hat{u}\hat{v}_{\tilde{x}}$', r'$-\hat{v}\hat{v}_{\tilde{y}}$',
        r'$-\hat{\varpi}\hat{v}_{\tilde{b}}$', r'$-f\hat{u}$',
        r'$-\overline{m_{\tilde{y}}}$',
        r"""$-\frac{1}{\overline{h}}(\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{x}}$""",
        r"""$-\frac{1}{\overline{h}}(\widehat{v^{\prime \prime}v^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{y}}$""",
        r"""$-\frac{1}{\overline{h}}(\widehat{v^{\prime \prime}\varpi ^{\prime \prime}} + \overline{\zeta^\prime m_{\tilde{y}}^\prime})_{\tilde{b}}$""",
        r'$\widehat{Y^H}$', r'$\widehat{Y^V}$'
    ]

    for i in range(P.shape[-1]):
        ax = plt.subplot(5, 2, i + 1)
        im = m6plot((X, Y, P[:, :, i]),
                    ax,
                    vmax=cmax,
                    vmin=-cmax,
                    txt=lab[i],
                    ylim=(-2500, 0),
                    cmap='RdBu_r')
        if i % 2:
            ax.set_yticklabels([])
        else:
            ax.set_ylabel('z (m)')

        if i > 7:
            xdegtokm(ax, 0.5 * (ystart + yend))

        else:
            ax.set_xticklabels([])

    if savfil:
        plt.savefig(savfil + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    if savfil:
        im = m6plot((X, Y, np.sum(P, axis=2)),
                    vmax=cmax,
                    vmin=-cmax,
                    cmap='RdBu_r',
                    ylim=(-2500, 0))
        plt.savefig(savfil + 'res.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    lab = [
        r'$-\frac{(\overline{huv})_{\tilde{x}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{hu})_{\tilde{x}}}{\overline{h}}$',
        r'$-\frac{(\overline{hvv})_{\tilde{y}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{hv})_{\tilde{y}}}{\overline{h}}$',
        r"""-$\frac{1}{2\overline{h}}\overline{\zeta ^{\prime 2}}_{\tilde{y}}$""",
        r'$-\frac{(\overline{hv\varpi})_{\tilde{b}}}{\overline{h}}$',
        r'$\frac{\hat{v}(\overline{h\varpi})_{\tilde{b}}}{\overline{h}}$',
        r"""$-\frac{(\overline{\zeta^\prime m_{\tilde{y}}^\prime})_{\tilde{b}}}{\overline{h}}$"""
    ]

    cmax = np.nanmax(np.absolute(Pep)) * cmaxscalefactorforep
    plt.figure(figsize=(12, 8))
    for i in range(Pep.shape[-1]):
        ax = plt.subplot(4, 2, i + 1)
        im = m6plot((X, Y, Pep[:, :, i]),
                    ax,
                    vmax=cmax,
                    vmin=-cmax,
                    txt=lab[i],
                    cmap='RdBu_r',
                    ylim=(-2500, 0))
        if i % 2:
            ax.set_yticklabels([])
        else:
            plt.ylabel('z (m)')

        if i > 5:
            xdegtokm(ax, 0.5 * (ystart + yend))
        else:
            ax.set_xticklabels([])

    if savfilep:
        plt.savefig(savfilep + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()
예제 #10
0
def extract_uv(geofil,
               fil,
               fil2,
               fil3,
               xstart,
               xend,
               ystart,
               yend,
               zs,
               ze,
               savfil=None,
               utwamaxscalefactor=1,
               vtwamaxscalefactor=1):

    fh = mfdset(fil)
    fh2 = mfdset(fil2)
    zi = rdp1.getdims(fh)[2][0]

    fhgeo = dset(geofil)

    (xs, xe), (ys, ye), dimutwa = rdp1.getlatlonindx(
        fh,
        wlon=xstart,
        elon=xend,
        slat=ystart,
        nlat=yend,
        zs=zs,
        ze=ze,
        xhxq='xq',
        yhyq='yh')
    em = fh.variables['e'][0:, zs:ze, ys:ye, xs:xe]
    elm = 0.5 * (em[:, 0:-1, :, :] + em[:, 1:, :, :])
    elm = np.ma.apply_over_axes(np.mean, elm, (0, 2))
    dycu = rdp1.getgeombyindx(fhgeo, xs, xe, ys, ye)[2][1]

    uh = fh.variables['uh'][0:, zs:ze, ys:ye, xs:xe]
    h_cu = fh2.variables['h_Cu'][0:, zs:ze, ys:ye, xs:xe]
    utwa = uh / h_cu / dycu

    fig = plt.figure()
    ax = fig.add_subplot(221)
    X = dimutwa[3]
    X = np.meshgrid(X, dimutwa[1])[0]
    Y = elm.squeeze()
    utwa = np.ma.apply_over_axes(np.nanmean, utwa, (0, 2))
    utwa = utwa.squeeze()
    cmax = np.nanmax(np.absolute(utwa)) * utwamaxscalefactor
    im = m6plot(
        (X, Y, utwa),
        ax=ax,
        ylabel='z (m)',
        txt=r'$\hat{u}$',
        vmin=-cmax,
        vmax=cmax,
        cmap='RdBu_r',
        ylim=(-3000, 0))
    ax.set_xticklabels([])

    (xs, xe), (ys, ye), dimvtwa = rdp1.getlatlonindx(
        fh,
        wlon=xstart,
        elon=xend,
        slat=ystart,
        nlat=yend,
        zs=zs,
        ze=ze,
        xhxq='xh',
        yhyq='yq')
    em = fh.variables['e'][0:, zs:ze, ys:ye, xs:xe]
    elm = 0.5 * (em[:, 0:-1, :, :] + em[:, 1:, :, :])
    elm = np.ma.apply_over_axes(np.mean, elm, (0, 2))
    dxcv = rdp1.getgeombyindx(fhgeo, xs, xe, ys, ye)[2][2]

    vh = fh.variables['vh'][0:, zs:ze, ys:ye, xs:xe]
    h_cv = fh2.variables['h_Cv'][0:, zs:ze, ys:ye, xs:xe]
    vtwa = vh / h_cv / dxcv

    ax = fig.add_subplot(222)
    X = dimvtwa[3]
    X = np.meshgrid(X, dimvtwa[1])[0]
    Y = elm.squeeze()
    vtwa = np.ma.apply_over_axes(np.nanmean, vtwa, (0, 2))
    vtwa = vtwa.squeeze()
    cmax = np.nanmax(np.absolute(vtwa)) * vtwamaxscalefactor
    im = m6plot(
        (X, Y, vtwa),
        ax=ax,
        txt=r'$\hat{v}$',
        vmin=-cmax,
        vmax=cmax,
        cmap='RdBu_r',
        ylim=(-3000, 0))
    ax.set_xticklabels([])
    ax.set_yticklabels([])

    fh2.close()
    fh.close()
    fhgeo.close()

    fh3 = mfdset(fil3)
    (xs, xe), (ys, ye), dimu = rdp1.getlatlonindx(
        fh3,
        wlon=xstart,
        elon=xend,
        slat=ystart,
        nlat=yend,
        zs=zs,
        ze=ze,
        xhxq='xq',
        yhyq='yh',
        zlzi='zlremap')
    u = fh3.variables['u'][0:, zs:ze, ys:ye, xs:xe]
    ax = fig.add_subplot(223)
    X = dimu[3]
    Y = dimu[1]
    u = np.ma.apply_over_axes(np.nanmean, u, (0, 2))
    u = u.squeeze()
    cmax = np.nanmax(np.absolute(u))
    im = m6plot(
        (X, -Y, u),
        ax=ax,
        txt='u',
        ylabel='z (m)',
        vmin=-cmax,
        vmax=cmax,
        cmap='RdBu_r')
    xdegtokm(ax, 0.5 * (ystart + yend))

    (xs, xe), (ys, ye), dimv = rdp1.getlatlonindx(
        fh3,
        wlon=xstart,
        elon=xend,
        slat=ystart,
        nlat=yend,
        zs=zs,
        ze=ze,
        xhxq='xh',
        yhyq='yq',
        zlzi='zlremap')
    v = fh3.variables['v'][0:, zs:ze, ys:ye, xs:xe]
    ax = fig.add_subplot(224)
    X = dimv[3]
    Y = dimv[1]
    v = np.ma.apply_over_axes(np.nanmean, v, (0, 2))
    v = v.squeeze()
    cmax = np.nanmax(np.absolute(v))
    im = m6plot(
        (X, -Y, v), ax=ax, txt='v', vmin=-cmax, vmax=cmax, cmap='RdBu_r')
    xdegtokm(ax, 0.5 * (ystart + yend))
    ax.set_yticklabels([])
    fh3.close()

    if savfil:
        plt.savefig(
            savfil + '.eps',
            dpi=300,
            facecolor='w',
            edgecolor='w',
            format='eps',
            transparent=False,
            bbox_inches='tight')
    else:
        plt.show()
def extract_ep_terms_pym6(initializer):

    domain = Domain.Domain(initializer)

    plot_loc = 'vl'
    with mfdset(initializer.fil) as fh, mfdset(initializer.fil2) as fh2:

        #initializer.z = np.linspace(-500, 0, 20)
        e = (gv('e', domain, 'hi', fh2, fh, plot_loc=plot_loc)
             .yep().read_array(
                 extend_kwargs={'method': 'mirror'}).move_to('vi'))
        h = (gv('h_Cv', domain, plot_loc, fh2, fh, plot_loc=plot_loc)
             .read_array(filled=0))
        vr = (gv('vh',
                 domain,
                 plot_loc,
                 fh2,
                 fh,
                 plot_loc=plot_loc,
                 divisor='h_Cv').read_array(
                     divide_by_dx=True, filled=0))
        hum = (gv('uh', domain, 'ul', fh2, fh, plot_loc=plot_loc).xsm().yep()
               .read_array(
                   divide_by_dy=True,
                   filled=0,
                   extend_kwargs={'method': 'vorticity'})
               .move_to('hl').move_to(plot_loc))
        huvm = (gv('huv_Bu', domain, 'ql', fh2, fh, plot_loc=plot_loc).xsm()
                .read_array(
                    filled=0,
                    extend_kwargs={'method': 'vorticity'}).move_to(plot_loc))
        uv_e_flux = (huvm - vr * hum) / h
        uv_e_flux = uv_e_flux.mean(axis=initializer.meanax).toz(initializer.z,
                                                                e=e)
        ex = (gv('e', domain, 'hi', fh2, fh, plot_loc=plot_loc)
              .xsm().xep().yep().read_array(extend_kwargs={'method': 'mirror'})
              .ddx(3).move_to('hi').move_to('vi').move_to('vl'))
        ex = ex.mean(axis=initializer.meanax).toz(initializer.z, e=e)

        e1 = (gv('e', domain, 'hi', fh2, fh, plot_loc=plot_loc)
              .yep().read_array(extend_kwargs={'method': 'mirror'})
              .move_to('hl'))
        esq = (gv('esq', domain, 'hl', fh2, fh, plot_loc=plot_loc)
               .yep().read_array(extend_kwargs={'method': 'mirror'}))
        edlsqm = esq - e1 * e1
        edlsqmy = edlsqm.ddx(2)
        hpfv = (gv('twa_hpfv', domain, plot_loc, fh2, fh, plot_loc=plot_loc)
                .read_array(filled=0))
        pfvm = (gv('PFv', domain, plot_loc, fh2, fh, plot_loc=plot_loc)
                .read_array(filled=0))
        edpfvdmb = -hpfv + h * pfvm - edlsqmy * domain.db * 0.5
        edpfvdmb1 = copy.copy(edpfvdmb)
        edpfvdmb1 = edpfvdmb1.mean(axis=initializer.meanax).toz(initializer.z,
                                                                e=e)
        edpfvdmb = edpfvdmb / domain.db
        edpfvdm = edpfvdmb.vert_integral()
        edpfvdm = edpfvdm.mean(axis=initializer.meanax).toz(initializer.z, e=e)

    flux_list = [uv_e_flux, edpfvdm]
    lab = [
        r"""$\widehat{u^{\prime \prime}v^{\prime \prime}}(\hat{i} + \bar{\zeta_{\tilde{x}}}\hat{k})$""",
        r"""$\overline{\zeta^\prime m_{\tilde{y}}^\prime} \hat{k}$""",
        r"""$\widehat{u^{\prime \prime}v^{\prime \prime}}(\hat{i} + \bar{\zeta_{\tilde{x}}}\hat{k}) +\overline{\zeta^\prime m_{\tilde{y}}^\prime} \hat{k}$"""
    ]

    dz = np.diff(initializer.z)[0]
    dx = np.radians(
        np.diff(domain.lonh[ex._plot_slice[3, 0]:ex._plot_slice[3, 1]])[0]
    ) * 6378000 * np.cos(
        np.radians(0.5 * (initializer.slat + initializer.nlat)))
    fig, ax = plt.subplots(1, 3, sharex=True, sharey=True, figsize=(10, 5))
    units = 'xy'
    angles = 'xy'
    q1 = ax[0].quiver(
        domain.lonh[ex._plot_slice[3, 0]:ex._plot_slice[3, 1]],
        initializer.z[::2],
        uv_e_flux.values.squeeze()[::2] / dx * np.sqrt(dx**2 + dz**2),
        uv_e_flux.values.squeeze()[::2] * ex.values.squeeze()[::2] / dz *
        np.sqrt(dx**2 + dz**2),
        units=units)
    #        angles=angles)
    tx = ax[0].text(0.05, 0.1, lab[0], transform=ax[0].transAxes)
    tx.set_fontsize(15)
    tx.set_bbox(dict(facecolor='white', alpha=1, edgecolor='white'))
    ax[0].quiverkey(
        q1, 0.75, 1.05, 1e-2, r'$1e-2$', labelpos='E', coordinates='axes')
    xdegtokm(ax[0], 0.5 * (initializer.slat + initializer.nlat))
    ax[0].set_ylabel('z (m)')
    q2 = ax[1].quiver(
        domain.lonh[ex._plot_slice[3, 0]:ex._plot_slice[3, 1]],
        initializer.z[::2],
        np.zeros(edpfvdm.values.squeeze()[::2].shape),
        edpfvdm.values.squeeze()[::2] / dx * np.sqrt(dx**2 + dz**2),
        units=units)
    #        angles=angles)
    tx = ax[1].text(0.05, 0.1, lab[1], transform=ax[1].transAxes)
    tx.set_fontsize(15)
    tx.set_bbox(dict(facecolor='white', alpha=1, edgecolor='white'))
    ax[1].quiverkey(
        q2, 0.75, 1.05, 1e-3, r'$1e-3$', labelpos='E', coordinates='axes')
    xdegtokm(ax[1], 0.5 * (initializer.slat + initializer.nlat))
    q3 = ax[2].quiver(
        domain.lonh[ex._plot_slice[3, 0]:ex._plot_slice[3, 1]],
        initializer.z[::2],
        np.zeros(edpfvdm.values.squeeze()[::2].shape) +
        uv_e_flux.values.squeeze()[::2] / dx * np.sqrt(dx**2 + dz**2),
        (edpfvdm.values.squeeze()[::2] + uv_e_flux.values.squeeze()[::2] *
         ex.values.squeeze()[::2]) / dz * np.sqrt(dx**2 + dz**2),
        units=units)
    #        angles=angles)
    tx = ax[2].text(0.05, 0.1, lab[2], transform=ax[2].transAxes)
    tx.set_fontsize(15)
    tx.set_bbox(dict(facecolor='white', alpha=1, edgecolor='white'))
    ax[2].quiverkey(
        q3, 0.75, 1.05, 1e-2, r'$1e-2$', labelpos='E', coordinates='axes')
    xdegtokm(ax[2], 0.5 * (initializer.slat + initializer.nlat))

    return fig
예제 #12
0
def plot_uv(geofil,
            vgeofil,
            fil,
            fil2,
            xstart,
            xend,
            ystart,
            yend,
            zs,
            ze,
            meanax,
            minperc=[1, 1, 0],
            xyasindices=False):

    X, Y, P = getuv(geofil,
                    vgeofil,
                    fil,
                    fil2,
                    xstart,
                    xend,
                    ystart,
                    yend,
                    zs,
                    ze,
                    meanax,
                    xyasindices=False)

    P1 = P[3:]
    P = P[:3]

    fig, ax = plt.subplots(len(P), 1, sharex=True, sharey=True, figsize=(4, 6))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [r'$\widehat{u}$', r'$\widehat{v}$', r'$w^{\#}$']

    for i in range(len(P)):
        P[i] = np.ma.masked_array(P[i], mask=np.isnan(P[i]))
        P[i] = P[i].squeeze()
        cmax = np.nanpercentile(P[i], [minperc[i], 100 - minperc[i]])
        cmax = np.max(np.fabs(cmax))
        axc = ax.ravel()[i]
        im = m6plot((X[i], Y[i], P[i]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=lab[i],
                    ylim=(-2500, 0),
                    cmap='RdBu_r',
                    cbar=False)
        cb = fig.colorbar(im, ax=axc)
        cb.formatter.set_powerlimits((0, 0))
        cb.update_ticks()
        if i == len(P) - 1:
            xdegtokm(axc, 0.5 * (ystart + yend))
        axc.set_ylabel('z (m)')

    fig1, ax = plt.subplots(len(P1),
                            1,
                            sharex=True,
                            sharey=True,
                            figsize=(4, 4))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [r'$\overline{u}$', r'$\overline{v}$', r'$w^{\#}$']
    for i in range(len(P1)):
        P1[i] = np.ma.masked_array(P1[i], mask=np.isnan(P[i]))
        P1[i] = P1[i].squeeze()
        cmax = np.nanpercentile(P1[i], [minperc[i], 100 - minperc[i]])
        cmax = np.max(np.fabs(cmax))
        axc = ax.ravel()[i]
        im = m6plot((X[i], Y[i], P1[i]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=lab[i],
                    ylim=(-2500, 0),
                    cmap='RdBu_r',
                    cbar=False)
        cb = fig.colorbar(im, ax=axc)
        cb.formatter.set_powerlimits((0, 0))
        cb.update_ticks()
        if i == len(P1) - 1:
            xdegtokm(axc, 0.5 * (ystart + yend))
        axc.set_ylabel('z (m)')
    return fig, fig1
예제 #13
0
def plot_twapv(geofil,
               vgeofil,
               fil,
               fil2,
               xstart,
               xend,
               ystart,
               yend,
               zs,
               ze,
               meanax,
               fil3=None,
               plotterms=[0, 1, 10, 11, 12, 13],
               swashperc=1,
               cmaxpercfactor=1,
               cmaxpercfactorpvhash=15,
               cmaxpercfactorPnew=15,
               savfil=None,
               savfilep=None,
               alreadysaved=False):
    X, Y, P, pvhash, Pnew, swash = extract_twapv_terms(
        geofil,
        vgeofil,
        fil,
        fil2,
        xstart,
        xend,
        ystart,
        yend,
        zs,
        ze,
        meanax,
        alreadysaved=alreadysaved,
        fil3=fil3)
    cmax = np.nanpercentile(P, [cmaxpercfactor, 100 - cmaxpercfactor])
    cmax = np.max(np.fabs(cmax))
    fig, ax = plt.subplots(np.int8(np.ceil(P.shape[-1] / 2)),
                           2,
                           sharex=True,
                           sharey=True,
                           figsize=(12, 9))
    ti = [
        '(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)',
        '(k)', '(l)', '(m)', '(n)', '(o)', '(p)', '(q)', '(r)'
    ]
    labx = [
        r'$(\hat{u}\hat{u}_{\tilde{x}})_{\tilde{y}}$',
        r'$(\hat{v}\hat{u}_{\tilde{y}})_{\tilde{y}}$',
        r'$(\hat{\varpi}\hat{u}_{\tilde{b}})_{\tilde{y}}$',
        r'$(-f\hat{v})_{\tilde{y}}$',
        r'$(\overline{m_{\tilde{x}}})_{\tilde{y}}$',
        r"""$(\frac{1}{\overline{h}}(\overline{h}\widehat{u^{\prime \prime}u^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{x}})_{\tilde{y}}$""",
        r"""$(\frac{1}{\overline{h}}(\overline{h}\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{y}}$""",
        r"""$(\frac{1}{\overline{h}}(\overline{h}\widehat{u^{\prime \prime}\varpi^{\prime \prime}} + \overline{\zeta^{\prime}m_{\tilde{x}}^{\prime}})_{\tilde{b}})_{\tilde{y}}$""",
        r'$(-\widehat{X^H})_{\tilde{y}}$', r'$(-\widehat{X^V})_{\tilde{y}}$'
    ]
    laby = [
        r'$(-\hat{u}\hat{v}_{\tilde{x}})_{\tilde{x}}$',
        r'$(-\hat{v}\hat{v}_{\tilde{y}})_{\tilde{x}}$',
        r'$(-\hat{\varpi}\hat{v}_{\tilde{b}})_{\tilde{x}}$',
        r'$(-f\hat{u})_{\tilde{x}}$',
        r'$(-\overline{m_{\tilde{y}}})_{\tilde{x}}$',
        r"""$(-\frac{1}{\overline{h}}(\overline{h}\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{x}})_{\tilde{x}}$""",
        r"""$(-\frac{1}{\overline{h}}(\overline{h}\widehat{v^{\prime \prime}v^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{y}})_{\tilde{x}}$""",
        r"""$(-\frac{1}{\overline{h}}(\overline{h}\widehat{v^{\prime \prime}\varpi^{\prime \prime}} + \overline{\zeta^{\prime}m_{\tilde{y}}^{\prime}})_{\tilde{b}})_{\tilde{x}}$""",
        r'$(\widehat{Y^H})_{\tilde{x}}$', r'$(\widehat{Y^V})_{\tilde{x}}$'
    ]
    for i in range(P.shape[-1]):
        axc = ax.ravel()[i]
        im = m6plot((X, Y, P[:, :, i]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=labx[i] + ' + ' + laby[i],
                    ylim=(-2500, 0),
                    cmap='RdBu_r',
                    cbar=False)
        if fil3:
            cs = axc.contour(X, Y, swash, np.array([swashperc]), colors='k')

        if i % 2 == 0:
            axc.set_ylabel('z (m)')
        if i > np.size(ax) - 3:
            xdegtokm(axc, 0.5 * (ystart + yend))

    fig.tight_layout()
    cb = fig.colorbar(im, ax=ax.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    if savfil:
        plt.savefig(savfil + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    im = m6plot((X, Y, np.sum(P, axis=2)),
                vmax=cmax,
                vmin=-cmax,
                ptype='imshow',
                cmap='RdBu_r',
                ylim=(-2500, 0))
    if savfil:
        plt.savefig(savfil + 'res.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    fig, ax = plt.subplots(np.int8(np.ceil(len(plotterms) / 2)),
                           2,
                           sharex=True,
                           sharey=True,
                           figsize=(12, 7))

    cmaxpvhash = np.nanpercentile(
        pvhash, [cmaxpercfactorpvhash, 100 - cmaxpercfactorpvhash])
    cmaxpvhash = np.max(np.fabs(cmaxpvhash))

    cmax = np.nanpercentile(Pnew,
                            [cmaxpercfactorPnew, 100 - cmaxpercfactorPnew])
    cmax = np.max(np.fabs(cmax))

    lab = [
        r"$-\hat{u}\Pi^{\#}_{\tilde{x}}$",
        r"$-\hat{v}\Pi^{\#}_{\tilde{y}}$",
        r"$\Pi^{\#}(\bar{h} \hat{\varpi})_{\tilde{b}}$",
        r"$\frac{(\hat{\varpi}\hat{u}_{\tilde{b}})_{\tilde{y}}}{\bar{h}}$",
        r"""$\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{u^{\prime \prime}u^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{x}})_{\tilde{y}}$""",
        r"""$\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{y}})_{\tilde{y}}$""",
        r"""$\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{u^{\prime \prime}\varpi^{\prime \prime}} + \overline{\zeta^{\prime}m_{\tilde{x}}^{\prime}})_{\tilde{b}})_{\tilde{y}}$""",
        r'$-\frac{1}{\bar{h}}(\widehat{X^H})_{\tilde{y}}$',
        r'$-\frac{1}{\bar{h}}(\widehat{X^V})_{\tilde{y}}$',
        r'$-\frac{(\hat{\varpi}\hat{v}_{\tilde{b}})_{\tilde{x}}}{\bar{h}}$',
        r"""$-\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{u^{\prime \prime}v^{\prime \prime}})_{\tilde{x}})_{\tilde{x}}$""",
        #r"""$-\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{v^{\prime \prime}v^{\prime \prime}}+\frac{1}{2}\overline{\zeta^{\prime 2}})_{\tilde{y}})_{\tilde{x}}$""",
        r"""$-\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{v^{\prime \prime}v^{\prime \prime}})_{\tilde{y}})_{\tilde{x}}$""",
        #r"""$-\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\bar{h}\widehat{v^{\prime \prime}\varpi^{\prime \prime}} + \overline{\zeta^{\prime}m_{\tilde{y}}^{\prime}})_{\tilde{b}})_{\tilde{x}}$""",
        r"""$-\frac{1}{\bar{h}}(\frac{1}{\bar{h}}(\overline{\zeta^{\prime}m_{\tilde{y}}^{\prime}})_{\tilde{b}})_{\tilde{x}}$""",
        r'$\frac{1}{\bar{h}}(\widehat{Y^H})_{\tilde{x}}$',
        r'$\frac{1}{\bar{h}}(\widehat{Y^V})_{\tilde{x}}$',
        r'$B_{\tilde{x} \tilde{y}} - B_{\tilde{y} \tilde{x}}$'
    ]

    matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
    for i, p in enumerate(plotterms):
        axc = ax.ravel()[i]
        im = m6plot((X, Y, Pnew[:, :, p]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    ylim=(-1200, 0),
                    txt=lab[p],
                    cmap='RdBu_r',
                    cbar=False)
        im2 = axc.contour(X, Y, pvhash, np.logspace(-6, -5.5, 5), colors='k')
        if fil3:
            cs = axc.contour(X, Y, swash, np.array([swashperc]), colors='k')
        if i % 2 == 0:
            axc.set_ylabel('z (m)')
        if i > np.size(ax) - 3:
            xdegtokm(axc, 0.5 * (ystart + yend))

    fig.tight_layout()
    cb = fig.colorbar(im, ax=ax.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()
    if savfil:
        plt.savefig(savfil + 'Pnew.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()
    im = m6plot((X, Y, np.sum(Pnew, axis=2)),
                ptype='imshow',
                vmax=cmax,
                vmin=-cmax,
                cmap='RdBu_r',
                ylim=(-2500, 0))
    if savfil:
        plt.savefig(savfil + 'Pnewres.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    cmax = np.nanpercentile(pvhash,
                            [cmaxpercfactorpvhash, 100 - cmaxpercfactorpvhash])
    cmax = np.max(np.fabs(cmax))
    im = m6plot((X, Y, pvhash),
                ptype='imshow',
                vmax=cmax,
                vmin=-cmax,
                cmap='RdBu_r',
                ylim=(-2500, 0))
    if fil3:
        cs = axc.contour(X, Y, swash, np.array([swashperc]), colors='k')
    if savfil:
        plt.savefig(savfil + 'pvhash.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()
예제 #14
0
def plot_buoy_budget(geofil,
                     vgeofil,
                     fil,
                     fil2,
                     xstart,
                     xend,
                     ystart,
                     yend,
                     zs,
                     ze,
                     meanax,
                     minperc=0,
                     savfil=None,
                     z=np.linspace(-3000, 0, 100),
                     htol=1e-3,
                     fil3=None):

    dims, P = extract_buoy_terms(geofil,
                                 vgeofil,
                                 fil,
                                 fil2,
                                 xstart,
                                 xend,
                                 ystart,
                                 yend,
                                 zs,
                                 ze,
                                 z=z,
                                 htol=htol,
                                 fil3=fil3)

    keepax = ()
    for i in range(4):
        if i not in meanax:
            keepax += (i, )

    fig, ax = plt.subplots(int(np.ceil(P.shape[4] / 2)),
                           2,
                           sharex=True,
                           sharey=True,
                           figsize=(6, 4))
    ti = ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)', '(j)']
    lab = [
        r'$\widehat{u}b^{\#}_{x}$', r'$\widehat{v}b^{\#}_{y}$',
        r'$w^{\#}b^{\#}_{z}$', r'$\widehat{\varpi}$'
    ]

    cmax = np.nanpercentile(P.ravel(), [minperc, 100 - minperc])
    cmax = np.max(np.fabs(cmax))
    P = np.ma.masked_array(P, mask=np.isnan(P))
    P = np.apply_over_axes(np.nanmean, P, meanax).squeeze()
    X = dims[keepax[1]]
    Y = dims[keepax[0]]
    if 1 in keepax:
        Y = z
    for i in range(ax.size):
        axc = ax.ravel()[i]
        im = m6plot((X, Y, P[:, :, i]),
                    axc,
                    vmax=cmax,
                    vmin=-cmax,
                    ptype='imshow',
                    txt=lab[i],
                    cmap='RdBu_r',
                    cbar=False)

        if i % 2 == 0:
            axc.set_ylabel('z (m)')
        if i >= np.size(ax) - 2:
            xdegtokm(axc, 0.5 * (ystart + yend))

    fig.tight_layout()
    cb = fig.colorbar(im, ax=ax.ravel().tolist())
    cb.formatter.set_powerlimits((0, 0))
    cb.update_ticks()

    if savfil:
        plt.savefig(savfil + '.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()

    im = m6plot((X, Y, np.sum(P, axis=2)),
                vmax=cmax,
                vmin=-cmax,
                ptype='imshow',
                cmap='RdBu_r',
                ylim=(-2500, 0))
    if savfil:
        plt.savefig(savfil + 'res.eps',
                    dpi=300,
                    facecolor='w',
                    edgecolor='w',
                    format='eps',
                    transparent=False,
                    bbox_inches='tight')
    else:
        plt.show()