Пример #1
0
def plotFrame(t):
    fig.clf()
    ax=plotAx()
    cplot=[]; gplot=[]; qplot=[]; bcplot=[]
    for mat1,ax1 in zip(mat,ax):
        #Time
        fig.suptitle(plotter.num2time(t).strftime('%Y-%b-%d %H:%M'))
        fig.subplots_adjust(bottom=.15,top=.85)
        
        it=np.interp(t,mat1['t'],np.arange(0,len(mat1['t'])))
        rho1=sw.pden(mat1['salt'][:,:,int(it)]*(1.-it%1)+mat1['salt'][:,:,int(it)+1]*(it%1),
                     mat1['temp'][:,:,int(it)]*(1.-it%1)+mat1['temp'][:,:,int(it)+1]*(it%1),
                     0.0*mat1['temp'][:,:,int(it)]*(1.-it%1)+0.0*mat1['temp'][:,:,int(it)+1]*(it%1) )
        salt1=mat1['salt'][:,:,int(it)]*(1.-it%1)+mat1['salt'][:,:,int(it)+1]*(it%1)
        it=np.interp(t,mat0['t'],np.arange(0,len(mat0['t'])))
        rho0=sw.pden(mat0['salt'][:,:,int(it)]*(1.-it%1)+mat0['salt'][:,:,int(it)+1]*(it%1),
                     mat0['temp'][:,:,int(it)]*(1.-it%1)+mat0['temp'][:,:,int(it)+1]*(it%1),
                     0.0*mat0['temp'][:,:,int(it)]*(1.-it%1)+0.0*mat0['temp'][:,:,int(it)+1]*(it%1) )
        salt0=mat0['salt'][:,:,int(it)]*(1.-it%1)+mat0['salt'][:,:,int(it)+1]*(it%1)
        #print([np.nanmax(rho1-rho0),np.nanmin(rho1-rho0)])
        cplot1=ax1.contourf(mat1['lon'],mat1['lat'],rho1-rho0,[tick1 for tick1 in np.arange(-5.0,5.01,.25) if np.abs(tick1)>1e-8],cmap=cmap,extend='both')
        bcplot1=ax1.contour(mat1['lon'],mat1['lat'],salt1,levels=[31.5],colors='k',linewidth=1)
        
        it=np.interp(t,mat1['t'],np.arange(0,len(mat1['t'])))
        u1=mat1['u'][:,:,int(it)]*(1.-it%1)+mat1['u'][:,:,int(it)+1]*(it%1)
        v1=mat1['v'][:,:,int(it)]*(1.-it%1)+mat1['v'][:,:,int(it)+1]*(it%1)
        it=np.interp(t,mat0['t'],np.arange(0,len(mat0['t'])))
        u0=mat0['u'][:,:,int(it)]*(1.-it%1)+mat0['u'][:,:,int(it)+1]*(it%1)
        v0=mat0['v'][:,:,int(it)]*(1.-it%1)+mat0['v'][:,:,int(it)+1]*(it%1)
        qplot1=plotter.add_uv2d(ax1,mat1['lon'],mat1['lat'],(u1-u0)*2,(v1-v0)*2)
        #print([np.nanmin(u1-u0),np.nanmax(u1-u0),np.nanmin(v1-v0),np.nanmax(v1-v0)])
    
        tLim1=3.*int((t-2)/3)+np.array([2.,5.])
        obsll=[(lon1,lat1) for (lon1,lat1,type1,t1) in zip(obs['lon'],obs['lat'],obs['type'],obs['t']) if type1==6 and tLim1[0]<=t1<=tLim1[1]]
        lon1,lat1=zip(*obsll)
        gplot1=ax1.plot(lon1,lat1,'.',color=(1.,.55,0.),markersize=2,fillstyle='full')
        
        #Colorbar
        fig.subplots_adjust(right=.8)
        cax=fig.add_axes([.82,.15,.02,.7])
        cbar=fig.colorbar(cplot1,cax=cax,orientation='vertical',spacing='proportional')
        cbar.set_ticks([tick1 for tick1 in np.arange(-5.0,5.01,1.)])
        cbar.formatter=ticker.FuncFormatter(lambda x,pos:'{:.1f}'.format(x))
        cbar.update_ticks()
        cbar.set_label(r'Density difference [$\mathrm{kg m^{-3}}$]')
        
        cplot.append(cplot1)
        gplot.append(gplot1)
        qplot.append(qplot1)
        bcplot.append(bcplot1)
        
        #plt.tight_layout()
        
    return cplot,qplot,gplot,bcplot
Пример #2
0
def plotFrame(t):
    fig.clf()
    ax=plotAx()
    cplot=[]; gplot=[];  bcplot=[]
    for model1,ax1 in zip(model,ax):
        #Time
        fig.suptitle(plotter.num2time(t).strftime('%Y-%b-%d %H:%M'))
        fig.subplots_adjust(bottom=0.15,top=.9,right=.85)
        
        it=np.interp(t,model1.t,np.arange(0,len(model1.t)))
        salt1=model1.salt[:,:,int(it)]*(1.-it%1)+model1.salt[:,:,int(it)+1]*(it%1)
        temp1=model1.temp[:,:,int(it)]*(1.-it%1)+model1.temp[:,:,int(it)+1]*(it%1)
        z1=model1.z[:,:,int(it)]*(1.-it%1)+model1.z[:,:,int(it)+1]*(it%1)
        rho1=sw.pden(salt1,temp1,-z1,0.0*z1 )
        rho1=rho1-1e3
        
        z2,rho2=plotter.z_interp(z1,rho1,np.array([-300.,0]))
        print([np.nanmax(rho2),np.nanmin(rho2)])
        cplot1=ax1.contourf(np.reshape(model1.lon[:,0],(-1,1))+np.zeros(np.shape(z2)),-z2,rho2,[tick1 for tick1 in np.arange(18.,28.01,.5)],cmap=cmap,extend='neither')
        bcplot1=ax1.contour(model1.lon,-z1,salt1,levels=[31.5],colors='k',linewidths=.5,linestyles='-')
        bcplot.append(bcplot1)
        bcplot2=ax1.contour(model1.lon,-z1,rho1,levels=[26.5],linestyles='--',colors='k',linewidths=.5)
        bcplot.append(bcplot2)
        
        #Coast   
        h=-z1[:,0]; h[np.isnan(h)]=3.
        h=np.concatenate(([10e3],h,[10e3]))
        hlon=np.concatenate(([-135.],model1.lon[:,0],[-120.]))
        p=patch.Polygon(np.column_stack((hlon,h)),facecolor=(.5,.6,.5),edgecolor=None,closed=True)
        ax1.add_patch(p)
    
        tLim1=3.*int((t-2)/3.)+np.array([2.,5.])
        obsll=[(lon1,z1) for (lon1,z1,type1,t1) in zip(obs['lon'],obs['z'],obs['type'],obs['t']) if type1==6 and tLim1[0]<=t1<=tLim1[1]]
        lon1,z1=zip(*obsll)
        gplot1=ax1.plot([np.min(lon1),np.min(lon1),np.max(lon1),np.max(lon1)],
                         [np.min(z1),np.max(z1),np.max(z1),np.min(z1)],':',
                         color=(.5,.5,.5),linewidth=1.)
        
        #Colorbar
        cax=fig.add_axes([.855,.15,.02,.75])
        cbar=fig.colorbar(cplot1,cax=cax,orientation='vertical',spacing='vertical')
        cbar.set_ticks([tick1 for tick1 in np.arange(18.0,28.01,1.)])
        cbar.formatter=ticker.FuncFormatter(lambda x,pos:'{:.0f}'.format(x))
        cbar.update_ticks()
        cbar.set_label(r'Density-$10^3$ [$\mathrm{kg m^{-3}}$]')
        
        cplot.append(cplot1)
        gplot.append(gplot1)
        
        #plt.tight_layout()
        
    return cplot,gplot,bcplot
Пример #3
0
def plotFrame(t):
    fig.clf()
    ax=plotAx()
    cplot=[]; gplot=[]; qplot=[]
    for mat1,ax1 in zip(mat,ax):
        #Time
        fig.suptitle(plotter.num2time(t).strftime('%Y-%b-%d %H:%M'))
        
        it=np.interp(t,mat1['t'],np.arange(0,len(mat1['t'])))
        vort1=mat1['vort'][:,:,int(it)]*(1.-it%1)+mat1['vort'][:,:,int(it)+1]*(it%1)
        cplot1=ax1.contourf(mat1['lon'],mat1['lat'],vort1,[tick1 for tick1 in np.arange(-1.4e-4,1.401e-4,.2e-4) if np.abs(tick1)>1e-8],cmap=cmap,extend='both')
        
        u1=mat1['u'][:,:,int(it)]*(1.-it%1)+mat1['u'][:,:,int(it)+1]*(it%1)
        v1=mat1['v'][:,:,int(it)]*(1.-it%1)+mat1['v'][:,:,int(it)+1]*(it%1)
        qplot1=plotter.add_uv2d(ax1,mat1['lon'],mat1['lat'],u1,v1)
    
        tLim1=3.*int((t-2)/3)+np.array([2.,5.])
        obsll=[(lon1,lat1) for (lon1,lat1,type1,t1) in zip(obs['lon'],obs['lat'],obs['type'],obs['t']) if type1==6 and tLim1[0]<=t1<=tLim1[1]]
        lon1,lat1=zip(*obsll)
        gplot1=ax1.plot(lon1,lat1,'.',color=(1.,.55,0.),markersize=5,fillstyle='full')
        
        #Colorbar
        fig.subplots_adjust(right=.8)
        cax=fig.add_axes([.82,.15,.02,.7])
        cbar=fig.colorbar(cplot1,cax=cax,orientation='vertical',spacing='proportional')
        cbar.set_ticks([tick1 for tick1 in np.arange(-1.4e-4,1.401e-4,.2e-4)])
        cbar.formatter=ticker.FuncFormatter(lambda x,pos:'{:.1f}'.format(x*1e4))
        cbar.update_ticks()
        cbar.set_label(r'Rel. vorticity [$10^{-4}\,\mathrm{s^{-1}}$]')
        
        cplot.append(cplot1)
        gplot.append(gplot1)
        qplot.append(qplot1)
        
        #plt.tight_layout()
        
    return cplot,qplot,gplot
Пример #4
0
for mat1 in mat:
    mat1.t = mat1.t - 366
    mat1.slope.t = mat1.slope.t - 366

ttick = np.arange(2392, 2413.01, 3) + plotter.time2num(
    datetime.datetime(2005, 1, 1))

#%% Figure

ax = fig.add_subplot(1, 1, 1)
#x
ax.set_xlim(ttick[[0, -1]])
ax.xaxis.set_major_locator(ticker.FixedLocator(ttick))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
ax.xaxis.set_major_formatter(
    ticker.FuncFormatter(lambda x, pos: plotter.num2time(x).strftime('%m/%d')))
ax.set_xlabel('2011')
#y
ax.set_ylim(0, 225)
ax.yaxis.set_major_locator(ticker.MultipleLocator(25))
ax.set_ylabel(r'Enstrophy [$\mathrm{m^2 s^{-2}}$]')
#Grid
ax.grid(color=(.7, .7, .7), linestyle='--')

#%%

markers = ['*', 'o', 'x', None]
colors = ['m', 'r', 'g', 'b']
labels = ['Surface', 'Glider', 'Combined', 'No DA']
linewidths = [1, 1, 1, 1]
Пример #5
0
def dateFormatter(x, pos):
    date = plotter.num2time(x).strftime('%m/%d')
    return date
Пример #6
0
def plotFrame(ax):
    cplot = []
    qplot = []
    bcplot = []

    for ax1, t in zip(ax, mat1['t']):
        #Time
        fig.subplots_adjust(bottom=.15, top=.85)

        it = np.interp(t, mat1['t'], np.arange(0, len(mat1['t'])))
        it2 = np.minimum(int(it) + 1, len(mat1['t']) - 1)
        print([it, it2])
        salt1 = mat1['salt'][:, :, int(it)] * (
            1. - it % 1) + mat1['salt'][:, :, it2] * (it % 1)
        #print([np.nanmax(rho1),np.nanmin(rho1)])
        cplot1 = ax1.contourf(mat1['lon'],
                              mat1['lat'],
                              salt1,
                              [tick1 for tick1 in np.arange(24., 33.01, .5)],
                              cmap=cmap,
                              extend='min')
        bcplot1 = ax1.contour(mat1['lon'],
                              mat1['lat'],
                              salt1,
                              levels=[31.5],
                              colors='k',
                              linewidth=1)

        it = np.interp(t, mat1['t'], np.arange(0, len(mat1['t'])))
        u1 = mat1['u'][:, :, int(it)] * (
            1. - it % 1) + mat1['u'][:, :, it2] * (it % 1)
        v1 = mat1['v'][:, :, int(it)] * (
            1. - it % 1) + mat1['v'][:, :, it2] * (it % 1)
        qplot1 = plotter.add_uv2d(ax1, mat1['lon'], mat1['lat'], u1, v1)
        #print([np.nanmin(u1-u0),np.nanmax(u1-u0),np.nanmin(v1-v0),np.nanmax(v1-v0)])

        #Add glider
        obsll = [(lon1, lat1)
                 for (lon1, lat1, type1,
                      t1) in zip(obs['lon'], obs['lat'], obs['type'], obs['t'])
                 if type1 == 6]
        lon1, lat1 = zip(*obsll)
        gplot1 = ax1.plot(lon1,
                          lat1,
                          '.',
                          color=(1., .55, 0.),
                          markersize=2,
                          fillstyle='full')

        ax1.set_title(plotter.num2time(t).strftime('%m/%d/%y'))
        #Colorbar
        fig.subplots_adjust(right=.8)
        cax = fig.add_axes([.82, .15, .02, .7])
        cbar = fig.colorbar(cplot1,
                            cax=cax,
                            orientation='vertical',
                            spacing='proportional')
        cbar.set_ticks([tick1 for tick1 in np.arange(24.0, 33.01, 1.)])
        cbar.formatter = ticker.FuncFormatter(
            lambda x, pos: '{:.0f}'.format(x))
        cbar.update_ticks()
        cbar.set_label(r'Salinity [$\mathrm{ppt}$]')

        cplot.append(cplot1)
        qplot.append(qplot1)
        bcplot.append(bcplot1)

        #plt.tight_layout()

    return cplot, qplot, bcplot
Пример #7
0
mat.t = mat.t
dateRef = datetime.datetime(2005, 1, 1).toordinal()

ax = []
for i1 in np.arange(0, 4):
    ax1 = fig.add_subplot(2, 2, i1 + 1)
    ax1.set_xlim(2392 + dateRef, 2413 + dateRef)
    ax1.grid(color=(.7, .7, .7), linestyle=':', linewidth=.5)
    #ax1.set_ylim(0,6)
    if i1 >= 0:
        ax1.set_xlabel('2011')
        ax1.xaxis.set_major_locator(
            ticker.FixedLocator(np.arange(2392, 2434.1, 3) + dateRef))
        ax1.xaxis.set_major_formatter(
            ticker.FuncFormatter(
                lambda x, pos: plotter.num2time(x).strftime('%m/%d')))
    else:
        ax1.xaxis.set_major_formatter(ticker.NullFormatter())
    if i1 == 4:
        ax1.set_axis_off()
    ax.append(ax1)

#%% Differences of the whole period


def rms(x):
    return np.sqrt(np.nanmean(x * x))


print('sst')
for val1 in mat.sst.rms:
Пример #8
0
def plotFrame(t):
    fig.clf()
    ax = plotAx()
    cplot = []
    gplot = []
    qplot = []
    bcplot = []
    level1 = levelList[0]

    for mat1, ax1, title1 in zip(mat, ax, titleList):
        #Time
        fig.suptitle(plotter.num2time(t).strftime('%Y-%b-%d %H:%M'))
        fig.subplots_adjust()

        inCon = level1 == mat1.contours
        it = np.interp(t, mat1.t, np.arange(0, len(mat1.t)))
        it1 = np.minimum(int(it) + 1, len(mat1.t) - 1)

        z0 = mat0.z[:, :, inCon, int(it)] * (
            1 - it % 1) + mat0.z[:, :, inCon, it1] * (it % 1)
        z1 = mat1.z[:, :, inCon, int(it)] * (
            1 - it % 1) + mat1.z[:, :, inCon, it1] * (it % 1)
        z0 = np.squeeze(z0)
        z1 = np.squeeze(z1)
        mask0 = np.where(np.isnan(z0), np.ones(np.shape(z0)),
                         np.zeros(np.shape(z0)))
        mask1 = np.where(np.isnan(z1 - z0), np.ones(np.shape(z1)),
                         np.zeros(np.shape(z1)))
        print(
            [np.nanpercentile(z1 - z0, 2.5),
             np.nanpercentile(z1 - z0, 97.5)])

        cplot1 = ax1.contourf(
            mat1.lon,
            mat1.lat,
            z1 - z0, [
                tick1
                for tick1 in np.arange(-40.0, 40.01, 5.0) if np.abs(tick1) > 1
            ],
            cmap=cmap,
            extend='both')

        if level1 <= 1024.5:
            bcplot1 = ax1.contour(mat1.lon,
                                  mat1.lat,
                                  z1,
                                  levels=np.arange(-200, 0.1, 10.),
                                  colors='k',
                                  linewidth=.5)
        else:
            bcplot1 = ax1.contour(mat1.lon,
                                  mat1.lat,
                                  z1,
                                  levels=np.arange(-2000, 0.1, 25.),
                                  colors='k',
                                  linewidth=.5)
        ax1.set_title(title1)
        bcplot2 = ax1.contourf(mat1.lon,
                               mat1.lat,
                               mask1,
                               levels=[-.5, .5, 1],
                               cmap=cgrey,
                               vmin=0.5,
                               vmax=1,
                               alpha=.5)

        tLim1 = 3. * int((t - 2) / 3) + np.array([2., 5.])
        obsll = [(lon1, lat1)
                 for (lon1, lat1, type1,
                      t1) in zip(obs['lon'], obs['lat'], obs['type'], obs['t'])
                 if type1 == 6 and tLim1[0] <= t1 <= tLim1[1]]
        lon1, lat1 = zip(*obsll)
        gplot1 = ax1.plot(lon1,
                          lat1,
                          '.',
                          color=(1., .55, 0.),
                          markersize=2,
                          fillstyle='full')

        #Colorbar
        fig.subplots_adjust(right=.8)
        cax = fig.add_axes([.8, .1, .02, .8])
        cbar = fig.colorbar(cplot1,
                            cax=cax,
                            orientation='vertical',
                            spacing='proportional')
        cbar.set_ticks([tick1 for tick1 in np.arange(-40.0, 40.1, 10.)])
        cbar.formatter = ticker.FuncFormatter(
            lambda x, pos: '{:.1f}'.format(x))
        cbar.update_ticks()
        cbar.set_label(r'Depth change [$\mathrm{m}$]')

        cplot.append(cplot1)
        gplot.append(gplot1)
        bcplot.append(bcplot1)

        #plt.tight_layout()

    return cplot, gplot, bcplot