source: trunk/python/asapplotter.py@ 744

Last change on this file since 744 was 734, checked in by mar637, 19 years ago

doc update
make use of rcParamplotter.gui

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