Changeset 773 in lmdz_wrf for trunk/tools/drawing.py
- Timestamp:
- May 24, 2016, 11:05:49 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r705 r773 3 3 from netCDF4 import Dataset as NetCDFFile 4 4 import drawing_tools as drw 5 import generic_tools as gen 5 6 from optparse import OptionParser 6 7 import sys … … 44 45 'draw_topo_geogrid', \ 45 46 'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories', \ 46 'draw_vectors', ' list_graphics', 'variable_values']47 'draw_vectors', 'draw_vertical_levels', 'list_graphics', 'variable_values'] 47 48 48 49 def draw_2D_shad(ncfile, values, varn): … … 1345 1346 [min/max]Topo: minimum and maximum values of topography to draw 1346 1347 lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] or None 1347 title: title of the graph 1348 title: title of the graph ('!' for spaces) 1348 1349 graphic_kind: kind of figure (jpg, pdf, png) 1349 1350 mapvalues: map characteristics [proj],[res] … … 1366 1367 quit() 1367 1368 1368 expectargs = '[minTopo] :[maxTopo]:[lonlatL]:[title]:[graphic_kind]:[mapvalues]'1369 expectargs = '[minTopo],[maxTopo]:[lonlatL]:[title]:[graphic_kind]:[mapvalues]' 1369 1370 1370 1371 drw.check_arguments(fname,values,expectargs,':') … … 1385 1386 lonlatL[3] = np.float(lonlatLS.split(',')[3]) 1386 1387 1387 grtit = values.split(':')[2] 1388 grtit = values.split(':')[2].replace('!',' ') 1388 1389 kindfig = values.split(':')[3] 1389 1390 mapvalues = values.split(':')[4] … … 1416 1417 [min/max]Topo: minimum and maximum values of topography to draw 1417 1418 lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] or None 1418 title: title of the graph 1419 title: title of the graph ('!' for spaces) 1419 1420 graphic_kind: kind of figure (jpg, pdf, png) 1420 1421 mapvalues: map characteristics [proj],[res] … … 1461 1462 lonlatL[3] = np.float(lonlatLS.split(',')[3]) 1462 1463 1463 grtit = values.split(':')[2] 1464 grtit = values.split(':')[2].replace('!', ' ') 1464 1465 kindfig = values.split(':')[3] 1465 1466 mapvalues = values.split(':')[4] … … 3662 3663 of.close() 3663 3664 3665 def draw_vertical_levels(ncfile, values, varn): 3666 """ plotting vertical levels distribution 3667 draw_topo_geogrid(ncfile, values, varn) 3668 ncfile= file to use 3669 values= [zlog]:[dzlog]:[title]:[graphic_kind]:[legloc] 3670 zlog: to use logarithmic scale on the height axis ('true/false') 3671 dzlog: to use logarithmic scale on the difference of height between levels axis ('true/false') 3672 title: title of the graph ('!' for spaces) 3673 graphic_kind: kind of figure (jpg, pdf, png) 3674 legloc= location of the legend (0, automatic) 3675 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3676 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 3677 9: 'upper center', 10: 'center' kfig= kind of figure 3678 varn= name of the variable with the vertical levels 3679 'WRFz': for WRF z-levels (computed as (PH + PHB)/g, from a PHB(0,i,j) = 0) 3680 """ 3681 fname = 'draw_vertical_levels' 3682 3683 if values == 'h': 3684 print fname + '_____________________________________________________________' 3685 print draw_vertical_levels.__doc__ 3686 quit() 3687 3688 expectargs = '[zlog]:[dzlog]:[title]:[graphic_kind]:[legloc]' 3689 3690 drw.check_arguments(fname,values,expectargs,':') 3691 3692 zlog = values.split(':')[0] 3693 dzlog = values.split(':')[1] 3694 title = values.split(':')[2].replace('!',' ') 3695 kindfig = values.split(':')[3] 3696 legloc = int(values.split(':')[4]) 3697 3698 if not os.path.isfile(ncfile): 3699 print errormsg 3700 print ' ' + fname + ': file "' + ncfile + '" does not exist !!' 3701 quit(-1) 3702 3703 objf = NetCDFFile(ncfile, 'r') 3704 3705 if varn == 'WRFz': 3706 if not gen.searchInlist(objf.variables,'PH'): 3707 print errormsg 3708 print ' ' + fname + ": WRF file '" + ncfile + "' does not have " + \ 3709 "variable 'PH' !!" 3710 quit(-1) 3711 if not gen.searchInlist(objf.variables,'PHB'): 3712 print errormsg 3713 print ' ' + fname + ": WRF file '" + ncfile + "' does not have " + \ 3714 "variable 'PHB' !!" 3715 quit(-1) 3716 3717 objph = objf.variables['PH'] 3718 objphb = objf.variables['PHB'] 3719 geop = objph[:] + objphb[:] 3720 3721 ijz0 = gen.index_mat(geop[0,], 0.) 3722 zvals = geop[0, :, ijz0[0], ijz0[1]] / 9.8 3723 else: 3724 if not objf.has_variable(varn): 3725 print errormsg 3726 print ' ' + fname + ": file '" + ncfile + "' does not have variable '" +\ 3727 varn + "' !!" 3728 quit(-1) 3729 objvar = objf.variables[varn] 3730 if len(objvar.shape) == 4: 3731 print warnmsg 3732 print ' ' + fname + ": assuming that variable '" + varn + "' with " + \ 3733 "shape: dt,dz,dy,dx. Tacking first time-step" 3734 3735 ijz0 = gen.index_mat(objvar[0,0,], 0.) 3736 zvals = objvar[0, :, ijz0[0], ijz0[1]] 3737 elif len(objvar.shape) == 3: 3738 print warnmsg 3739 print ' ' + fname + ": assuming that variable '" + varn + "' with " + \ 3740 "shape: dz,dy,dx" 3741 3742 ijz0 = gen.index_mat(objvar[0,], 0.) 3743 zvals = objvar[:, ijz0[0], ijz0[1]] 3744 3745 elif len(objvar.shape) == 2: 3746 print warnmsg 3747 print ' ' + fname + ": assuming that variable '" + varn + "' with " + \ 3748 "shape: dz,dyx" 3749 3750 ijz0 = gen.index_mat(objvar[0,], 0.) 3751 zvals = objvar[:, ijz0[0]] 3752 else: 3753 zvals = objvar[:] 3754 3755 if zlog == 'true': 3756 zlogv = True 3757 elif zlog == 'false': 3758 zlogv = False 3759 else: 3760 print errormsg 3761 print ' ' + fname + ": wrong value for zlog: '" + zlog + "' !!" 3762 print " must be either: 'true' or 'false'" 3763 quit(-1) 3764 if dzlog == 'true': 3765 dzlogv = True 3766 elif dzlog == 'false': 3767 dzlogv = False 3768 else: 3769 print errormsg 3770 print ' ' + fname + ": wrong value for dzlog: '" + dzlog + "' !!" 3771 print " must be either: 'true' or 'false'" 3772 quit(-1) 3773 3774 drw.plot_vertical_lev(zvals, zlogv, dzlogv, title, kindfig, legloc) 3775 3776 objf.close() 3777 3778 return 3779 3664 3780 #quit() 3665 3781 … … 3760 3876 elif oper == 'draw_vectors': 3761 3877 draw_vectors(opts.ncfile, opts.values, opts.varname) 3878 elif oper == 'draw_vertical_levels': 3879 draw_vertical_levels(opts.ncfile, opts.values, opts.varname) 3762 3880 elif oper == 'list_graphics': 3763 3881 # From: http://www.diveintopython.net/power_of_introspection/all_together.html
Note: See TracChangeset
for help on using the changeset viewer.