- Timestamp:
- Dec 1, 2014, 11:50:52 AM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 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) -
trunk/tools/drawing_tools.py
r192 r194 4459 4459 4460 4460 return 4461 4462 def plot_lines_time(vardv, varvv, vaxis, dtit, linesn, vtit, vunit, tpos, tlabs, \ 4463 gtit, kfig): 4464 """ Function to plot a collection of lines with a time axis 4465 vardv= list of set of dimension values 4466 varvv= list of set of values 4467 vaxis= which axis will be used for the time values ('x', or 'y') 4468 dtit= title for the common dimension 4469 linesn= names for the legend 4470 vtit= title for the vaxis 4471 vunit= units of the vaxis 4472 tpos= positions of the time ticks 4473 tlabs= labels of the time ticks 4474 gtit= main title 4475 kfig= kind of figure 4476 plot_lines([np.arange(10)], [np.sin(np.arange(10)*np.pi/2.5)], 'y', 'time (s)', \ 4477 ['2.5'], 'sin', '-', 'sinus frequency dependency', 'pdf') 4478 """ 4479 fname = 'plot_lines' 4480 4481 if vardv == 'h': 4482 print fname + '_____________________________________________________________' 4483 print plot_lines.__doc__ 4484 quit() 4485 4486 # Canging line kinds every 7 lines (end of standard colors) 4487 linekinds=['.-','x-','o-'] 4488 4489 Ntraj = len(vardv) 4490 4491 N7lines = 0 4492 4493 plt.rc('text', usetex=True) 4494 4495 if vaxis == 'x': 4496 for il in range(Ntraj): 4497 plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il]) 4498 if il == 6: N7lines = N7lines + 1 4499 4500 plt.xlabel(vtit + ' (' + vunit + ')') 4501 plt.ylabel(dtit) 4502 plt.xlim(np.min(varvv[:]),np.max(varvv[:])) 4503 plt.ylim(np.min(vardv[:]),np.max(vardv[:])) 4504 plt.yticks(tpos, tlabs) 4505 else: 4506 for il in range(Ntraj): 4507 plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il]) 4508 if il == 6: N7lines = N7lines + 1 4509 4510 plt.xlabel(dtit) 4511 plt.ylabel(vtit + ' (' + vunit + ')') 4512 plt.xlim(np.min(vardv[:]),np.max(vardv[:])) 4513 plt.ylim(np.min(varvv[:]),np.max(varvv[:])) 4514 plt.xticks(tpos, tlabs) 4515 4516 figname = 'lines_time' 4517 graphtit = gtit 4518 4519 plt.title(graphtit) 4520 plt.legend() 4521 4522 output_kind(kfig, figname, True) 4523 4524 return
Note: See TracChangeset
for help on using the changeset viewer.