Ignore:
Timestamp:
11/11/05 10:01:49 (19 years ago)
Author:
mar637
Message:

create_mask now also handles args[0]=list. auto_quotient checks for conformance between # of ons and offs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r670 r710  
    88        The ASAP container for scans
    99    """
    10    
     10
    1111    def __init__(self, filename, average=None, unit=None):
    1212        """
     
    2727                         (input rpfits/sdfits/ms) or replaces the value
    2828                         in existing scantables
    29         """       
     29        """
    3030        if average is None or type(average) is not bool:
    31             average = rcParams['scantable.autoaverage']           
     31            average = rcParams['scantable.autoaverage']
    3232
    3333        varlist = vars()
    3434        self._vb = rcParams['verbose']
    3535        self._p = None
    36 
     36        from asap import asaplog
    3737        if isinstance(filename,sdtable):
    38             sdtable.__init__(self, filename)           
     38            sdtable.__init__(self, filename)
    3939            if unit is not None:
    40                 self.set_fluxunit(unit)                       
     40                self.set_fluxunit(unit)
    4141        else:
    4242            import os.path
    4343            if not os.path.exists(filename):
    44                 print "File '%s' not found." % (filename)
    45                 return
     44                s = "File '%s' not found." % (filename)
     45                if rcParams['verbose']:
     46                    asaplog.push(s)
     47                    print asaplog.pop().strip()
     48                    return
     49                raise IOError(s)
    4650            filename = os.path.expandvars(filename)
    4751            if os.path.isdir(filename):
     
    5054                    sdtable.__init__(self, filename)
    5155                    if unit is not None:
    52                         self.set_fluxunit(unit)                       
     56                        self.set_fluxunit(unit)
    5357                else:
    5458                    print "The given file '%s'is not a valid asap table." % (filename)
    5559                    return
    56             else:           
     60            else:
    5761                from asap._asap import sdreader
    5862                ifSel = -1
    5963                beamSel = -1
    60                 r = sdreader(filename,ifSel,beamSel)
    61                 print 'Importing data...'
     64                r = sdreader()
     65                r._setlog(asaplog)
     66                r._open(filename,ifSel,beamSel)
     67                asaplog.push('Importing data...')
    6268                r._read([-1])
    6369                tbl = r._getdata()
     
    6672                if average:
    6773                    from asap._asap import average as _av
    68                     print 'Auto averaging integrations...'
     74                    asaplog.push('Auto averaging integrations...')
    6975                    tbl2 = _av((tbl,),(),True,'none')
    7076                    sdtable.__init__(self,tbl2)
     
    7480                del r,tbl
    7581                self._add_history("scantable", varlist)
     82                log = asaplog.pop()
     83                if len(log): print log
    7684
    7785    def save(self, name=None, format=None, stokes=False, overwrite=False):
    7886        """
    79         Store the scantable on disk. This can be an asap (aips++) Table, SDFITS, 
     87        Store the scantable on disk. This can be an asap (aips++) Table, SDFITS,
    8088        Image FITS or MS2 format.
    8189        Parameters:
     
    8896                         Allowed are - 'ASAP' (save as ASAP [aips++] Table),
    8997                                       'SDFITS' (save as SDFITS file)
    90                                        'FITS' (saves each row as a FITS Image) 
     98                                       'FITS' (saves each row as a FITS Image)
    9199                                       'ASCII' (saves as ascii text file)
    92100                                       'MS2' (saves as an aips++
     
    192200                print "Illegal file name '%s'." % (filename)
    193201        print info
    194            
     202
    195203    def set_cursor(self, beam=0, IF=0, pol=0):
    196204        """
     
    370378            retval = {'axes': axes, 'data': array(statval), 'cursor':(i,j,k)}
    371379            return retval
    372        
     380
    373381    def get_time(self, row=-1):
    374382        """
     
    409417        Set the instrument for subsequent processing
    410418        Parameters:
    411             instr:    Select from 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 
     419            instr:    Select from 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA',
    412420                      'DSS-43' (Tid), 'CEDUNA', and 'HOBART'
    413421        """
     
    427435        if self._p: self.plot()
    428436        self._add_history("set_doppler",vars())
    429  
     437
    430438    def set_freqframe(self, frame=None):
    431439        """
     
    450458        else:
    451459            print "Please specify a valid freq type. Valid types are:\n",valid
    452            
     460
    453461    def get_unit(self):
    454462        """
     
    474482        """
    475483        abc = self._getabcissa(rowno)
    476         lbl = self._getabcissalabel(rowno)       
     484        lbl = self._getabcissalabel(rowno)
    477485        return abc, lbl
    478486        #return {'abcissa':abc,'label':lbl}
     
    505513            # masks the regions between 400 and 500
    506514            # and 800 and 900 in the unit 'channel'
    507            
     515
    508516        """
    509517        row = 0
     
    517525        n = self.nchan()
    518526        msk = zeros(n)
    519         for window in args:
     527        # test if args is a 'list' or a 'normal *args - UGLY!!!
     528
     529        ws = (isinstance(args[-1][-1],int) or isinstance(args[-1][-1],float)) and args or args[0]
     530        print ws
     531        for window in ws:
     532            print window
    520533            if (len(window) != 2 or window[0] > window[1] ):
    521534                print "A window needs to be defined as [min,max]"
     
    527540            if kwargs.get('invert'):
    528541                from numarray import logical_not
    529                 msk = logical_not(msk)           
     542                msk = logical_not(msk)
    530543        return msk
    531    
     544
    532545    def get_restfreqs(self):
    533546        """
     
    558571        a vector, then it MUST be of length the number of IFs
    559572        (and the available restfrequencies will be replaced by
    560         this vector).  In this case, *all* data ('source' and 
    561         'theif' are ignored) have the restfrequency set per IF according 
    562         to the corresponding value you give in the 'freqs' vector. 
    563         E.g. 'freqs=[1e9,2e9]'  would mean IF 0 gets restfreq 1e9 and 
     573        this vector).  In this case, *all* data ('source' and
     574        'theif' are ignored) have the restfrequency set per IF according
     575        to the corresponding value you give in the 'freqs' vector.
     576        E.g. 'freqs=[1e9,2e9]'  would mean IF 0 gets restfreq 1e9 and
    564577        IF 1 gets restfreq 2e9.
    565578
     
    596609        sdtable._setrestfreqs(self, freqs, unit, lines, source, theif)
    597610        self._add_history("set_restfreqs", varlist)
    598        
     611
    599612
    600613
     
    633646        """
    634647        print "Warning! Not fully functional. Use plotter.plot() instead"
    635        
     648
    636649        validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()}
    637650
     
    659672        xlab,ylab,tlab = None,None,None
    660673        self._vb = False
    661         sel = self.get_cursor()       
     674        sel = self.get_cursor()
    662675        for i in range(npan):
    663676            if npan > 1:
     
    700713        return
    701714
    702         print out 
     715        print out
    703716
    704717    def _print_values(self, dat, label='', timestamps=[]):
     
    722735        print " ", label
    723736        print "-"*80
    724         print out 
     737        print out
    725738
    726739    def history(self):
     
    735748                func = items[1]
    736749                items = items[2:]
    737                 print date           
     750                print date
    738751                print "Function: %s\n  Parameters:" % (func)
    739752                for i in items:
     
    765778        Example:
    766779            # time average the scantable without using a mask
    767             newscan = scan.average_time()           
     780            newscan = scan.average_time()
    768781        """
    769782        varlist = vars()
    770783        if weight is None: weight = 'tint'
    771784        if mask is None: mask = ()
    772         from asap._asap import average as _av       
     785        from asap._asap import average as _av
    773786        s = scantable(_av((self,), mask, scanav, weight))
    774787        s._add_history("average_time",varlist)
    775788        return s
    776        
     789
    777790    def convert_flux(self, jyperk=None, eta=None, d=None, insitu=None,
    778791                     allaxes=None):
     
    873886            self._add_history("gain_el", varlist)
    874887            return
    875    
     888
    876889    def freq_align(self, reftime=None, method='cubic', perif=False,
    877890                   insitu=None):
     
    957970            return
    958971
    959    
     972
    960973    def resample(self, width=5, method='cubic', insitu=None):
    961974        """
     
    11111124        from asap.asaplinefind import linefinder
    11121125        from asap import _is_sequence_or_number as _is_valid
    1113        
     1126
    11141127        if not _is_valid(edge, int):
    11151128            raise RuntimeError, "Parameter 'edge' has to be an integer or a \
    11161129            pair of integers specified as a tuple"
    1117        
     1130
    11181131        # setup fitter
    11191132        f = fitter()
     
    11611174    def rotate_linpolphase(self, angle, allaxes=None):
    11621175        """
    1163         Rotate the phase of the complex polarization O=Q+iU correlation. 
    1164         This is always done in situ in the raw data.  So if you call this 
     1176        Rotate the phase of the complex polarization O=Q+iU correlation.
     1177        This is always done in situ in the raw data.  So if you call this
    11651178        function more than once then each call rotates the phase further.
    11661179        Parameters:
     
    11781191        self._add_history("rotate_linpolphase", varlist)
    11791192        return
    1180    
     1193
    11811194
    11821195    def rotate_xyphase(self, angle, allaxes=None):
     
    12661279                            trailing '_R' (Mopra/Parkes) or
    12671280                            '_e'/'_w' (Tid)
    1268             preserve:       you can preserve (default) the continuum or 
    1269                             remove it.  The equations used are 
     1281            preserve:       you can preserve (default) the continuum or
     1282                            remove it.  The equations used are
    12701283                            preserve: Output = Toff * (on/off) - Toff
    12711284                            remove:   Output = Tref * (on/off) - Ton
     
    12801293            srcs = self.get_scan("*[^_ewR]")
    12811294            refs = self.get_scan("*[_ewR]")
    1282             return scantable(_quot(srcs,refs, preserve))       
     1295            if isinstance(srcs,scantable) and isinstance(refs,scantable):
     1296                ns,nr = srcs.nrow(),refs.nrow()
     1297                if nr > ns:
     1298                    refs = refs.get_scan(range(ns))
     1299                return scantable(_quot(srcs,refs, preserve))
     1300            else:
     1301                raise RuntimeError("Couldn't find any on/off pairs")
    12831302        else:
    12841303            print "not yet implemented"
    12851304            return None
    1286        
     1305
    12871306    def quotient(self, other, isreference=True, preserve=True):
    12881307        """
     
    12961315            isreference:    if the 'other' scan is the reference (default)
    12971316                            or source
    1298             preserve:       you can preserve (default) the continuum or 
    1299                             remove it.  The equations used are 
     1317            preserve:       you can preserve (default) the continuum or
     1318                            remove it.  The equations used are
    13001319                            preserve: Output = Toff * (on/off) - Toff
    13011320                            remove:   Output = Tref * (on/off) - Ton
     
    13161335        s = None
    13171336        if isinstance(other, scantable):
    1318             from asap._asap import b_operate as _bop           
     1337            from asap._asap import b_operate as _bop
    13191338            s = scantable(_bop(self, other, 'add', True))
    13201339        elif isinstance(other, float):
     
    13351354        s = None
    13361355        if isinstance(other, scantable):
    1337             from asap._asap import b_operate as _bop           
     1356            from asap._asap import b_operate as _bop
    13381357            s = scantable(_bop(self, other, 'sub', True))
    13391358        elif isinstance(other, float):
     
    13451364        s._add_history("operator -", varlist)
    13461365        return s
    1347    
     1366
    13481367    def __mul__(self, other):
    13491368        """
     
    13531372        s = None
    13541373        if isinstance(other, scantable):
    1355             from asap._asap import b_operate as _bop           
     1374            from asap._asap import b_operate as _bop
    13561375            s = scantable(_bop(self, other, 'mul', True))
    13571376        elif isinstance(other, float):
     
    13661385        s._add_history("operator *", varlist)
    13671386        return s
    1368    
     1387
    13691388
    13701389    def __div__(self, other):
     
    13751394        s = None
    13761395        if isinstance(other, scantable):
    1377             from asap._asap import b_operate as _bop           
     1396            from asap._asap import b_operate as _bop
    13781397            s = scantable(_bop(self, other, 'div', True))
    13791398        elif isinstance(other, float):
     
    14421461        hist = hist[:-2] # remove trailing '##'
    14431462        self._addhistory(hist)
    1444        
     1463
    14451464
    14461465    def _zip_mask(self, mask):
     
    14531472                j = i + mask[i:].index(0)
    14541473            else:
    1455                 j = len(mask)               
     1474                j = len(mask)
    14561475            segments.append([i,j])
    1457             i = j       
     1476            i = j
    14581477        return segments
    14591478    def _get_ordinate_label(self):
     
    14661485            lbl = "Flux density "+ fu
    14671486        return lbl
    1468        
     1487
Note: See TracChangeset for help on using the changeset viewer.