Changeset 2990 for trunk/python
- Timestamp:
- 09/12/14 21:08:55 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r2989 r2990 1461 1461 plot telescope pointings 1462 1462 Parameters: 1463 infile : input filename orscantable instance1463 scan : input scantable instance 1464 1464 colorby : change color by either 1465 1465 'type'(source type)|'scan'|'if'|'pol'|'beam' … … 1645 1645 # plotting in time is not yet implemented.. 1646 1646 @asaplog_post_dec 1647 def plottp(self, scan=None): 1647 def plottp(self, scan=None, colorby=''): 1648 """ 1649 Plot averaged spectra (total power) in time or in row ID (colorby='') 1650 Parameters: 1651 scan : input scantable instance 1652 colorby : change color by either 1653 'type'(source type)|'scan'|'if'|'pol'|'beam'|'' 1654 """ 1648 1655 self._plotmode = "totalpower" 1649 1656 from asap import scantable … … 1676 1683 left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp) 1677 1684 if self.casabar_exists(): self._plotter.figmgr.casabar.disable_button() 1678 self._plottp(self._data) 1685 if len(colorby) == 0: 1686 self._plottp(self._data) 1687 else: 1688 self._plottp2(self._data,colorby) 1679 1689 if self._minmaxy is not None: 1680 1690 self._plotter.set_limits(ylim=self._minmaxy) … … 1683 1693 self._plotter.show(hardrefresh=False) 1684 1694 return 1695 1696 def _plottp2(self,scan,colorby): 1697 """ 1698 private method for plotting total power data in time 1699 """ 1700 from numpy import ma, array, arange, logical_not 1701 r=0 1702 nr = scan.nrow() 1703 a0,b0 = -1,-1 1704 allxlim = [] 1705 allylim = [] 1706 y=[] 1707 self._plotter.set_panels() 1708 self._plotter.palette(0) 1709 #title 1710 #xlab = self._abcissa and self._abcissa[panelcount] \ 1711 # or scan._getabcissalabel() 1712 #ylab = self._ordinate and self._ordinate[panelcount] \ 1713 # or scan._get_ordinate_label() 1714 tmplab = 'row number' if colorby=='' else 'Time (UTC)' 1715 xlab = self._abcissa or tmplab 1716 ylab = self._ordinate or scan._get_ordinate_label() 1717 self._plotter.set_axes('xlabel',xlab) 1718 self._plotter.set_axes('ylabel',ylab) 1719 lbl = self._get_label(scan, r, 's', self._title) 1720 if isinstance(lbl, list) or isinstance(lbl, tuple): 1721 # if 0 <= panelcount < len(lbl): 1722 # lbl = lbl[panelcount] 1723 # else: 1724 # get default label 1725 lbl = self._get_label(scan, r, self._panelling, None) 1726 self._plotter.set_axes('title',lbl) 1727 # check of overlay settings 1728 validtypes=['type','scan','if','pol', 'beam'] 1729 stype = None 1730 if (colorby in validtypes): 1731 stype = colorby[0] 1732 elif len(colorby) > 0: 1733 msg = "Invalid choice of 'colorby' (choices: %s)" % str(validtypes) 1734 raise ValueError(msg) 1735 if not stype: 1736 selIds = [""] # cheating 1737 sellab = "all points" 1738 elif stype == 't': 1739 selIds = range(15) 1740 sellab = "src type " 1741 else: 1742 selIds = getattr(scan,'get'+colorby+'nos')() 1743 sellab = colorby.upper() 1744 selFunc = "set_"+colorby+"s" 1745 basesel = scan.get_selection() 1746 if stype: basesel.set_order(["TIME"]) 1747 alldates = [] 1748 for idx in selIds: 1749 sel = selector() + basesel 1750 if stype: 1751 bid = getattr(basesel,'get_'+colorby+"s")() 1752 if (len(bid) > 0) and (not idx in bid): 1753 # base selection doesn't contain idx 1754 # Note summation of selector is logical sum if 1755 continue 1756 getattr(sel, selFunc)([idx]) 1757 if not sel.is_empty(): 1758 try: 1759 scan.set_selection(sel) 1760 except RuntimeError, instance: 1761 if stype == 't' and str(instance).startswith("Selection contains no data."): 1762 continue 1763 else: 1764 scan.set_selection(basesel) 1765 raise RuntimeError, instance 1766 if scan.nrow() == 0: 1767 scan.set_selection(basesel) 1768 continue 1769 y=array(scan._get_column(scan._getspectrum,-1)) 1770 m = array(scan._get_column(scan._getmask,-1)) 1771 y = ma.masked_array(y,mask=logical_not(array(m,copy=False))) 1772 # try to handle spectral data somewhat... 1773 l,m = y.shape 1774 if m > 1: 1775 y=y.mean(axis=1) 1776 # flag handling 1777 m = [ scan._is_all_chan_flagged(i) for i in range(scan.nrow()) ] 1778 y = ma.masked_array(y,mask=m) 1779 if len(y) == 0: continue 1780 #llbl = self._get_label(scan, r, self._stacking, None) 1781 #self._plotter.set_line(label=llbl) 1782 self._plotter.set_line(label=(sellab+str(idx))) 1783 if stype: 1784 from matplotlib.dates import date2num 1785 from pytz import timezone 1786 dates = self._data.get_time(asdatetime=True) 1787 alldates += list(dates) 1788 x = date2num(dates) 1789 tz = timezone('UTC') 1790 self._plotter.axes.plot_date(x,y,'-',tz=tz) 1791 else: 1792 x = arange(len(y)) 1793 self._plotter.plot(x,y) 1794 # legend and axis formatting 1795 if stype: 1796 (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(alldates) 1797 ax = self.gca() 1798 ax.xaxis.set_major_formatter(timefmt) 1799 ax.xaxis.set_major_locator(majloc) 1800 ax.xaxis.set_minor_locator(minloc) 1801 self._plotter.legend(self._legendloc) 1802 else: self._plotter.legend(None) 1685 1803 1686 1804 def _plottp(self,scan):
Note:
See TracChangeset
for help on using the changeset viewer.