Changeset 638 for trunk


Ignore:
Timestamp:
Apr 30, 2012, 11:23:18 AM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON: added maplatlon function, a user-friendly way to map fields and winds. a few cosmetic changes.

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/myplot.py

    r637 r638  
    329329        subv = 2
    330330        subh = 3
    331         fig.subplots_adjust(wspace = 0.4, hspace = 0.0)
     331        #fig.subplots_adjust(wspace = 0.4, hspace = 0.0)
     332        fig.subplots_adjust(wspace = 0.5, hspace = 0.3)
    332333        rcParams['font.size'] = int( rcParams['font.size'] * 1. / 2. )
    333334    elif numplot <= 8:
     
    651652    import  matplotlib.pyplot               as plt
    652653    import  numpy                           as np
    653     posx = np.min(x) - np.std(x) / 10.
    654     posy = np.min(y) - np.std(y) / 10.
     654    #posx = np.min(x) - np.std(x) / 10.
     655    #posy = np.min(y) - np.std(y) / 10.
     656    posx = np.min(x)
     657    posy = np.min(y) - 4.*np.std(y) / 10.
    655658    u = smooth(u,csmooth)
    656659    v = smooth(v,csmooth)
     
    12681271#      return error
    12691272
     1273## Author : AS
     1274def maplatlon( lon,lat,field,\
     1275               proj="cyl",colorb="jet",ndiv=10,zeback="molabw",trans=0.6,title="",\
     1276               vecx=None,vecy=None,stride=2 ):
     1277    ### an easy way to map a field over lat/lon grid
     1278    import numpy as np
     1279    import matplotlib.pyplot as mpl
     1280    from matplotlib.cm import get_cmap
     1281    ## get lon and lat in 2D version. get lat/lon intervals
     1282    numdim = len(np.array(lon).shape)
     1283    if numdim == 2:     [lon2d,lat2d] = [lon,lat]
     1284    elif numdim == 1:   [lon2d,lat2d] = np.meshgrid(lon,lat)
     1285    else:               errormess("lon and lat arrays must be 1D or 2D")
     1286    [wlon,wlat] = latinterv()
     1287    ## define projection and background. define x and y given the projection
     1288    m = define_proj(proj,wlon,wlat,back=zeback,blat=None,blon=None)
     1289    x, y = m(lon2d, lat2d)
     1290    ## define field. bound field.
     1291    what_I_plot = np.transpose(field)
     1292    zevmin, zevmax = calculate_bounds(what_I_plot)  ## vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame))
     1293    what_I_plot = bounds(what_I_plot,zevmin,zevmax)
     1294    ## define contour field levels. define color palette
     1295    ticks = ndiv + 1
     1296    zelevels = np.linspace(zevmin,zevmax,ticks)
     1297    palette = get_cmap(name=colorb)
     1298    ## contour field
     1299    m.contourf( x, y, what_I_plot, zelevels, cmap = palette, alpha = trans )
     1300    ## draw colorbar
     1301    if proj in ['moll','cyl']:        zeorientation="horizontal" ; zepad = 0.07
     1302    else:                             zeorientation="vertical" ; zepad = 0.03
     1303    #daformat = fmtvar(fvar.upper())
     1304    daformat = "%.0f"
     1305    zecb = mpl.colorbar( fraction=0.05,pad=zepad,format=daformat,orientation=zeorientation,\
     1306                 ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,21])),extend='neither',spacing='proportional' )
     1307    ## give a title
     1308    if zeorientation == "horizontal": zecb.ax.set_xlabel(title)
     1309    else:                             ptitle(title)
     1310    ## draw vector
     1311    if vecx is not None and vecy is not None:
     1312       [vecx_frame,vecy_frame] = m.rotate_vector( np.transpose(vecx), np.transpose(vecy), lon2d, lat2d ) ## for metwinds
     1313       vectorfield(vecx_frame, vecy_frame, x, y, stride=stride, csmooth=2,\
     1314                                             scale=30., factor=500., color=definecolorvec(colorb), key=True)
     1315    ## scale regle la reference du vecteur. factor regle toutes les longueurs (dont la reference). l'AUGMENTER pour raccourcir les vecteurs.
     1316    return
  • trunk/UTIL/PYTHON/planetoplot.py

    r637 r638  
    566566                                key = False
    567567                            if metwind and mapmode == 1:   [vecx_frame,vecy_frame] = m.rotate_vector(vecx_frame, vecy_frame, lon2d, lat2d)
    568                             if var:       colorvec = definecolorvec(back)
    569                             else:         colorvec = definecolorvec(colorb)
     568                            if var:       colorvec = definecolorvec(colorb)
     569                            else:         colorvec = definecolorvec(back)
    570570                            vectorfield(vecx_frame, vecy_frame, x, y, stride=stride, csmooth=2,\
    571571                                             #scale=15., factor=300., color=colorvec, key=key)
Note: See TracChangeset for help on using the changeset viewer.