Changeset 651 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Sep 23, 2015, 11:26:56 AM (10 years ago)
Author:
lfita
Message:

Adding `draw_ptZvals' to draw lon,lat stations distributions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r641 r651  
    2424## e.g. # ~/etudes/WRF_LMDZ/svn/LMDZ_WRF/tools/drawing.py -o draw_points -S 'tslist.dat,#,3,2,1:SuperStorm|sfc|stations:cyl,i:legend:auto:None:0:png:stations_loc' -f $HOME'/etudes/domains/WRFdynamicoSENS_SuperStorm/geo_em.d02.nc,XLONG_M,XLAT_M,HGT_M,Time|0,height,0.,3000.,terrain,m'
    2525## e.g. # drawing.py -o draw_points -S 'tslist.dat,#,3,2,1:SuperStorm|sfc|stations:cyl,i:labelled,8,black:auto:None:0:png:stations_loc' -f $HOME'/etudes/domains/WRFdynamicoSENS_SuperStorm/geo_em_west_east_B25-E180-I1_south_north_B160-E262-I1.nc,XLONG_M,XLAT_M,HGT_M,Time|0,height,0.,1500.,terrain,m'
     26## e.g. # drawing.py -o draw_ptZvals -f geo_v2_2012102123_RR1.nc -S 'pracc:lon,lat:o:80:2,42,7,47,:values!of!values:Blues:cyl,l:pdf' -v pr
     27
    2628main = 'drawing.py'
    2729
     
    3234namegraphics = ['create_movie', 'draw_2D_shad', 'draw_2D_shad_time',                 \
    3335  'draw_2D_shad_cont', 'draw_2D_shad_cont_time', 'draw_2D_shad_line',                \
    34   'draw_2D_shad_line_time', 'draw_barbs', 'draw_points', 'draw_timeSeries',          \
    35    'draw_topo_geogrid',                                                              \
     36  'draw_2D_shad_line_time', 'draw_barbs', 'draw_points', 'draw_ptZvals',             \
     37   'draw_timeSeries',                                                                \
     38  'draw_topo_geogrid',                                                               \
    3639  'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories',          \
    3740  'draw_lines', 'draw_lines_time', 'draw_Neighbourghood_evol', 'list_graphics',      \
     
    28462849    return
    28472850
     2851def draw_ptZvals(ncfile, values, variable):
     2852    """ Function to plot a given list of points and values
     2853      ncfile= netCDF file to use
     2854      values= [fvname]:[XYvar]:[pointype]:[pointsize]:[graphlimits]:[nxtype]:
     2855        [figuretitle]:[colorbar]:[mapvalue]:[kindfig]
     2856        fvname: name of the variable in the graph
     2857        XYvar: [lon],[lat] variable names
     2858        ptype: type of the point
     2859        ptsize: size of the point
     2860        graphlimits: minLON,minLAT,maxLON,maxLAT limits of the graph 'None' for the full size
     2861        nxtype: minimum and maximum type
     2862          'auto': values taken from the extrems of the data
     2863          [min],[max]: given minimum and maximum values
     2864        figtitle: title of the figure
     2865        cbar: color bar
     2866        mapv: map characteristics: [proj],[res]
     2867          see full documentation: http://matplotlib.org/basemap/
     2868          [proj]: projection
     2869            * 'cyl', cilindric
     2870            * 'lcc', lambert-conformal
     2871          [res]: resolution:
     2872            * 'c', crude
     2873            * 'l', low
     2874            * 'i', intermediate
     2875            * 'h', high
     2876            * 'f', full
     2877        kfig: kind of figure
     2878      variable= name of the variable to plot
     2879    """
     2880    fname = 'draw_ptZvals'
     2881    import numpy.ma as ma
     2882
     2883    if values == 'h':
     2884        print fname + '_____________________________________________________________'
     2885        print draw_ptZvals.__doc__
     2886        quit()
     2887
     2888    expectargs = '[fvname]:[XYvar]:[pointype]:[pointsize]:[graphlmits]:[nxtype]:' +  \
     2889      '[figuretit]:[colorbar]:[mapvalue]:[kindfig]'
     2890 
     2891    drw.check_arguments(fname,len(expectargs.split(':')),values,':',expectargs)
     2892
     2893    fvname = values.split(':')[0]
     2894    XYvar = values.split(':')[1]
     2895    pointype = values.split(':')[2]
     2896    pointsize = int(values.split(':')[3])
     2897    graphlimits = values.split(':')[4]
     2898    nxtype = values.split(':')[5]
     2899    figuretitle = values.split(':')[6].replace('!',' ')
     2900    colorbar = values.split(':')[7]
     2901    mapvalue = values.split(':')[8]
     2902    kindfig = values.split(':')[9]
     2903
     2904    onc = NetCDFFile(ncfile, 'r')
     2905   
     2906    if not onc.variables.has_key(variable):
     2907        print errormsg
     2908        print '  ' + fname + ": file '" + ncfile + "' does not have variable '" +    \
     2909          variable + "' !!"
     2910        quit(-1)
     2911
     2912# points
     2913    lonvarn = XYvar.split(',')[0]
     2914    latvarn = XYvar.split(',')[1]
     2915
     2916    if not onc.variables.has_key(lonvarn):
     2917        print errormsg
     2918        print '  ' + fname + ": file '" + ncfile + "' does not have longitude " +    \
     2919          "variable '" + lonvarn + "' !!"
     2920        quit(-1)
     2921   
     2922    if not onc.variables.has_key(latvarn):
     2923        print errormsg
     2924        print '  ' + fname + ": file '" + ncfile + "' does not have latitude " +    \
     2925          "variable '" + latvarn + "' !!"
     2926        quit(-1)
     2927
     2928    olonvar = onc.variables[lonvarn]
     2929    olatvar = onc.variables[latvarn]
     2930    ovarvar = onc.variables[variable]
     2931
     2932    Lpts = len(olonvar[:].flatten())
     2933
     2934    pointvalues = ma.masked_array(np.zeros((Lpts,3), dtype=np.float))
     2935    pointvalues[:,0] = olonvar[:]
     2936    pointvalues[:,1] = olatvar[:]
     2937    pointvalues[:,2] = ovarvar[:]
     2938
     2939    varattrs = ovarvar.ncattrs()
     2940    if drw.searchInlist(varattrs, 'units'):
     2941        fvunits = ovarvar.getncattr('units')
     2942    else:
     2943        fvunits = drw.variables_values(variable)[5]
     2944
     2945# map value
     2946    if mapvalue == 'None': mapvalue = None
     2947
     2948# Graph limits
     2949    if graphlimits != 'None':
     2950        graphlts = np.zeros((4), dtype=np.float)
     2951        for il in range(4): graphlts[il] = np.float(graphlimits.split(',')[il])
     2952        pointvalues[:,0] = ma.masked_outside(pointvalues[:,0], graphlts[0],          \
     2953          graphlts[2])
     2954        pointvalues[:,1] = ma.masked_outside(pointvalues[:,1], graphlts[3],          \
     2955          graphlts[2])
     2956
     2957#        for ip in range(Lpts): 
     2958#            if pointvalues[ip,0] < graphlts[0] or pointvalues[ip,0] > graphlts[2]    \
     2959#              or pointvalues[ip,1] < graphlts[1] or pointvalues[ip,1] > graphlts[3]:
     2960#                print ip,pointvalues[ip,0:2], graphlts
     2961#                pointvalues[ip,2] = None
     2962    else:
     2963        graphlts = None
     2964
     2965    drw.plot_ptZvals(fvname,fvunits,pointvalues,pointype,pointsize,graphlts, nxtype, \
     2966      figuretitle,colorbar,mapvalue,kindfig)
     2967
     2968    return
     2969
     2970#draw_ptZvals('OBSnetcdf.nc', 'pracc:lon,lat:o:80:2,42,7,47,:values!of!values:Blues:cyl,l:pdf', 'pr')
     2971#quit()
     2972
    28482973####### ###### ##### #### ### ## #
    28492974
     
    29223047elif oper == 'draw_points':
    29233048    draw_points(opts.ncfile, opts.values)
     3049elif oper == 'draw_ptZvals':
     3050    draw_ptZvals(opts.ncfile, opts.values, opts.varname)
    29243051elif oper == 'draw_timeSeries':
    29253052    draw_timeSeries(opts.ncfile, opts.values, opts.varname)
Note: See TracChangeset for help on using the changeset viewer.