source: branches/Release-2-fixes/python/asapplotter.py@ 2377

Last change on this file since 2377 was 693, checked in by mar637, 19 years ago

added user customisable color and linestyles

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.2 KB
RevLine 
[203]1from asap.asaplot import ASAPlot
[226]2from asap import rcParams
[203]3
4class asapplotter:
[226]5 """
6 The ASAP plotter.
7 By default the plotter is set up to plot polarisations
8 'colour stacked' and scantables across panels.
9 Note:
10 Currenly it only plots 'spectra' not Tsys or
11 other variables.
12 """
[203]13 def __init__(self):
14 self._plotter = ASAPlot()
15
16 self._tdict = {'Time':'t','time':'t','t':'t','T':'t'}
17 self._bdict = {'Beam':'b','beam':'b','b':'b','B':'b'}
18 self._idict = {'IF':'i','if':'i','i':'i','I':'i'}
19 self._pdict = {'Pol':'p','pol':'p','p':'p'}
20 self._sdict = {'scan':'s','Scan':'s','s':'s','S':'s'}
[525]21 self._cdict = {'t':'len(self._cursor["t"])',
22 'b':'len(self._cursor["b"])',
23 'i':'len(self._cursor["i"])',
24 'p':'len(self._cursor["p"])',
[203]25 's':'len(scans)'}
26 self._ldict = {'b':'Beam',
27 'i':'IF',
28 'p':'Pol',
29 's':'Scan'}
30 self._dicts = [self._tdict,self._bdict,
31 self._idict,self._pdict,
32 self._sdict]
[554]33 self._panelling = None
34 self._stacking = None
35 self.set_panelling()
36 self.set_stacking()
[377]37 self._rows = None
38 self._cols = None
[203]39 self._autoplot = False
[525]40 self._minmaxx = None
41 self._minmaxy = None
[203]42 self._data = None
[607]43 self._lmap = None
[226]44 self._title = None
[257]45 self._ordinate = None
46 self._abcissa = None
[672]47 self._abcunit = None
[525]48 self._cursor = {'t':None, 'b':None,
49 'i':None, 'p':None
50 }
[203]51
52 def _translate(self, name):
53 for d in self._dicts:
54 if d.has_key(name):
55 return d[name]
56 return None
57
[525]58 def plot(self, *args):
[203]59 """
60 Plot a (list of) scantables.
61 Parameters:
62 one or more comma separated scantables
63 Note:
64 If a (list) of scantables was specified in a previous call
65 to plot, no argument has to be given to 'replot'
[525]66 NO checking is done that the abcissas of the scantables
[203]67 are consistent e.g. all 'channel' or all 'velocity' etc.
68 """
69 if self._plotter.is_dead:
70 self._plotter = ASAPlot()
[600]71 self._plotter.hold()
[203]72 self._plotter.clear()
73 if len(args) > 0:
[525]74 if self._data is not None:
75 if list(args) != self._data:
76 self._data = list(args)
77 # reset cursor
[541]78 self.set_cursor(refresh=False)
[525]79 else:
80 self._data = list(args)
[541]81 self.set_cursor(refresh=False)
[672]82 # ranges become invalid when unit changes
83 if self._abcunit != self._data[0].get_unit():
84 self._minmaxx = None
85 self._minmaxy = None
86 self._abcunit = self._data[0].get_unit()
[554]87 if self._panelling == 't':
[626]88 maxrows = 25
[541]89 if self._data[0].nrow() > maxrows:
[603]90 if self._cursor["t"] is None or \
91 (isinstance(self._cursor["t"],list) and \
92 len(self._cursor["t"]) > maxrows ):
93 print "Scan to be plotted contains more than %d rows.\n" \
94 "Selecting first %d rows..." % (maxrows,maxrows)
95 self._cursor["t"] = range(maxrows)
[203]96 self._plot_time(self._data[0], self._stacking)
[554]97 elif self._panelling == 's':
[203]98 self._plot_scans(self._data, self._stacking)
99 else:
100 self._plot_other(self._data, self._stacking)
[672]101 if self._minmaxy is not None:
102 self._plotter.set_limits(ylim=self._minmaxy)
[203]103 self._plotter.release()
104 return
105
106 def _plot_time(self, scan, colmode):
107 if colmode == 't':
108 return
[525]109 n = len(self._cursor["t"])
[203]110 cdict = {'b':'scan.setbeam(j)',
111 'i':'scan.setif(j)',
112 'p':'scan.setpol(j)'}
[525]113 cdict2 = {'b':'self._cursor["b"]',
114 'i':'self._cursor["i"]',
115 'p':'self._cursor["p"]'}
116 ncol = 1
[203]117 if self._stacking is not None:
118 ncol = eval(self._cdict.get(colmode))
119 if n > 1:
[377]120 if self._rows and self._cols:
121 n = min(n,self._rows*self._cols)
122 self._plotter.set_panels(rows=self._rows,cols=self._cols,
123 nplots=n)
124 else:
[485]125 self._plotter.set_panels(rows=n,cols=0,nplots=n)
[600]126 else:
127 self._plotter.set_panels()
[525]128 rows = self._cursor["t"]
[652]129 self._plotter.palette(0)
[525]130 for rowsel in rows:
131 i = self._cursor["t"].index(rowsel)
[203]132 if n > 1:
[652]133 self._plotter.palette(0)
[203]134 self._plotter.subplot(i)
[525]135 colvals = eval(cdict2.get(colmode))
136 for j in colvals:
137 polmode = "raw"
138 jj = colvals.index(j)
139 savej = j
140 for k in cdict.keys():
141 sel = eval(cdict2.get(k))
142 j = sel[0]
143 if k == "p":
144 which = self._cursor["p"].index(j)
145 polmode = self._polmode[which]
146 j = which
147 eval(cdict.get(k))
148 j = savej
149 if colmode == "p":
150 polmode = self._polmode[self._cursor["p"].index(j)]
[672]151 #j = jj
[203]152 eval(cdict.get(colmode))
153 x = None
154 y = None
155 m = None
[626]156 if self._title is None:
[525]157 tlab = scan._getsourcename(rowsel)
[226]158 else:
[626]159 if len(self._title) >= n:
[525]160 tlab = self._title[rowsel]
[226]161 else:
[525]162 tlab = scan._getsourcename(rowsel)
163 x,xlab = scan.get_abcissa(rowsel)
[257]164 if self._abcissa: xlab = self._abcissa
[525]165 y = None
166 if polmode == "stokes":
167 y = scan._getstokesspectrum(rowsel)
168 elif polmode == "stokes2":
169 y = scan._getstokesspectrum(rowsel,True)
[541]170 elif polmode == "circular":
171 y = scan._stokestopolspectrum(rowsel,False,-1)
[525]172 else:
173 y = scan._getspectrum(rowsel)
[257]174 if self._ordinate:
175 ylab = self._ordinate
176 else:
[626]177 ylab = scan._get_ordinate_label()
[525]178 m = scan._getmask(rowsel)
[226]179 if self._lmap and len(self._lmap) > 0:
[525]180 llab = self._lmap[jj]
[203]181 else:
[525]182 if colmode == 'p':
[603]183 llab = self._get_pollabel(scan, polmode)
[525]184 else:
185 llab = self._ldict.get(colmode)+' '+str(j)
[203]186 self._plotter.set_line(label=llab)
[672]187 if self._minmaxx is not None:
188 s,e = self._slice_indeces(x)
189 x = x[s:e]
190 y = y[s:e]
191 m = m[s:e]
[203]192 self._plotter.plot(x,y,m)
[672]193
[203]194 xlim=[min(x),max(x)]
[693]195 if self._minmaxx is not None:
196 xlim = self._minmaxx
[203]197 self._plotter.axes.set_xlim(xlim)
198 self._plotter.set_axes('xlabel',xlab)
199 self._plotter.set_axes('ylabel',ylab)
200 self._plotter.set_axes('title',tlab)
201 return
202
[525]203 def _plot_scans(self, scans, colmode):
[693]204 print "Plotting mode is scans across panels. Can only plot one row per scan."
[203]205 if colmode == 's':
206 return
207 cdict = {'b':'scan.setbeam(j)',
208 'i':'scan.setif(j)',
209 'p':'scan.setpol(j)'}
[525]210 cdict2 = {'b':'self._cursor["b"]',
211 'i':'self._cursor["i"]',
212 'p':'self._cursor["p"]'}
213
[203]214 n = len(scans)
[525]215 ncol = 1
[203]216 if self._stacking is not None:
217 scan = scans[0]
218 ncol = eval(self._cdict.get(colmode))
219 if n > 1:
[377]220 if self._rows and self._cols:
221 n = min(n,self._rows*self._cols)
[626]222 self._plotter.set_panels(rows=self._rows,cols=self._cols,
[377]223 nplots=n)
224 else:
[626]225 self._plotter.set_panels(rows=n,cols=0,nplots=n)
[600]226 else:
227 self._plotter.set_panels()
[626]228
[203]229 for scan in scans:
[652]230 self._plotter.palette(0)
[203]231 if n > 1:
[525]232 self._plotter.subplot(scans.index(scan))
233 colvals = eval(cdict2.get(colmode))
234 rowsel = self._cursor["t"][0]
235 for j in colvals:
236 polmode = "raw"
237 jj = colvals.index(j)
238 savej = j
239 for k in cdict.keys():
240 sel = eval(cdict2.get(k))
241 j = sel[0]
242 eval(cdict.get(k))
243 if k == "p":
244 which = self._cursor["p"].index(j)
245 polmode = self._polmode[which]
246 j = which
247 j = savej
248 if colmode == "p":
249 polmode = self._polmode[self._cursor["p"].index(j)]
[672]250 #j = jj
[203]251 eval(cdict.get(colmode))
252 x = None
253 y = None
254 m = None
[226]255 tlab = self._title
256 if not self._title:
[525]257 tlab = scan._getsourcename(rowsel)
258 x,xlab = scan.get_abcissa(rowsel)
[257]259 if self._abcissa: xlab = self._abcissa
[525]260 if polmode == "stokes":
261 y = scan._getstokesspectrum(rowsel)
262 elif polmode == "stokes2":
263 y = scan._getstokesspectrum(rowsel,True)
[541]264 elif polmode == "circular":
265 y = scan._stokestopolspectrum(rowsel,False,-1)
[525]266 else:
267 y = scan._getspectrum(rowsel)
[257]268 if self._ordinate:
269 ylab = self._ordinate
270 else:
[626]271 ylab = scan._get_ordinate_label()
[525]272 m = scan._getmask(rowsel)
[257]273 if self._lmap and len(self._lmap) > 0:
[525]274 llab = self._lmap[jj]
[203]275 else:
[525]276 if colmode == 'p':
[603]277 llab = self._get_pollabel(scan, polmode)
[525]278 else:
279 llab = self._ldict.get(colmode)+' '+str(j)
[203]280 self._plotter.set_line(label=llab)
[672]281 if self._minmaxx is not None:
282 s,e = self._slice_indeces(x)
283 x = x[s:e]
284 y = y[s:e]
285 m = m[s:e]
286
[203]287 self._plotter.plot(x,y,m)
288 xlim=[min(x),max(x)]
[693]289 if self._minmaxx is not None:
290 xlim = self._minmaxx
[203]291 self._plotter.axes.set_xlim(xlim)
292
293 self._plotter.set_axes('xlabel',xlab)
294 self._plotter.set_axes('ylabel',ylab)
295 self._plotter.set_axes('title',tlab)
296 return
297
298 def _plot_other(self,scans,colmode):
[554]299 if colmode == self._panelling:
[203]300 return
[525]301 cdict = {'b':'scan.setbeam(i)',
302 'i':'scan.setif(i)',
303 'p':'scan.setpol(i)'}
304 cdict2 = {'b':'self._cursor["b"]',
305 'i':'self._cursor["i"]',
306 'p':'self._cursor["p"]',
307 's': 'scans',
308 't': 'self._cursor["t"]'}
[203]309 scan = scans[0]
[554]310 n = eval(self._cdict.get(self._panelling))
[525]311 ncol=1
[203]312 if self._stacking is not None:
313 ncol = eval(self._cdict.get(colmode))
314 if n > 1:
[377]315 if self._rows and self._cols:
316 n = min(n,self._rows*self._cols)
317 self._plotter.set_panels(rows=self._rows,cols=self._cols,
318 nplots=n)
319 else:
[485]320 self._plotter.set_panels(rows=n,cols=0,nplots=n)
[600]321 else:
322 self._plotter.set_panels()
[554]323 panels = self._cursor[self._panelling]
[525]324 for i in panels:
[652]325 self._plotter.palette(0)
[525]326 polmode = "raw"
[554]327 ii = self._cursor[self._panelling].index(i)
[203]328 if n>1:
[525]329 self._plotter.subplot(ii)
[554]330 if self._panelling == "p":
[525]331 polmode = self._polmode[ii]
[554]332 eval(cdict.get(self._panelling))
[525]333 else:
[554]334 eval(cdict.get(self._panelling))
[525]335 colvals = eval(cdict2.get(colmode))
336 for j in colvals:
337 rowsel = self._cursor["t"][0]
338 jj = colvals.index(j)
339 savei = i
340 for k in cdict.keys():
[554]341 if k != self._panelling:
[525]342 sel = eval(cdict2.get(k))
343 i = sel[0]
344 if k == "p":
[557]345 which = self._cursor["p"].index(i)
[525]346 polmode = self._polmode[which]
347 i = which
348 eval(cdict.get(k))
349 i = savei
[203]350 if colmode == 's':
[525]351 scan = j
[203]352 elif colmode == 't':
[525]353 rowsel = j
[203]354 else:
[525]355 savei = i
356 if colmode == 'p':
357 polmode = self._polmode[self._cursor["p"].index(j)]
358 i = j
[203]359 eval(cdict.get(colmode))
[525]360 i = savei
[203]361 x = None
362 y = None
363 m = None
[525]364 x,xlab = scan.get_abcissa(rowsel)
[257]365 if self._abcissa: xlab = self._abcissa
[525]366 if polmode == "stokes":
367 y = scan._getstokesspectrum(rowsel)
368 elif polmode == "stokes2":
369 y = scan._getstokesspectrum(rowsel,True)
[541]370 elif polmode == "circular":
371 y = scan._stokestopolspectrum(rowsel,False,-1)
[525]372 else:
373 y = scan._getspectrum(rowsel)
374
[257]375 if self._ordinate:
376 ylab = self._ordinate
377 else:
[626]378 ylab = scan._get_ordinate_label()
[525]379 m = scan._getmask(rowsel)
[203]380 if colmode == 's' or colmode == 't':
[525]381 if self._title and len(self._title) > 0:
382 tlab = self._title[ii]
[652]383 else:
384 if self._panelling == 'p':
385 tlab = self._get_pollabel(scan, polmode)
386 else:
387 tlab = self._ldict.get(self._panelling)+' '+str(i)
[607]388 if self._lmap and len(self._lmap) > 0:
389 llab = self._lmap[jj]
390 else:
391 llab = scan._getsourcename(rowsel)
[203]392 else:
[226]393 if self._title and len(self._title) > 0:
[525]394 tlab = self._title[ii]
[226]395 else:
[603]396 if self._panelling == 'p':
397 tlab = self._get_pollabel(scan, polmode)
398 else:
399 tlab = self._ldict.get(self._panelling)+' '+str(i)
[226]400 if self._lmap and len(self._lmap) > 0:
[525]401 llab = self._lmap[jj]
[203]402 else:
[525]403 if colmode == 'p':
[603]404 llab = self._get_pollabel(scan, polmode)
[525]405 else:
406 llab = self._ldict.get(colmode)+' '+str(j)
[203]407 self._plotter.set_line(label=llab)
[672]408 if self._minmaxx is not None:
409 s,e = self._slice_indeces(x)
410 x = x[s:e]
411 y = y[s:e]
412 m = m[s:e]
413
[203]414 self._plotter.plot(x,y,m)
415 xlim=[min(x),max(x)]
[693]416 if self._minmaxx is not None:
417 xlim = self._minmaxx
[203]418 self._plotter.axes.set_xlim(xlim)
419
420 self._plotter.set_axes('xlabel',xlab)
421 self._plotter.set_axes('ylabel',ylab)
422 self._plotter.set_axes('title',tlab)
423
424 return
425
426
[226]427 def set_mode(self, stacking=None, panelling=None):
[203]428 """
[377]429 Set the plots look and feel, i.e. what you want to see on the plot.
[203]430 Parameters:
431 stacking: tell the plotter which variable to plot
[693]432 as line color overlays (default 'pol')
[203]433 panelling: tell the plotter which variable to plot
434 across multiple panels (default 'scan'
435 Note:
436 Valid modes are:
437 'beam' 'Beam' 'b': Beams
438 'if' 'IF' 'i': IFs
439 'pol' 'Pol' 'p': Polarisations
440 'scan' 'Scan' 's': Scans
441 'time' 'Time' 't': Times
442 """
[554]443 if not self.set_panelling(panelling):
[203]444 print "Invalid mode"
[226]445 return
[203]446 if not self.set_stacking(stacking):
447 print "Invalid mode"
[226]448 return
449 if self._data: self.plot()
[203]450 return
451
[554]452 def set_panelling(self, what=None):
453 mode = what
454 if mode is None:
455 mode = rcParams['plotter.panelling']
456 md = self._translate(mode)
[203]457 if md:
[554]458 self._panelling = md
[226]459 self._title = None
[203]460 return True
461 return False
462
[377]463 def set_layout(self,rows=None,cols=None):
464 """
465 Set the multi-panel layout, i.e. how many rows and columns plots
466 are visible.
467 Parameters:
468 rows: The number of rows of plots
469 cols: The number of columns of plots
470 Note:
471 If no argument is given, the potter reverts to its auto-plot
472 behaviour.
473 """
474 self._rows = rows
475 self._cols = cols
476 if self._data: self.plot()
477 return
478
[226]479 def set_stacking(self, what=None):
[554]480 mode = what
481 if mode is None:
482 mode = rcParams['plotter.stacking']
483 md = self._translate(mode)
[203]484 if md:
485 self._stacking = md
[226]486 self._lmap = None
[203]487 return True
488 return False
489
[525]490 def set_range(self,xstart=None,xend=None,ystart=None,yend=None):
[203]491 """
492 Set the range of interest on the abcissa of the plot
493 Parameters:
[525]494 [x,y]start,[x,y]end: The start and end points of the 'zoom' window
[203]495 Note:
496 These become non-sensical when the unit changes.
497 use plotter.set_range() without parameters to reset
498
499 """
[525]500 if xstart is None and xend is None:
501 self._minmaxx = None
[600]502 else:
503 self._minmaxx = [xstart,xend]
[525]504 if ystart is None and yend is None:
505 self._minmaxy = None
[600]506 else:
507 self._minmaxy = [ystart,yend]
[525]508 if self._data: self.plot()
[203]509 return
510
[257]511 def set_legend(self, mp=None):
[203]512 """
513 Specify a mapping for the legend instead of using the default
514 indices:
515 Parameters:
516 mp: a list of 'strings'. This should have the same length
517 as the number of elements on the legend and then maps
[693]518 to the indeces in order. It is possible to uses latex
519 math expression. These have to be enclosed in r'', e.g. r'$x^{2}$'
[203]520
521 Example:
[485]522 If the data has two IFs/rest frequencies with index 0 and 1
[203]523 for CO and SiO:
524 plotter.set_stacking('i')
[693]525 plotter.set_legend(['CO','SiO'])
[203]526 plotter.plot()
[693]527 plotter.set_legend([r'$^{12}CO$', r'SiO'])
[203]528 """
529 self._lmap = mp
[226]530 if self._data: self.plot()
531 return
532
533 def set_title(self, title=None):
[693]534 """
535 Set the title of the plot. If multiple panels are plotted,
536 multiple titles have to be specified.
537 Example:
538 # two panels are visible on the plotter
539 plotter.set_title(["First Panel","Second Panel"])
540 """
[226]541 self._title = title
542 if self._data: self.plot()
543 return
544
[257]545 def set_ordinate(self, ordinate=None):
[693]546 """
547 Set the y-axis label of the plot. If multiple panels are plotted,
548 multiple labels have to be specified.
549 Example:
550 # two panels are visible on the plotter
551 plotter.set_ordinate(["First Y-Axis","Second Y-Axis"])
552 """
[257]553 self._ordinate = ordinate
554 if self._data: self.plot()
555 return
556
557 def set_abcissa(self, abcissa=None):
[693]558 """
559 Set the x-axis label of the plot. If multiple panels are plotted,
560 multiple labels have to be specified.
561 Example:
562 # two panels are visible on the plotter
563 plotter.set_ordinate(["First X-Axis","Second X-Axis"])
564 """
[257]565 self._abcissa = abcissa
566 if self._data: self.plot()
567 return
568
[693]569 def set_colors(self, colormap):
570 """
571 Set the colors to be used. The plotter will cycle through
572 these colors when lines are overlaid (stacking mode).
573 Example:
574 plotter.set_colors("red green blue")
575 # If for example four lines are overlaid e.g I Q U V
576 # 'I' will be 'red', 'Q' will be 'green', U will be 'blue'
577 # and 'V' will be 'red' again.
578 """
579 self._plotter.palette(0,colormap=colormap)
580 if self._data: self.plot()
581
582 def set_linestyles(self, linestyles):
583 """
584 Parameters:
585 linestyles: a list of linestyles to use.
586 'line', 'dashed', 'dotted', 'dashdot',
587 'dashdotdot' and 'dashdashdot' are
588 possible
589
590 Set the linestyles to be used. The plotter will cycle through
591 these linestyles when lines are overlaid (stacking mode) AND
592 only one color has been set.
593 Example:
594 plotter.set_colors("black")
595 plotter.set_linestyles("line dashed dotted dashdot")
596 # If for example four lines are overlaid e.g I Q U V
597 # 'I' will be 'solid', 'Q' will be 'dashed',
598 # U will be 'dotted' and 'V' will be 'dashdot'.
599 """
600 self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
601 if self._data: self.plot()
602
[671]603 def save(self, filename=None, orientation=None):
[377]604 """
605 Save the plot to a file. The know formats are 'png', 'ps', 'eps'.
606 Parameters:
607 filename: The name of the output file. This is optional
608 and autodetects the image format from the file
609 suffix. If non filename is specified a file
610 called 'yyyymmdd_hhmmss.png' is created in the
611 current directory.
[671]612 orientation: optional parameter for postscript only (not eps).
613 'landscape', 'portrait' or None (default) are valid.
614 If None is choosen for 'ps' output, the plot is
615 automatically oriented to fill the page.
[377]616 """
[652]617 self._plotter.save(filename,orientation)
[377]618 return
[525]619
[541]620 def set_cursor(self, row=None,beam=None,IF=None,pol=None, refresh=True):
[525]621 """
622 Specify a 'cursor' for plotting selected spectra. Time (rows),
623 Beam, IF, Polarisation ranges can be specified.
624 Parameters:
625 Default for all paramaters is to select all available
626 row: selects the rows (time stamps) to be plotted, this has
627 to be a vector of row indices, e.g. row=[0,2,5] or row=[2]
628 beam: select a range of beams
629 IF: select a range of IFs
630 pol: select Polarisations for plotting these can be by index
631 (raw polarisations (default)) or by names any of:
632 ["I", "Q", "U", "V"] or
633 ["I", "Plinear", "Pangle", "V"] or
[541]634 ["XX", "YY", "Real(XY)", "Imag(XY)"] or
635 ["RR", "LL"]
[525]636 Example:
637 plotter.set_mode('pol','time')
638 plotter.plot(myscan) # plots all raw polarisations colour stacked
639 plotter.set_cursor(pol=["I"]) # plot "I" only for all rows
640 # plot "I" only for two time stamps row=0 and row=2
641 plotter.set_cursor(row=[0,2],pol=["I"])
[257]642
[525]643 Note:
644 Be careful to select only exisiting polarisations.
645 """
646 if not self._data:
647 print "Can only set cursor after a first call to plot()"
648 return
649
650 n = self._data[0].nrow()
651 if row is None:
652 self._cursor["t"] = range(n)
653 else:
654 for i in row:
[554]655 if i < 0 or i >= n:
[525]656 print "Row index '%d' out of range" % i
657 return
658 self._cursor["t"] = row
659
660 n = self._data[0].nbeam()
661 if beam is None:
662 self._cursor["b"] = range(n)
663 else:
664 for i in beam:
[554]665 if i < 0 or i >= n:
[525]666 print "Beam index '%d' out of range" % i
667 return
668 self._cursor["b"] = beam
669
670 n = self._data[0].nif()
671 if IF is None:
672 self._cursor["i"] = range(n)
673 else:
674 for i in IF:
[554]675 if i < 0 or i >= n:
[525]676 print "IF index '%d' out of range" %i
677 return
678 self._cursor["i"] = IF
679
680 n = self._data[0].npol()
681 dstokes = {"I":0,"Q":1,"U":2,"V":3}
682 dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3}
683 draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3}
[693]684 dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3}
[525]685
686 if pol is None:
687 self._cursor["p"] = range(n)
688 self._polmode = ["raw" for i in range(n)]
689 else:
690 if isinstance(pol,str):
691 pol = pol.split()
692 polmode = []
693 pols = []
694 for i in pol:
695 if isinstance(i,str):
696 if draw.has_key(i):
697 pols.append(draw.get(i))
698 polmode.append("raw")
699 elif dstokes.has_key(i):
700 pols.append(dstokes.get(i))
701 polmode.append("stokes")
702 elif dstokes2.has_key(i):
703 pols.append(dstokes2.get(i))
704 polmode.append("stokes2")
705 elif dcirc.has_key(i):
706 pols.append(dcirc.get(i))
[541]707 polmode.append("circular")
[525]708 else:
[652]709 print "Pol type '%s' not valid" %i
[525]710 return
711 elif 0 > i >= n:
712 print "Pol index '%d' out of range" %i
713 return
714 else:
715 pols.append(i)
716 polmode.append("raw")
717 self._cursor["p"] = pols
718 self._polmode = polmode
[541]719 if self._data and refresh: self.plot()
[525]720
[603]721 def _get_pollabel(self, scan, polmode):
722 tlab = ""
723 if polmode == "stokes":
724 tlab = scan._getpolarizationlabel(0,1,0)
725 elif polmode == "stokes2":
726 tlab = scan._getpolarizationlabel(0,1,1)
727 elif polmode == "circular":
728 tlab = scan._getpolarizationlabel(0,0,0)
729 else:
730 tlab = scan._getpolarizationlabel(1,0,0)
731 return tlab
[672]732
733 def _slice_indeces(self, data):
734 mn = self._minmaxx[0]
735 mx = self._minmaxx[1]
736 asc = data[0] < data[-1]
737 start=0
738 end = len(data)-1
739 inc = 1
740 if not asc:
741 start = len(data)-1
742 end = 0
743 inc = -1
744 # find min index
745 while data[start] < mn:
746 start+= inc
747 # find max index
748 while data[end] > mx:
749 end-=inc
750 end +=1
751 if start > end:
752 return end,start
753 return start,end
[525]754
[203]755if __name__ == '__main__':
756 plotter = asapplotter()
Note: See TracBrowser for help on using the repository browser.