source: trunk/python/asapplotter.py@ 711

Last change on this file since 711 was 710, checked in by mar637, 19 years ago

create_mask now also handles args[0]=list. auto_quotient checks for conformance between # of ons and offs

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