Changeset 194 in lmdz_wrf for trunk/tools/drawing.py
- Timestamp:
- Dec 1, 2014, 11:50:52 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r193 r194 31 31 'draw_2D_shad_line_time', 'draw_timeSeries', 'draw_topo_geogrid', \ 32 32 'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories', \ 33 'draw_lines', 'draw_Neighbourghood_evol', 'list_graphics', 'variable_values'] 33 'draw_lines', 'draw_lines_time', 'draw_Neighbourghood_evol', 'list_graphics', \ 34 'variable_values'] 34 35 35 36 def draw_2D_shad(ncfile, values, varn): … … 1475 1476 def draw_lines(ncfilens, values, varname): 1476 1477 """ Function to draw different lines at the same time from different files 1477 draw_ trajectories(ncfilens, values, varname):1478 draw_lines(ncfilens, values, varname): 1478 1479 ncfilens= [filen] ',' separated list of netCDF files 1479 1480 values= [dimvname]:[valuesaxis]:[dimtit]:[leglabels]:[vtit]:[title]:[graphk] … … 1569 1570 drw.plot_lines(dimvalues, varvalues, valuesaxis, dimtit, leglabels.split(','), \ 1570 1571 vartit, varunits, title, graphk) 1572 1573 return 1574 1575 def draw_lines_time(ncfilens, values, varname): 1576 """ Function to draw different lines at the same time from different files with times 1577 draw_lines_time(ncfilens, values, varname): 1578 ncfilens= [filen] ',' separated list of netCDF files 1579 values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[graphk] 1580 [dimvname]: name of the variable with he values of the common dimension 1581 [valuesaxis]: which axis will be used for the values ('x', or 'y') 1582 [dimtit]: title for the common dimension 1583 [leglabels]: ',' separated list of names for the legend 1584 [vartit]: name of the variable in the graph 1585 [title]: title of the plot ('|' for spaces) 1586 [timevals]: [timen]|[units]|[kind]|[tfmt] time labels characteristics 1587 [timen]; name of the time variable 1588 [units]; units string according to CF conventions ([tunits] since 1589 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) 1590 [kind]; kind of output 1591 'Nval': according to a given number of values as 'Nval',[Nval] 1592 'exct': according to an exact time unit as 'exct',[tunit]; 1593 tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month, 1594 'w': week, 'd': day, 'h': hour, 'i': minute, 's': second, 1595 'l': milisecond 1596 [tfmt]; desired format 1597 [graphk]: kind of the graphic 1598 varname= variable to plot 1599 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}$;pdf' 1600 """ 1601 1602 fname = 'draw_lines_time' 1603 1604 if values == 'h': 1605 print fname + '_____________________________________________________________' 1606 print draw_lines.__doc__ 1607 quit() 1608 1609 expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];' 1610 expectargs = expectargs + '[timevals];[graphk]' 1611 drw.check_arguments(fname,len(expectargs.split(';')),values,';',expectargs) 1612 1613 ncfiles = ncfilens.split(',') 1614 dimvname = values.split(';')[0] 1615 valuesaxis = values.split(';')[1] 1616 dimtit = values.split(';')[2] 1617 leglabels = values.split(';')[3].replace('_','\_') 1618 vartit = values.split(';')[4] 1619 title = values.split(';')[5].replace('|',' ') 1620 timevals = values.split(';')[6] 1621 graphk = values.split(';')[7] 1622 1623 Nfiles = len(ncfiles) 1624 1625 # Getting values 1626 ## 1627 varvalues = [] 1628 dimvalues = [] 1629 timvalues = [] 1630 timvals0 = timvalues 1631 1632 print ' ' + fname 1633 ifn = 0 1634 for ifile in ncfiles: 1635 filen = ifile.split('@')[0] 1636 1637 print ' filen:',filen 1638 1639 if not os.path.isfile(filen): 1640 print errormsg 1641 print ' ' + fname + ": netCDF file '" + filen + "' does not exist !!" 1642 quit(-1) 1643 1644 objfile = NetCDFFile(filen, 'r') 1645 1646 if not objfile.variables.has_key(dimvname): 1647 print errormsg 1648 print ' ' + fname + ": netCDF file '" + filen + \ 1649 "' does not have variable '" + dimvname + "' !!" 1650 quit(-1) 1651 1652 if not objfile.variables.has_key(varname): 1653 print errormsg 1654 print ' ' + fname + ": netCDF file '" + filen + \ 1655 "' does not have variable '" + varname + "' !!" 1656 quit(-1) 1657 1658 vvobj = objfile.variables[varname] 1659 if len(vvobj.shape) != 1: 1660 print errormsg 1661 print ' ' + fname + ': wrong shape:',vvobj.shape," of variable '" + \ 1662 varname + "' !!" 1663 quit(-1) 1664 1665 vdobj = objfile.variables[dimvname] 1666 if len(vdobj.shape) != 1: 1667 print errormsg 1668 print ' ' + fname + ': wrong shape:',vdobj.shape," of variable '" + \ 1669 dimvname + "' !!" 1670 quit(-1) 1671 1672 varvalues.append(vvobj[:]) 1673 dimvalues.append(vdobj[:]) 1674 1675 timvalues = timvalues + list(vdobj[:]) 1676 1677 if ifn == 0: 1678 varunits = vvobj.units 1679 1680 objfile.close() 1681 1682 ifn = ifn + 1 1683 1684 # Times 1685 timename = timevals.split('|')[0] 1686 timeunit = timevals.split('|')[1].replace('!',' ') 1687 timekind = timevals.split('|')[2] 1688 timefmt = timevals.split('|')[3] 1689 1690 tvals = list(set(timvalues)) 1691 tvals.sort() 1692 1693 timepos, timelabels = drw.CFtimes_plot(tvals, timeunit, timekind, timefmt) 1694 1695 drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, leglabels.split(','), \ 1696 vartit, varunits, timepos, timelabels, title, graphk) 1571 1697 1572 1698 return … … 2275 2401 elif oper == 'draw_lines': 2276 2402 draw_lines(opts.ncfile, opts.values, opts.varname) 2403 elif oper == 'draw_lines_time': 2404 draw_lines_time(opts.ncfile, opts.values, opts.varname) 2277 2405 elif oper == 'draw_timeSeries': 2278 2406 draw_timeSeries(opts.ncfile, opts.values, opts.varname)
Note: See TracChangeset
for help on using the changeset viewer.