Changeset 2014 in lmdz_wrf


Ignore:
Timestamp:
Aug 2, 2018, 5:25:56 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `draw_stations_map': Function to plot a map with the stations
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1996 r2014  
    6464## e.g. # drawing.py -o draw_2D_shad_contdisc -f 'simout_sfcdiags.nc;tdas;XLONG;XLAT;Time|0,time|0,west_east|-1,south_north|-1@all_single-stations.nc;tdas;stslon;stslat;time|0,lon|-1,lat|-1' -S 'tdas:west_east,south_north:auto:YlGnBu,auto,auto:286.,298.:auto:obs!&!sim!tdas!on!1995/01/01!00!UTC:png:None:cyl,f:sponge,0.1,0.1:yes'
    6565## e.g. # drawing.py -o draw_multiWindRose -f '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/sounding_uava_10868.nc@pres|-1;time|1@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_38lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev_assigned.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_80lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_120lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_NOaerosol.nc@bottom_top|-1;time|0@ua,va' -S 'linepoint;multicol;pres;-;auto;spectral;auto:obs,38lev,50lev,50leva,80lev,120lev:WindRose!obs!sim!comparison!on!2012/10/23!00!UTC:png:auto:True'
     66## e.g. # drawing.py -o draw_stations_map -f stations.inf -S 'snd|x|#FFAAAA|2|8@sfc|x|#AAFFAA|2|8:cyl,l:1.,20.,35.,49.:FPS!Alps!stations:pdf:true'
    6667
    6768#######
     
    9899# draw_ptZvals: Function to plot a given list of points by their Z value and a colorbar
    99100# draw_SkewT: creation of a SkewT-logP diagram using matplotlib's API example 
     101# draw_stations_map: Function to plot a map with the stations
    100102# draw_time_lag: Function to plot a time-lag figure with multiple sources (x, previous values; y, future values)
    101103# draw_timeSeries: Function to draw a time-series
     
    131133  'draw_Neighbourghood_evol',                                                        \
    132134  'draw_points', 'draw_points_lonlat',                                               \
    133   'draw_ptZvals', 'draw_river_desc', 'draw_SkewT', 'draw_subbasin', 'draw_Taylor',   \
     135  'draw_ptZvals', 'draw_river_desc', 'draw_SkewT', 'draw_subbasin',                  \
     136  'draw_stations_map', 'draw_Taylor',                                                \
    134137  'draw_time_lag', 'draw_timeSeries', 'draw_topo_geogrid',                           \
    135138  'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories',          \
     
    1016510168#draw_multiWindRose(filenames, figvalues)
    1016610169
     10170def draw_stations_map(filename, values):
     10171    """ Function to plot a map with the stations
     10172      filename= name of ASCII file with the values of the stations as: ('#' comments)
     10173        [sttype],[label],[lon],[lat],[height]
     10174          [sttype]: type of the station
     10175          [label]: label of the station (LaTeX format, 'None' for no label)
     10176          [lon]: longitude of the station
     10177          [lat]: latitude of the station
     10178          [height]: height of the station
     10179      values=[stypevals]:[mapvals]:[SWNEbox]:[imgtit]:[imgkind]:[close]
     10180        stypevals='@' separated list of [sttype]|[marker]|[color]|[size]|[fontsize]
     10181          [sttype]: label of the type of the marker
     10182          [marker]: type of the marker
     10183          [color]: color of the marker
     10184          [size]: size of the marker
     10185        mapvals= map characteristics: [proj],[res]
     10186          see full documentation: http://matplotlib.org/basemap/
     10187          [proj]: projection
     10188            * 'cyl', cilindric
     10189            * 'lcc', lambert-conformal
     10190          [res]: resolution:
     10191            * 'c', crude
     10192            * 'l', low
     10193            * 'i', intermediate
     10194            * 'h', high
     10195            * 'f', full
     10196        SWNEbox: ',' list of the vertexs of the map [SWlon, NElon, SWlat, NElat]
     10197        imgtit: title of the image ('!' for spaces)
     10198        imgkind: kind of file output of the image (ps, pns, pdf, ...)
     10199        close: whether figure should be closed or not
     10200    """
     10201    fname = 'draw_stations_map'
     10202
     10203    if values == 'h':
     10204        print fname + '_____________________________________________________________'
     10205        print draw_stations_map.__doc__
     10206        quit()
     10207
     10208    expectargs = '[stypevals]:[mapvals]:[SWNEbox]:[imgtit]:[imgkind]:[close]'
     10209    drw.check_arguments(fname,values,expectargs,':')
     10210
     10211    stypevals = values.split(':')[0].split('@')
     10212    mapvals = values.split(':')[1]
     10213    SWNEbox = gen.str_list_k(values.split(':')[2], ',', 'F')
     10214    imgtit = values.split(':')[3].replace('!', ' ')
     10215    imgkind = values.split(':')[4]
     10216    close = gen.Str_Bool(values.split(':')[5])
     10217
     10218    if not os.path.isfile(filename):
     10219        print errormsg
     10220        print '  ' + fname + ": file '" + filename + "' does not exist !!"
     10221        quit(-1)
     10222
     10223    # Getting stations values
     10224    styypes = {}
     10225    sttyps = []
     10226    for stvs in stypevals:
     10227        stv = stvs.split('|')
     10228        styp = stv[0]
     10229        smk = stv[1]
     10230        scol = stv[2]
     10231        ssz = np.float(stv[3])
     10232        fsz = stv[4]
     10233        styypes[styp] = [smk, scol, ssz, fsz]
     10234        sttyps.append(styp)
     10235
     10236    ofile = open(filename, 'r')
     10237    dicstations = {}
     10238    for line in ofile:
     10239        if line[0:1] != '#' and len(line) > 1:
     10240            linev = line.replace('\n','').replace('\r','').split(',')
     10241            ltyp = linev[0]
     10242            lid = linev[1]
     10243            llon = np.float(linev[2])
     10244            llat = np.float(linev[3])
     10245            lhgt = np.float(linev[4])
     10246
     10247            if not gen.searchInlist(sttyps, ltyp):
     10248                print errormsg
     10249                print '  ' + fname + ": station type '" + ltyp + "' not ready !!"
     10250                print '    available ones:', sttyps
     10251                quit(-1)
     10252           
     10253            typsv = styypes[ltyp]
     10254            dicstations[lid] = [llon, llat, lhgt, lid, typsv[0], typsv[1], typsv[2], \
     10255              typsv[3]]
     10256
     10257    ofile.close()
     10258
     10259    Nd = 100
     10260    nlon = SWNEbox[0]
     10261    xlon = SWNEbox[1]
     10262    nlat = SWNEbox[2]
     10263    xlat = SWNEbox[3]
     10264
     10265    ddlon = (xlon - nlon)/Nd
     10266    ddlat = (xlat - nlat)/Nd
     10267
     10268    lon1D = np.arange(nlon, xlon+ddlon, ddlon)
     10269    lat1D = np.arange(nlat, xlat+ddlat, ddlat)
     10270   
     10271    drw.plot_stations_map(dicstations, lon1D, lat1D, mapvals, SWNEbox, ddlon, imgtit,\
     10272      imgkind, close)
     10273
     10274    return
     10275
    1016710276#quit()
    1016810277
     
    1029910408    elif oper == 'draw_SkewT':
    1030010409        draw_SkewT(opts.ncfile, opts.values, opts.varname)
     10410    elif oper == 'draw_stations_map':
     10411        draw_stations_map(opts.ncfile, opts.values)
    1030110412    elif oper == 'draw_Taylor':
    1030210413        draw_Taylor(opts.ncfile, opts.values, opts.varname)
  • trunk/tools/drawing_tools.py

    r1996 r2014  
    187187# plot_multiWindRose: Function to plot multi wind roses (from where the dinw blows)
    188188# plot_SkewT: Function to plot a SkewT-logP diagram using matplotlib's API example
     189# plot_stations_map: Function to plot a map with a series of stations
    189190# plot_Taylor: Function to draw a Taylor diagram (Taylor 2001)
    190191# plot_TimeEnsembles: Function to plot a of an Ensemble of values with a time-axis
     
    1263012631
    1263112632    return
     12633
     12634def plot_stations_map(dicstations, dimxv, dimyv, mapv, lonlatbox, ddlon, figtitle,   \
     12635  kfig, close):
     12636    """ Function to plot a map with a series of stations
     12637      dicstations: dictionary with the values of the stations as:
     12638        dicstations[refst]= [[lon], [lat], [height], [label], [marker], [color],
     12639            [size], [fontsize]]
     12640          [lon]: longitude of the station
     12641          [lat]: latitude of the station
     12642          [height]: height of the station
     12643          [label]: label in the figure ('None' for no label)
     12644          [marker]: type of marker
     12645          [color]: coor of the marker
     12646          [size]: size of the marker   
     12647          [fontsize]: size of the label font
     12648      dimxv: values along x-axis
     12649      dimyv: values along y-axis
     12650      mapv= map characteristics: [proj],[res]
     12651        see full documentation: http://matplotlib.org/basemap/
     12652        [proj]: projection
     12653          * 'cyl', cilindric
     12654          * 'lcc', lambert-conformal
     12655        [res]: resolution:
     12656          * 'c', crude
     12657          * 'l', low
     12658          * 'i', intermediate
     12659          * 'h', high
     12660          * 'f', full
     12661      lonlatbox: list of the vertexs of the map [SWlon, NElon, SWlat, NElat]
     12662      ddlon: diferential of longitude
     12663      figtitle: title of the figure
     12664      kfig: kind of figure file (ps, png, pdf, ...)
     12665      close: whether figure should be closed or not
     12666    """
     12667    fname = 'plot_stations_map'
     12668
     12669    nlon = lonlatbox[0]
     12670    xlon = lonlatbox[1]
     12671    nlat = lonlatbox[2]
     12672    xlat = lonlatbox[3]
     12673
     12674    plt.rc('text', usetex=True)
     12675
     12676    if not mapv is None:
     12677        map_proj=mapv.split(',')[0]
     12678        map_res=mapv.split(',')[1]
     12679
     12680        lon, lat = np.meshgrid(dimxv, dimyv)
     12681
     12682        lon2 = (nlon + xlon)/2.
     12683        lat2 = (nlat + xlat)/2.
     12684
     12685        print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:',     \
     12686          xlon, ',', xlat
     12687
     12688        if map_proj == 'cyl':
     12689            m = Basemap(projection=map_proj, llcrnrlon=nlon, llcrnrlat=nlat,         \
     12690              urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res)
     12691        elif map_proj == 'lcc':
     12692            m = Basemap(projection=map_proj, lat_0=lat2, lon_0=lon2, llcrnrlon=nlon, \
     12693              llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res)
     12694        else:
     12695            print errormsg
     12696            print '  ' + fname + ": map projection '" + map_proj + "' not defined!!!"
     12697            print '    available: cyl, lcc'
     12698            quit(-1)
     12699 
     12700        x,y = m(lon,lat)
     12701
     12702        m.drawcoastlines()
     12703
     12704        meridians = gen.pretty_int(nlon,xlon,5)
     12705        m.drawmeridians(meridians,labels=[True,False,False,True])
     12706
     12707        parallels = gen.pretty_int(nlat,xlat,5)
     12708        m.drawparallels(parallels,labels=[False,True,True,False])
     12709
     12710    else:
     12711        # No following data values
     12712        x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
     12713        y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
     12714
     12715    for ist in dicstations.keys():
     12716        stv = dicstations[ist]
     12717        stlon = stv[0]
     12718        stlat = stv[1]
     12719        stlab = stv[3]
     12720        stmrk = stv[4]
     12721        stcol = stv[5]
     12722        stsiz = stv[6]
     12723        fontsiz = stv[7]
     12724
     12725        plt.plot(stlon, stlat, stmrk, color=stcol, markersize=stsiz)
     12726        if stlab != 'None':
     12727            plt.annotate(gen.latex_text(stlab), xy=(stlon+ddlon,stlat),         \
     12728              xycoords='data', color=stcol, fontsize=fontsiz)
     12729
     12730    plt.title(gen.latex_text(figtitle))
     12731
     12732    figname = 'stations_map'
     12733    output_kind(kfig, figname, close)
     12734
     12735    return
     12736
Note: See TracChangeset for help on using the changeset viewer.