示例#1
0
from vacumm.config import data_sample
f = cdms2.open(data_sample('mars3d.t.nc'))
xe = f('xe')
f.close()
xe.long_name = 'Original'

# On crée des trous
# - petits
xe[:4] = MV2.masked
xe[12:16] = MV2.masked
# - gros
xe[40:46] = MV2.masked

# On rempli les petits trous (5 heures max) par interpolation cubique
from vacumm.misc.grid.regridding import fill1d
import time
t0 = time.time()
xef = fill1d(xe, method='cubic', maxgap=5)
print time.time() - t0
xef.long_name = 'Rempli'
xef[:] += xef.max() / 5.  # on décalle pour les plots

# Plots
from vacumm.misc.plot import curve2, P, savefigs
P.rc('font', size=9)
curve2(xe, show=False, linewidth=1.5, figsize=(6, 3), top=.88, bottom=.15)
curve2(xef, show=False, linewidth=1.5, title='Niveau de la mer')
P.legend()
savefigs(__file__, pdf=True)
P.close()
kwhov.update(cmap=cmap_jets(stretch=-.4), colorbar=False, xrotation=25.)
kwcurve = dict(kwplot)
kwcurve.update(transpose=True, color='r', yhide=True)
kwplot.update(order='-d', title=True)
kwhov['date_fmt'] = '%Hh'
# - original
#print xe.getTime().asComponentTime()
hov2(xe,
     subplot=421,
     top=.95,
     hspace=.45,
     figsize=(5.5, 8),
     bottom=.06,
     **kwhov)
axlims = P.axis()
curve2(xe[:, 15], 'o', subplot=422, **kwcurve)
xscale(1.1, keep_min=1)
# - nearest
hov2(xe_nea, subplot=423, **kwhov)
P.axis(axlims)
curve2(xe[:, 15], 'o', subplot=424, **kwcurve)
print 'ok'
curve2(xe_nea[:, 15], **kwplot)
xscale(1.1, keep_min=1)
# - linear
hov2(xe_lin, subplot=425, **kwhov)
P.axis(axlims)
curve2(xe[:, 15], 'o', subplot=426, **kwcurve)
curve2(xe_lin[:, 15], **kwplot)
xscale(1.1, keep_min=1)
# - cubic
示例#3
0
# -*- coding: utf8 -*-
import cdms2
from vacumm.misc.plot import curve2
from vacumm.config import data_sample

# Trace de la moyenne spatiale
# - lecture
f = cdms2.open(data_sample('mars3d.t.nc'))
tsst = f('temp')
f.close()
# - plot
c = curve2(tsst, title=u'Série temporelle de SST',units = r'$^{\circ}C$',
    subplot=211, show=False, )

# Trace de la moyenne meridienne
# - lecture
f = cdms2.open(data_sample('mars3d.xy.nc'))
zsst = cdms2.MV2.average(f('temp'), axis=0)
f.close()
# - plot
curve2(zsst, title=u'SST zonale', color='r', show=False, 
    subplot=212,top=.9,hspace=.4,left=.15,bottom=.07, 
    savefigs=__file__)




示例#4
0
# -*- coding: utf8 -*-
import cdms2
from vacumm.misc.plot import curve2
from vacumm.config import data_sample

# Trace de la moyenne spatiale
# - lecture
f = cdms2.open(data_sample('mars3d.t.nc'))
tsst = f('temp')
f.close()
# - plot
c = curve2(
    tsst,
    title=u'Série temporelle de SST',
    units=r'$^{\circ}C$',
    subplot=211,
    show=False,
)

# Trace de la moyenne meridienne
# - lecture
f = cdms2.open(data_sample('mars3d.xy.nc'))
zsst = cdms2.MV2.average(f('temp'), axis=0)
f.close()
# - plot
curve2(zsst,
       title=u'SST zonale',
       color='r',
       show=False,
       close=True,
       subplot=212,
示例#5
0
        xy *= 1e-3
    else:
        units = 'm'
    taxis = cdms2.createAxis(xy)
    taxis.units = units
    taxis.long_name = 'Distance'
tbathy.setAxis(0, taxis)

# Plot
c = curve2(tbathy,
           'k',
           bgcolor=(.95, .95, 1),
           order='d-',
           show=False,
           yfmt='%gm',
           yunits=False,
           bottom=0.12,
           zorder=10,
           figsize=eval(options.figsize),
           title=options.title,
           ymin=options.zmin,
           ymax=options.zmax)
xylims = c.axes.axis()
xx = c.get_xdata(scalar=0)
yy = c.get_ydata(scalar=0)
if xylims[2] < 0.:  # ocean
    #    c.axes.axhspan(xylims[2], 0, color=(.8, .8, 1), zorder=2, linewidth=0)
    c.axes.imshow(
        N.resize(N.arange(256), (2, 256)).T,
        cmap=cmap_custom([((.3, 0, .5), 0), ('#000055', .2), ('#007da9', .7),
                          ('#7cbed3', 1)]),  #'ocean',
示例#6
0
    taxis = create_lat(lats)
else:
    xy = N.sqrt((xx-xx[0])**2+(yy-yy[0])**2)
    if xy.max()-xy.min()>2500 or options.along=='km':
        units = 'km'
        xy *= 1e-3
    else:
        units = 'm'
    taxis = cdms2.createAxis(xy)
    taxis.units = units
    taxis.long_name = 'Distance'
tbathy.setAxis(0, taxis)

# Plot
c = curve2(tbathy, 'k', bgcolor=(.95, .95, 1), order='d-',
    show=False, yfmt='%gm', yunits=False, bottom=0.12, zorder=10,
    figsize=eval(options.figsize), title=options.title, ymin=options.zmin, ymax=options.zmax)
xylims = c.axes.axis()
xx = c.get_xdata(scalar=0)
yy = c.get_ydata(scalar=0)
if xylims[2]<0.: # ocean
#    c.axes.axhspan(xylims[2], 0, color=(.8, .8, 1), zorder=2, linewidth=0)
    c.axes.imshow(N.resize(N.arange(256), (2,256)).T,
        cmap=cmap_custom([((.3,0,.5),0),  ('#000055', .2), ('#007da9', .7), ('#7cbed3',1)]),#'ocean',
        extent=[xylims[0], xylims[1], 0., tbathy.min()], aspect='auto')
c.axes.fill_between(xx, yy, xylims[2], color='.5', zorder=9, linewidth=0) # earth
c.axes.axhline(zorder=8, color='b', linewidth=.8) # sea surface
if options.map:
    m = minimap((lons, lats), zoom=1./options.mapscale)
    xm, ym = m(lons, lats)
    m.axes.plot(xm, ym, color='r')
示例#7
0
colors[MV2.sqrt(u**2+v**2).filled(0.)>5.] = '#ff0000'         # red if modulus > 4.
qv = stick2(u, v, color=colors.tolist(), xticklabels=False, subplot=211, 
    shadow=True, right=.85, hspace=.2, left=.14, hldays=True, 
    key=1, key_size=11, key_color='.3', ylabel_color='r', units=r'$m.s^{-1}$', 
    mod=True, mod_color='.4', mod_linewidth=2, title='Wind', quiver_scale = 50., 
    quiver_headwidth=3,quiver_headlength=3,quiver_headaxislength=2,
    quiverkey_pos=(.05, 1.05), quiverkey_color='k', 
    quiver_width=.006, alpha=.8, show=False)
qv.add_text(1.01, 1, 'North', va='top', size=11, fontweight='heavy') 
qv.add_text(1.01, 0, 'South', va='bottom', size=11, fontweight='heavy')


# - precipitations
dr = r.clone() # variation != accumulation
dr[:-1] = N.diff(r) ; dr[-1] = r[-1]-r[-2] 
lr = bar2(dr, width=.8, subplot=212, hldays=True, 
    long_name='Precipitations', shadow=True, ylabel = '%(long_name)s [$%(units)s$]', 
    title=False, dayhl=True, ylabel_color='#008888',zorder=100, 
    key=2, key_size=11, key_color='.3', log=True, ymin=0.01,
    color='#00ffff', linewidth=.2, edgecolor='#888888', show=False)
lr.axes.yaxis.grid(False)

# - pression
p[:] /= 100.
lp = curve2(p, color='g', vminmax=1015, ymaxmin=1025, twin='x', 
    zorder=150, title=False, ylabel = '%(long_name)s [$%(units)s$]', 
    ylabel_color='g', shadow=True, show=False)
    
lp.savefigs(__file__, pdf=True)

# - basse résolution
lon_lr = create_lon((lon.min()+dlon*.7, lon.max()+dlon, dlon*3.3))
# - haute résolution
lon_hr = create_lon((lon.min()+dlon, lon.max()+dlon, dlon/3.3))
# - dict
lons = dict(haute=lon_hr, basse=lon_lr)

# Regrillages et plots
from matplotlib import rcParams ; rcParams['font.size'] = 9
from vacumm.misc.grid.regridding import regrid1d
from vacumm.misc.plot import curve2,savefigs, yscale ; import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False,vmin=v.min(),vmax=v.max(),alpha=.7)
for ilh,resdst  in enumerate(['basse', 'haute']):

    # Regrillage
    vlinear = regrid1d(v, lons[resdst], 'linear')
    vremap = regrid1d(v, lons[resdst], 'cellave')

    # Plots
    P.subplot(2, 1, ilh+1)
    curve2(v, 'o', markersize=4, color='k', label=u'Original', hspace=.3, **kwplot)
    curve2(vremap, 'o', markersize=2, label=u'Cellave', linewidth=1.2, color='b', **kwplot)
    curve2(vlinear, 'o', markersize=2, label=u'Linear', linewidth=1.2, color='r', **kwplot)
    yscale(1.1)
    P.title(u'Vers la %s resolution'%resdst)
    if not ilh: P.legend(loc='lower left').legendPatch.set_alpha(.6)

savefigs(__file__, pdf=True)

# Lecture du niveau de la mer horaire
import cdms2, MV2
from vacumm.config import data_sample
f =cdms2.open(data_sample('mars3d.t.nc'))
xe = f('xe')
f.close()
xe.long_name = 'Original'

# On crée des trous
# - petits
xe[:4] = MV2.masked
xe[12:16] = MV2.masked
# - gros
xe[40:46] = MV2.masked

# On rempli les petits trous (5 heures max) par interpolation cubique
from vacumm.misc.grid.regridding import fill1d
import time ; t0=time.time()
xef = fill1d(xe, method='cubic', maxgap=5)
print time.time()-t0
xef.long_name = 'Rempli'
xef[:] += xef.max()/5. # on décalle pour les plots

# Plots
from vacumm.misc.plot import curve2, P, savefigs
P.rc('font', size=9)
curve2(xe, show=False, linewidth=1.5, figsize=(6, 3), top=.88, bottom=.15)
curve2(xef, show=False, linewidth=1.5, title='Niveau de la mer')
P.legend()
savefigs(__file__, pdf=True)
from vacumm.misc.plot import yhide, xscale, savefigs, hov2, curve2
from vacumm.misc.color import cmap_jets
from genutil import minmax
vmin, vmax = minmax(xe, xe_lin)
kwplot = dict(vmin=vmin, vmax=vmax, show=False)
kwhov = dict(kwplot)
kwhov.update(cmap=cmap_jets(stretch=-.4), colorbar=False, xrotation=25.)
kwcurve = dict(kwplot)
kwcurve.update(transpose=True, color='r', yhide=True)
kwplot.update(order = '-d', title=True)
kwhov['date_fmt'] = '%Hh'
# - original
#print xe.getTime().asComponentTime()
hov2(xe, subplot=421, top=.95, hspace=.45, figsize=(5.5, 8), bottom=.06, **kwhov)
axlims = P.axis()
curve2(xe[:, 15], 'o', subplot=422, **kwcurve)
xscale(1.1, keep_min=1)
# - nearest
hov2(xe_nea, subplot=423, **kwhov)
P.axis(axlims)
curve2(xe[:, 15], 'o', subplot=424, **kwcurve)
print 'ok'
curve2(xe_nea[:, 15], **kwplot)
xscale(1.1, keep_min=1)
# - linear
hov2(xe_lin, subplot=425, **kwhov)
P.axis(axlims)
curve2(xe[:, 15], 'o', subplot=426, **kwcurve)
curve2(xe_lin[:, 15], **kwplot)
xscale(1.1, keep_min=1)
# - cubic
lon_lr = create_lon((lon.min()+dlon*.7, lon.max()+dlon, dlon*3.3))
# - haute résolution
lon_hr = create_lon((lon.min()+dlon, lon.max()+dlon, dlon/3.3))
# - dict
lons = dict(haute=lon_hr, basse=lon_lr)

# Regrillages et plots
from matplotlib import rcParams ; rcParams['font.size'] = 9
from vacumm.misc.grid.regridding import regrid1d
from vacumm.misc.plot import curve2,savefigs, yscale ; import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False,vmin=v.min(),vmax=v.max(),alpha=.7)
for ilh,resdst  in enumerate(['basse', 'haute']):

    # Regrillage
    vlinear = regrid1d(v, lons[resdst], 'linear')
    vremap = regrid1d(v, lons[resdst], 'cellave')

    # Plots
    P.subplot(2, 1, ilh+1)
    curve2(v, 'o', markersize=4, color='k', label=u'Original', hspace=.3, **kwplot)
    curve2(vremap, 'o', markersize=2, label=u'Cellave', linewidth=1.2, color='b', **kwplot)
    curve2(vlinear, 'o', markersize=2, label=u'Linear', linewidth=1.2, color='r', **kwplot)
    yscale(1.1)
    P.title(u'Vers la %s resolution'%resdst)
    if not ilh: P.legend(loc='lower left').legendPatch.set_alpha(.6)

savefigs(__file__, pdf=True)
P.close()