[226] | 1 | from asap import rcParams
|
---|
[709] | 2 | from numarray import logical_and
|
---|
[203] | 3 |
|
---|
| 4 | class 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 | """
|
---|
[709] | 13 | def __init__(self, visible=True):
|
---|
[710] | 14 |
|
---|
| 15 | self._visible = visible
|
---|
| 16 | self._plotter = self._newplotter()
|
---|
| 17 |
|
---|
[203] | 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'}
|
---|
[525] | 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"])',
|
---|
[203] | 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]
|
---|
[554] | 35 | self._panelling = None
|
---|
| 36 | self._stacking = None
|
---|
| 37 | self.set_panelling()
|
---|
| 38 | self.set_stacking()
|
---|
[377] | 39 | self._rows = None
|
---|
| 40 | self._cols = None
|
---|
[203] | 41 | self._autoplot = False
|
---|
[525] | 42 | self._minmaxx = None
|
---|
| 43 | self._minmaxy = None
|
---|
[710] | 44 | self._datamask = None
|
---|
[203] | 45 | self._data = None
|
---|
[607] | 46 | self._lmap = None
|
---|
[226] | 47 | self._title = None
|
---|
[257] | 48 | self._ordinate = None
|
---|
| 49 | self._abcissa = None
|
---|
[709] | 50 | self._abcunit = None
|
---|
[525] | 51 | self._cursor = {'t':None, 'b':None,
|
---|
| 52 | 'i':None, 'p':None
|
---|
| 53 | }
|
---|
[710] | 54 | self._usermask = None
|
---|
| 55 | self._usermaskspectra = None
|
---|
[203] | 56 |
|
---|
[710] | 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 |
|
---|
[203] | 65 | def _translate(self, name):
|
---|
| 66 | for d in self._dicts:
|
---|
| 67 | if d.has_key(name):
|
---|
| 68 | return d[name]
|
---|
| 69 | return None
|
---|
[709] | 70 |
|
---|
[525] | 71 | def plot(self, *args):
|
---|
[203] | 72 | """
|
---|
| 73 | Plot a (list of) scantables.
|
---|
| 74 | Parameters:
|
---|
[709] | 75 | one or more comma separated scantables
|
---|
[203] | 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'
|
---|
[525] | 79 | NO checking is done that the abcissas of the scantables
|
---|
[203] | 80 | are consistent e.g. all 'channel' or all 'velocity' etc.
|
---|
| 81 | """
|
---|
[710] | 82 | if self._plotter.is_dead:
|
---|
| 83 | self._plotter = self._newplotter()
|
---|
[600] | 84 | self._plotter.hold()
|
---|
[203] | 85 | self._plotter.clear()
|
---|
| 86 | if len(args) > 0:
|
---|
[709] | 87 | if self._data is not None:
|
---|
[525] | 88 | if list(args) != self._data:
|
---|
| 89 | self._data = list(args)
|
---|
[710] | 90 | # reset
|
---|
| 91 | self._reset()
|
---|
[525] | 92 | else:
|
---|
[710] | 93 | if isinstance(args[0], list):
|
---|
| 94 | self._data = args[0]
|
---|
| 95 | else:
|
---|
| 96 | self._data = list(args)
|
---|
| 97 | self._reset()
|
---|
[709] | 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()
|
---|
[710] | 103 | self._datamask = None
|
---|
[554] | 104 | if self._panelling == 't':
|
---|
[626] | 105 | maxrows = 25
|
---|
[541] | 106 | if self._data[0].nrow() > maxrows:
|
---|
[603] | 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)
|
---|
[203] | 113 | self._plot_time(self._data[0], self._stacking)
|
---|
[554] | 114 | elif self._panelling == 's':
|
---|
[203] | 115 | self._plot_scans(self._data, self._stacking)
|
---|
| 116 | else:
|
---|
| 117 | self._plot_other(self._data, self._stacking)
|
---|
[709] | 118 | if self._minmaxy is not None:
|
---|
| 119 | self._plotter.set_limits(ylim=self._minmaxy)
|
---|
[203] | 120 | self._plotter.release()
|
---|
| 121 | return
|
---|
| 122 |
|
---|
| 123 | def _plot_time(self, scan, colmode):
|
---|
| 124 | if colmode == 't':
|
---|
| 125 | return
|
---|
[525] | 126 | n = len(self._cursor["t"])
|
---|
[203] | 127 | cdict = {'b':'scan.setbeam(j)',
|
---|
| 128 | 'i':'scan.setif(j)',
|
---|
| 129 | 'p':'scan.setpol(j)'}
|
---|
[525] | 130 | cdict2 = {'b':'self._cursor["b"]',
|
---|
| 131 | 'i':'self._cursor["i"]',
|
---|
| 132 | 'p':'self._cursor["p"]'}
|
---|
| 133 | ncol = 1
|
---|
[203] | 134 | if self._stacking is not None:
|
---|
| 135 | ncol = eval(self._cdict.get(colmode))
|
---|
| 136 | if n > 1:
|
---|
[710] | 137 | ganged = rcParams['plotter.ganged']
|
---|
[377] | 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,
|
---|
[710] | 141 | nplots=n,ganged=ganged)
|
---|
[377] | 142 | else:
|
---|
[710] | 143 | self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
|
---|
[600] | 144 | else:
|
---|
| 145 | self._plotter.set_panels()
|
---|
[525] | 146 | rows = self._cursor["t"]
|
---|
[652] | 147 | self._plotter.palette(0)
|
---|
[525] | 148 | for rowsel in rows:
|
---|
| 149 | i = self._cursor["t"].index(rowsel)
|
---|
[203] | 150 | if n > 1:
|
---|
[652] | 151 | self._plotter.palette(0)
|
---|
[203] | 152 | self._plotter.subplot(i)
|
---|
[525] | 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():
|
---|
[709] | 159 | sel = eval(cdict2.get(k))
|
---|
[525] | 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)]
|
---|
[709] | 169 | #j = jj
|
---|
[203] | 170 | eval(cdict.get(colmode))
|
---|
| 171 | x = None
|
---|
| 172 | y = None
|
---|
| 173 | m = None
|
---|
[626] | 174 | if self._title is None:
|
---|
[709] | 175 | tlab = scan._getsourcename(rowsel)
|
---|
[226] | 176 | else:
|
---|
[626] | 177 | if len(self._title) >= n:
|
---|
[525] | 178 | tlab = self._title[rowsel]
|
---|
[226] | 179 | else:
|
---|
[525] | 180 | tlab = scan._getsourcename(rowsel)
|
---|
| 181 | x,xlab = scan.get_abcissa(rowsel)
|
---|
[257] | 182 | if self._abcissa: xlab = self._abcissa
|
---|
[525] | 183 | y = None
|
---|
[710] | 184 | m = scan._getmask(rowsel)
|
---|
| 185 | if self._usermask and self._usermask.count(j):
|
---|
| 186 | m = logical_and(self._usermask, m)
|
---|
[525] | 187 | if polmode == "stokes":
|
---|
| 188 | y = scan._getstokesspectrum(rowsel)
|
---|
| 189 | elif polmode == "stokes2":
|
---|
| 190 | y = scan._getstokesspectrum(rowsel,True)
|
---|
[541] | 191 | elif polmode == "circular":
|
---|
| 192 | y = scan._stokestopolspectrum(rowsel,False,-1)
|
---|
[525] | 193 | else:
|
---|
| 194 | y = scan._getspectrum(rowsel)
|
---|
[257] | 195 | if self._ordinate:
|
---|
| 196 | ylab = self._ordinate
|
---|
| 197 | else:
|
---|
[626] | 198 | ylab = scan._get_ordinate_label()
|
---|
[525] | 199 | m = scan._getmask(rowsel)
|
---|
[710] | 200 | if self._datamask is not None:
|
---|
| 201 | if len(m) == len(self._datamask):
|
---|
| 202 | m = logical_and(m,self._datamask)
|
---|
[226] | 203 | if self._lmap and len(self._lmap) > 0:
|
---|
[525] | 204 | llab = self._lmap[jj]
|
---|
[203] | 205 | else:
|
---|
[525] | 206 | if colmode == 'p':
|
---|
[603] | 207 | llab = self._get_pollabel(scan, polmode)
|
---|
[709] | 208 | else:
|
---|
[525] | 209 | llab = self._ldict.get(colmode)+' '+str(j)
|
---|
[203] | 210 | self._plotter.set_line(label=llab)
|
---|
[709] | 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]
|
---|
[710] | 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]
|
---|
[203] | 221 | self._plotter.plot(x,y,m)
|
---|
| 222 | xlim=[min(x),max(x)]
|
---|
[709] | 223 | if self._minmaxx is not None:
|
---|
[710] | 224 | xlim = self._minmaxx
|
---|
| 225 | self._plotter.axes.set_xlim(xlim)
|
---|
[203] | 226 | self._plotter.set_axes('xlabel',xlab)
|
---|
| 227 | self._plotter.set_axes('ylabel',ylab)
|
---|
[709] | 228 | self._plotter.set_axes('title',tlab)
|
---|
[203] | 229 | return
|
---|
| 230 |
|
---|
[525] | 231 | def _plot_scans(self, scans, colmode):
|
---|
[710] | 232 | print "Plotting mode is scans across panels. Can only plot one row per scan."
|
---|
[203] | 233 | if colmode == 's':
|
---|
| 234 | return
|
---|
| 235 | cdict = {'b':'scan.setbeam(j)',
|
---|
| 236 | 'i':'scan.setif(j)',
|
---|
| 237 | 'p':'scan.setpol(j)'}
|
---|
[525] | 238 | cdict2 = {'b':'self._cursor["b"]',
|
---|
| 239 | 'i':'self._cursor["i"]',
|
---|
| 240 | 'p':'self._cursor["p"]'}
|
---|
[709] | 241 |
|
---|
[203] | 242 | n = len(scans)
|
---|
[525] | 243 | ncol = 1
|
---|
[203] | 244 | if self._stacking is not None:
|
---|
| 245 | scan = scans[0]
|
---|
| 246 | ncol = eval(self._cdict.get(colmode))
|
---|
| 247 | if n > 1:
|
---|
[710] | 248 | ganged = rcParams['plotter.ganged']
|
---|
[377] | 249 | if self._rows and self._cols:
|
---|
| 250 | n = min(n,self._rows*self._cols)
|
---|
[626] | 251 | self._plotter.set_panels(rows=self._rows,cols=self._cols,
|
---|
[710] | 252 | nplots=n,ganged=ganged)
|
---|
[377] | 253 | else:
|
---|
[710] | 254 | self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
|
---|
[600] | 255 | else:
|
---|
| 256 | self._plotter.set_panels()
|
---|
[709] | 257 |
|
---|
[203] | 258 | for scan in scans:
|
---|
[652] | 259 | self._plotter.palette(0)
|
---|
[203] | 260 | if n > 1:
|
---|
[525] | 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():
|
---|
[709] | 269 | sel = eval(cdict2.get(k))
|
---|
[525] | 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)]
|
---|
[709] | 279 | #j = jj
|
---|
[203] | 280 | eval(cdict.get(colmode))
|
---|
| 281 | x = None
|
---|
| 282 | y = None
|
---|
| 283 | m = None
|
---|
[226] | 284 | tlab = self._title
|
---|
| 285 | if not self._title:
|
---|
[525] | 286 | tlab = scan._getsourcename(rowsel)
|
---|
| 287 | x,xlab = scan.get_abcissa(rowsel)
|
---|
[257] | 288 | if self._abcissa: xlab = self._abcissa
|
---|
[525] | 289 | if polmode == "stokes":
|
---|
| 290 | y = scan._getstokesspectrum(rowsel)
|
---|
| 291 | elif polmode == "stokes2":
|
---|
| 292 | y = scan._getstokesspectrum(rowsel,True)
|
---|
[541] | 293 | elif polmode == "circular":
|
---|
| 294 | y = scan._stokestopolspectrum(rowsel,False,-1)
|
---|
[525] | 295 | else:
|
---|
| 296 | y = scan._getspectrum(rowsel)
|
---|
[257] | 297 | if self._ordinate:
|
---|
| 298 | ylab = self._ordinate
|
---|
| 299 | else:
|
---|
[626] | 300 | ylab = scan._get_ordinate_label()
|
---|
[525] | 301 | m = scan._getmask(rowsel)
|
---|
[710] | 302 | if self._usermask and self._usermask.count(j):
|
---|
| 303 | m = logical_and(self._usermask, m)
|
---|
[257] | 304 | if self._lmap and len(self._lmap) > 0:
|
---|
[525] | 305 | llab = self._lmap[jj]
|
---|
[203] | 306 | else:
|
---|
[525] | 307 | if colmode == 'p':
|
---|
[603] | 308 | llab = self._get_pollabel(scan, polmode)
|
---|
[525] | 309 | else:
|
---|
| 310 | llab = self._ldict.get(colmode)+' '+str(j)
|
---|
[203] | 311 | self._plotter.set_line(label=llab)
|
---|
[709] | 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]
|
---|
[710] | 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]
|
---|
[203] | 322 | self._plotter.plot(x,y,m)
|
---|
| 323 | xlim=[min(x),max(x)]
|
---|
[709] | 324 | if self._minmaxx is not None:
|
---|
[710] | 325 | xlim = self._minmaxx
|
---|
[203] | 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
|
---|
[709] | 332 |
|
---|
[203] | 333 | def _plot_other(self,scans,colmode):
|
---|
[554] | 334 | if colmode == self._panelling:
|
---|
[203] | 335 | return
|
---|
[525] | 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"]'}
|
---|
[203] | 344 | scan = scans[0]
|
---|
[554] | 345 | n = eval(self._cdict.get(self._panelling))
|
---|
[525] | 346 | ncol=1
|
---|
[709] | 347 | if self._stacking is not None:
|
---|
[203] | 348 | ncol = eval(self._cdict.get(colmode))
|
---|
| 349 | if n > 1:
|
---|
[710] | 350 | ganged = rcParams['plotter.ganged']
|
---|
[377] | 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,
|
---|
[710] | 354 | nplots=n,ganged=ganged)
|
---|
[377] | 355 | else:
|
---|
[710] | 356 | self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
|
---|
[600] | 357 | else:
|
---|
[709] | 358 | self._plotter.set_panels()
|
---|
| 359 | panels = self._cursor[self._panelling]
|
---|
[525] | 360 | for i in panels:
|
---|
[652] | 361 | self._plotter.palette(0)
|
---|
[525] | 362 | polmode = "raw"
|
---|
[554] | 363 | ii = self._cursor[self._panelling].index(i)
|
---|
[203] | 364 | if n>1:
|
---|
[525] | 365 | self._plotter.subplot(ii)
|
---|
[554] | 366 | if self._panelling == "p":
|
---|
[525] | 367 | polmode = self._polmode[ii]
|
---|
[554] | 368 | eval(cdict.get(self._panelling))
|
---|
[525] | 369 | else:
|
---|
[554] | 370 | eval(cdict.get(self._panelling))
|
---|
[525] | 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():
|
---|
[554] | 377 | if k != self._panelling:
|
---|
[525] | 378 | sel = eval(cdict2.get(k))
|
---|
| 379 | i = sel[0]
|
---|
| 380 | if k == "p":
|
---|
[557] | 381 | which = self._cursor["p"].index(i)
|
---|
[525] | 382 | polmode = self._polmode[which]
|
---|
[709] | 383 | i = which
|
---|
[525] | 384 | eval(cdict.get(k))
|
---|
| 385 | i = savei
|
---|
[203] | 386 | if colmode == 's':
|
---|
[525] | 387 | scan = j
|
---|
[203] | 388 | elif colmode == 't':
|
---|
[709] | 389 | rowsel = j
|
---|
[203] | 390 | else:
|
---|
[525] | 391 | savei = i
|
---|
| 392 | if colmode == 'p':
|
---|
| 393 | polmode = self._polmode[self._cursor["p"].index(j)]
|
---|
| 394 | i = j
|
---|
[203] | 395 | eval(cdict.get(colmode))
|
---|
[525] | 396 | i = savei
|
---|
[203] | 397 | x = None
|
---|
| 398 | y = None
|
---|
| 399 | m = None
|
---|
[525] | 400 | x,xlab = scan.get_abcissa(rowsel)
|
---|
[257] | 401 | if self._abcissa: xlab = self._abcissa
|
---|
[525] | 402 | if polmode == "stokes":
|
---|
| 403 | y = scan._getstokesspectrum(rowsel)
|
---|
| 404 | elif polmode == "stokes2":
|
---|
| 405 | y = scan._getstokesspectrum(rowsel,True)
|
---|
[541] | 406 | elif polmode == "circular":
|
---|
| 407 | y = scan._stokestopolspectrum(rowsel,False,-1)
|
---|
[525] | 408 | else:
|
---|
| 409 | y = scan._getspectrum(rowsel)
|
---|
| 410 |
|
---|
[257] | 411 | if self._ordinate:
|
---|
| 412 | ylab = self._ordinate
|
---|
| 413 | else:
|
---|
[626] | 414 | ylab = scan._get_ordinate_label()
|
---|
[525] | 415 | m = scan._getmask(rowsel)
|
---|
[710] | 416 | if self._usermask and self._usermask.count(j):
|
---|
| 417 | m = logical_and(self._usermask, m)
|
---|
| 418 |
|
---|
[203] | 419 | if colmode == 's' or colmode == 't':
|
---|
[525] | 420 | if self._title and len(self._title) > 0:
|
---|
| 421 | tlab = self._title[ii]
|
---|
[709] | 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)
|
---|
[607] | 427 | if self._lmap and len(self._lmap) > 0:
|
---|
| 428 | llab = self._lmap[jj]
|
---|
| 429 | else:
|
---|
| 430 | llab = scan._getsourcename(rowsel)
|
---|
[203] | 431 | else:
|
---|
[226] | 432 | if self._title and len(self._title) > 0:
|
---|
[525] | 433 | tlab = self._title[ii]
|
---|
[226] | 434 | else:
|
---|
[603] | 435 | if self._panelling == 'p':
|
---|
| 436 | tlab = self._get_pollabel(scan, polmode)
|
---|
| 437 | else:
|
---|
| 438 | tlab = self._ldict.get(self._panelling)+' '+str(i)
|
---|
[226] | 439 | if self._lmap and len(self._lmap) > 0:
|
---|
[525] | 440 | llab = self._lmap[jj]
|
---|
[203] | 441 | else:
|
---|
[525] | 442 | if colmode == 'p':
|
---|
[603] | 443 | llab = self._get_pollabel(scan, polmode)
|
---|
[525] | 444 | else:
|
---|
| 445 | llab = self._ldict.get(colmode)+' '+str(j)
|
---|
[203] | 446 | self._plotter.set_line(label=llab)
|
---|
[709] | 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]
|
---|
[710] | 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]
|
---|
[203] | 457 | self._plotter.plot(x,y,m)
|
---|
| 458 | xlim=[min(x),max(x)]
|
---|
[709] | 459 | if self._minmaxx is not None:
|
---|
[710] | 460 | xlim = self._minmaxx
|
---|
[203] | 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)
|
---|
[709] | 466 |
|
---|
[203] | 467 | return
|
---|
| 468 |
|
---|
| 469 |
|
---|
[226] | 470 | def set_mode(self, stacking=None, panelling=None):
|
---|
[203] | 471 | """
|
---|
[377] | 472 | Set the plots look and feel, i.e. what you want to see on the plot.
|
---|
[203] | 473 | Parameters:
|
---|
| 474 | stacking: tell the plotter which variable to plot
|
---|
[710] | 475 | as line color overlays (default 'pol')
|
---|
[203] | 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 | """
|
---|
[554] | 486 | if not self.set_panelling(panelling):
|
---|
[203] | 487 | print "Invalid mode"
|
---|
[226] | 488 | return
|
---|
[203] | 489 | if not self.set_stacking(stacking):
|
---|
| 490 | print "Invalid mode"
|
---|
[226] | 491 | return
|
---|
| 492 | if self._data: self.plot()
|
---|
[203] | 493 | return
|
---|
| 494 |
|
---|
[554] | 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)
|
---|
[203] | 500 | if md:
|
---|
[554] | 501 | self._panelling = md
|
---|
[226] | 502 | self._title = None
|
---|
[203] | 503 | return True
|
---|
| 504 | return False
|
---|
| 505 |
|
---|
[377] | 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 |
|
---|
[709] | 522 | def set_stacking(self, what=None):
|
---|
[554] | 523 | mode = what
|
---|
[709] | 524 | if mode is None:
|
---|
| 525 | mode = rcParams['plotter.stacking']
|
---|
[554] | 526 | md = self._translate(mode)
|
---|
[203] | 527 | if md:
|
---|
| 528 | self._stacking = md
|
---|
[226] | 529 | self._lmap = None
|
---|
[203] | 530 | return True
|
---|
| 531 | return False
|
---|
| 532 |
|
---|
[525] | 533 | def set_range(self,xstart=None,xend=None,ystart=None,yend=None):
|
---|
[203] | 534 | """
|
---|
| 535 | Set the range of interest on the abcissa of the plot
|
---|
| 536 | Parameters:
|
---|
[525] | 537 | [x,y]start,[x,y]end: The start and end points of the 'zoom' window
|
---|
[203] | 538 | Note:
|
---|
| 539 | These become non-sensical when the unit changes.
|
---|
| 540 | use plotter.set_range() without parameters to reset
|
---|
| 541 |
|
---|
| 542 | """
|
---|
[525] | 543 | if xstart is None and xend is None:
|
---|
| 544 | self._minmaxx = None
|
---|
[600] | 545 | else:
|
---|
| 546 | self._minmaxx = [xstart,xend]
|
---|
[525] | 547 | if ystart is None and yend is None:
|
---|
| 548 | self._minmaxy = None
|
---|
[600] | 549 | else:
|
---|
[709] | 550 | self._minmaxy = [ystart,yend]
|
---|
[525] | 551 | if self._data: self.plot()
|
---|
[203] | 552 | return
|
---|
[709] | 553 |
|
---|
[257] | 554 | def set_legend(self, mp=None):
|
---|
[203] | 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
|
---|
[710] | 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}$'
|
---|
[203] | 563 |
|
---|
| 564 | Example:
|
---|
[485] | 565 | If the data has two IFs/rest frequencies with index 0 and 1
|
---|
[203] | 566 | for CO and SiO:
|
---|
| 567 | plotter.set_stacking('i')
|
---|
[710] | 568 | plotter.set_legend(['CO','SiO'])
|
---|
[203] | 569 | plotter.plot()
|
---|
[710] | 570 | plotter.set_legend([r'$^{12}CO$', r'SiO'])
|
---|
[203] | 571 | """
|
---|
| 572 | self._lmap = mp
|
---|
[226] | 573 | if self._data: self.plot()
|
---|
| 574 | return
|
---|
| 575 |
|
---|
| 576 | def set_title(self, title=None):
|
---|
[710] | 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 | """
|
---|
[226] | 584 | self._title = title
|
---|
| 585 | if self._data: self.plot()
|
---|
| 586 | return
|
---|
| 587 |
|
---|
[257] | 588 | def set_ordinate(self, ordinate=None):
|
---|
[710] | 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 | """
|
---|
[257] | 596 | self._ordinate = ordinate
|
---|
| 597 | if self._data: self.plot()
|
---|
| 598 | return
|
---|
| 599 |
|
---|
| 600 | def set_abcissa(self, abcissa=None):
|
---|
[710] | 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 | """
|
---|
[257] | 608 | self._abcissa = abcissa
|
---|
| 609 | if self._data: self.plot()
|
---|
| 610 | return
|
---|
| 611 |
|
---|
[710] | 612 | def set_colors(self, colormap):
|
---|
[377] | 613 | """
|
---|
[710] | 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 | """
|
---|
[377] | 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.
|
---|
[709] | 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.
|
---|
[710] | 663 | dpi: The dpi of the output non-ps plot
|
---|
[377] | 664 | """
|
---|
[709] | 665 | self._plotter.save(filename,orientation,dpi)
|
---|
[377] | 666 | return
|
---|
[709] | 667 |
|
---|
[541] | 668 | def set_cursor(self, row=None,beam=None,IF=None,pol=None, refresh=True):
|
---|
[525] | 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
|
---|
[541] | 682 | ["XX", "YY", "Real(XY)", "Imag(XY)"] or
|
---|
| 683 | ["RR", "LL"]
|
---|
[525] | 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"])
|
---|
[257] | 690 |
|
---|
[525] | 691 | Note:
|
---|
[709] | 692 | Be careful to select only exisiting polarisations.
|
---|
[525] | 693 | """
|
---|
| 694 | if not self._data:
|
---|
| 695 | print "Can only set cursor after a first call to plot()"
|
---|
| 696 | return
|
---|
[709] | 697 |
|
---|
[525] | 698 | n = self._data[0].nrow()
|
---|
| 699 | if row is None:
|
---|
| 700 | self._cursor["t"] = range(n)
|
---|
| 701 | else:
|
---|
| 702 | for i in row:
|
---|
[554] | 703 | if i < 0 or i >= n:
|
---|
[525] | 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:
|
---|
[554] | 713 | if i < 0 or i >= n:
|
---|
[525] | 714 | print "Beam index '%d' out of range" % i
|
---|
[709] | 715 | return
|
---|
[525] | 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:
|
---|
[554] | 723 | if i < 0 or i >= n:
|
---|
[525] | 724 | print "IF index '%d' out of range" %i
|
---|
[709] | 725 | return
|
---|
| 726 | self._cursor["i"] = IF
|
---|
[525] | 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}
|
---|
[710] | 732 | dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3}
|
---|
[709] | 733 |
|
---|
[525] | 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))
|
---|
[541] | 755 | polmode.append("circular")
|
---|
[525] | 756 | else:
|
---|
[652] | 757 | print "Pol type '%s' not valid" %i
|
---|
[525] | 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
|
---|
[541] | 767 | if self._data and refresh: self.plot()
|
---|
[525] | 768 |
|
---|
[710] | 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 |
|
---|
[603] | 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
|
---|
[709] | 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 |
|
---|
[710] | 831 | def _reset(self):
|
---|
| 832 | self._usermask = None
|
---|
| 833 | self._usermaskspectra = None
|
---|
| 834 | self.set_cursor(refresh=False)
|
---|