Changeset 531 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 25, 2015, 11:46:49 AM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r489 r531 1640 1640 return 1641 1641 1642 def draw_lines_time(ncfilens, values, varname ):1642 def draw_lines_time(ncfilens, values, varname0): 1643 1643 """ Function to draw different lines at the same time from different files with times 1644 1644 draw_lines_time(ncfilens, values, varname): 1645 1645 ncfilens= [filen] ',' separated list of netCDF files 1646 values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg];[graphk] 1647 [dimvname]: name of the variable with he values of the common dimension 1646 values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg]; 1647 [graphk];[collines] 1648 [dimvname]: ',' list of names of the variables with he values of the common dimension 1648 1649 [valuesaxis]: which axis will be used for the values ('x', or 'y') 1649 1650 [dimtit]: title for the common dimension … … 1667 1668 9: 'upper center', 10: 'center' 1668 1669 [graphk]: kind of the graphic 1669 varname= variable to plot 1670 [collines]: ',' list of colors for the lines or None for automatic 1671 varname0= ',' list of variable names to plot (assuming only 1 variable per file) 1670 1672 values= 'time;y;time ([DD]${[HH]}$);32x32;$wss^{*}$;wss Taylor's turbulence term;time|hours!since!1949-12-01_00:00:00;exct,12,h|%d$^{%H}$;2;pdf' 1671 1673 """ … … 1679 1681 1680 1682 expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];' 1681 expectargs = expectargs + '[timevals];[locleg];[graphk] '1683 expectargs = expectargs + '[timevals];[locleg];[graphk];[collines]' 1682 1684 drw.check_arguments(fname,len(expectargs.split(';')),values,';',expectargs) 1683 1685 1684 1686 ncfiles = ncfilens.split(',') 1685 dimvname = values.split(';')[0]1687 dimvname0 = values.split(';')[0] 1686 1688 valuesaxis = values.split(';')[1] 1687 1689 dimtit = values.split(';')[2] … … 1692 1694 locleg = int(values.split(';')[7]) 1693 1695 graphk = values.split(';')[8] 1696 collines0 = values.split(';')[9] 1694 1697 1695 1698 Nfiles = len(ncfiles) 1699 1700 # Multiple variable-dimension names? 1701 if dimvname0.find(',') != -1: 1702 dimvname = dimvname0.split(',') 1703 else: 1704 dimvname = [dimvname0] 1705 1706 # Multiple variables? 1707 if varname0.find(',') != -1: 1708 varname = varname0.split(',') 1709 else: 1710 varname = [varname0] 1711 1712 # Multiple color names? 1713 if collines0.find(',') != -1: 1714 collines = collines0.split(',') 1715 else: 1716 collines = None 1696 1717 1697 1718 # Getting values … … 1719 1740 objfile = NetCDFFile(filen, 'r') 1720 1741 1721 if not objfile.variables.has_key(dimvname): 1742 founddvar = False 1743 for dvar in dimvname: 1744 if objfile.variables.has_key(dvar): 1745 founddvar = True 1746 vdobj = objfile.variables[dvar] 1747 if len(vdobj.shape) != 1: 1748 print errormsg 1749 print ' ' + fname + ': wrong shape:',vdobj.shape," of " + \ 1750 "variable '" + dvar + "' !!" 1751 quit(-1) 1752 break 1753 if not founddvar: 1722 1754 print errormsg 1723 1755 print ' ' + fname + ": netCDF file '" + filen + \ 1724 "' does not have variable '" + dimvname +"' !!"1756 "' has any variable '", dimvname, "' !!" 1725 1757 quit(-1) 1726 1758 1727 if not objfile.variables.has_key(varname): 1759 foundvar = False 1760 for var in varname: 1761 if objfile.variables.has_key(var): 1762 foundvar = True 1763 vvobj = objfile.variables[var] 1764 if len(vvobj.shape) != 1: 1765 print errormsg 1766 print ' ' + fname + ': wrong shape:',vvobj.shape," of " + \ 1767 "variable '" + var + "' !!" 1768 quit(-1) 1769 1770 break 1771 if not foundvar: 1728 1772 print errormsg 1729 1773 print ' ' + fname + ": netCDF file '" + filen + \ 1730 "' does not have variable '" + varname + "' !!" 1731 quit(-1) 1732 1733 vvobj = objfile.variables[varname] 1734 if len(vvobj.shape) != 1: 1735 print errormsg 1736 print ' ' + fname + ': wrong shape:',vvobj.shape," of variable '" + \ 1737 varname + "' !!" 1738 quit(-1) 1739 1740 vdobj = objfile.variables[dimvname] 1741 if len(vdobj.shape) != 1: 1742 print errormsg 1743 print ' ' + fname + ': wrong shape:',vdobj.shape," of variable '" + \ 1744 dimvname + "' !!" 1774 "' has any variable '", varname, "' !!" 1745 1775 quit(-1) 1746 1776 … … 1773 1803 1774 1804 drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, leglabels.split(','), \ 1775 vartit, varunits, timepos, timelabels, title, locleg, graphk )1805 vartit, varunits, timepos, timelabels, title, locleg, graphk, collines) 1776 1806 1777 1807 return -
trunk/tools/drawing_tools.py
r530 r531 1406 1406 1407 1407 # Units which does not change 1408 same = ['1', 'category', 'day', 'deg rees East', 'degrees Nord', 'degrees North',\1409 ' g', 'gpm', 'hour', 'hPa', 'K', 'Km', 'kg', 'km', 'm', 'minute', 'mm', 'month', 'Pa',\1410 ' s', 'second', 'um', 'year', '-']1408 same = ['1', 'category', 'day', 'deg', 'degrees East', 'degrees Nord', \ 1409 'degrees North', 'g', 'gpm', 'hour', 'hPa', 'K', 'Km', 'kg', 'km', 'm', \ 1410 'minute', 'mm', 'month', 'Pa', 's', 'second', 'um', 'year', '-'] 1411 1411 1412 1412 if searchInlist(same,u): … … 5086 5086 5087 5087 def plot_lines_time(vardv, varvv, vaxis, dtit, linesn, vtit, vunit, tpos, tlabs, \ 5088 gtit, gloc, kfig ):5088 gtit, gloc, kfig, coll): 5089 5089 """ Function to plot a collection of lines with a time axis 5090 5090 vardv= list of set of dimension values … … 5103 5103 9: 'upper center', 10: 'center' 5104 5104 kfig= kind of figure 5105 coll= ',' list of colors for the lines or None for automatic 5105 5106 plot_lines([np.arange(10)], [np.sin(np.arange(10)*np.pi/2.5)], 'y', 'time (s)', \ 5106 5107 ['2.5'], 'sin', '-', 'sinus frequency dependency', 'pdf') … … 5126 5127 if vaxis == 'x': 5127 5128 for il in range(Ntraj): 5128 plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il]) 5129 if coll is None: 5130 plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il]) 5131 else: 5132 plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il],\ 5133 color=coll[il]) 5134 5129 5135 varTvv = varTvv + list(varvv[il]) 5130 5136 varTdv = varTdv + list(vardv[il]) … … 5138 5144 else: 5139 5145 for il in range(Ntraj): 5140 plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il]) 5146 if coll is None: 5147 plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il]) 5148 else: 5149 plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il],\ 5150 color=coll[il]) 5151 5141 5152 varTvv = varTvv + list(varvv[il]) 5142 5153 varTdv = varTdv + list(vardv[il])
Note: See TracChangeset
for help on using the changeset viewer.