Ignore:
Timestamp:
12/12/12 20:01:06 (11 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (Trac-287)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: a new method, asapplotter.plotpointings2

Test Programs:

Put in Release Notes: No

Module(s): asapplotter, sdplot

Description:

a new method, asapplotter.plotpointings2, is created.
This method will be supposed to replace asapplotter.plotpointing
in near future if there's no issue found.
plotpointings2 plots pointing directions of a scantable.
It is possible to plot pointings of different source type, scanno,
ifno, polno, or beamno in different colors by setting the 'colorby'
paramter. When showline=True, the scan pattern is plotted in dotted
line.
This function alway plots pointings on ASAP plotter and works properly
with custom toolbar.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r2691 r2693  
    13631363           PL.savefig(outfile)
    13641364
     1365
     1366    def plotpointing2(self, scan=None, colorby='', showline=False, projection=''):
     1367        """
     1368        plot telescope pointings
     1369        Parameters:
     1370            infile  : input filename or scantable instance
     1371            colorby : change color by either
     1372                      'type'(source type)|'scan'|'if'|'pol'|'beam'
     1373            showline : show dotted line
     1374            projection : projection type either
     1375                         ''(no projection [deg])|'coord'(not implemented)
     1376        """
     1377        from numpy import array, pi
     1378        from asap import scantable
     1379        # check for scantable
     1380        if isinstance(scan, scantable):
     1381            if self._data is not None:
     1382                if scan != self._data:
     1383                    self._data = scan
     1384                    # reset
     1385                    self._reset()
     1386            else:
     1387                self._data = scan
     1388                self._reset()
     1389        if not self._data:
     1390            msg = "Input is not a scantable"
     1391            raise TypeError(msg)
     1392        # check for color mode
     1393        validtypes=['type','scan','if','pol', 'beam']
     1394        stype = None
     1395        if (colorby in validtypes):
     1396            stype = colorby[0]
     1397        elif len(colorby) > 0:
     1398            msg = "Invalid choice of 'colorby' (choices: %s)" % str(validtypes)
     1399            raise ValueError(msg)
     1400        self._assert_plotter(action="reload")
     1401        self._plotter.hold()
     1402        if self.casabar_exists(): self._plotter.figmgr.casabar.disable_button()
     1403        # for now, only one plot
     1404        self._plotter.set_panels(rows=1,cols=1)
     1405        # first panel
     1406        self._plotter.subplot(0)
     1407        # first color and linestyles
     1408        self._plotter.palette(0)
     1409        self.gca().set_aspect('equal')
     1410        basesel = scan.get_selection()
     1411        marker = "+"
     1412        if showline:
     1413            basesel.set_order(["TIME"])
     1414            scan.set_selection(basesel)
     1415            if not (stype in ["t", "s"]):
     1416                marker = "+:"
     1417        if not stype:
     1418            selIds = [""] # cheating
     1419            sellab = "all points"
     1420        elif stype == 't':
     1421            selIds = range(15)
     1422            sellab = "src type "
     1423        else:
     1424            selIds = getattr(self._data,'get'+colorby+'nos')()
     1425            sellab = colorby.upper()
     1426        selFunc = "set_"+colorby+"s"
     1427        for idx in selIds:
     1428            sel = selector() + basesel
     1429            if stype:
     1430                bid = getattr(basesel,'get_'+colorby+"s")()
     1431                if (len(bid) > 0) and (not idx in bid):
     1432                    # base selection doesn't contain idx
     1433                    # Note summation of selector is logical sum if
     1434                    continue
     1435                getattr(sel, selFunc)([idx])
     1436            if not sel.is_empty():
     1437                try:
     1438                    self._data.set_selection(sel)
     1439                except RuntimeError, instance:
     1440                    if stype == 't' and str(instance).startswith("Selection contains no data."):
     1441                        continue
     1442                    else:
     1443                        self._data.set_selection(basesel)
     1444                        raise RuntimeError, instance
     1445            if self._data.nrow() == 0:
     1446                self._data.set_selection(basesel)
     1447                continue
     1448            print "Plotting direction of %s = %s" % (colorby, str(idx))
     1449            dir = array(self._data.get_directionval()).transpose()
     1450            ra = dir[0]*180./pi
     1451            dec = dir[1]*180./pi
     1452            self._plotter.set_line(label=(sellab+str(idx)))
     1453            self._plotter.plot(ra,dec,marker)
     1454
     1455        # restore original selection
     1456        self._data.set_selection(basesel)
     1457        # need to plot scan pattern explicitly
     1458        if showline and (stype in ["t", "s"]):
     1459            dir = array(self._data.get_directionval()).transpose()
     1460            ra = dir[0]*180./pi
     1461            dec = dir[1]*180./pi
     1462            self._plotter.set_line(label="scan pattern")
     1463            self._plotter.plot(ra,dec,":")
     1464           
     1465        xlab = 'RA [deg.]'
     1466        ylab = 'Declination [deg.]'
     1467        self._plotter.set_axes('xlabel', xlab)
     1468        self._plotter.set_axes('ylabel', ylab)
     1469        self._plotter.set_axes('title', 'Telescope pointings')
     1470        if stype: self._plotter.legend(self._legendloc)
     1471        else: self._plotter.legend(None)
     1472        # reverse x-axis
     1473        xmin, xmax = self.gca().get_xlim()
     1474        self._plotter.set_limits(xlim=[xmax,xmin])
     1475
     1476        self._plotter.release()
     1477        self._plotter.show(hardrefresh=False)
     1478        return
     1479
    13651480    def plotpointing(self, scan=None, outfile=None):
    13661481        """
     
    14071522    @asaplog_post_dec
    14081523    def plottp(self, scan=None):
    1409         self._assert_plotter(action="reload")
    1410         self._plotter.hold()
    1411         self._plotter.clear()
    14121524        from asap import scantable
    14131525        if not self._data and not scan:
     
    14301542        #    self._datamask = None
    14311543
     1544        self._assert_plotter(action="reload")
     1545        self._plotter.hold()
     1546        self._plotter.clear()
    14321547        # Adjust subplot margins
    14331548        if not self._margins or len(self._margins) !=6:
     
    17411856        self._assert_plotter(action="reload")
    17421857        self._plotter.hold()
    1743         self._plotter.clear()
     1858        #self._plotter.clear() #all artists are cleared at set_panels
    17441859        self._plotter.legend()
    17451860
     
    17481863            self.set_margin(refresh=False)
    17491864        self._plotter.set_panels(rows=self._rows,cols=self._cols,
    1750                                  nplots=ntotpl,margin=self._margins,ganged=True)
     1865                                 nplots=ntotpl,margin=self._margins,ganged=True)       
    17511866        if self.casabar_exists():
    17521867            self._plotter.figmgr.casabar.set_pagecounter(1)
Note: See TracChangeset for help on using the changeset viewer.