Changeset 776 in lmdz_wrf
- Timestamp:
- May 25, 2016, 5:10:25 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r774 r776 3668 3668 draw_topo_geogrid(ncfile, values, varn) 3669 3669 ncfile= file to use 3670 values= [zlog]:[dzlog]:[title]:[graphic_kind]:[legloc] 3670 values= [zlogs]:[plogs]:[title]:[graphic_kind]:[legloc] 3671 zlogs= zlog,dzlog 3671 3672 zlog: to use logarithmic scale on the height axis ('true/false') 3672 3673 dzlog: to use logarithmic scale on the difference of height between levels axis ('true/false') 3674 plogs= plog,dplog 3675 plog: to use logarithmic scale on the height axis ('true/false') 3676 dplog: to use logarithmic scale on the difference of height between levels axis ('true/false') 3673 3677 title: title of the graph ('!' for spaces) 3674 3678 graphic_kind: kind of figure (jpg, pdf, png) … … 3677 3681 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 3678 3682 9: 'upper center', 10: 'center' kfig= kind of figure 3679 varn= name of the variable with the vertical levels 3680 'WRFz': for WRF z-levels (computed as (PH + PHB)/g, from a PHB(0,i,j) = 0) 3683 varn= [varnheight],[varnpres] 3684 varnheight: name of the variable with the height of the vertical levels 3685 'WRFz': for WRF z-levels (computed as (PH + PHB)/g, from a PHB(0,i,j) = 0) 3686 varnpres: name of the variable with the pressure of the vertical levels ('None', for no pressure plot) 3687 'WRFp': for WRF p-levels (computed as P + PB, from a PHB(0,i,j) = 0) 3681 3688 """ 3682 3689 fname = 'draw_vertical_levels' … … 3687 3694 quit() 3688 3695 3689 expectargs = '[zlog ]:[dzlog]:[title]:[graphic_kind]:[legloc]'3696 expectargs = '[zlogs]:[plogs]:[title]:[graphic_kind]:[legloc]' 3690 3697 3691 3698 drw.check_arguments(fname,values,expectargs,':') 3692 3699 3693 zlog = values.split(':')[0] 3694 dzlog = values.split(':')[1] 3700 zlog = values.split(':')[0].split(',')[0] 3701 dzlog = values.split(':')[0].split(',')[1] 3702 plog = values.split(':')[1].split(',')[0] 3703 dplog = values.split(':')[1].split(',')[1] 3695 3704 title = values.split(':')[2].replace('!',' ') 3696 3705 kindfig = values.split(':')[3] 3697 3706 legloc = int(values.split(':')[4]) 3698 3707 3708 if varn.find(',') == -1: 3709 varnheight = varn 3710 varnpres = None 3711 pvals = None 3712 print warnmsg 3713 print ' ' + fname + ': assuming no pressure variable!!' 3714 else: 3715 varnheight = varn.split(',')[0] 3716 varnpres = varn.split(',')[1] 3717 if varnpres == 'None': 3718 varnpres = None 3719 pvals = None 3720 3699 3721 if not os.path.isfile(ncfile): 3700 3722 print errormsg … … 3704 3726 objf = NetCDFFile(ncfile, 'r') 3705 3727 3706 if varn == 'WRFz':3728 if varnheight == 'WRFz': 3707 3729 if not gen.searchInlist(objf.variables,'PH'): 3708 3730 print errormsg … … 3723 3745 zvals = geop[0, :, ijz0[0], ijz0[1]] / 9.8 3724 3746 else: 3725 if not gen.searchInlist(objf.variables, varn ):3747 if not gen.searchInlist(objf.variables, varnheight): 3726 3748 print errormsg 3727 print ' ' + fname + ": file '" + ncfile + "' does not have variable '" +\3728 varn+ "' !!"3749 print ' ' + fname + ": file '" + ncfile + "' does not have height " + \ 3750 " variable '" + varnheight + "' !!" 3729 3751 quit(-1) 3730 3752 objvar = objf.variables[varn] 3731 3753 if len(objvar.shape) == 4: 3732 3754 print warnmsg 3733 print ' ' + fname + ": assuming that variable '" + varn + "' with " +\3734 " shape: dt,dz,dy,dx. Tacking first time-step"3755 print ' ' + fname + ": assuming that height variable '" + varnheight + \ 3756 "' with shape: dt,dz,dy,dx. Tacking first time-step" 3735 3757 3736 3758 ijz0 = gen.index_mat(objvar[0,0,], 0.) … … 3738 3760 elif len(objvar.shape) == 3: 3739 3761 print warnmsg 3740 print ' ' + fname + ": assuming that variable '" + varn + "' with " +\3741 " shape: dz,dy,dx"3762 print ' ' + fname + ": assuming that height variable '" + varnheight + \ 3763 "' with shape: dz,dy,dx" 3742 3764 3743 3765 ijz0 = gen.index_mat(objvar[0,], 0.) … … 3746 3768 elif len(objvar.shape) == 2: 3747 3769 print warnmsg 3748 print ' ' + fname + ": assuming that variable '" + varn + "' with " +\3749 " shape: dz,dyx"3770 print ' ' + fname + ": assuming that height variable '" + varnheight + \ 3771 "' with shape: dz,dyx" 3750 3772 3751 3773 ijz0 = gen.index_mat(objvar[0,], 0.) … … 3754 3776 zvals = objvar[:] 3755 3777 3778 # Pressure 3779 if varnpres is not None: 3780 if varnpres == 'WRFp': 3781 if not gen.searchInlist(objf.variables,'P'): 3782 print errormsg 3783 print ' ' + fname + ": WRF file '" + ncfile + "' does not have " + \ 3784 "variable 'P' !!" 3785 quit(-1) 3786 if not gen.searchInlist(objf.variables,'PB'): 3787 print errormsg 3788 print ' ' + fname + ": WRF file '" + ncfile + "' does not have " + \ 3789 "variable 'PB' !!" 3790 quit(-1) 3791 3792 objph = objf.variables['P'] 3793 objphb = objf.variables['PB'] 3794 pres = objph[:] + objphb[:] 3795 3796 pvals = pres[0, :, ijz0[0], ijz0[1]] 3797 else: 3798 if not gen.searchInlist(objf.variables, varnpres): 3799 print errormsg 3800 print ' ' + fname + ": file '" + ncfile + "' does not have pressure " + \ 3801 " variable '" + varnpres + "' !!" 3802 quit(-1) 3803 objvar = objf.variables[varnpres] 3804 if len(objvar.shape) == 4: 3805 print warnmsg 3806 print ' ' + fname + ": assuming that pressure variable '" + varnpres + \ 3807 "' with shape: dt,dz,dy,dx. Tacking first time-step" 3808 3809 pvals = objvar[0, :, ijz0[0], ijz0[1]] 3810 elif len(objvar.shape) == 3: 3811 print warnmsg 3812 print ' ' + fname + ": assuming that pressure variable '" + varnpres + \ 3813 "' with shape: dz,dy,dx" 3814 3815 pvals = objvar[:, ijz0[0], ijz0[1]] 3816 3817 elif len(objvar.shape) == 2: 3818 print warnmsg 3819 print ' ' + fname + ": assuming that pressure variable '" + varnpres + \ 3820 "' with shape: dz,dyx" 3821 3822 pvals = objvar[:, ijz0[0]] 3823 else: 3824 pvals = objvar[:] 3825 3826 # Logarithmic axes 3756 3827 if zlog == 'true': 3757 3828 zlogv = True … … 3763 3834 print " must be either: 'true' or 'false'" 3764 3835 quit(-1) 3836 3765 3837 if dzlog == 'true': 3766 3838 dzlogv = True … … 3773 3845 quit(-1) 3774 3846 3775 drw.plot_vertical_lev(zvals, zlogv, dzlogv, title, kindfig, legloc) 3847 if pvals is not None: 3848 if plog == 'true': 3849 plogv = True 3850 elif plog == 'false': 3851 plogv = False 3852 else: 3853 print errormsg 3854 print ' ' + fname + ": wrong value for plog: '" + plog + "' !!" 3855 print " must be either: 'true' or 'false'" 3856 quit(-1) 3857 if dplog == 'true': 3858 dplogv = True 3859 elif dplog == 'false': 3860 dplogv = False 3861 else: 3862 print errormsg 3863 print ' ' + fname + ": wrong value for dplog: '" + dplog + "' !!" 3864 print " must be either: 'true' or 'false'" 3865 quit(-1) 3866 3867 drw.plot_vertical_lev(zvals, pvals, zlogv, dzlogv, plogv, dplogv, title, kindfig, legloc) 3776 3868 3777 3869 objf.close() -
trunk/tools/drawing_tools.py
r773 r776 1484 1484 elif u == 'C': lu='$^{\circ}C$' 1485 1485 elif u == 'days': lu='$day$' 1486 elif u == 'degrees_East': lu='$degrees\ East$' 1486 1487 elif u == 'degrees_east': lu='$degrees\ East$' 1487 1488 elif u == 'degree_east': lu='$degrees\ East$' 1488 1489 elif u == 'degrees longitude': lu='$degrees\ East$' 1489 1490 elif u == 'degrees latitude': lu='$degrees\ North$' 1491 elif u == 'degrees_North': lu='$degrees\ North$' 1490 1492 elif u == 'degrees_north': lu='$degrees\ North$' 1491 1493 elif u == 'degree_north': lu='$degrees\ North$' … … 6562 6564 6563 6565 6564 def plot_vertical_lev(vertz, zlog, dzlog, gtit, kfig, lloc):6566 def plot_vertical_lev(vertz, vertp, zlog, dzlog, plog, dplog, gtit, kfig, lloc): 6565 6567 """ plotting vertical levels distribution 6566 6568 plot_vertical_lev(vertz, gtit, kfig, lloc) 6567 6569 vertz= distribution of vertical heights [z] 6570 vertp= distribution of vertical pressures [Pa] 6568 6571 zlog: to use logarithmic scale on the height axis ('true/false') 6569 6572 dzlog: to use logarithmic scale on the difference of height between levels axis ('true/false') 6573 plog: to use logarithmic scale on the pressure axis ('true/false') 6574 pzlog: to use logarithmic scale on the difference of pressure between levels axis ('true/false') 6570 6575 gtit= title of the graph ('!' for spaces) 6571 6576 kfig= kind of figure (jpg, pdf, png) … … 6590 6595 6591 6596 plt.rc('text', usetex=True) 6592 6593 fig, ax1 = plt.subplots() 6597 # Height plot 6598 ## 6599 if vertp is not None: 6600 print plt.subplots.__doc__ 6601 fig, (ax1, ax3) = plt.subplots(nrows=2, ncols=1, sharex=True) 6602 else: 6603 fig, ax1 = plt.subplots() 6594 6604 ax2 = ax1.twinx() 6595 6605 6596 6606 plt.xlim(0,Nlev) 6597 6607 6598 6608 l1 = ax1.plot(range(Nlev), vertz, 'r-x', label='height') 6599 6609 l2 = ax2.plot(range(1,Nlev), dvertz, 'b-x', label='dheight') 6600 6610 6601 ax1.set_xlabel('level (\#)')6611 # ax1.set_xlabel('level (\#)') 6602 6612 ax1.set_ylabel('height (m)', color='r') 6603 6613 ax1.set_ylim(1,np.max(vertz)) … … 6605 6615 ax2.set_ylabel('difference between levels (m)', color='b') 6606 6616 6607 plt.title(gtit)6617 if vertp is not None: ax1.set_title('height') 6608 6618 if zlog: ax1.set_yscale('log') 6609 6619 if dzlog: ax2.set_yscale('log') 6610 6620 6621 # Pressure plot 6622 ## 6623 if vertp is not None: 6624 6625 Nlev = len(vertp) 6626 dvertp = vertp[0:Nlev-1] - vertp[1:Nlev] 6627 6628 ax4 = ax3.twinx() 6629 6630 l3 = ax3.plot(range(Nlev), vertp, 'r-o', label='pressure') 6631 l4 = ax4.plot(range(1,Nlev), dvertp, 'b-o', label='dpressure') 6632 6633 ax3.set_xlim(0, Nlev) 6634 ax3.set_xlabel('level (\#)') 6635 ax3.set_ylabel('pressure (Pa)', color='r') 6636 ax3.set_ylim(np.min(vertp), np.max(vertp)) 6637 ax3.grid() 6638 ax4.set_ylabel('difference between levels (Pa)', color='b') 6639 6640 if plog: ax3.set_yscale('log') 6641 if dplog: ax4.set_yscale('log') 6642 6643 if vertp is not None: 6644 fig.suptitle(gtit) 6645 ax3.set_title('pressure') 6646 else: 6647 plt.title(gtit) 6648 6611 6649 output_kind(kfig, figname, True) 6612 6650
Note: See TracChangeset
for help on using the changeset viewer.