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