Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r2704 r3038  
    112112        self._plotter.legend(self._legendloc)
    113113
     114    ### TODO: it's probably better to define following two methods in
     115    ###       backend dependent class.
    114116    def _new_custombar(self):
    115117        backend=matplotlib.get_backend()
     
    130132            return True
    131133        return False
     134    ### end of TODO
    132135
    133136    def _assert_plotter(self,action="status",errmsg=None):
     
    276279
    277280
    278     ### Forwards to matplotlib axes ###
     281    ### Forwards to methods in matplotlib axes ###
    279282    def text(self, *args, **kwargs):
    280283        self._assert_plotter(action="reload")
     
    415418                del self._data
    416419                msg = "A new scantable is set to the plotter. "\
    417                       "The masks and data selections are reset."
    418                 asaplog.push( msg )
     420                      "The masks, data selections, and labels are reset."
     421                asaplog.push(msg)
    419422            self._data = scan
    420423            # reset
     
    514517        self._rows = rows
    515518        self._cols = cols
     519        # new layout is set. need to reset counters for multi page plotting
     520        self._reset_counters()
    516521        if refresh and self._data: self.plot(self._data)
    517522        return
     
    905910            msg = "Can only set mask after a first call to plot()"
    906911            raise RuntimeError(msg)
    907         if len(mask):
     912        if (mask is not None) and len(mask):
    908913            if isinstance(mask, list) or isinstance(mask, tuple):
    909914                self._usermask = array(mask)
     
    926931    ### Reset methods ###
    927932    def _reset(self):
    928         self._usermask = []
    929         self._usermaskspectra = None
     933        """Reset method called when new data is set"""
     934        # reset selections and masks
     935        self.set_selection(None, False)
     936        self.set_mask(None, None, False)
     937        # reset offset
    930938        self._offset = None
    931         self.set_selection(None, False)
     939        # reset header
    932940        self._reset_header()
     941        # reset labels
     942        self._lmap = None # related to stack
     943        self.set_title(None, None, False)
     944        self.set_ordinate(None, None, False)
     945        self.set_abcissa(None, None, False)
    933946
    934947    def _reset_header(self):
     
    938951        self._startrow = 0
    939952        self._ipanel = -1
     953        self._panelrows = []
    940954        self._reset_header()
    941         self._panelrows = []
    942955        if self.casabar_exists():
    943956            self._plotter.figmgr.casabar.set_pagecounter(1)
     
    10311044        if self._panelling == 'i':
    10321045            ganged = False
    1033         if not firstpage:
    1034             # not the first page just clear the axis
     1046        if (not firstpage) and \
     1047               self._plotter._subplotsOk(self._rows, self._cols, n):
     1048            # Not the first page and subplot number is ok.
     1049            # Just clear the axis
    10351050            nx = self._plotter.cols
    10361051            ipaxx = n - nx - 1 #the max panel id to supress x-label
     
    13021317            return start,end
    13031318
     1319    def _get_date_axis_setup(self, dates, axlim=None):
     1320        """
     1321        Returns proper axis title and formatters for a list of dates
     1322        Input
     1323            dates : a list of datetime objects returned by,
     1324                    e.g. scantable.get_time(asdatetime=True)
     1325            axlim : a tuple of min and max day range in the plot axis.
     1326                    if defined, the values are taken into account.
     1327        Output
     1328            a set of
     1329            * date axis title string
     1330            * formatter of date axis
     1331            * major axis locator
     1332            * minor axis locator
     1333        """
     1334        from matplotlib import pylab as PL
     1335        from matplotlib.dates import DateFormatter
     1336        from matplotlib.dates import HourLocator, MinuteLocator,SecondLocator, DayLocator, YearLocator, MonthLocator
     1337        t = PL.date2num(dates)
     1338        tmin = min(t)
     1339        tmax = max(t)
     1340        if axlim is not None:
     1341            tmin = min(tmin, min(axlim))
     1342            tmax = max(tmax, max(axlim))
     1343        tdel = tmax - tmin # interval in day
     1344        dstr = dates[0].strftime('%Y/%m/%d')
     1345        if tdel > 365.0: # >1year (also the case for single or very small time range)
     1346            majloc = YearLocator()
     1347            minloc = MonthLocator(range(1,12,6))
     1348            timefmt = DateFormatter('%Y/%m/%d')
     1349        elif tdel > 1.0: # >1day
     1350            dstr2 = dates[len(dates)-1].strftime('%Y/%m/%d')
     1351            dstr = dstr + " - " + dstr2
     1352            majloc = DayLocator()
     1353            minloc = HourLocator(range(0,23,12))
     1354            timefmt = DateFormatter("%b%d")
     1355        elif tdel > 24./60.: # 9.6h - 1day
     1356            timefmt = DateFormatter('%H:%M')
     1357            majloc = HourLocator()
     1358            minloc = MinuteLocator(range(0,60,30))
     1359        elif tdel > 2./24.: # 2h-9.6h
     1360            timefmt = DateFormatter('%H:%M')
     1361            majloc = HourLocator()
     1362            minloc = MinuteLocator(range(0,60,10))
     1363        elif tdel> 10./24./60.: # 10min-2h
     1364            timefmt = DateFormatter('%H:%M')
     1365            majloc = MinuteLocator(range(0,60,10))
     1366            minloc = MinuteLocator()
     1367        else: # <10min
     1368            timefmt = DateFormatter('%H:%M')
     1369            majloc = MinuteLocator()
     1370            minloc = SecondLocator(30)
     1371        return (dstr, timefmt, majloc, minloc)
     1372
    13041373    def plotazel(self, scan=None, outfile=None):
    13051374        """
     
    13091378        visible = rcParams['plotter.gui']
    13101379        from matplotlib import pylab as PL
    1311         from matplotlib.dates import DateFormatter
    13121380        from pytz import timezone
    1313         from matplotlib.dates import HourLocator, MinuteLocator,SecondLocator, DayLocator
    13141381        from matplotlib.ticker import MultipleLocator
    1315         from numpy import array, pi
     1382        from numpy import array, pi, ma
    13161383        if self._plotter and (PL.gcf() == self._plotter.figure):
    13171384            # the current figure is ASAP plotter. Use mpl plotter
     
    13251392        self._data = scan
    13261393        dates = self._data.get_time(asdatetime=True)
     1394        # for flag handling
     1395        mask = [ self._data._is_all_chan_flagged(i) for i in range(self._data.nrow())]
    13271396        t = PL.date2num(dates)
    13281397        tz = timezone('UTC')
     
    13371406                                 wspace=wsp,hspace=hsp)
    13381407
    1339         tdel = max(t) - min(t)
     1408        tdel = max(t) - min(t) # interval in day
    13401409        ax = PL.subplot(2,1,1)
    1341         el = array(self._data.get_elevation())*180./pi
     1410        el = ma.masked_array(array(self._data.get_elevation())*180./pi, mask)
    13421411        PL.ylabel('El [deg.]')
    1343         dstr = dates[0].strftime('%Y/%m/%d')
    1344         if tdel > 1.0:
    1345             dstr2 = dates[len(dates)-1].strftime('%Y/%m/%d')
    1346             dstr = dstr + " - " + dstr2
    1347             majloc = DayLocator()
    1348             minloc = HourLocator(range(0,23,12))
    1349             timefmt = DateFormatter("%b%d")
    1350         elif tdel > 24./60.:
    1351             timefmt = DateFormatter('%H:%M')
    1352             majloc = HourLocator()
    1353             minloc = MinuteLocator(30)
    1354         else:
    1355             timefmt = DateFormatter('%H:%M')
    1356             majloc = MinuteLocator(interval=5)
    1357             minloc = SecondLocator(30)
    1358 
     1412        (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(dates)
     1413       
    13591414        PL.title(dstr)
    13601415        if tdel == 0.0:
     
    13631418        else:
    13641419            PL.plot_date(t,el,'o', markersize=2, markerfacecolor='b', markeredgecolor='b',tz=tz)
    1365             #ax.grid(True)
    1366             ax.xaxis.set_major_formatter(timefmt)
    1367             ax.xaxis.set_major_locator(majloc)
    1368             ax.xaxis.set_minor_locator(minloc)
     1420            #ax.xaxis.set_major_formatter(timefmt)
     1421            #ax.xaxis.set_major_locator(majloc)
     1422            #ax.xaxis.set_minor_locator(minloc)
    13691423        ax.yaxis.grid(True)
    1370         yloc = MultipleLocator(30)
    13711424        ax.set_ylim(0,90)
    1372         ax.yaxis.set_major_locator(yloc)
     1425        #yloc = MultipleLocator(30)
     1426        #ax.yaxis.set_major_locator(yloc)
    13731427        if tdel > 1.0:
    13741428            labels = ax.get_xticklabels()
     
    13771431
    13781432        # Az plot
    1379         az = array(self._data.get_azimuth())*180./pi
     1433        az = ma.masked_array(array(self._data.get_azimuth())*180./pi, mask)
    13801434        if min(az) < 0:
    13811435            for irow in range(len(az)):
     
    13891443        else:
    13901444            PL.plot_date(t,az,'o', markersize=2,markeredgecolor='b',markerfacecolor='b',tz=tz)
    1391             ax2.xaxis.set_major_formatter(timefmt)
    1392             ax2.xaxis.set_major_locator(majloc)
    1393             ax2.xaxis.set_minor_locator(minloc)
    1394         #ax2.grid(True)
     1445            #ax2.xaxis.set_major_formatter(timefmt)
     1446            #ax2.xaxis.set_major_locator(majloc)
     1447            #ax2.xaxis.set_minor_locator(minloc)
    13951448        ax2.set_ylim(0,360)
    13961449        ax2.yaxis.grid(True)
    13971450        #hfmt = DateFormatter('%H')
    13981451        #hloc = HourLocator()
    1399         yloc = MultipleLocator(60)
    1400         ax2.yaxis.set_major_locator(yloc)
     1452        #yloc = MultipleLocator(60)
     1453        #ax2.yaxis.set_major_locator(yloc)
    14011454        if tdel > 1.0:
    14021455            labels = ax2.get_xticklabels()
    14031456            PL.setp(labels, fontsize=10)
    1404             PL.xlabel('Time (UT [day])')
    1405         else:
    1406             PL.xlabel('Time (UT [hour])')
     1457        #    PL.xlabel('Time (UT [day])')
     1458        #else:
     1459        #    PL.xlabel('Time (UT [hour])')
     1460        PL.xlabel('Time (UT)')
    14071461
    14081462        PL.ion()
     
    14171471        plot telescope pointings
    14181472        Parameters:
    1419             infile  : input filename or scantable instance
     1473            scan    : input scantable instance
    14201474            colorby : change color by either
    14211475                      'type'(source type)|'scan'|'if'|'pol'|'beam'
     
    14251479        """
    14261480        self._plotmode = "pointing"
    1427         from numpy import array, pi
     1481        from numpy import array, pi, ma
    14281482        from asap import scantable
    14291483        # check for scantable
     
    15011555                self._data.set_selection(basesel)
    15021556                continue
    1503             print "Plotting direction of %s = %s" % (colorby, str(idx))
     1557            #print "Plotting direction of %s = %s" % (colorby, str(idx))
    15041558            # getting data to plot
    15051559            dir = array(self._data.get_directionval()).transpose()
     1560            # for flag handling
     1561            mask = [ self._data._is_all_chan_flagged(i) for i in range(self._data.nrow())]
    15061562            ra = dir[0]*180./pi
    1507             dec = dir[1]*180./pi
     1563            dec = ma.masked_array(dir[1]*180./pi, mask)
    15081564            # actual plot
    15091565            self._plotter.set_line(label=(sellab+str(idx)))
     
    15311587        # reverse x-axis
    15321588        xmin, xmax = self.gca().get_xlim()
    1533         self._plotter.set_limits(xlim=[xmax,xmin])
     1589        ymin, ymax = self.gca().get_ylim()
     1590        # expand plotrange if xmin==xmax or ymin==ymax
     1591        if abs(ymax-ymin) < 1.e-3: #~4arcsec
     1592            delx = 0.5*abs(xmax - xmin)
     1593            if delx < 5.e-4:
     1594                dxy = 5.e-4 #~2arcsec
     1595                (ymin, ymax) = (ymin-dxy, ymax+dxy)
     1596                (xmin, xmax) = (xmin-dxy, xmax+dxy)
     1597            (ymin, ymax) = (ymin-delx, ymax+delx)
     1598        elif abs(xmax-xmin) < 1.e-3:
     1599            dely = 0.5*abs(ymax - ymin)
     1600            (xmin, xmax) = (xmin-dely, xmax+dely)
     1601        self._plotter.set_limits(xlim=[xmax,xmin], ylim=[ymin, ymax])
    15341602
    15351603        self._plotter.release()
     
    15871655    # plotting in time is not yet implemented..
    15881656    @asaplog_post_dec
    1589     def plottp(self, scan=None):
     1657    def plottp(self, scan=None, colorby=''):
     1658        """
     1659        Plot averaged spectra (total power) in time or in row ID (colorby='')
     1660        Parameters:
     1661            scan    : input scantable instance
     1662            colorby : change color by either
     1663                      'type'(source type)|'scan'|'if'|'pol'|'beam'|''
     1664        """
    15901665        self._plotmode = "totalpower"
    15911666        from asap import scantable
     
    16181693            left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp)
    16191694        if self.casabar_exists(): self._plotter.figmgr.casabar.disable_button()
    1620         self._plottp(self._data)
     1695        if len(colorby) == 0:
     1696            self._plottp(self._data)
     1697        else:
     1698            self._plottp_in_time(self._data,colorby)
    16211699        if self._minmaxy is not None:
    16221700            self._plotter.set_limits(ylim=self._minmaxy)
     
    16251703        self._plotter.show(hardrefresh=False)
    16261704        return
     1705
     1706    def _plottp_in_time(self,scan,colorby):
     1707        """
     1708        private method for plotting total power data in time
     1709        Parameters:
     1710            scan    : input scantable instance
     1711            colorby : change color by either
     1712                      'type'(source type)|'scan'|'if'|'pol'|'beam'
     1713        """
     1714        from numpy import ma, array, arange, logical_not
     1715        r=0
     1716        nr = scan.nrow()
     1717        a0,b0 = -1,-1
     1718        allxlim = []
     1719        allylim = []
     1720        y=[]
     1721        self._plotter.set_panels()
     1722        self._plotter.palette(0)
     1723        # check of overlay settings
     1724        time_types = ['type','scan'] # time dependent meta-data
     1725        misc_types = ['if','pol','beam'] # time independent meta-data
     1726        validtypes=time_types + misc_types
     1727        stype = None
     1728        col_msg = "Invalid choice of 'colorby' (choices: %s)" % str(validtypes)
     1729        colorby = colorby.lower()
     1730        if (colorby in validtypes):
     1731            stype = colorby[0]
     1732        elif len(colorby) > 0:
     1733            raise ValueError(col_msg)
     1734        if not stype:
     1735            raise ValueError(col_msg)
     1736        # Selection and sort order
     1737        basesel = scan.get_selection()
     1738        if colorby in misc_types: misc_types.pop(misc_types.index(colorby))
     1739        sel_lbl = ""
     1740        for meta in misc_types:
     1741            idx = getattr(scan,'get'+meta+'nos')()
     1742            if len(idx) > 1: getattr(basesel, 'set_'+meta+'s')([idx[0]])
     1743            sel_lbl += ("%s%d, " % (meta.upper(), idx[0]))
     1744        sel_lbl = sel_lbl.rstrip(', ')
     1745        scan.set_selection(basesel)
     1746        if len(sel_lbl) > 0:
     1747            asaplog.push("Selection contains multiple IFs/Pols/Beams. Plotting the first ones: %s" % sel_lbl)
     1748            asaplog.post("WARN")
     1749        if stype == 't':
     1750            selIds = range(15)
     1751            sellab = "src type "
     1752        else:
     1753            selIds = getattr(scan,'get'+colorby+'nos')()
     1754            sellab = colorby.upper()
     1755        selFunc = "set_"+colorby+"s"
     1756        basesel.set_order(["TIME"])
     1757        # define axes labels
     1758        xlab = self._abcissa or 'Time (UTC)'
     1759        ylab = self._ordinate or scan._get_ordinate_label()
     1760        self._plotter.set_axes('xlabel',xlab)
     1761        self._plotter.set_axes('ylabel',ylab)
     1762        # define the panel title
     1763        if len(sel_lbl) > 0: lbl = sel_lbl
     1764        else: lbl = self._get_label(scan, r, 's', self._title)
     1765        if isinstance(lbl, list) or isinstance(lbl, tuple):
     1766            # get default label
     1767            lbl = self._get_label(scan, r, self._panelling, None)
     1768        self._plotter.set_axes('title',lbl)
     1769        # linestyle
     1770        lstyle = '' if colorby in time_types else ':'
     1771        alldates = []
     1772        for idx in selIds:
     1773            sel = selector() + basesel
     1774            bid = getattr(basesel,'get_'+colorby+"s")()
     1775            if (len(bid) > 0) and (not idx in bid):
     1776                # base selection doesn't contain idx
     1777                # Note summation of selector is logical sum if
     1778                continue
     1779            getattr(sel, selFunc)([idx])
     1780            if not sel.is_empty():
     1781                try:
     1782                    scan.set_selection(sel)
     1783                except RuntimeError, instance:
     1784                    if stype == 't' and str(instance).startswith("Selection contains no data."):
     1785                        continue
     1786                    else:
     1787                        scan.set_selection(basesel)
     1788                        raise RuntimeError, instance
     1789            if scan.nrow() == 0:
     1790                scan.set_selection(basesel)
     1791                continue
     1792            y=array(scan._get_column(scan._getspectrum,-1))
     1793            m = array(scan._get_column(scan._getmask,-1))
     1794            y = ma.masked_array(y,mask=logical_not(array(m,copy=False)))
     1795            # try to handle spectral data somewhat...
     1796            try:
     1797                l,m = y.shape
     1798            except ValueError, e:
     1799                raise ValueError(str(e)+" This error usually occurs when you select multiple spws with different number of channels. Try selecting single spw and retry.")
     1800            if m > 1:
     1801                y=y.mean(axis=1)
     1802            # flag handling
     1803            m = [ scan._is_all_chan_flagged(i) for i in range(scan.nrow()) ]
     1804            y = ma.masked_array(y,mask=m)
     1805            if len(y) == 0: continue
     1806            # line label
     1807            llbl=sellab+str(idx)
     1808            from matplotlib.dates import date2num
     1809            from pytz import timezone
     1810            dates = self._data.get_time(asdatetime=True)
     1811            alldates += list(dates)
     1812            x = date2num(dates)
     1813            tz = timezone('UTC')
     1814            # get color
     1815            lc = self._plotter.colormap[self._plotter.color]
     1816            self._plotter.palette( (self._plotter.color+1) % len(self._plotter.colormap) )
     1817            # actual plotting
     1818            self._plotter.axes.plot_date(x,y,tz=tz,label=llbl,linestyle=lstyle,color=lc,
     1819                                         marker='o',markersize=3,markeredgewidth=0)
     1820
     1821        # legend and axis formatting
     1822        ax = self.gca()
     1823        (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(alldates, ax.get_xlim())
     1824        ax.xaxis.set_major_formatter(timefmt)
     1825        ax.xaxis.set_major_locator(majloc)
     1826        ax.xaxis.set_minor_locator(minloc)
     1827        self._plotter.axes.legend(loc=self._legendloc)
    16271828
    16281829    def _plottp(self,scan):
     
    16611862        x = arange(len(y))
    16621863        # try to handle spectral data somewhat...
    1663         l,m = y.shape
     1864        try:
     1865            l,m = y.shape
     1866        except ValueError, e:
     1867                raise ValueError(str(e)+" This error usually occurs when you select multiple spws with different number of channels. Try selecting single spw and retry.")
    16641868        if m > 1:
    16651869            y=y.mean(axis=1)
     1870        # flag handling
     1871        m = [ scan._is_all_chan_flagged(i) for i in range(scan.nrow()) ]
     1872        y = ma.masked_array(y,mask=m)
    16661873        plotit = self._plotter.plot
    16671874        llbl = self._get_label(scan, r, self._stacking, None)
     
    17011908            selstr += '\n'
    17021909            self._headtext['selstr'] = selstr
    1703         ssel=(selstr+self._data.get_selection().__str__()+self._selection.__str__() or 'none')
    1704         headstr.append('***Selections***\n'+ssel)
     1910        #ssel=(selstr+self._data.get_selection().__str__()+self._selection.__str__() or 'none')
     1911        curr_selstr = selstr+self._data.get_selection().__str__() or "none"
     1912        ssel=(curr_selstr+"\n" +self._selection.__str__())
     1913        headstr.append('\n\n***Selections***\n'+ssel.replace('$','\$'))
    17051914
    17061915        if plot:
     
    17521961    # plot spectra by pointing
    17531962    @asaplog_post_dec
    1754     def plotgrid(self, scan=None,center=None,spacing=None,rows=None,cols=None):
     1963    def plotgrid(self, scan=None,center="",spacing=[],rows=None,cols=None):
    17551964        """
    17561965        Plot spectra based on direction.
     
    17581967        Parameters:
    17591968            scan:      a scantable to plot
    1760             center:    the grid center direction (a list) of plots in the
    1761                        unit of DIRECTION column.
     1969            center:    the grid center direction (a string)
    17621970                       (default) the center of map region
     1971                       (example) 'J2000 19h30m00s -25d00m00s'
    17631972            spacing:   a list of horizontal (R.A.) and vertical (Dec.)
    1764                        spacing in the unit of DIRECTION column.
     1973                       spacing.
    17651974                       (default) Calculated by the extent of map region and
     1975                       (example) ['1arcmin', '1arcmin']
    17661976                       the number of rows and cols to cover
    17671977            rows:      number of panels (grid points) in horizontal direction
     
    17871997
    17881998        # Rows and cols
    1789         if rows:
    1790             self._rows = int(rows)
    1791         else:
    1792             msg = "Number of rows to plot are not specified. "
    1793             if self._rows:
    1794                 msg += "Using previous value = %d" % (self._rows)
    1795                 asaplog.push(msg)
    1796             else:
    1797                 self._rows = 1
    1798                 msg += "Setting rows = %d" % (self._rows)
    1799                 asaplog.post()
    1800                 asaplog.push(msg)
    1801                 asaplog.post("WARN")
    1802         if cols:
    1803             self._cols = int(cols)
    1804         else:
    1805             msg = "Number of cols to plot are not specified. "
    1806             if self._cols:
    1807                 msg += "Using previous value = %d" % (self._cols)
    1808                 asaplog.push(msg)
    1809             else:
    1810                 self._cols = 1
    1811                 msg += "Setting cols = %d" % (self._cols)
    1812                 asaplog.post()
    1813                 asaplog.push(msg)
    1814                 asaplog.post("WARN")
    1815 
    1816         # Center and spacing
    1817         dirarr = array(self._data.get_directionval()).transpose()
    1818         print "Pointing range: (x, y) = (%f - %f, %f - %f)" %\
    1819               (dirarr[0].min(),dirarr[0].max(),dirarr[1].min(),dirarr[1].max())
    1820         dircent = [0.5*(dirarr[0].max() + dirarr[0].min()),
    1821                    0.5*(dirarr[1].max() + dirarr[1].min())]
    1822         del dirarr
    1823         if center is None:
    1824             #asaplog.post()
    1825             asaplog.push("Grid center is not specified. Automatically calculated from pointing center.")
    1826             #asaplog.post("WARN")
    1827             #center = [dirarr[0].mean(), dirarr[1].mean()]
    1828             center = dircent
    1829         elif (type(center) in (list, tuple)) and len(center) > 1:
    1830             from numpy import pi
    1831             # make sure center_x is in +-pi of pointing center
    1832             # (assumes dirs are in rad)
    1833             rotnum = round(abs(center[0] - dircent[0])/(2*pi))
    1834             if center[0] < dircent[0]: rotnum *= -1
    1835             cenx = center[0] - rotnum*2*pi
    1836             center = [cenx, center[1]]
    1837         else:
    1838             msg = "Direction of grid center should be a list of float (R.A., Dec.)"
    1839             raise ValueError, msg
    1840         asaplog.push("Grid center: (%f, %f) " % (center[0],center[1]))
    1841 
    1842         if spacing is None:
    1843             #asaplog.post()
    1844             asaplog.push("Grid spacing not specified. Automatically calculated from map coverage")
    1845             #asaplog.post("WARN")
    1846             # automatically get spacing
    1847             dirarr = array(self._data.get_directionval()).transpose()
    1848             wx = 2. * max(abs(dirarr[0].max()-center[0]),
    1849                           abs(dirarr[0].min()-center[0]))
    1850             wy = 2. * max(abs(dirarr[1].max()-center[1]),
    1851                           abs(dirarr[1].min()-center[1]))
    1852             ## slightly expand area to plot the edges
    1853             #wx *= 1.1
    1854             #wy *= 1.1
    1855             xgrid = wx/max(self._cols-1.,1.)
    1856             #xgrid = wx/float(max(self._cols,1.))
    1857             xgrid *= cos(center[1])
    1858             ygrid = wy/max(self._rows-1.,1.)
    1859             #ygrid = wy/float(max(self._rows,1.))
    1860             # single pointing (identical R.A. and/or Dec. for all spectra.)
    1861             if xgrid == 0:
    1862                 xgrid = 1.
    1863             if ygrid == 0:
    1864                 ygrid = 1.
    1865             # spacing should be negative to transpose plot
    1866             spacing = [- xgrid, - ygrid]
    1867             del dirarr, xgrid, ygrid
    1868         #elif isinstance(spacing, str):
    1869         #    # spacing is a quantity
    1870         elif (type(spacing) in (list, tuple)) and len(spacing) > 1:
    1871             for i in xrange(2):
    1872                 val = spacing[i]
    1873                 if not isinstance(val, float):
    1874                     raise TypeError("spacing should be a list of float")
    1875                 if val > 0.:
    1876                     spacing[i] = -val
    1877             spacing = spacing[0:2]
    1878         else:
    1879             msg = "Invalid spacing."
    1880             raise TypeError(msg)
    1881         asaplog.push("Spacing: (%f, %f) (projected)" % (spacing[0],spacing[1]))
    1882 
     1999        if (self._rows is None):
     2000            rows = max(1, rows)
     2001        if (self._cols is None):
     2002            cols = max(1, cols)
     2003        self.set_layout(rows,cols,False)
     2004
     2005        # Select the first IF, POL, and BEAM for plotting
    18832006        ntotpl = self._rows * self._cols
    18842007        ifs = self._data.getifnos()
     
    19072030            asaplog.push(msg)
    19082031            asaplog.post("WARN")
    1909        
     2032
     2033        # Prepare plotter
    19102034        self._assert_plotter(action="reload")
    19112035        self._plotter.hold()
     
    19232047        from asap._asap import plothelper as plhelper
    19242048        ph = plhelper(self._data)
    1925         ph.set_gridval(self._cols, self._rows, spacing[0], spacing[1],
    1926                           center[0], center[1], epoch="J2000", projname="SIN")
     2049        #ph.set_gridval(self._cols, self._rows, spacing[0], spacing[1],
     2050        #                  center[0], center[1], epoch="J2000", projname="SIN")
     2051        if type(spacing) in (list, tuple, array):
     2052            if len(spacing) == 0:
     2053                spacing = ["", ""]
     2054            elif len(spacing) == 1:
     2055                spacing = [spacing[0], spacing[0]]
     2056        else:
     2057            spacing = [spacing, spacing]
     2058        ph.set_grid(self._cols, self._rows, spacing[0], spacing[1], \
     2059                    center, projname="SIN")
     2060
    19272061        # Actual plot
    19282062        npl = 0
Note: See TracChangeset for help on using the changeset viewer.