Changeset 718


Ignore:
Timestamp:
11/17/05 16:37:53 (18 years ago)
Author:
mar637
Message:

more asaplog migration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r714 r718  
    3333
    3434        varlist = vars()
    35         self._vb = rcParams['verbose']
    3635        self._p = None
    3736        from asap import asaplog
     
    5756                        self.set_fluxunit(unit)
    5857                else:
    59                     print "The given file '%s'is not a valid asap table." % (filename)
    60                     return
     58                    msg = "The given file '%s'is not a valid asap table." % (filename)
     59                    if rcParams['verbose']:
     60                        print msg
     61                        return
     62                    else:
     63                        raise IOError(msg)
    6164            else:
    6265                from asap._asap import sdreader
     
    114117        if name is None or name =="":
    115118            name = 'scantable'+suffix
    116             print "No filename given. Using default name %s..." % name
     119            from asap import asaplog
     120            msg = "No filename given. Using default name %s..." % name
     121            asaplog.push(msg)
    117122        name = path.expandvars(name)
    118123        if path.isfile(name) or path.isdir(name):
    119124            if not overwrite:
    120                 print "File %s already exists." % name
    121                 return
     125                msg = "File %s exists." % name
     126                if rcParams['verbose']:
     127                    print msg
     128                    return
     129                else:
     130                    raise IOError(msg)
    122131        format2 = format.upper()
    123132        if format2 == 'ASAP':
     
    127136            w = _sw(format2)
    128137            w.write(self, name, stokes)
     138
     139        print_log()
    129140        return
    130141
     
    157168        """
    158169        if scanid is None:
    159             print "Please specify a scan no or name to retrieve from the scantable"
     170            if rcParams['verbose']:
     171                print "Please specify a scan no or name to retrieve from the scantable"
     172                return
     173            else:
     174                raise RuntimeError("No scan given")
     175
    160176        try:
    161177            if type(scanid) is str:
     
    169185                return scantable(s)
    170186            else:
    171                 print "Illegal scanid type, use 'int' or 'list' if ints."
     187                msg = "Illegal scanid type, use 'int' or 'list' if ints."
     188                if rcParams['verbose']:
     189                    print msg
     190                else:
     191                    raise TypeError(msg)
    172192        except RuntimeError:
    173             print "Couldn't find any match."
     193            if rcParams['verbose']: print "Couldn't find any match."
     194            else: raise
    174195
    175196    def __str__(self):
     
    197218                data.close()
    198219            else:
    199                 print "Illegal file name '%s'." % (filename)
    200         print info
     220                msg = "Illegal file name '%s'." % (filename)
     221                if rcParams['verbose']:
     222                    print msg
     223                else:
     224                    raise IOError(msg)
     225        if rcParams['verbose']:
     226            print info
     227        else:
     228            return info
    201229
    202230    def set_cursor(self, beam=0, IF=0, pol=0):
     
    230258        j = self.getif()
    231259        k = self.getpol()
    232         if self._vb:
     260        if rcParams['verbose']:
    233261            print "--------------------------------------------------"
    234262            print " Cursor position"
     
    236264            out = 'Beam=%d IF=%d Pol=%d ' % (i,j,k)
    237265            print out
    238         return i,j,k
     266        else:
     267            return i,j,k
    239268
    240269    def stats(self, stat='stddev', mask=None, allaxes=None):
     
    278307            retval = {'axes': axes, 'data': arr, 'cursor':None}
    279308            tm = [self._gettime(val) for val in range(self.nrow())]
    280             if self._vb:
     309            if rcParams['verbose']:
    281310                self._print_values(retval,stat,tm)
    282311            self.setbeam(beamSel)
     
    297326                out +=  "--------------------------------------------------\n"
    298327
    299             if self._vb:
     328            if rcParams['verbose']:
    300329                print "--------------------------------------------------"
    301330                print " ",stat
     
    353382            retval = {'axes': axes, 'data': arr, 'cursor':None}
    354383            tm = [self._gettime(val) for val in range(self.nrow())]
    355             if self._vb:
     384            if rcParams['verbose']:
    356385                self._print_values(retval,'Tsys',tm)
    357386            return retval
     
    370399                out +=  "--------------------------------------------------\n"
    371400
    372             if self._vb:
     401            if rcParams['verbose']:
    373402                print "--------------------------------------------------"
    374403                print " TSys"
     
    437466        self._setInstrument(instr)
    438467        self._add_history("set_instument",vars())
     468        print_log()
    439469
    440470    def set_doppler(self, doppler='RADIO'):
     
    450480        if self._p: self.plot()
    451481        self._add_history("set_doppler",vars())
     482        print_log()
    452483
    453484    def set_freqframe(self, frame=None):
     
    472503            self._add_history("set_freqframe",varlist)
    473504        else:
    474             print "Please specify a valid freq type. Valid types are:\n",valid
     505            msg  = "Please specify a valid freq type. Valid types are:\n",valid
     506            if rcParams['verbose']:
     507                print msg
     508            else:
     509                raise TypeError(msg)
     510        print_log()
    475511
    476512    def get_unit(self):
     
    498534        abc = self._getabcissa(rowno)
    499535        lbl = self._getabcissalabel(rowno)
     536        print_log()
    500537        return abc, lbl
    501         #return {'abcissa':abc,'label':lbl}
    502538
    503539    def create_mask(self, *args, **kwargs):
     
    535571        data = self._getabcissa(row)
    536572        u = self._getcoordinfo()[0]
    537         if self._vb:
     573        if rcParams['verbose']:
    538574            if u == "": u = "channel"
    539             print "The current mask window unit is", u
     575            from asap import asaplog
     576            msg = "The current mask window unit is %s" % u
     577            asaplog.push(msg)
    540578        n = self.nchan()
    541579        msk = zeros(n)
     
    543581
    544582        ws = (isinstance(args[-1][-1],int) or isinstance(args[-1][-1],float)) and args or args[0]
    545         print ws
    546583        for window in ws:
    547             print window
    548584            if (len(window) != 2 or window[0] > window[1] ):
    549                 print "A window needs to be defined as [min,max]"
    550                 return
     585                raise TypeError("A window needs to be defined as [min,max]")
    551586            for i in range(n):
    552587                if data[i] >= window[0] and data[i] < window[1]:
     
    556591                from numarray import logical_not
    557592                msk = logical_not(msk)
     593        print_log()
    558594        return msk
    559595
     
    654690            print "Please specify a valid (Beam/IF/Pol)"
    655691        return
    656 
    657     def plot(self, what='spectrum',col='Pol', panel=None):
    658         """
    659         Plot the spectra contained in the scan. Alternatively you can also
    660         Plot Tsys vs Time
    661         Parameters:
    662             what:     a choice of 'spectrum' (default) or 'tsys'
    663             col:      which out of Beams/IFs/Pols should be colour stacked
    664             panel:    set up multiple panels, currently not working.
    665         """
    666         print "Warning! Not fully functional. Use plotter.plot() instead"
    667 
    668         validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()}
    669 
    670         validyax = ['spectrum','tsys']
    671         from asap.asaplot import ASAPlot
    672         if not self._p:
    673             self._p = ASAPlot()
    674             #print "Plotting not enabled"
    675             #return
    676         if self._p.is_dead:
    677             del self._p
    678             self._p = ASAPlot()
    679         npan = 1
    680         x = None
    681         if what == 'tsys':
    682             n = self.nrow()
    683             if n < 2:
    684                 print "Only one integration. Can't plot."
    685                 return
    686         self._p.hold()
    687         self._p.clear()
    688         if panel == 'Time':
    689             npan = self.nrow()
    690             self._p.set_panels(rows=npan)
    691         xlab,ylab,tlab = None,None,None
    692         self._vb = False
    693         sel = self.get_cursor()
    694         for i in range(npan):
    695             if npan > 1:
    696                 self._p.subplot(i)
    697             for j in range(validcol[col]):
    698                 x = None
    699                 y = None
    700                 m = None
    701                 tlab = self._getsourcename(i)
    702                 import re
    703                 tlab = re.sub('_S','',tlab)
    704                 if col == 'Beam':
    705                     self.setbeam(j)
    706                 elif col == 'IF':
    707                     self.setif(j)
    708                 elif col == 'Pol':
    709                     self.setpol(j)
    710                 if what == 'tsys':
    711                     x = range(self.nrow())
    712                     xlab = 'Time [pixel]'
    713                     m = list(ones(len(x)))
    714                     y = []
    715                     ylab = r'$T_{sys}$'
    716                     for k in range(len(x)):
    717                         y.append(self._gettsys(k))
    718                 else:
    719                     x,xlab = self.get_abcissa(i)
    720                     y = self._getspectrum(i)
    721                     ylab = r'Flux'
    722                     m = self._getmask(i)
    723                 llab = col+' '+str(j)
    724                 self._p.set_line(label=llab)
    725                 self._p.plot(x,y,m)
    726             self._p.set_axes('xlabel',xlab)
    727             self._p.set_axes('ylabel',ylab)
    728             self._p.set_axes('title',tlab)
    729         self._p.release()
    730         self.set_cursor(sel[0],sel[1],sel[2])
    731         self._vb = rcParams['verbose']
    732         return
    733 
    734         print out
    735692
    736693    def _print_values(self, dat, label='', timestamps=[]):
     
    805762        s = scantable(_av((self,), mask, scanav, weight))
    806763        s._add_history("average_time",varlist)
     764        print_log()
    807765        return s
    808766
     
    837795            s = scantable(_convert(self, d, eta, jyperk, allaxes))
    838796            s._add_history("convert_flux", varlist)
     797            print_log()
    839798            return s
    840799        else:
     
    842801            _convert(self, d, eta, jyperk, allaxes)
    843802            self._add_history("convert_flux", varlist)
     803            print_log()
    844804            return
    845805
     
    899859            s = scantable(_gainEl(self, poly, filename, method, allaxes))
    900860            s._add_history("gain_el", varlist)
     861            print_log()
    901862            return s
    902863        else:
     
    904865            _gainEl(self, poly, filename, method, allaxes)
    905866            self._add_history("gain_el", varlist)
     867            print_log()
    906868            return
    907869
     
    932894            s = scantable(_align(self, reftime, method, perfreqid))
    933895            s._add_history("freq_align", varlist)
     896            print_log()
    934897            return s
    935898        else:
     
    937900            _align(self, reftime, method, perfreqid)
    938901            self._add_history("freq_align", varlist)
     902            print_log()
    939903            return
    940904
     
    961925            s = scantable(_opacity(self, tau, allaxes))
    962926            s._add_history("opacity", varlist)
     927            print_log()
    963928            return s
    964929        else:
     
    966931            _opacity(self, tau, allaxes)
    967932            self._add_history("opacity", varlist)
     933            print_log()
    968934            return
    969935
     
    982948            s = scantable(_bin(self, width))
    983949            s._add_history("bin",varlist)
     950            print_log()
    984951            return s
    985952        else:
     
    987954            _bin(self, width)
    988955            self._add_history("bin",varlist)
     956            print_log()
    989957            return
    990958
     
    1007975            s = scantable(_resample(self, method, width))
    1008976            s._add_history("resample",varlist)
     977            print_log()
    1009978            return s
    1010979        else:
     
    1012981            _resample(self, method, width)
    1013982            self._add_history("resample",varlist)
     983            print_log()
    1014984            return
    1015985
     
    10371007            s = scantable(_avpol(self, mask, weight))
    10381008            s._add_history("average_pol",varlist)
     1009            print_log()
    10391010            return s
    10401011        else:
     
    10421013            _avpol(self, mask, weight)
    10431014            self._add_history("average_pol",varlist)
     1015            print_log()
    10441016            return
    10451017
     
    10721044            s = scantable(_smooth(self,kernel,width,allaxes))
    10731045            s._add_history("smooth", varlist)
     1046            print_log()
    10741047            return s
    10751048        else:
     
    10771050            _smooth(self,kernel,width,allaxes)
    10781051            self._add_history("smooth", varlist)
     1052            print_log()
    10791053            return
    10801054
     
    11071081        if insitu:
    11081082            self._add_history("poly_baseline", varlist)
     1083            print_log()
    11091084            return
    11101085        else:
    11111086            sf._add_history("poly_baseline", varlist)
     1087            print_log()
    11121088            return sf
    11131089
     
    11201096
    11211097        Parameters:
    1122             scan:    a scantable
    11231098            mask:       an optional mask retreived from scantable
    11241099            edge:       an optional number of channel to drop at
     
    11451120
    11461121        if not _is_valid(edge, int):
     1122
    11471123            raise RuntimeError, "Parameter 'edge' has to be an integer or a \
    11481124            pair of integers specified as a tuple"
     
    11621138            workscan=self
    11631139
    1164         vb=workscan._vb
    1165         # remember the verbose parameter and selection
    1166         workscan._vb=False
    11671140        sel=workscan.get_cursor()
    11681141        rows=range(workscan.nrow())
     1142        from asap import asaplog
    11691143        for i in range(workscan.nbeam()):
    11701144            workscan.setbeam(i)
     
    11731147                for k in range(workscan.npol()):
    11741148                    workscan.setpol(k)
    1175                     if f._vb:
    1176                        print "Processing:"
    1177                        print 'Beam[%d], IF[%d], Pol[%d]' % (i,j,k)
     1149                    asaplog.push("Processing:")
     1150                    msg = 'Beam[%d], IF[%d], Pol[%d]' % (i,j,k)
     1151                    asaplog.push(msg)
    11781152                    for iRow in rows:
    11791153                       fl.set_scan(workscan,mask,edge)
     
    11871161                       workscan._setspectrum(f.fitter.getresidual(),iRow)
    11881162        workscan.set_cursor(sel[0],sel[1],sel[2])
    1189         workscan._vb = vb
    11901163        if not insitu:
    1191            return workscan
     1164            return workscan
    11921165
    11931166    def rotate_linpolphase(self, angle, allaxes=None):
     
    12091182        _rotate(self, angle, allaxes)
    12101183        self._add_history("rotate_linpolphase", varlist)
     1184        print_log()
    12111185        return
    12121186
     
    12301204        _rotate_xyphase(self, angle, allaxes)
    12311205        self._add_history("rotate_xyphase", varlist)
     1206        print_log()
    12321207        return
    12331208
     
    12521227            s = scantable(_add(self, offset, allaxes))
    12531228            s._add_history("add",varlist)
     1229            print_log()
    12541230            return s
    12551231        else:
     
    12571233            _add(self, offset, allaxes)
    12581234            self._add_history("add",varlist)
     1235            print_log()
    12591236            return
    12601237
     
    12801257            s = scantable(_scale(self, factor, allaxes, tsys))
    12811258            s._add_history("scale",varlist)
     1259            print_log()
    12821260            return s
    12831261        else:
     
    12851263            _scale(self, factor, allaxes, tsys)
    12861264            self._add_history("scale",varlist)
     1265            print_log()
    12871266            return
    12881267
     
    13151294                if nr > ns:
    13161295                    refs = refs.get_scan(range(ns))
     1296                print_log()
    13171297                return scantable(_quot(srcs,refs, preserve))
    13181298            else:
    1319                 raise RuntimeError("Couldn't find any on/off pairs")
    1320         else:
    1321             print "not yet implemented"
     1299                msg = "Couldn't find any on/off pairs"
     1300                if rcParams['verbose']:
     1301                    print msg
     1302                    return
     1303                else:
     1304                    raise RuntimeError()
     1305        else:
     1306            if rcParams['verbose']: print "not yet implemented"
    13221307            return None
    13231308
     
    13441329        """
    13451330        from asap._asap import quotient as _quot
    1346         if isreference:
    1347             return scantable(_quot(self, other, preserve))
    1348         else:
    1349             return scantable(_quot(other, self, preserve))
     1331        try:
     1332            s = None
     1333            if isreference:
     1334                s = scantable(_quot(self, other, preserve))
     1335            else:
     1336                s = scantable(_quot(other, self, preserve))
     1337            print_log()
     1338            return s
     1339        except RuntimeError,e:
     1340            if rcParams['verbose']:
     1341                print e
     1342                return
     1343            else: raise
     1344
     1345    def freq_switch(self, insitu=None):
     1346        """
     1347        Apply frequency switching to the data.
     1348        Parameters:
     1349            insitu:      if False a new scantable is returned.
     1350                         Otherwise, the swictching is done in-situ
     1351                         The default is taken from .asaprc (False)
     1352        Example:
     1353            none
     1354        """
     1355        if insitu is None: insitu = rcParams['insitu']
     1356        varlist = vars()
     1357        try:
     1358            if insitu:
     1359                from asap._asap import _frequency_switch_insitu
     1360                _frequency_switch_insitu(self)
     1361                self._add_history("freq_switch", varlist)
     1362                print_log()
     1363                return
     1364            else:
     1365                from asap._asap import _frequency_switch
     1366                sf = scantable(_frequency_switch(self))
     1367                sf._add_history("freq_switch", varlist)
     1368                print_log()
     1369                return sf
     1370        except RuntimeError,e:
     1371            if rcParams['verbose']: print e
     1372            else: raise
    13501373
    13511374    def __add__(self, other):
     
    13591382            s = scantable(_add(self, other, True))
    13601383        else:
    1361             print "Other input is not a scantable or float value"
    1362             return
     1384            raise TypeError("Other input is not a scantable or float value")
    13631385        s._add_history("operator +", varlist)
     1386        print_log()
    13641387        return s
    13651388
     
    13781401            s = scantable(_add(self, -other, True))
    13791402        else:
    1380             print "Other input is not a scantable or float value"
    1381             return
     1403            raise TypeError("Other input is not a scantable or float value")
    13821404        s._add_history("operator -", varlist)
     1405        print_log()
    13831406        return s
    13841407
     
    13941417        elif isinstance(other, float):
    13951418            if other == 0.0:
    1396                 print "Multiplying by zero is not recommended."
    1397                 return
     1419                raise ZeroDivisionError("Dividing by zero is not recommended")
    13981420            from asap._asap import scale as _sca
    13991421            s = scantable(_sca(self, other, True))
    14001422        else:
    1401             print "Other input is not a scantable or float value"
    1402             return
     1423            raise TypeError("Other input is not a scantable or float value")
    14031424        s._add_history("operator *", varlist)
     1425        print_log()
    14041426        return s
    14051427
     
    14161438        elif isinstance(other, float):
    14171439            if other == 0.0:
    1418                 print "Dividing by zero is not recommended"
    1419                 return
     1440                raise ZeroDivisionError("Dividing by zero is not recommended")
    14201441            from asap._asap import scale as _sca
    14211442            s = scantable(_sca(self, 1.0/other, True))
    14221443        else:
    1423             print "Other input is not a scantable or float value"
    1424             return
     1444            raise TypeError("Other input is not a scantable or float value")
    14251445        s._add_history("operator /", varlist)
     1446        print_log()
    14261447        return s
    14271448
     
    14361457        from asap import asapfit
    14371458        fit = asapfit(self._getfit(row))
    1438         if self._vb:
     1459        if rcParams['verbose']:
    14391460            print fit
    14401461            return
Note: See TracChangeset for help on using the changeset viewer.