Changeset 1779 for branches/mergetest/python/asapplotter.py
- Timestamp:
- 07/29/10 19:13:46 (14 years ago)
- Location:
- branches/mergetest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mergetest
- Property svn:mergeinfo changed
-
branches/mergetest/python/asapplotter.py
r1739 r1779 1 1 from asap import rcParams, print_log, print_log_dec 2 2 from asap import selector, scantable 3 from asap import asaplog 3 4 import matplotlib.axes 4 5 from matplotlib.font_manager import FontProperties … … 21 22 self._visible = visible 22 23 self._plotter = self._newplotter(**kwargs) 24 # additional tool bar 25 self._plotter.figmgr.casabar=self._newcasabar() 23 26 24 27 self._panelling = None … … 43 46 self._hist = rcParams['plotter.histogram'] 44 47 self._fp = FontProperties() 48 self._panellayout = self.set_panellayout(refresh=False) 45 49 46 50 def _translate(self, instr): … … 53 57 54 58 def _newplotter(self, **kwargs): 55 if self._visible: 59 backend=matplotlib.get_backend() 60 if not self._visible: 61 from asap.asaplot import asaplot 62 elif backend == 'TkAgg': 56 63 from asap.asaplotgui import asaplotgui as asaplot 64 elif backend == 'Qt4Agg': 65 from asap.asaplotgui_qt4 import asaplotgui as asaplot 66 elif backend == 'GTkAgg': 67 from asap.asaplotgui_gtk import asaplotgui as asaplot 57 68 else: 58 69 from asap.asaplot import asaplot 59 70 return asaplot(**kwargs) 60 71 61 @print_log_dec 72 def _newcasabar(self): 73 backend=matplotlib.get_backend() 74 if self._visible and backend == "TkAgg": 75 from asap.casatoolbar import CustomToolbarTkAgg 76 return CustomToolbarTkAgg(self) 77 else: return None 78 79 #@print_log_dec 62 80 def plot(self, scan=None): 63 81 """ … … 72 90 """ 73 91 if self._plotter.is_dead: 92 if hasattr(self._plotter.figmgr,'casabar'): 93 del self._plotter.figmgr.casabar 74 94 self._plotter = self._newplotter() 95 self._plotter.figmgr.casabar=self._newcasabar() 75 96 self._plotter.hold() 76 97 self._plotter.clear() 77 from asap import scantable78 98 if not self._data and not scan: 79 99 msg = "Input is not a scantable" 80 100 if rcParams['verbose']: 81 print msg 101 #print msg 102 asaplog.push( msg ) 103 print_log( 'ERROR' ) 82 104 return 83 105 raise TypeError(msg) 84 if isinstance(scan, scantable): 85 if self._data is not None: 86 if scan != self._data: 87 self._data = scan 88 # reset 89 self._reset() 90 else: 91 self._data = scan 92 self._reset() 93 # ranges become invalid when unit changes 94 if self._abcunit and self._abcunit != self._data.get_unit(): 95 self._minmaxx = None 96 self._minmaxy = None 97 self._abcunit = self._data.get_unit() 98 self._datamask = None 106 if scan: self.set_data(scan,refresh=False) 99 107 self._plot(self._data) 100 108 if self._minmaxy is not None: 101 109 self._plotter.set_limits(ylim=self._minmaxy) 110 if self._plotter.figmgr.casabar: self._plotter.figmgr.casabar.enable_button() 102 111 self._plotter.release() 103 112 self._plotter.tidy() 104 113 self._plotter.show(hardrefresh=False) 114 print_log() 105 115 return 106 116 … … 170 180 def text(self, *args, **kwargs): 171 181 if kwargs.has_key("interactive"): 172 if kwargs.pop("interactive"): 173 pos = self._plotter.get_point() 174 args = tuple(pos)+args 182 #if kwargs.pop("interactive"): 183 # pos = self._plotter.get_point() 184 # args = tuple(pos)+args 185 kwargs.pop("interactive") 175 186 self._axes_callback("text", *args, **kwargs) 176 187 … … 179 190 def arrow(self, *args, **kwargs): 180 191 if kwargs.has_key("interactive"): 181 if kwargs.pop("interactive"): 182 pos = self._plotter.get_region() 183 dpos = (pos[0][0], pos[0][1], 184 pos[1][0]-pos[0][0], 185 pos[1][1] - pos[0][1]) 186 args = dpos + args 192 #if kwargs.pop("interactive"): 193 # pos = self._plotter.get_region() 194 # dpos = (pos[0][0], pos[0][1], 195 # pos[1][0]-pos[0][0], 196 # pos[1][1] - pos[0][1]) 197 # args = dpos + args 198 kwargs.pop("interactive") 187 199 self._axes_callback("arrow", *args, **kwargs) 188 200 … … 191 203 def annotate(self, text, xy=None, xytext=None, **kwargs): 192 204 if kwargs.has_key("interactive"): 193 if kwargs.pop("interactive"): 194 xy = self._plotter.get_point() 195 xytext = self._plotter.get_point() 205 #if kwargs.pop("interactive"): 206 # xy = self._plotter.get_point() 207 # xytext = self._plotter.get_point() 208 kwargs.pop("interactive") 196 209 if not kwargs.has_key("arrowprops"): 197 210 kwargs["arrowprops"] = dict(arrowstyle="->") … … 202 215 def axvline(self, *args, **kwargs): 203 216 if kwargs.has_key("interactive"): 204 if kwargs.pop("interactive"): 205 pos = self._plotter.get_point() 206 args = (pos[0],)+args 217 #if kwargs.pop("interactive"): 218 # pos = self._plotter.get_point() 219 # args = (pos[0],)+args 220 kwargs.pop("interactive") 207 221 self._axes_callback("axvline", *args, **kwargs) 208 222 … … 211 225 def axhline(self, *args, **kwargs): 212 226 if kwargs.has_key("interactive"): 213 if kwargs.pop("interactive"): 214 pos = self._plotter.get_point() 215 args = (pos[1],)+args 227 #if kwargs.pop("interactive"): 228 # pos = self._plotter.get_point() 229 # args = (pos[1],)+args 230 kwargs.pop("interactive") 216 231 self._axes_callback("axhline", *args, **kwargs) 217 232 … … 220 235 def axvspan(self, *args, **kwargs): 221 236 if kwargs.has_key("interactive"): 222 if kwargs.pop("interactive"): 223 pos = self._plotter.get_region() 224 dpos = (pos[0][0], pos[1][0]) 225 args = dpos + args 237 #if kwargs.pop("interactive"): 238 # pos = self._plotter.get_region() 239 # dpos = (pos[0][0], pos[1][0]) 240 # args = dpos + args 241 kwargs.pop("interactive") 226 242 self._axes_callback("axvspan", *args, **kwargs) 227 243 # hack to preventy mpl from redrawing the patch … … 234 250 def axhspan(self, *args, **kwargs): 235 251 if kwargs.has_key("interactive"): 236 if kwargs.pop("interactive"):237 pos = self._plotter.get_region()238 dpos = (pos[0][1], pos[1][1])239 args = dpos + args240 252 #if kwargs.pop("interactive"): 253 # pos = self._plotter.get_region() 254 # dpos = (pos[0][1], pos[1][1]) 255 # args = dpos + args 256 kwargs.pop("interactive") 241 257 self._axes_callback("axhspan", *args, **kwargs) 242 258 # hack to preventy mpl from redrawing the patch … … 265 281 # end matplotlib.axes fowarding functions 266 282 267 268 def set_mode(self, stacking=None, panelling=None): 283 def set_data(self, scan, refresh=True): 284 """ 285 Set a scantable to plot. 286 Parameters: 287 scan: a scantable 288 refresh: True (default) or False. If True, the plot is 289 replotted based on the new parameter setting(s). 290 Otherwise,the parameter(s) are set without replotting. 291 Note: 292 The user specified masks and data selections will be reset 293 if a new scantable is set. This method should be called before 294 setting data selections (set_selection) and/or masks (set_mask). 295 """ 296 from asap import scantable 297 if isinstance(scan, scantable): 298 if self._data is not None: 299 if scan != self._data: 300 self._data = scan 301 # reset 302 self._reset() 303 msg = "A new scantable is set to the plotter. The masks and data selections are reset." 304 asaplog.push( msg ) 305 print_log( 'INFO' ) 306 else: 307 self._data = scan 308 self._reset() 309 else: 310 msg = "Input is not a scantable" 311 if rcParams['verbose']: 312 #print msg 313 asaplog.push( msg ) 314 print_log( 'ERROR' ) 315 return 316 raise TypeError(msg) 317 318 # ranges become invalid when unit changes 319 if self._abcunit and self._abcunit != self._data.get_unit(): 320 self._minmaxx = None 321 self._minmaxy = None 322 self._abcunit = self._data.get_unit() 323 self._datamask = None 324 if refresh: self.plot() 325 326 327 def set_mode(self, stacking=None, panelling=None, refresh=True): 269 328 """ 270 329 Set the plots look and feel, i.e. what you want to see on the plot. … … 274 333 panelling: tell the plotter which variable to plot 275 334 across multiple panels (default 'scan' 335 refresh: True (default) or False. If True, the plot is 336 replotted based on the new parameter setting(s). 337 Otherwise,the parameter(s) are set without replotting. 276 338 Note: 277 339 Valid modes are: … … 286 348 not self.set_stacking(stacking): 287 349 if rcParams['verbose']: 288 print msg 350 #print msg 351 asaplog.push( msg ) 352 print_log( 'ERROR' ) 289 353 return 290 354 else: 291 355 raise TypeError(msg) 292 if self._data: self.plot(self._data)356 if refresh and self._data: self.plot(self._data) 293 357 return 294 358 … … 304 368 return False 305 369 306 def set_layout(self,rows=None,cols=None ):370 def set_layout(self,rows=None,cols=None,refresh=True): 307 371 """ 308 372 Set the multi-panel layout, i.e. how many rows and columns plots … … 311 375 rows: The number of rows of plots 312 376 cols: The number of columns of plots 377 refresh: True (default) or False. If True, the plot is 378 replotted based on the new parameter setting(s). 379 Otherwise,the parameter(s) are set without replotting. 313 380 Note: 314 381 If no argument is given, the potter reverts to its auto-plot … … 317 384 self._rows = rows 318 385 self._cols = cols 319 if self._data: self.plot(self._data)386 if refresh and self._data: self.plot(self._data) 320 387 return 321 388 … … 331 398 return False 332 399 333 def set_range(self,xstart=None,xend=None,ystart=None,yend=None ):400 def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True): 334 401 """ 335 402 Set the range of interest on the abcissa of the plot 336 403 Parameters: 337 404 [x,y]start,[x,y]end: The start and end points of the 'zoom' window 405 refresh: True (default) or False. If True, the plot is 406 replotted based on the new parameter setting(s). 407 Otherwise,the parameter(s) are set without replotting. 338 408 Note: 339 409 These become non-sensical when the unit changes. … … 349 419 else: 350 420 self._minmaxy = [ystart,yend] 351 if self._data: self.plot(self._data)421 if refresh and self._data: self.plot(self._data) 352 422 return 353 423 354 def set_legend(self, mp=None, fontsize = None, mode = 0 ):424 def set_legend(self, mp=None, fontsize = None, mode = 0, refresh=True): 355 425 """ 356 426 Specify a mapping for the legend instead of using the default … … 376 446 9: upper center 377 447 10: center 448 refresh: True (default) or False. If True, the plot is 449 replotted based on the new parameter setting(s). 450 Otherwise,the parameter(s) are set without replotting. 378 451 379 452 Example: … … 390 463 from matplotlib import rc as rcp 391 464 rcp('legend', fontsize=fontsize) 392 if self._data: 393 self.plot(self._data) 465 if refresh and self._data: self.plot(self._data) 394 466 return 395 467 396 def set_title(self, title=None, fontsize=None ):468 def set_title(self, title=None, fontsize=None, refresh=True): 397 469 """ 398 470 Set the title of the plot. If multiple panels are plotted, 399 471 multiple titles have to be specified. 472 Parameters: 473 refresh: True (default) or False. If True, the plot is 474 replotted based on the new parameter setting(s). 475 Otherwise,the parameter(s) are set without replotting. 400 476 Example: 401 477 # two panels are visible on the plotter … … 406 482 from matplotlib import rc as rcp 407 483 rcp('axes', titlesize=fontsize) 408 if self._data: self.plot(self._data)484 if refresh and self._data: self.plot(self._data) 409 485 return 410 486 411 def set_ordinate(self, ordinate=None, fontsize=None ):487 def set_ordinate(self, ordinate=None, fontsize=None, refresh=True): 412 488 """ 413 489 Set the y-axis label of the plot. If multiple panels are plotted, … … 416 492 ordinate: a list of ordinate labels. None (default) let 417 493 data determine the labels 494 refresh: True (default) or False. If True, the plot is 495 replotted based on the new parameter setting(s). 496 Otherwise,the parameter(s) are set without replotting. 418 497 Example: 419 498 # two panels are visible on the plotter … … 425 504 rcp('axes', labelsize=fontsize) 426 505 rcp('ytick', labelsize=fontsize) 427 if self._data: self.plot(self._data)506 if refresh and self._data: self.plot(self._data) 428 507 return 429 508 430 def set_abcissa(self, abcissa=None, fontsize=None ):509 def set_abcissa(self, abcissa=None, fontsize=None, refresh=True): 431 510 """ 432 511 Set the x-axis label of the plot. If multiple panels are plotted, … … 435 514 abcissa: a list of abcissa labels. None (default) let 436 515 data determine the labels 516 refresh: True (default) or False. If True, the plot is 517 replotted based on the new parameter setting(s). 518 Otherwise,the parameter(s) are set without replotting. 437 519 Example: 438 520 # two panels are visible on the plotter … … 444 526 rcp('axes', labelsize=fontsize) 445 527 rcp('xtick', labelsize=fontsize) 446 if self._data: self.plot(self._data)528 if refresh and self._data: self.plot(self._data) 447 529 return 448 530 449 def set_colors(self, colmap ):531 def set_colors(self, colmap, refresh=True): 450 532 """ 451 533 Set the colours to be used. The plotter will cycle through … … 453 535 Parameters: 454 536 colmap: a list of colour names 537 refresh: True (default) or False. If True, the plot is 538 replotted based on the new parameter setting(s). 539 Otherwise,the parameter(s) are set without replotting. 455 540 Example: 456 541 plotter.set_colors("red green blue") … … 462 547 colmap = colmap.split() 463 548 self._plotter.palette(0, colormap=colmap) 464 if self._data: self.plot(self._data)549 if refresh and self._data: self.plot(self._data) 465 550 466 551 # alias for english speakers 467 552 set_colours = set_colors 468 553 469 def set_histogram(self, hist=True, linewidth=None ):554 def set_histogram(self, hist=True, linewidth=None, refresh=True): 470 555 """ 471 556 Enable/Disable histogram-like plotting. … … 474 559 is taken from the .asaprc setting 475 560 plotter.histogram 561 refresh: True (default) or False. If True, the plot is 562 replotted based on the new parameter setting(s). 563 Otherwise,the parameter(s) are set without replotting. 476 564 """ 477 565 self._hist = hist … … 479 567 from matplotlib import rc as rcp 480 568 rcp('lines', linewidth=linewidth) 481 if self._data: self.plot(self._data)482 483 def set_linestyles(self, linestyles=None, linewidth=None ):569 if refresh and self._data: self.plot(self._data) 570 571 def set_linestyles(self, linestyles=None, linewidth=None, refresh=True): 484 572 """ 485 573 Set the linestyles to be used. The plotter will cycle through … … 491 579 'dashdotdot' and 'dashdashdot' are 492 580 possible 493 581 refresh: True (default) or False. If True, the plot is 582 replotted based on the new parameter setting(s). 583 Otherwise,the parameter(s) are set without replotting. 494 584 Example: 495 585 plotter.set_colors("black") … … 505 595 from matplotlib import rc as rcp 506 596 rcp('lines', linewidth=linewidth) 507 if self._data: self.plot(self._data)508 509 def set_font(self, **kwargs):597 if refresh and self._data: self.plot(self._data) 598 599 def set_font(self, refresh=True,**kwargs): 510 600 """ 511 601 Set font properties. … … 516 606 size: the 'general' font size, individual elements can be adjusted 517 607 seperately 608 refresh: True (default) or False. If True, the plot is 609 replotted based on the new parameter setting(s). 610 Otherwise,the parameter(s) are set without replotting. 518 611 """ 519 612 from matplotlib import rc as rcp … … 523 616 fdict[k] = v 524 617 self._fp = FontProperties(**fdict) 525 if self._data: 526 self.plot() 618 if refresh and self._data: self.plot(self._data) 619 620 def set_panellayout(self,layout=[],refresh=True): 621 """ 622 Set the layout of subplots. 623 Parameters: 624 layout: a list of subplots layout in figure coordinate (0-1), 625 i.e., fraction of the figure width or height. 626 The order of elements should be: 627 [left, bottom, right, top, horizontal space btw panels, 628 vertical space btw panels]. 629 refresh: True (default) or False. If True, the plot is 630 replotted based on the new parameter setting(s). 631 Otherwise,the parameter(s) are set without replotting. 632 Note 633 * When layout is not specified, the values are reset to the defaults 634 of matplotlib. 635 * If any element is set to be None, the current value is adopted. 636 """ 637 if layout == []: self._panellayout=self._reset_panellayout() 638 else: 639 self._panellayout=[None]*6 640 self._panellayout[0:len(layout)]=layout 641 #print "panel layout set to ",self._panellayout 642 if refresh and self._data: self.plot(self._data) 643 644 def _reset_panellayout(self): 645 ks=map(lambda x: 'figure.subplot.'+x, 646 ['left','bottom','right','top','hspace','wspace']) 647 return map(matplotlib.rcParams.get,ks) 527 648 528 649 def plot_lines(self, linecat=None, doppler=0.0, deltachan=10, rotate=90.0, … … 622 743 623 744 624 def set_mask(self, mask=None, selection=None ):745 def set_mask(self, mask=None, selection=None, refresh=True): 625 746 """ 626 747 Set a plotting mask for a specific polarization. … … 629 750 mask: a mask from scantable.create_mask 630 751 selection: the spectra to apply the mask to. 752 refresh: True (default) or False. If True, the plot is 753 replotted based on the new parameter setting(s). 754 Otherwise,the parameter(s) are set without replotting. 631 755 Example: 632 756 select = selector() … … 637 761 msg = "Can only set mask after a first call to plot()" 638 762 if rcParams['verbose']: 639 print msg 763 #print msg 764 asaplog.push( msg ) 765 print_log( 'ERROR' ) 640 766 return 641 767 else: … … 657 783 else: 658 784 self._maskselection = None 659 self.plot(self._data)785 if refresh: self.plot(self._data) 660 786 661 787 def _slice_indeces(self, data): … … 671 797 inc = -1 672 798 # find min index 673 while start > 0 and data[start] < mn: 674 start+= inc 799 #while start > 0 and data[start] < mn: 800 # start+= inc 801 minind=start 802 for ind in xrange(start,end+inc,inc): 803 if data[ind] > mn: break 804 minind=ind 675 805 # find max index 676 while end > 0 and data[end] > mx: 677 end-=inc 678 if end > 0: end +=1 806 #while end > 0 and data[end] > mx: 807 # end-=inc 808 #if end > 0: end +=1 809 maxind=end 810 for ind in xrange(end,start-inc,-inc): 811 if data[ind] < mx: break 812 maxind=ind 813 start=minind 814 end=maxind 679 815 if start > end: 680 return end,start 681 return start,end 816 return end,start+1 817 elif start < end: 818 return start,end+1 819 else: 820 return start,end 682 821 683 822 def _reset(self): … … 708 847 maxpanel, maxstack = 16,16 709 848 if n > maxpanel or nstack > maxstack: 710 from asap import asaplog711 849 maxn = 0 712 850 if nstack > maxstack: maxn = maxstack … … 715 853 "Selecting first %d selections..." % (maxn, maxn) 716 854 asaplog.push(msg) 717 print_log( )855 print_log('WARN') 718 856 n = min(n,maxpanel) 719 857 nstack = min(nstack,maxstack) 720 858 if n > 1: 721 859 ganged = rcParams['plotter.ganged'] 860 if self._panelling == 'i': 861 ganged = False 722 862 if self._rows and self._cols: 723 863 n = min(n,self._rows*self._cols) 724 864 self._plotter.set_panels(rows=self._rows,cols=self._cols, 725 nplots=n,ganged=ganged) 865 # nplots=n,ganged=ganged) 866 nplots=n,layout=self._panellayout,ganged=ganged) 726 867 else: 727 self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 868 # self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 869 self._plotter.set_panels(rows=n,cols=0,nplots=n,layout=self._panellayout,ganged=ganged) 728 870 else: 729 self._plotter.set_panels() 871 # self._plotter.set_panels() 872 self._plotter.set_panels(layout=self._panellayout) 730 873 r=0 731 874 nr = scan.nrow() … … 799 942 ylim= self._minmaxy or [ma.minimum(y),ma.maximum(y)] 800 943 allylim += ylim 944 else: 945 xlim = self._minmaxx or [] 946 allxlim += xlim 947 ylim= self._minmaxy or [] 948 allylim += ylim 801 949 stackcount += 1 802 950 # last in colour stack -> autoscale x 803 if stackcount == nstack :951 if stackcount == nstack and len(allxlim) > 0: 804 952 allxlim.sort() 805 self._plotter. axes.set_xlim([allxlim[0],allxlim[-1]])953 self._plotter.subplots[panelcount-1]['axes'].set_xlim([allxlim[0],allxlim[-1]]) 806 954 # clear 807 955 allxlim =[] … … 813 961 if (panelcount == n) and (stackcount == nstack): 814 962 # last panel -> autoscale y if ganged 815 if rcParams['plotter.ganged'] :963 if rcParams['plotter.ganged'] and len(allylim) > 0: 816 964 allylim.sort() 817 965 self._plotter.set_limits(ylim=[allylim[0],allylim[-1]]) … … 820 968 #reset the selector to the scantable's original 821 969 scan.set_selection(savesel) 822 if self._fp is not None: 970 971 #temporary switch-off for older matplotlib 972 #if self._fp is not None: 973 if self._fp is not None and getattr(self._plotter.figure,'findobj',False): 823 974 for o in self._plotter.figure.findobj(Text): 824 975 o.set_fontproperties(self._fp) 825 976 826 827 977 def set_selection(self, selection=None, refresh=True, **kw): 978 """ 979 Parameters: 980 selection: a selector object (default unset the selection) 981 refresh: True (default) or False. If True, the plot is 982 replotted based on the new parameter setting(s). 983 Otherwise,the parameter(s) are set without replotting. 984 """ 828 985 if selection is None: 829 986 # reset … … 845 1002 order = [d0[self._panelling],d0[self._stacking]] 846 1003 self._selection.set_order(order) 847 if self._data and refresh: self.plot(self._data)1004 if refresh and self._data: self.plot(self._data) 848 1005 849 1006 def _get_selected_n(self, scan): … … 868 1025 poleval = scan._getpollabel(scan.getpol(row),scan.poltype()) 869 1026 d = {'b': "Beam "+str(scan.getbeam(row)), 870 's': scan._getsourcename(row), 1027 #'s': scan._getsourcename(row), 1028 's': "Scan "+str(scan.getscan(row))+\ 1029 " ("+str(scan._getsourcename(row))+")", 871 1030 'i': "IF"+str(scan.getif(row)), 872 1031 'p': poleval, … … 874 1033 return userlabel or d[mode] 875 1034 876 def plotazel(self): 1035 def plotazel(self, scan=None, outfile=None): 1036 #def plotazel(self): 877 1037 """ 878 1038 plot azimuth and elevation versus time of a scantable … … 883 1043 from matplotlib.ticker import MultipleLocator 884 1044 from numpy import array, pi 1045 self._data = scan 1046 self._outfile = outfile 885 1047 dates = self._data.get_time(asdatetime=True) 886 1048 t = PL.date2num(dates) … … 889 1051 PL.ioff() 890 1052 PL.clf() 1053 # Adjust subplot layouts 1054 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1055 lef, bot, rig, top, wsp, hsp = self._panellayout 1056 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, 1057 wspace=wsp,hspace=hsp) 1058 891 1059 tdel = max(t) - min(t) 892 1060 ax = PL.subplot(2,1,1) … … 910 1078 911 1079 PL.title(dstr) 912 PL.plot_date(t,el,'b,', tz=tz) 1080 if tdel == 0.0: 1081 th = (t - PL.floor(t))*24.0 1082 PL.plot(th,el,'o',markersize=2, markerfacecolor='b', markeredgecolor='b') 1083 else: 1084 PL.plot_date(t,el,'o', markersize=2, markerfacecolor='b', markeredgecolor='b',tz=tz) 1085 #ax.grid(True) 1086 ax.xaxis.set_major_formatter(timefmt) 1087 ax.xaxis.set_major_locator(majloc) 1088 ax.xaxis.set_minor_locator(minloc) 913 1089 ax.yaxis.grid(True) 914 1090 yloc = MultipleLocator(30) 1091 ax.set_ylim(0,90) 1092 ax.yaxis.set_major_locator(yloc) 915 1093 if tdel > 1.0: 916 1094 labels = ax.get_xticklabels() 917 1095 # PL.setp(labels, fontsize=10, rotation=45) 918 1096 PL.setp(labels, fontsize=10) 1097 919 1098 # Az plot 920 1099 az = array(self._data.get_azimuth())*180./pi … … 923 1102 if az[irow] < 0: az[irow] += 360.0 924 1103 925 ax2 = ax.figure.add_subplot(2,1,2, sharex=ax) 926 ax2.set_xlabel('Time (UT)') 927 ax2.set_ylabel('Az [deg.]') 928 ax2.plot_date(t,az,'b,', tz=tz) 1104 ax2 = PL.subplot(2,1,2) 1105 #PL.xlabel('Time (UT [hour])') 1106 PL.ylabel('Az [deg.]') 1107 if tdel == 0.0: 1108 PL.plot(th,az,'o',markersize=2, markeredgecolor='b',markerfacecolor='b') 1109 else: 1110 PL.plot_date(t,az,'o', markersize=2,markeredgecolor='b',markerfacecolor='b',tz=tz) 1111 ax2.xaxis.set_major_formatter(timefmt) 1112 ax2.xaxis.set_major_locator(majloc) 1113 ax2.xaxis.set_minor_locator(minloc) 1114 #ax2.grid(True) 1115 ax2.set_ylim(0,360) 929 1116 ax2.yaxis.grid(True) 930 # set this last as x axis is shared 931 ax.xaxis.set_major_formatter(timefmt) 932 ax.xaxis.set_major_locator(majloc) 933 ax.xaxis.set_minor_locator(minloc) 1117 #hfmt = DateFormatter('%H') 1118 #hloc = HourLocator() 1119 yloc = MultipleLocator(60) 1120 ax2.yaxis.set_major_locator(yloc) 1121 if tdel > 1.0: 1122 labels = ax2.get_xticklabels() 1123 PL.setp(labels, fontsize=10) 1124 PL.xlabel('Time (UT [day])') 1125 else: 1126 PL.xlabel('Time (UT [hour])') 1127 934 1128 PL.ion() 935 1129 PL.draw() 936 937 def plotpointing(self): 1130 if (self._outfile is not None): 1131 PL.savefig(self._outfile) 1132 1133 def plotpointing(self, scan=None, outfile=None): 1134 #def plotpointing(self): 938 1135 """ 939 1136 plot telescope pointings 940 1137 """ 941 1138 from matplotlib import pylab as PL 942 from numpy import array 1139 from numpy import array, pi 1140 self._data = scan 1141 self._outfile = outfile 943 1142 dir = array(self._data.get_directionval()).transpose() 944 1143 ra = dir[0]*180./pi 945 1144 dec = dir[1]*180./pi 946 1145 PL.cla() 947 PL.ioff()1146 #PL.ioff() 948 1147 PL.clf() 949 ax = PL.axes([0.1,0.1,0.8,0.8]) 950 ax = PL.axes([0.1,0.1,0.8,0.8]) 1148 # Adjust subplot layouts 1149 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1150 lef, bot, rig, top, wsp, hsp = self._panellayout 1151 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, 1152 wspace=wsp,hspace=hsp) 1153 ax = PL.gca() 1154 #ax = PL.axes([0.1,0.1,0.8,0.8]) 1155 #ax = PL.axes([0.1,0.1,0.8,0.8]) 951 1156 ax.set_aspect('equal') 952 1157 PL.plot(ra, dec, 'b,') … … 956 1161 [xmin,xmax,ymin,ymax] = PL.axis() 957 1162 PL.axis([xmax,xmin,ymin,ymax]) 958 PL.ion()1163 #PL.ion() 959 1164 PL.draw() 1165 if (self._outfile is not None): 1166 PL.savefig(self._outfile) 1167 1168 # plot total power data 1169 # plotting in time is not yet implemented.. 1170 def plottp(self, scan=None, outfile=None): 1171 if self._plotter.is_dead: 1172 if hasattr(self._plotter.figmgr,'casabar'): 1173 del self._plotter.figmgr.casabar 1174 self._plotter = self._newplotter() 1175 self._plotter.figmgr.casabar=self._newcasabar() 1176 self._plotter.hold() 1177 self._plotter.clear() 1178 from asap import scantable 1179 if not self._data and not scan: 1180 msg = "Input is not a scantable" 1181 if rcParams['verbose']: 1182 #print msg 1183 asaplog.push( msg ) 1184 print_log( 'ERROR' ) 1185 return 1186 raise TypeError(msg) 1187 if isinstance(scan, scantable): 1188 if self._data is not None: 1189 if scan != self._data: 1190 self._data = scan 1191 # reset 1192 self._reset() 1193 else: 1194 self._data = scan 1195 self._reset() 1196 # ranges become invalid when abcissa changes? 1197 #if self._abcunit and self._abcunit != self._data.get_unit(): 1198 # self._minmaxx = None 1199 # self._minmaxy = None 1200 # self._abcunit = self._data.get_unit() 1201 # self._datamask = None 1202 1203 # Adjust subplot layouts 1204 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1205 lef, bot, rig, top, wsp, hsp = self._panellayout 1206 self._plotter.figure.subplots_adjust( 1207 left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp) 1208 if self._plotter.figmgr.casabar: self._plotter.figmgr.casabar.disable_button() 1209 self._plottp(self._data) 1210 if self._minmaxy is not None: 1211 self._plotter.set_limits(ylim=self._minmaxy) 1212 self._plotter.release() 1213 self._plotter.tidy() 1214 self._plotter.show(hardrefresh=False) 1215 print_log() 1216 return 1217 1218 def _plottp(self,scan): 1219 """ 1220 private method for plotting total power data 1221 """ 1222 from matplotlib.numerix import ma, array, arange, logical_not 1223 r=0 1224 nr = scan.nrow() 1225 a0,b0 = -1,-1 1226 allxlim = [] 1227 allylim = [] 1228 y=[] 1229 self._plotter.set_panels() 1230 self._plotter.palette(0) 1231 #title 1232 #xlab = self._abcissa and self._abcissa[panelcount] \ 1233 # or scan._getabcissalabel() 1234 #ylab = self._ordinate and self._ordinate[panelcount] \ 1235 # or scan._get_ordinate_label() 1236 xlab = self._abcissa or 'row number' #or Time 1237 ylab = self._ordinate or scan._get_ordinate_label() 1238 self._plotter.set_axes('xlabel',xlab) 1239 self._plotter.set_axes('ylabel',ylab) 1240 lbl = self._get_label(scan, r, 's', self._title) 1241 if isinstance(lbl, list) or isinstance(lbl, tuple): 1242 # if 0 <= panelcount < len(lbl): 1243 # lbl = lbl[panelcount] 1244 # else: 1245 # get default label 1246 lbl = self._get_label(scan, r, self._panelling, None) 1247 self._plotter.set_axes('title',lbl) 1248 y=array(scan._get_column(scan._getspectrum,-1)) 1249 m = array(scan._get_column(scan._getmask,-1)) 1250 y = ma.masked_array(y,mask=logical_not(array(m,copy=False))) 1251 x = arange(len(y)) 1252 # try to handle spectral data somewhat... 1253 l,m = y.shape 1254 if m > 1: 1255 y=y.mean(axis=1) 1256 plotit = self._plotter.plot 1257 llbl = self._get_label(scan, r, self._stacking, None) 1258 self._plotter.set_line(label=llbl) 1259 if len(x) > 0: 1260 plotit(x,y) 1261 1262 1263 # forwards to matplotlib.Figure.text 1264 def figtext(self, *args, **kwargs): 1265 """ 1266 Add text to figure at location x,y (relative 0-1 coords). 1267 This method forwards *args and **kwargs to a Matplotlib method, 1268 matplotlib.Figure.text. 1269 See the method help for detailed information. 1270 """ 1271 self._plotter.text(*args, **kwargs) 1272 # end matplotlib.Figure.text forwarding function 1273 1274 1275 # printing header information 1276 def print_header(self, plot=True, fontsize=9, logger=False, selstr='', extrastr=''): 1277 """ 1278 print data (scantable) header on the plot and/or logger. 1279 Parameters: 1280 plot: whether or not print header info on the plot. 1281 fontsize: header font size (valid only plot=True) 1282 autoscale: whether or not autoscale the plot (valid only plot=True) 1283 logger: whether or not print header info on the logger. 1284 selstr: additional selection string (not verified) 1285 extrastr: additional string to print (not verified) 1286 """ 1287 if not plot and not logger: return 1288 if not self._data: raise RuntimeError("No scantable has been set yet.") 1289 # Now header will be printed on plot and/or logger. 1290 # Get header information and format it. 1291 ssum=self._data.__str__() 1292 # Print Observation header to the upper-left corner of plot 1293 if plot: 1294 headstr=[ssum[ssum.find('Observer:'):ssum.find('Flux Unit:')]] 1295 headstr.append(ssum[ssum.find('Beams:'):ssum.find('Observer:')] 1296 +ssum[ssum.find('Rest Freqs:'):ssum.find('Abcissa:')]) 1297 if extrastr != '': headstr[0]=extrastr+'\n'+headstr[0] 1298 #headstr[1]='Data File: '+(filestr or 'unknown')+'\n'+headstr[1] 1299 ssel='***Selections***\n'+(selstr+self._data.get_selection().__str__() or 'none') 1300 headstr.append(ssel) 1301 nstcol=len(headstr) 1302 1303 self._plotter.hold() 1304 for i in range(nstcol): 1305 self._plotter.figure.text(0.03+float(i)/nstcol,0.98, 1306 headstr[i], 1307 horizontalalignment='left', 1308 verticalalignment='top', 1309 fontsize=fontsize) 1310 import time 1311 self._plotter.figure.text(0.99,0.0, 1312 time.strftime("%a %d %b %Y %H:%M:%S %Z"), 1313 horizontalalignment='right', 1314 verticalalignment='bottom',fontsize=8) 1315 self._plotter.release() 1316 del headstr, ssel 1317 if logger: 1318 asaplog.push("----------------\n Plot Summary\n----------------") 1319 asaplog.push(extrastr) 1320 asaplog.push(ssum[ssum.find('Beams:'):]) 1321 print_log() 1322 del ssum 1323 1324
Note:
See TracChangeset
for help on using the changeset viewer.