Ignore:
Timestamp:
12/01/04 11:29:39 (20 years ago)
Author:
mar637
Message:

version 0.1a

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r102 r113  
    77        The ASAP container for scans
    88    """
    9     def functions(self):
    10         return ['copy','get_scan','summary','rms','set_unit','create_mask']
    11 
     9   
    1210    def __init__(self, filename):
    1311        """
     
    1816                         scantable
    1917        """
     18        self._vb = True
     19        self._p = None
    2020        sdtable.__init__(self, filename)
    21         self._unit = 'channel'
     21
     22    def _verbose(self, *args):
     23        """
     24        Set the verbose level True or False, to indicate if output
     25        should be printed as well as returned.
     26        """
     27        if type(args[0]) is bool:
     28            self._vb = args[0]
     29            return
     30        elif len(args) == 0:
     31            return self._vb
     32
    2233
    2334    def copy(self):
     
    2536        Return a copy of this scantable.
    2637        Parameters:
    27 
     38            none
    2839        Example:
    2940            copiedscan = scan.copy()
    3041        """
    31         sd = sdtable._copy(self)
    32         return scantable(sd)
     42        sd = scantable(sdtable._copy(self))
     43        return sd
     44
    3345    def get_scan(self, scanid=None):
    3446        """
     
    3850            scanid:    a scanno or a source name
    3951        Example:
    40             scan.getscan('323p459')
     52            scan.get_scan('323p459')
    4153            # gets all scans containing the source '323p459'
    4254        """
     
    4557        try:
    4658            if type(scanid) is str:
    47                 s = sdtable.getsource(self,scanid)
     59                s = sdtable._getsource(self,scanid)
    4860                return scantable(s)
    4961            elif type(scanid) is int:
    50                 s = sdtable.getscan(self,scanid)
     62                s = sdtable._getscan(self,scanid)
    5163                return scantable(s)
    5264        except RuntimeError:
     
    8698
    8799    def get_selection(self):
     100        """
     101        Return/print a the current 'cursor' into the Beam/IF/Pol cube.
     102        Parameters:
     103            none
     104        Returns:
     105            a list of values (currentBeam,currentIF,currentPol)
     106        Example:
     107            none
     108        """
    88109        i = self.getbeam()
    89110        j = self.getif()
    90111        k = self.getpol()
    91         out = 'Beam=%d IF=%d Pol=%d '% (i,j,k)
    92         print out
     112        if self._vb:
     113            out = 'Beam=%d IF=%d Pol=%d '% (i,j,k)
     114            print out
    93115        return i,j,k
    94116
     
    105127
    106128        Example:
    107             scan.setuint('channel')
     129            scan.set_unit('channel')
    108130            msk = scan.create_mask([100,200],[500,600])
    109131            scan.rms(mask=m)
     
    124146                        tmp.append(rmsval)
    125147                        out += 'Beam[%d], IF[%d], Pol[%d] = %3.3f\n' % (i,j,k,rmsval)
    126             print out
     148            if self._vb:
     149                print out
    127150            return tmp
    128151
     
    133156            rmsval = _rms(self,mask)
    134157            out = 'Beam[%d], IF[%d], Pol[%d] = %3.3f' % (i,j,k,rmsval)
    135             print out
     158            if self._vb:
     159                print out
    136160            return rmsval
    137161
    138162    def get_tsys(self, all=True):
     163        """
     164        Return the System temperatures.
     165        Parameters:
     166            all:    optional parameter to get the Tsys values for all
     167                    Beams/IFs/Pols (default) or just the one selected
     168                    with scantable.set_selection()
     169                    [True or False]
     170        Returns:
     171            a list of Tsys values.
     172        """
    139173        if all:
    140174            tmp = []
     
    146180                    for k in range(self.npol()):
    147181                        self.setpol(k)
    148                         ts = self.gettsys()
     182                        ts = self._gettsys()
    149183                        tmp.append(ts)
    150184                        out += 'TSys: Beam[%d], IF[%d], Pol[%d] = %3.3f\n' % (i,j,k,ts)
    151             print out
     185            if self._vb:
     186                print out
    152187            return tmp
    153188        else:
     
    155190            j = self.getif()
    156191            k = self.getpol()
    157             ts = self.gettsys()
     192            ts = self._gettsys()
    158193            out = 'TSys: Beam[%d], IF[%d], Pol[%d] = %3.3f' % (i,j,k,ts)
    159             print out
     194            if self._vb:
     195                print out
    160196            return ts
     197       
     198    def get_time(self):
     199        """
     200        Get a list of time stamps for the observations.
     201        Return a string for each intergration in the scantable.
     202        Parameters:
     203            none
     204        Example:
     205            none
     206        """
     207        out = []
     208        for i in range(self.nrow()):
     209            out.append(self._gettime(i))
     210        return out
    161211
    162212    def set_unit(self, unit='channel'):
     
    165215        Parameters:
    166216            unit:    optional unit, default is 'channel'
    167                      one of 'GHz','MHz','km/s','channel'
    168         """
    169         units = ['GHz','MHz','km/s','channel','pixel','']
    170         if unit in units:
    171             if unit in ['','pixel']:
    172                 unit = 'channel'
    173             self._unit = unit
     217                     one of '*Hz','km/s','channel', ''
     218        """
     219
     220        if unit in ['','pixel', 'channel']:
     221            unit = ''
     222        inf = list(self._getcoordinfo())
     223        inf[0] = unit
     224        self._setcoordinfo(inf)
     225        if self._p: self.plot()
     226
     227    def set_freqframe(self, frame='LSRK'):
     228        """
     229        Set the frame type of the Spectral Axis.
     230        Parameters:
     231            frame:   an optional frame type, default 'LSRK'.
     232        Examples:
     233            scan.set_freqframe('BARY')
     234        """
     235        valid = ['REST','TOPO','LSRD','LSRK','BARY', \
     236                   'GEO','GALACTO','LGROUP','CMB']
     237        if frame in valid:
     238            inf = list(self._getcoordinfo())
     239            inf[1] = frame
     240            self._setcoordinfo(inf)
    174241        else:
    175             print "Invalid unit given, please use one of:"
    176             print units
    177 
    178     def create_mask(self, *args):
     242            print "Please specify a valid freq type. Valid types are:\n",valid
     243           
     244    def get_unit(self):
     245        """
     246        Get the default unit set in this scantable
     247        Parameters:
     248        Returns:
     249            A unit string
     250        """
     251        inf = self._getcoordinfo()
     252        unit = inf[0]
     253        if unit == '': unit = 'channel'
     254        return unit
     255
     256    def get_abscissa(self, rowno=0):
     257        """
     258        Get the abscissa in the current coordinate setup for the currently
     259        selected Beam/IF/Pol
     260        Parameters:
     261            none
     262        Returns:
     263            The abscissa values and it's format string.
     264        """
     265        absc = self.getabscissa(rowno)
     266        lbl = self.getabscissalabel(rowno)
     267        return absc, lbl
     268
     269    def create_mask(self, *args, **kwargs):
    179270        """
    180271        Compute and return a mask based on [min,max] windows.
     272        The specified windows are to be EXCLUDED, when the mask is
     273        applied.
    181274        Parameters:
    182275            [min,max],[min2,max2],...
    183276                Pairs of start/end points specifying the regions
    184277                to be masked
    185         Example:
    186             scan.setunit('channel')
     278            invert:     return an inverted mask, i.e. the regions
     279                        specified are not masked (INCLUDED)
     280        Example:
     281            scan.set_unit('channel')
     282
     283            a)
    187284            msk = scan.set_mask([400,500],[800,900])
    188             masks the regions between 400 and 500
    189             and 800 and 900 in the unit 'channel'
    190         """
    191         print "The current mask window unit is", self._unit
     285            # masks the regions between 400 and 500
     286            # and 800 and 900 in the unit 'channel'
     287
     288            b)
     289            msk = scan.set_mask([400,500],[800,900], invert=True)
     290            # masks the regions outside 400 and 500
     291            # and 800 and 900 in the unit 'channel'
     292           
     293        """
     294        u = self._getcoordinfo()[0]
     295        if self._vb:
     296            if u == "": u = "channel"
     297            print "The current mask window unit is", u
    192298        n = self.nchan()
    193         if self._unit == 'channel':
    194             data = range(n)
    195         else:
    196             data = self.getabscissa(unit=self._unit)
     299        data = self.getabscissa()
    197300        msk = ones(n)
    198301        for  window in args:
     
    201304                return
    202305            for i in range(n):
    203                 if data[i] > window[0] and data[i] < window[1]:
     306                if data[i] >= window[0] and data[i] < window[1]:
    204307                    msk[i] = 0
     308        if kwargs.has_key('invert'):
     309            if kwargs.get('invert'):
     310                from numarray import logical_not
     311                msk = logical_not(msk)
    205312        return msk
    206     def set_restfrequencies(self, freqs, unit='Hz'):
     313   
     314    def set_restfreqs(self, freqs, unit='Hz'):
    207315        """
    208316        Set the restfrequency(s) for this scantable.
     
    211319            unit:     optional 'unit', default 'Hz'
    212320        Example:
    213             scan.set_restfrequencies([1000000000.0])
    214         """
    215         self.setrestfreqs(freqs, unit)
     321            scan.set_restfreqs([1000000000.0])
     322        """
     323        if type(freqs) is float or int:
     324            freqs = (freqs)
     325        sdtable._setrestfreqs(self,freqs, unit)
    216326        return
    217327
     
    236346            print "Please specify a valid (Beam/IF/Pol)"
    237347        return
     348
     349    def plot(self, what='spectrum',col='Pol', panel=None):
     350        """
     351        Plot the spectra contained in the scan. Alternatively you can also
     352        Plot Tsys vs Time
     353        Parameters:
     354            what:     a choice of 'spectrum' (default) or 'tsys'
     355            col:      which out of Beams/IFs/Pols should be colour stacked
     356            panel:    set up multiple panels, currently not working.
     357        """
     358        validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()}
     359        validyax = ['spectrum','tsys']
     360        if not self._p:
     361            from asap.asaplot import ASAPlot
     362            self._p = ASAPlot()
     363#            print "Plotting not enabled"
     364#            return
     365        npan = 1
     366        x = None
     367        if what == 'tsys':
     368            n = self.nrow()
     369            if n < 2:
     370                print "Only one integration. Can't plot."
     371                return
     372        if panel == 'Time':
     373            npan = self.nrow()
     374        self._p.hold()
     375        self._p.clear()
     376        xlab,ylab,tlab = None,None,None
     377        vb = self._verbose
     378        self._verbose(False)
     379        sel = self.get_selection()
     380        for i in range(npan):
     381            for j in range(validcol[col]):
     382                x = None
     383                y = None
     384                m = None
     385                tlab = self._getsourcename(i)
     386                if col == 'Beam':
     387                    self.setbeam(j)
     388                elif col == 'IF':
     389                    self.setif(j)
     390                elif col == 'Pol':
     391                    self.setpol(j)
     392                if what == 'tsys':
     393                    x = range(self.nrow())
     394                    xlab = 'Time [pixel]'
     395                    m = list(ones(len(x)))
     396                    y = []
     397                    ylab = r'$T_{sys}$'
     398                    for k in range(len(x)):
     399                        y.append(self._gettsys(k))
     400                else:
     401                    x,xlab = self.get_abscissa(i)
     402                    y = self.getspectrum(i)
     403                    ylab = r'Flux'
     404                    m = self.getmask(i)
     405                llab = col+' '+str(j)
     406                self._p.set_line(label=llab)
     407                self._p.plot(x,y,m)
     408        self._p.set_axes('xlabel',xlab)
     409        self._p.set_axes('ylabel',ylab)
     410        self._p.set_axes('title',tlab)
     411        self._p.release()
     412        self.set_selection(sel[0],sel[1],sel[2])
     413        self._verbose(vb)
     414        return
Note: See TracChangeset for help on using the changeset viewer.