Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r3038 r2704  
    112112        self._plotter.legend(self._legendloc)
    113113
    114     ### TODO: it's probably better to define following two methods in
    115     ###       backend dependent class.
    116114    def _new_custombar(self):
    117115        backend=matplotlib.get_backend()
     
    132130            return True
    133131        return False
    134     ### end of TODO
    135132
    136133    def _assert_plotter(self,action="status",errmsg=None):
     
    279276
    280277
    281     ### Forwards to methods in matplotlib axes ###
     278    ### Forwards to matplotlib axes ###
    282279    def text(self, *args, **kwargs):
    283280        self._assert_plotter(action="reload")
     
    418415                del self._data
    419416                msg = "A new scantable is set to the plotter. "\
    420                       "The masks, data selections, and labels are reset."
    421                 asaplog.push(msg)
     417                      "The masks and data selections are reset."
     418                asaplog.push( msg )
    422419            self._data = scan
    423420            # reset
     
    517514        self._rows = rows
    518515        self._cols = cols
    519         # new layout is set. need to reset counters for multi page plotting
    520         self._reset_counters()
    521516        if refresh and self._data: self.plot(self._data)
    522517        return
     
    910905            msg = "Can only set mask after a first call to plot()"
    911906            raise RuntimeError(msg)
    912         if (mask is not None) and len(mask):
     907        if len(mask):
    913908            if isinstance(mask, list) or isinstance(mask, tuple):
    914909                self._usermask = array(mask)
     
    931926    ### Reset methods ###
    932927    def _reset(self):
    933         """Reset method called when new data is set"""
    934         # reset selections and masks
     928        self._usermask = []
     929        self._usermaskspectra = None
     930        self._offset = None
    935931        self.set_selection(None, False)
    936         self.set_mask(None, None, False)
    937         # reset offset
    938         self._offset = None
    939         # reset header
    940932        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)
    946933
    947934    def _reset_header(self):
     
    951938        self._startrow = 0
    952939        self._ipanel = -1
     940        self._reset_header()
    953941        self._panelrows = []
    954         self._reset_header()
    955942        if self.casabar_exists():
    956943            self._plotter.figmgr.casabar.set_pagecounter(1)
     
    10441031        if self._panelling == 'i':
    10451032            ganged = False
    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
     1033        if not firstpage:
     1034            # not the first page just clear the axis
    10501035            nx = self._plotter.cols
    10511036            ipaxx = n - nx - 1 #the max panel id to supress x-label
     
    13171302            return start,end
    13181303
    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 
    13731304    def plotazel(self, scan=None, outfile=None):
    13741305        """
     
    13781309        visible = rcParams['plotter.gui']
    13791310        from matplotlib import pylab as PL
     1311        from matplotlib.dates import DateFormatter
    13801312        from pytz import timezone
     1313        from matplotlib.dates import HourLocator, MinuteLocator,SecondLocator, DayLocator
    13811314        from matplotlib.ticker import MultipleLocator
    1382         from numpy import array, pi, ma
     1315        from numpy import array, pi
    13831316        if self._plotter and (PL.gcf() == self._plotter.figure):
    13841317            # the current figure is ASAP plotter. Use mpl plotter
     
    13921325        self._data = scan
    13931326        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())]
    13961327        t = PL.date2num(dates)
    13971328        tz = timezone('UTC')
     
    14061337                                 wspace=wsp,hspace=hsp)
    14071338
    1408         tdel = max(t) - min(t) # interval in day
     1339        tdel = max(t) - min(t)
    14091340        ax = PL.subplot(2,1,1)
    1410         el = ma.masked_array(array(self._data.get_elevation())*180./pi, mask)
     1341        el = array(self._data.get_elevation())*180./pi
    14111342        PL.ylabel('El [deg.]')
    1412         (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(dates)
    1413        
     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
    14141359        PL.title(dstr)
    14151360        if tdel == 0.0:
     
    14181363        else:
    14191364            PL.plot_date(t,el,'o', markersize=2, markerfacecolor='b', markeredgecolor='b',tz=tz)
    1420             #ax.xaxis.set_major_formatter(timefmt)
    1421             #ax.xaxis.set_major_locator(majloc)
    1422             #ax.xaxis.set_minor_locator(minloc)
     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)
    14231369        ax.yaxis.grid(True)
     1370        yloc = MultipleLocator(30)
    14241371        ax.set_ylim(0,90)
    1425         #yloc = MultipleLocator(30)
    1426         #ax.yaxis.set_major_locator(yloc)
     1372        ax.yaxis.set_major_locator(yloc)
    14271373        if tdel > 1.0:
    14281374            labels = ax.get_xticklabels()
     
    14311377
    14321378        # Az plot
    1433         az = ma.masked_array(array(self._data.get_azimuth())*180./pi, mask)
     1379        az = array(self._data.get_azimuth())*180./pi
    14341380        if min(az) < 0:
    14351381            for irow in range(len(az)):
     
    14431389        else:
    14441390            PL.plot_date(t,az,'o', markersize=2,markeredgecolor='b',markerfacecolor='b',tz=tz)
    1445             #ax2.xaxis.set_major_formatter(timefmt)
    1446             #ax2.xaxis.set_major_locator(majloc)
    1447             #ax2.xaxis.set_minor_locator(minloc)
     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)
    14481395        ax2.set_ylim(0,360)
    14491396        ax2.yaxis.grid(True)
    14501397        #hfmt = DateFormatter('%H')
    14511398        #hloc = HourLocator()
    1452         #yloc = MultipleLocator(60)
    1453         #ax2.yaxis.set_major_locator(yloc)
     1399        yloc = MultipleLocator(60)
     1400        ax2.yaxis.set_major_locator(yloc)
    14541401        if tdel > 1.0:
    14551402            labels = ax2.get_xticklabels()
    14561403            PL.setp(labels, fontsize=10)
    1457         #    PL.xlabel('Time (UT [day])')
    1458         #else:
    1459         #    PL.xlabel('Time (UT [hour])')
    1460         PL.xlabel('Time (UT)')
     1404            PL.xlabel('Time (UT [day])')
     1405        else:
     1406            PL.xlabel('Time (UT [hour])')
    14611407
    14621408        PL.ion()
     
    14711417        plot telescope pointings
    14721418        Parameters:
    1473             scan    : input scantable instance
     1419            infile  : input filename or scantable instance
    14741420            colorby : change color by either
    14751421                      'type'(source type)|'scan'|'if'|'pol'|'beam'
     
    14791425        """
    14801426        self._plotmode = "pointing"
    1481         from numpy import array, pi, ma
     1427        from numpy import array, pi
    14821428        from asap import scantable
    14831429        # check for scantable
     
    15551501                self._data.set_selection(basesel)
    15561502                continue
    1557             #print "Plotting direction of %s = %s" % (colorby, str(idx))
     1503            print "Plotting direction of %s = %s" % (colorby, str(idx))
    15581504            # getting data to plot
    15591505            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())]
    15621506            ra = dir[0]*180./pi
    1563             dec = ma.masked_array(dir[1]*180./pi, mask)
     1507            dec = dir[1]*180./pi
    15641508            # actual plot
    15651509            self._plotter.set_line(label=(sellab+str(idx)))
     
    15871531        # reverse x-axis
    15881532        xmin, xmax = self.gca().get_xlim()
    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])
     1533        self._plotter.set_limits(xlim=[xmax,xmin])
    16021534
    16031535        self._plotter.release()
     
    16551587    # plotting in time is not yet implemented..
    16561588    @asaplog_post_dec
    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         """
     1589    def plottp(self, scan=None):
    16651590        self._plotmode = "totalpower"
    16661591        from asap import scantable
     
    16931618            left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp)
    16941619        if self.casabar_exists(): self._plotter.figmgr.casabar.disable_button()
    1695         if len(colorby) == 0:
    1696             self._plottp(self._data)
    1697         else:
    1698             self._plottp_in_time(self._data,colorby)
     1620        self._plottp(self._data)
    16991621        if self._minmaxy is not None:
    17001622            self._plotter.set_limits(ylim=self._minmaxy)
     
    17031625        self._plotter.show(hardrefresh=False)
    17041626        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)
    18281627
    18291628    def _plottp(self,scan):
     
    18621661        x = arange(len(y))
    18631662        # try to handle spectral data somewhat...
    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.")
     1663        l,m = y.shape
    18681664        if m > 1:
    18691665            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)
    18731666        plotit = self._plotter.plot
    18741667        llbl = self._get_label(scan, r, self._stacking, None)
     
    19081701            selstr += '\n'
    19091702            self._headtext['selstr'] = selstr
    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('$','\$'))
     1703        ssel=(selstr+self._data.get_selection().__str__()+self._selection.__str__() or 'none')
     1704        headstr.append('***Selections***\n'+ssel)
    19141705
    19151706        if plot:
     
    19611752    # plot spectra by pointing
    19621753    @asaplog_post_dec
    1963     def plotgrid(self, scan=None,center="",spacing=[],rows=None,cols=None):
     1754    def plotgrid(self, scan=None,center=None,spacing=None,rows=None,cols=None):
    19641755        """
    19651756        Plot spectra based on direction.
     
    19671758        Parameters:
    19681759            scan:      a scantable to plot
    1969             center:    the grid center direction (a string)
     1760            center:    the grid center direction (a list) of plots in the
     1761                       unit of DIRECTION column.
    19701762                       (default) the center of map region
    1971                        (example) 'J2000 19h30m00s -25d00m00s'
    19721763            spacing:   a list of horizontal (R.A.) and vertical (Dec.)
    1973                        spacing.
     1764                       spacing in the unit of DIRECTION column.
    19741765                       (default) Calculated by the extent of map region and
    1975                        (example) ['1arcmin', '1arcmin']
    19761766                       the number of rows and cols to cover
    19771767            rows:      number of panels (grid points) in horizontal direction
     
    19971787
    19981788        # Rows and cols
    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
     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
    20061883        ntotpl = self._rows * self._cols
    20071884        ifs = self._data.getifnos()
     
    20301907            asaplog.push(msg)
    20311908            asaplog.post("WARN")
    2032 
    2033         # Prepare plotter
     1909       
    20341910        self._assert_plotter(action="reload")
    20351911        self._plotter.hold()
     
    20471923        from asap._asap import plothelper as plhelper
    20481924        ph = plhelper(self._data)
    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 
     1925        ph.set_gridval(self._cols, self._rows, spacing[0], spacing[1],
     1926                          center[0], center[1], epoch="J2000", projname="SIN")
    20611927        # Actual plot
    20621928        npl = 0
Note: See TracChangeset for help on using the changeset viewer.