Changes in trunk/python/asapplotter.py [1824:1949]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r1824 r1949 2 2 from asap.selector import selector 3 3 from asap.scantable import scantable 4 from asap.logging import asaplog, print_log, print_log_dec4 from asap.logging import asaplog, asaplog_post_dec 5 5 import matplotlib.axes 6 6 from matplotlib.font_manager import FontProperties … … 14 14 By default the plotter is set up to plot polarisations 15 15 'colour stacked' and scantables across panels. 16 Note: 16 17 .. note:: 18 17 19 Currenly it only plots 'spectra' not Tsys or 18 20 other variables. 21 19 22 """ 20 23 def __init__(self, visible=None , **kwargs): … … 48 51 self._fp = FontProperties() 49 52 self._panellayout = self.set_panellayout(refresh=False) 53 self._offset = None 54 self._rowcount = 0 55 self._panelcnt = 0 50 56 51 57 def _translate(self, instr): 52 keys = "s b i p t ".split()58 keys = "s b i p t r".split() 53 59 if isinstance(instr, str): 54 60 for key in keys: … … 78 84 else: return None 79 85 80 @ print_log_dec86 @asaplog_post_dec 81 87 def plot(self, scan=None): 82 88 """ … … 90 96 are consistent e.g. all 'channel' or all 'velocity' etc. 91 97 """ 98 self._rowcount = self._panelcnt = 0 92 99 if self._plotter.is_dead: 93 100 if hasattr(self._plotter.figmgr,'casabar'): … … 96 103 self._plotter.figmgr.casabar=self._newcasabar() 97 104 self._plotter.hold() 98 self._plotter.clear()105 #self._plotter.clear() 99 106 if not self._data and not scan: 100 107 msg = "Input is not a scantable" 101 if rcParams['verbose']:102 #print msg103 asaplog.push( msg )104 print_log( 'ERROR' )105 return106 108 raise TypeError(msg) 107 if scan: self.set_data(scan,refresh=False) 109 if scan: 110 self.set_data(scan, refresh=False) 108 111 self._plot(self._data) 109 112 if self._minmaxy is not None: … … 113 116 self._plotter.tidy() 114 117 self._plotter.show(hardrefresh=False) 115 print_log()116 118 return 117 119 … … 125 127 def create_mask(self, nwin=1, panel=0, color=None): 126 128 """ 127 Interactively define a mask. It retruns a mask that is equivalent to129 Interactively define a mask. It retruns a mask that is equivalent to 128 130 the one created manually with scantable.create_mask. 129 131 Parameters: … … 275 277 # end matplotlib.axes fowarding functions 276 278 279 @asaplog_post_dec 277 280 def set_data(self, scan, refresh=True): 278 281 """ … … 295 298 # reset 296 299 self._reset() 297 msg = "A new scantable is set to the plotter. The masks and data selections are reset." 300 msg = "A new scantable is set to the plotter. "\ 301 "The masks and data selections are reset." 298 302 asaplog.push( msg ) 299 print_log( 'INFO' )300 303 else: 301 304 self._data = scan … … 303 306 else: 304 307 msg = "Input is not a scantable" 305 if rcParams['verbose']:306 #print msg307 asaplog.push( msg )308 print_log( 'ERROR' )309 return310 308 raise TypeError(msg) 311 309 … … 318 316 if refresh: self.plot() 319 317 320 318 @asaplog_post_dec 321 319 def set_mode(self, stacking=None, panelling=None, refresh=True): 322 320 """ … … 341 339 if not self.set_panelling(panelling) or \ 342 340 not self.set_stacking(stacking): 343 if rcParams['verbose']: 344 #print msg 345 asaplog.push( msg ) 346 print_log( 'ERROR' ) 347 return 348 else: 349 raise TypeError(msg) 341 raise TypeError(msg) 342 if self._panelling == 'r': 343 self._stacking = '_r' 344 elif self._stacking == 'r': 345 self._panelling = '_r' 350 346 if refresh and self._data: self.plot(self._data) 351 347 return 352 348 353 349 def set_panelling(self, what=None): 350 """Set the 'panelling' mode i.e. which type of spectra should be 351 spread across different panels. 352 """ 353 354 354 mode = what 355 355 if mode is None: … … 359 359 self._panelling = md 360 360 self._title = None 361 if md == 'r': 362 self._stacking = '_r' 361 363 return True 362 364 return False … … 382 384 383 385 def set_stacking(self, what=None): 386 """Set the 'stacking' mode i.e. which type of spectra should be 387 overlayed. 388 """ 384 389 mode = what 385 390 if mode is None: … … 389 394 self._stacking = md 390 395 self._lmap = None 396 if md == 'r': 397 self._panelling = '_r' 391 398 return True 392 399 return False 393 400 394 def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True ):401 def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True, offset=None): 395 402 """ 396 403 Set the range of interest on the abcissa of the plot … … 400 407 replotted based on the new parameter setting(s). 401 408 Otherwise,the parameter(s) are set without replotting. 409 offset: shift the abcissa by the given amount. The abcissa label will 410 have '(relative)' appended to it. 402 411 Note: 403 412 These become non-sensical when the unit changes. … … 405 414 406 415 """ 416 self._offset = offset 407 417 if xstart is None and xend is None: 408 418 self._minmaxx = None … … 650 660 deltachan: the number of channels to include each side of the 651 661 line to determine a local maximum/minimum 652 rotate: the rotation (in degrees) )for the text label (default 90.0)662 rotate: the rotation (in degrees) for the text label (default 90.0) 653 663 location: the location of the line annotation from the 'top', 654 664 'bottom' or alternate (None - the default) … … 720 730 def save(self, filename=None, orientation=None, dpi=None): 721 731 """ 722 Save the plot to a file. The know formats are 'png', 'ps', 'eps'.732 Save the plot to a file. The known formats are 'png', 'ps', 'eps'. 723 733 Parameters: 724 734 filename: The name of the output file. This is optional … … 736 746 return 737 747 738 748 @asaplog_post_dec 739 749 def set_mask(self, mask=None, selection=None, refresh=True): 740 750 """ … … 754 764 if not self._data: 755 765 msg = "Can only set mask after a first call to plot()" 756 if rcParams['verbose']: 757 #print msg 758 asaplog.push( msg ) 759 print_log( 'ERROR' ) 760 return 761 else: 762 raise RuntimeError(msg) 766 raise RuntimeError(msg) 763 767 if len(mask): 764 768 if isinstance(mask, list) or isinstance(mask, tuple): … … 817 821 self._usermask = [] 818 822 self._usermaskspectra = None 823 self._offset = None 819 824 self.set_selection(None, False) 820 825 … … 822 827 savesel = scan.get_selection() 823 828 sel = savesel + self._selection 824 d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO', 825 'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' } 826 order = [d0[self._panelling],d0[self._stacking]] 827 sel.set_order(order) 829 order = self._get_sortstring([self._panelling,self._stacking]) 830 if order: 831 sel.set_order(order) 828 832 scan.set_selection(sel) 829 833 d = {'b': scan.getbeam, 's': scan.getscan, 830 'i': scan.getif, 'p': scan.getpol, 't': scan._gettime } 834 #'i': scan.getif, 'p': scan.getpol, 't': scan._gettime, 835 'i': scan.getif, 'p': scan.getpol, 't': scan.get_time, 836 'r': int, '_r': int} 831 837 832 838 polmodes = dict(zip(self._selection.get_pols(), … … 839 845 if isinstance(nstack0, int): nstack = nstack0 840 846 else: nstack = len(nstack0) 847 nptot = n 841 848 maxpanel, maxstack = 16,16 842 if n > maxpanel or nstack > maxstack: 843 maxn = 0 844 if nstack > maxstack: maxn = maxstack 845 if n > maxpanel: maxn = maxpanel 846 msg ="Scan to be plotted contains more than %d selections.\n" \ 847 "Selecting first %d selections..." % (maxn, maxn) 849 if nstack > maxstack: 850 msg ="Scan to be overlayed contains more than %d selections.\n" \ 851 "Selecting first %d selections..." % (maxstack, maxstack) 848 852 asaplog.push(msg) 849 print_log('WARN') 850 n = min(n,maxpanel) 853 asaplog.post('WARN') 851 854 nstack = min(nstack,maxstack) 855 n = min(n,maxpanel) 856 852 857 if n > 1: 853 858 ganged = rcParams['plotter.ganged'] … … 865 870 # self._plotter.set_panels() 866 871 self._plotter.set_panels(layout=self._panellayout) 867 r=0 872 #r = 0 873 r = self._rowcount 868 874 nr = scan.nrow() 869 875 a0,b0 = -1,-1 … … 882 888 xlab = self._abcissa and self._abcissa[panelcount] \ 883 889 or scan._getabcissalabel() 890 if self._offset and not self._abcissa: 891 xlab += " (relative)" 884 892 ylab = self._ordinate and self._ordinate[panelcount] \ 885 893 or scan._get_ordinate_label() … … 887 895 self._plotter.set_axes('ylabel', ylab) 888 896 lbl = self._get_label(scan, r, self._panelling, self._title) 897 #if self._panelling == 'r': lbl = '' 889 898 if isinstance(lbl, list) or isinstance(lbl, tuple): 890 899 if 0 <= panelcount < len(lbl): … … 895 904 self._plotter.set_axes('title',lbl) 896 905 newpanel = True 897 stackcount = 0906 stackcount = 0 898 907 panelcount += 1 899 if (b > b0 or newpanel) and stackcount < nstack: 908 #if (b > b0 or newpanel) and stackcount < nstack: 909 if stackcount < nstack and (newpanel or (a == a0 and b > b0)): 900 910 y = [] 901 911 if len(polmodes): … … 908 918 if d[self._stacking](r) in self._maskselection[self._stacking]: 909 919 m = logical_and(m, self._usermask) 910 x = scan._getabcissa(r)911 920 from numpy import ma, array 921 x = array(scan._getabcissa(r)) 922 if self._offset: 923 x += self._offset 912 924 y = ma.masked_array(y,mask=logical_not(array(m,copy=False))) 913 925 if self._minmaxx is not None: … … 960 972 break 961 973 r+=1 # next row 974 ###-S 975 self._rowcount = r+1 976 self._panelcnt += panelcount 977 if self._plotter.figmgr.casabar: 978 if self._panelcnt >= nptot-1: 979 self._plotter.figmgr.casabar.disable_next() 980 else: 981 self._plotter.figmgr.casabar.enable_next() 982 #if self._panelcnt - panelcount > 0: 983 # self._plotter.figmgr.casabar.enable_prev() 984 #else: 985 # self._plotter.figmgr.casabar.disable_prev() 986 ###-E 962 987 #reset the selector to the scantable's original 963 988 scan.set_selection(savesel) … … 968 993 for o in self._plotter.figure.findobj(Text): 969 994 o.set_fontproperties(self._fp) 995 996 def _get_sortstring(self, lorders): 997 d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO', 998 'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME', 'r':None, '_r':None } 999 if not (type(lorders) == list) and not (type(lorders) == tuple): 1000 return None 1001 if len(lorders) > 0: 1002 lsorts = [] 1003 for order in lorders: 1004 ssort = d0[order] 1005 if ssort: 1006 lsorts.append(ssort) 1007 return lsorts 1008 return None 970 1009 971 1010 def set_selection(self, selection=None, refresh=True, **kw): … … 992 1031 raise TypeError("'selection' is not of type selector") 993 1032 994 d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO', 995 'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' } 996 order = [d0[self._panelling],d0[self._stacking]] 997 self._selection.set_order(order) 1033 order = self._get_sortstring([self._panelling,self._stacking]) 1034 if order: 1035 self._selection.set_order(order) 998 1036 if refresh and self._data: self.plot(self._data) 999 1037 1000 1038 def _get_selected_n(self, scan): 1001 1039 d1 = {'b': scan.getbeamnos, 's': scan.getscannos, 1002 'i': scan.getifnos, 'p': scan.getpolnos, 't': scan.ncycle } 1040 'i': scan.getifnos, 'p': scan.getpolnos, 't': scan.ncycle, 1041 'r': scan.nrow, '_r': False} 1003 1042 d2 = { 'b': self._selection.get_beams(), 1004 1043 's': self._selection.get_scans(), 1005 1044 'i': self._selection.get_ifs(), 1006 1045 'p': self._selection.get_pols(), 1007 't': self._selection.get_cycles() } 1046 't': self._selection.get_cycles(), 1047 'r': False, '_r': 1} 1008 1048 n = d2[self._panelling] or d1[self._panelling]() 1009 1049 nstack = d2[self._stacking] or d1[self._stacking]() … … 1024 1064 'i': "IF"+str(scan.getif(row)), 1025 1065 'p': poleval, 1026 't': str(scan.get_time(row)) } 1066 't': str(scan.get_time(row)), 1067 'r': "row "+str(row), 1068 #'_r': str(scan.get_time(row))+",\nIF"+str(scan.getif(row))+", "+poleval+", Beam"+str(scan.getbeam(row)) } 1069 '_r': "" } 1027 1070 return userlabel or d[mode] 1028 1071 1029 1072 def plotazel(self, scan=None, outfile=None): 1030 #def plotazel(self):1031 1073 """ 1032 1074 plot azimuth and elevation versus time of a scantable 1033 1075 """ 1076 visible = rcParams['plotter.gui'] 1034 1077 from matplotlib import pylab as PL 1035 1078 from matplotlib.dates import DateFormatter, timezone … … 1037 1080 from matplotlib.ticker import MultipleLocator 1038 1081 from numpy import array, pi 1082 if not visible or not self._visible: 1083 PL.ioff() 1084 from matplotlib.backends.backend_agg import FigureCanvasAgg 1085 PL.gcf().canvas.switch_backends(FigureCanvasAgg) 1039 1086 self._data = scan 1040 1087 self._outfile = outfile … … 1046 1093 PL.clf() 1047 1094 # Adjust subplot layouts 1048 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1095 if len(self._panellayout) != 6: 1096 self.set_panellayout(refresh=False) 1049 1097 lef, bot, rig, top, wsp, hsp = self._panellayout 1050 1098 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, … … 1126 1174 1127 1175 def plotpointing(self, scan=None, outfile=None): 1128 #def plotpointing(self):1129 1176 """ 1130 1177 plot telescope pointings 1131 1178 """ 1179 visible = rcParams['plotter.gui'] 1132 1180 from matplotlib import pylab as PL 1133 1181 from numpy import array, pi 1182 if not visible or not self._visible: 1183 PL.ioff() 1184 from matplotlib.backends.backend_agg import FigureCanvasAgg 1185 PL.gcf().canvas.switch_backends(FigureCanvasAgg) 1134 1186 self._data = scan 1135 1187 self._outfile = outfile … … 1141 1193 PL.clf() 1142 1194 # Adjust subplot layouts 1143 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1195 if len(self._panellayout) != 6: 1196 self.set_panellayout(refresh=False) 1144 1197 lef, bot, rig, top, wsp, hsp = self._panellayout 1145 1198 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, … … 1162 1215 # plot total power data 1163 1216 # plotting in time is not yet implemented.. 1217 @asaplog_post_dec 1164 1218 def plottp(self, scan=None, outfile=None): 1165 1219 if self._plotter.is_dead: … … 1173 1227 if not self._data and not scan: 1174 1228 msg = "Input is not a scantable" 1175 if rcParams['verbose']:1176 #print msg1177 asaplog.push( msg )1178 print_log( 'ERROR' )1179 return1180 1229 raise TypeError(msg) 1181 1230 if isinstance(scan, scantable): … … 1207 1256 self._plotter.tidy() 1208 1257 self._plotter.show(hardrefresh=False) 1209 print_log()1210 1258 return 1211 1259 … … 1268 1316 1269 1317 # printing header information 1318 @asaplog_post_dec 1270 1319 def print_header(self, plot=True, fontsize=9, logger=False, selstr='', extrastr=''): 1271 1320 """ … … 1274 1323 plot: whether or not print header info on the plot. 1275 1324 fontsize: header font size (valid only plot=True) 1276 autoscale: whether or not autoscale the plot (valid only plot=True)1277 1325 logger: whether or not print header info on the logger. 1278 1326 selstr: additional selection string (not verified) 1279 1327 extrastr: additional string to print (not verified) 1280 1328 """ 1281 if not plot and not logger: return 1282 if not self._data: raise RuntimeError("No scantable has been set yet.") 1329 if not plot and not logger: 1330 return 1331 if not self._data: 1332 raise RuntimeError("No scantable has been set yet.") 1283 1333 # Now header will be printed on plot and/or logger. 1284 1334 # Get header information and format it. … … 1313 1363 asaplog.push(extrastr) 1314 1364 asaplog.push(ssum[ssum.find('Beams:'):]) 1315 print_log()1316 1365 del ssum
Note:
See TracChangeset
for help on using the changeset viewer.