Ignore:
Timestamp:
01/19/05 18:24:16 (19 years ago)
Author:
mar637
Message:

added rcParams to support rc style default parameters, read from .asaprc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r200 r226  
    11from asap._asap import sdtable
     2from asap import rcParams
    23from numarray import ones,zeros
    34import sys
     
    2122                         scantable
    2223        """
    23         self._vb = True
     24        self._vb = rcParams['verbose']
    2425        self._p = None
    2526        from os import stat as st
     
    2829            sdtable.__init__(self, filename)           
    2930        else:
    30             mode = st(filename)[stat.ST_MODE]
     31            try:
     32                mode = st(filename)[stat.ST_MODE]
     33            except OSError:
     34                print "File not found"
     35                return
    3136            if stat.S_ISDIR(mode):
    3237                # crude check if asap table
     
    3540                else:
    3641                    print 'The given file is not a valid asap table'
    37             else:           
     42                    return
     43            else:
     44                autoav = rcParams['scantable.autoaverage']
     45
    3846                from asap._asap import sdreader
    3947                r = sdreader(filename)
     
    4149                r.read([-1])
    4250                tbl = r.getdata()
    43                
    44                 from asap._asap import average
    45                 tmp = tuple([tbl])
    46                 print 'Auto averging integrations...'
    47                 tbl2 = average(tmp,(),True,'none')
    48                 sdtable.__init__(self,tbl2)
    49                 del r,tbl
    50 
    51     def save(self, name="", format='ASAP'):
     51                if autoav:
     52                    from asap._asap import average
     53                    tmp = tuple([tbl])
     54                    print 'Auto averaging integrations...'
     55                    tbl2 = average(tmp,(),True,'none')
     56                    sdtable.__init__(self,tbl2)
     57                    del r,tbl
     58                else:
     59                    sdtable.__init__(self,tbl)
     60
     61    def save(self, name="", format=None):
    5262        """
    5363        Store the scantable on disk. This can be a asap file or SDFITS/MS2.
     
    6070                                       'FITS' (saves each row as a FITS Image)
    6171                                       'ASCII' (saves as ascii text file)
    62                                        'MS2' (saves as an aips++ MeasurementSet V2)
     72                                       'MS2' (saves as an aips++
     73                                              MeasurementSet V2)
    6374        Example:
    6475            scan.save('myscan.asap')
    6576            scan.save('myscan.sdfits','SDFITS')
    6677        """
     78        if format is None: format = rcParams['scantable.save']
    6779        if format == 'ASAP':
    6880            self._save(name)
     
    7284            w.write(self, name)
    7385        return
    74 
    75     def _verbose(self, *args):
    76         """
    77         Set the verbose level True or False, to indicate if output
    78         should be printed as well as returned.
    79         """
    80         if len(args) == 0:
    81             return self._vb
    82         elif type(args[0]) is bool:
    83             self._vb = args[0]
    84             return
    8586
    8687    def copy(self):
     
    166167            print " Cursor selection"
    167168            print "--------------------------------------------------"
    168             out = 'Beam=%d IF=%d Pol=%d '% (i,j,k)
     169            out = 'Beam=%d IF=%d Pol=%d ' % (i,j,k)
    169170            print out
    170171        return i,j,k
    171172
    172     def stats(self, stat='stddev', mask=None, all=True):
     173    def stats(self, stat='stddev', mask=None, all=None):
    173174        """
    174175        Determine the specified statistic of the current beam/if/pol
     
    180181            mask:    an optional mask specifying where the statistic
    181182                     should be determined.
    182             all:     optional flag to show all (default) or a selected
    183                      spectrum of Beam/IF/Pol
     183            all:     optional flag to show all (default or .asaprc) or a
     184                     cursor selected spectrum of Beam/IF/Pol
    184185
    185186        Example:
     
    188189            scan.stats(stat='mean', mask=m)
    189190        """
     191        if all is None: all = rcParams['scantable.allaxes']
    190192        from asap._asap import stats as _stats
    191193        if mask == None:
     
    210212                            out += '= %3.3f\n' % (statval[l])
    211213                out += "--------------------------------------------------\n"
    212 
    213214            if self._vb:
    214215                print "--------------------------------------------------"
     
    232233                out += '= %3.3f\n' % (statval[l])
    233234                out +=  "--------------------------------------------------\n"
     235
    234236            if self._vb:
    235237                print "--------------------------------------------------"
     
    239241            return statval
    240242
    241     def stddev(self,mask=None, all=True):
     243    def stddev(self,mask=None, all=None):
    242244        """
    243245        Determine the standard deviation of the current beam/if/pol
     
    247249            mask:    an optional mask specifying where the standard
    248250                     deviation should be determined.
    249             all:     optional flag to show all or a selected
    250                      spectrum of Beam/IF/Pol
     251            all:     optional flag to show all or a cursor selected
     252                     spectrum of Beam/IF/Pol. Default is all or taken
     253                     from .asaprc
    251254
    252255        Example:
     
    255258            scan.stddev(mask=m)
    256259        """
     260        if all is None: all = rcParams['scantable.allaxes']
    257261        return self.stats(stat='stddev',mask=mask, all=all);
    258262
    259     def get_tsys(self, all=True):
     263    def get_tsys(self, all=None):
    260264        """
    261265        Return the System temperatures.
     
    268272            a list of Tsys values.
    269273        """
     274        if all is None: all = rcParams['scantable.allaxes']
    270275        if all:
    271276            out = ''
     
    287292                            out += '= %3.3f\n' % (ts[l])
    288293                out+= "--------------------------------------------------\n"
    289 
    290294            if self._vb:
    291295                print "--------------------------------------------------"
     
    308312                out += '= %3.3f\n' % (ts[l])
    309313                out += "--------------------------------------------------\n"
    310 
    311314            if self._vb:
    312315                print "--------------------------------------------------"
     
    345348        if self._p: self.plot()
    346349
    347     def set_freqframe(self, frame='LSRK'):
     350    def set_freqframe(self, frame=None):
    348351        """
    349352        Set the frame type of the Spectral Axis.
     
    353356            scan.set_freqframe('BARY')
    354357        """
     358        if not frame: frame = rcParams['scantable.freqframe']
    355359        valid = ['REST','TOPO','LSRD','LSRK','BARY', \
    356360                   'GEO','GALACTO','LGROUP','CMB']
     
    379383        selected Beam/IF/Pol
    380384        Parameters:
    381             none
     385            rowno:    an optional row number in the scantable. Default is the
     386                      first row, i.e. rowno=0
    382387        Returns:
    383388            The abcissa values and it's format string.
     
    501506            self._p.set_panels(rows=npan)
    502507        xlab,ylab,tlab = None,None,None
    503         vb = self._verbose()
    504         self._verbose(False)
    505         sel = self.get_selection()
     508        self._vb = False
     509        sel = self.get_selection()       
    506510        for i in range(npan):
    507             self._p.subplot(i)
     511            if npan > 1:
     512                self._p.subplot(i)
    508513            for j in range(validcol[col]):
    509514                x = None
     
    540545        self._p.release()
    541546        self.set_selection(sel[0],sel[1],sel[2])
    542         self._verbose(vb)
     547        self._vb = rcParams['verbose']
    543548        return
Note: See TracChangeset for help on using the changeset viewer.