Exemplo n.º 1
0
select = dict(lat=slice(4, -4), lon=slice(4, -4), squeeze=1)
slp = f('pslvl', **select)
rain = f('rain', **select)
u = f('u10m', **select)
v = f('v10m', **select)
f.close()

# Pression de surface
slp[:] = generic2d(slp*0.01, 5)
map2(slp, fill=False, contour=True, show=False,  figsize=(6, 5.5),
    title='WRF Bretagne',
    fillcontinents=True, zorder=5, projection='merc', right=1, bottom=.07,
    lowhighs=True, lowhighs_smooth=9, lowhighs_zorder=5, fillcontinents_color='.95',
    lowhighs_color=(0, .5, 0), contour_colors=[(0, .5, 0)], drawcoastlines_linewidth=.6)

# Pluie
cmap_rain = cmap_custom([('0.9', 0), ('b', .8), ('r', 1.)])
rain[:] = MV2.masked_less(rain, 0.1)
map2(rain, cmap=cmap_rain, vmin=0.,
    fill='pcolor', fillcontinents=False, show=False,
    shadow_xoffset=4, shadow_yoffset=-4,shadow_width=4, colorbar_shrink=.7,
    alpha=.7, shadow=True, shadow_alpha=.3, contour=False, zorder=15)

# Vent
u[:] = ms2kt(u*5)
v[:] = ms2kt(v*5)
m = map2((u[::3, ::3], v[::3, ::3]), fill=False, contour=False, barbs=True, projection='merc',
    quiver_sizes=dict(height=.2, spacing=.15), quiver_linewidths=.8, zorder=10,
    shadow=True, quiver_alpha=.5, savefigs=__file__, show=False, savefigs_pdf=True,
    fillcontinents=False)
Exemplo n.º 2
0
    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')
if options.figname:
    c.savefig(options.figname)
else:
    c.show()

Exemplo n.º 3
0
def plot_bathy(bathy, shadow=True, contour=True, shadow_stretch=1., shadow_shapiro=False,
    show=True, shadow_alpha=1., shadow_black=.3, white_deep=False, nmax=30,m=None, alpha=1.,
    zmin=None, zmax=None, **kwargs):
    """Plot a bathymetry

    - *lon*: Longitude range.
    - *lat*: Latitude range.
    - *show*:Display the figure [default: True]
    - *pcolor*: Use pcolor instead of contour [default: False]
    - *contour*: Add line contours [default: True]
    - *shadow*:Plot south-west shadows instead of filled contours.
    - *nmax*: Max number of levels for contours [default: 30]
    - *white_deep*: Deep contours are white [default: False]
    - All other keyword are passed to :func:`~vacumm.misc.plot.map2`
    """

    # Input
    bb = bathy
    if isinstance(bathy, GriddedBathy):
        bathy = bathy.bathy()
        if shadow:
            xxs = getattr(bb, '_xxs', None)
            yys = getattr(bb, '_yys', None)
            if xxs is None:
                lon2d = bb._lon2d
                lat2d = bb._lat2d
    elif shadow:
        xxs = yys = None
        lon2d,lat2d = meshgrid(get_axis(bathy, -1).getValue(),get_axis(bathy, -2).getValue())

    # Masking
    if 'maxdep' in kwargs:
        zmin = -maxdep
    if 'maxalt' in kwargs:
        zmax = maxalt
    if zmin is not None:
        bathy[:] = MV2.masked_less(bathy, zmin)
    if zmax is not None:
        bathy[:] = MV2.masked_greater(bathy, zmax)

    # Default arguments for map
    if hasattr(bathy, 'long_name'):
        kwargs.setdefault('title',bathy.long_name)
    if 'cmap' not in kwargs:
        vmin, vmax = minmax(bathy)
#        print 'cmap topo', vmin, vmax
        kwargs['cmap'] = auto_cmap_topo((kwargs.get('vmin', vmin), kwargs.get('vmax', vmax)))
#       kwargs.setdefault('ticklabel_size','smaller')
    kwargs.setdefault('clabel_fontsize', 8)
    kwargs.setdefault('clabel_alpha',.7*alpha)
    kwargs.setdefault('clabel_glow_alpha', kwargs['clabel_alpha'])
    kwargs.setdefault('fill', 'contourf')
    kwargs['nmax'] = nmax
    kwargs['show'] = False
    kwargs['contour'] = contour
    if shadow: kwargs.setdefault('alpha',.5*alpha)
    kwargs.setdefault('projection', 'merc')
    kwargs.setdefault('fmt', BathyFormatter())
    kwargs.setdefault('colorbar_format', BathyFormatter())
    kwargs.setdefault('units', False)
    kwargs.setdefault('levels_mode','normal')
    kwargs.setdefault('bgcolor', '0.8')
    kwargs.setdefault('contour_linestyle', '-')
    savefig = kwargs.pop('savefig', None)
    kwsavefig = kwfilter(kwargs, 'savefig_')


    # White contour when dark
    if contour and white_deep:
        levels = auto_scale(bathy,nmax=nmax)
        colors = []
        nlevel = len(levels)
        for i in range(nlevel):
            if i < old_div(nlevel,2):
                colors.append('w')
            else:
                colors.append('k')
        kwargs.setdefault('contour_colors',tuple(colors))

    # Call to map
    m = map2(bathy, m=m, **kwargs)

    # Add shadow
    if shadow:

        # Filter
        data = MV.array(bathy,'f',fill_value=0.)
        if shadow_shapiro:
            data = shapiro2d(data,fast=True).shape

        # Gradient
        grd = deriv2d(data,direction=45.,fast=True,fill_value=0.).filled(0.)
        grdn = refine(grd, 3)
        grdn = norm_atan(grdn,stretch=shadow_stretch).clip(0,1.) ; del grd

        # Grid
#           im = m.map.imshow(grdn,cmap=P.get_cmap('gist_yarg'),alpha=1) # gist_yarg , YlGnBu
        if xxs is None or yys is None:
            xx, yy = m(lon2d,lat2d)
            xxr = refine(xx, 3)
            yyr = refine(yy, 3)
            xxs, yys = meshbounds(xxr, yyr)
            if isinstance(bb, GriddedBathy):
                bb._xxs = xxs
                bb._yys = yys
            del xx, yy, xxr, yyr

        # Cmap
        cmap = cmap_custom(( ((1, )*3, 0), ((shadow_black, )*3, 1) ))

        # Plot
        pp = m.map.pcolormesh(xxs, yys, grdn,cmap=cmap)#P.get_cmap('gist_yarg'))
        pp.set_zorder(.9)
        pp.set_linewidth(0)
        pp.set_alpha(shadow_alpha*N.clip(alpha*2, 0, 1))
        del grdn

    # Show it?
    if savefig:
        m.savefig(savefig, **kwsavefig)
    if show:
        P.show()
    return m
Exemplo n.º 4
0
           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')
if options.figname:
    c.savefig(options.figname)
else:
    c.show()