Ignore:
Timestamp:
08/05/10 14:40:38 (14 years ago)
Author:
Malte Marquarding
Message:

Ticket #193: the rcParamsverbose? flag is only used in standard asap cli mode. Otherwise log messages are always send to the logger and one needs to call asaplog.disable()/asaplog.enable() to controls this. I have also added the function name as the log origin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r1857 r1859  
    1515from asap.linecatalog import linecatalog
    1616from asap.coordinate import coordinate
    17 from asap.utils import _n_bools, mask_not, mask_and, mask_or
     17from asap.utils import _n_bools, mask_not, mask_and, mask_or, page
    1818
    1919
     
    101101                    tmpstr=tmpstr+antenna[i]+','
    102102                else:
    103                     asaplog.push('Bad antenna selection.')
    104                     print_log('ERROR')
    105                     return
     103                    raise TypeError('Bad antenna selection.')
    106104            antenna = tmpstr.rstrip(',')
    107105        parallactify = parallactify or rcParams['scantable.parallactify']
     
    117115                if not os.path.exists(filename):
    118116                    s = "File '%s' not found." % (filename)
    119                     if rcParams['verbose']:
    120                         asaplog.push(s)
    121                         print_log('ERROR')
    122                         return
    123117                    raise IOError(s)
    124118                if is_scantable(filename):
     
    133127                    msg = "The given file '%s'is not a valid " \
    134128                          "asap table." % (filename)
    135                     if rcParams['verbose']:
    136                         #print msg
    137                         asaplog.push( msg )
    138                         print_log( 'ERROR' )
    139                         return
    140                     else:
    141                         raise IOError(msg)
     129                    raise IOError(msg)
    142130                else:
    143131                    self._fill([filename], unit, average, getpt, antenna)
     
    191179            if not overwrite:
    192180                msg = "File %s exists." % name
    193                 if rcParams['verbose']:
    194                     #print msg
    195                     asaplog.push( msg )
    196                     print_log( 'ERROR' )
    197                     return
    198                 else:
    199                     raise IOError(msg)
     181                raise IOError(msg)
    200182        format2 = format.upper()
    201183        if format2 == 'ASAP':
     
    236218        from asap import unique
    237219        if not _is_valid(scanid):
    238             if rcParams['verbose']:
    239                 asaplog.push( 'Please specify a scanno to drop from the scantable' )
    240                 print_log( 'ERROR' )
    241                 return
    242             else:
    243                 raise RuntimeError("No scan given")
    244         try:
    245             scanid = _to_list(scanid)
    246             allscans = unique([ self.getscan(i) for i in range(self.nrow())])
    247             for sid in scanid: allscans.remove(sid)
    248             if len(allscans) == 0:
    249                 raise ValueError("Can't remove all scans")
    250         except ValueError:
    251             if rcParams['verbose']:
    252                 print_log()
    253                 asaplog.push( "Couldn't find any match." )
    254                 print_log( 'ERROR' )
    255                 return
    256             else: raise
    257         try:
    258             sel = selector(scans=allscans)
    259             return self._select_copy(sel)
    260         except RuntimeError:
    261             if rcParams['verbose']:
    262                 print_log()
    263                 asaplog.push( "Couldn't find any match." )
    264                 print_log( 'ERROR' )
    265             else:
    266                 raise
     220            raise RuntimeError( 'Please specify a scanno to drop from the scantable' )
     221        scanid = _to_list(scanid)
     222        allscans = unique([ self.getscan(i) for i in range(self.nrow())])
     223        for sid in scanid: allscans.remove(sid)
     224        if len(allscans) == 0:
     225            raise ValueError("Can't remove all scans")
     226        sel = selector(scans=allscans)
     227        return self._select_copy(sel)
    267228
    268229    def _select_copy(self, selection):
     
    299260        """
    300261        if scanid is None:
    301             if rcParams['verbose']:
    302                 #print "Please specify a scan no or name to " \
    303                 #      "retrieve from the scantable"
    304                 asaplog.push( 'Please specify a scan no or name to retrieve'
    305                              ' from the scantable' )
    306                 print_log( 'ERROR' )
    307                 return
    308             else:
    309                 raise RuntimeError("No scan given")
    310 
     262            raise RuntimeError( 'Please specify a scan no or name to '
     263                                'retrieve from the scantable' )
    311264        try:
    312265            bsel = self.get_selection()
     
    323276            else:
    324277                msg = "Illegal scanid type, use 'int' or 'list' if ints."
    325                 if rcParams['verbose']:
    326                     #print msg
    327                     asaplog.push( msg )
    328                     print_log( 'ERROR' )
    329                 else:
    330                     raise TypeError(msg)
     278                raise TypeError(msg)
    331279        except RuntimeError:
    332             if rcParams['verbose']:
    333                 #print "Couldn't find any match."
    334                 print_log()
    335                 asaplog.push( "Couldn't find any match." )
    336                 print_log( 'ERROR' )
    337             else: raise
     280            raise
    338281
    339282    def __str__(self):
     
    362305            else:
    363306                msg = "Illegal file name '%s'." % (filename)
    364                 if rcParams['verbose']:
    365                     #print msg
    366                     asaplog.push( msg )
    367                     print_log( 'ERROR' )
    368                 else:
    369                     raise IOError(msg)
    370         if rcParams['verbose']:
    371             try:
    372                 from IPython.genutils import page as pager
    373             except ImportError:
    374                 from pydoc import pager
    375             pager(info)
    376         else:
    377             return info
     307                raise IOError(msg)
     308        return page(info)
    378309
    379310    def get_spectrum(self, rowno):
     
    518449            return workscan
    519450
    520     #def stats(self, stat='stddev', mask=None):
     451    @print_log_dec
    521452    def stats(self, stat='stddev', mask=None, form='3.3f'):
    522453        """\
     
    591522            out +=  sep+"\n"
    592523
    593         if rcParams['verbose']:
    594             import os
    595             if os.environ.has_key( 'USER' ):
    596                 usr=os.environ['USER']
    597             else:
    598                 import commands
    599                 usr=commands.getoutput( 'whoami' )
    600             tmpfile='/tmp/tmp_'+usr+'_casapy_asap_scantable_stats'
    601             f=open(tmpfile,'w')
    602             print >> f, sep
    603             print >> f, ' %s %s' % (label, statunit)
    604             print >> f, sep
    605             print >> f, out
    606             f.close()
    607             f=open(tmpfile,'r')
    608             x=f.readlines()
    609             f.close()
    610             blanc=''
    611             asaplog.push(blanc.join(x), False)
    612             #for xx in x:
    613             #    asaplog.push( xx, False )
    614             print_log()
     524
     525        import os
     526        if os.environ.has_key( 'USER' ):
     527            usr = os.environ['USER']
     528        else:
     529            import commands
     530            usr = commands.getoutput( 'whoami' )
     531        tmpfile = '/tmp/tmp_'+usr+'_casapy_asap_scantable_stats'
     532        f = open(tmpfile,'w')
     533        print >> f, sep
     534        print >> f, ' %s %s' % (label, statunit)
     535        print >> f, sep
     536        print >> f, out
     537        f.close()
     538        f = open(tmpfile,'r')
     539        x = f.readlines()
     540        f.close()
     541        asaplog.push(''.join(x), False)
     542
    615543        return statvals
    616544
     
    727655            out += '= %3.3f\n' % (outvec[i])
    728656            out +=  sep+'\n'
    729         if rcParams['verbose']:
    730             asaplog.push(sep)
    731             asaplog.push(" %s" % (label))
    732             asaplog.push(sep)
    733             asaplog.push(out)
    734             print_log()
     657
     658        asaplog.push(sep)
     659        asaplog.push(" %s" % (label))
     660        asaplog.push(sep)
     661        asaplog.push(out)
     662        print_log()
    735663        return outvec
    736664
     
    945873        else:
    946874            msg  = "Please specify a valid freq type. Valid types are:\n", valid
    947             if rcParams['verbose']:
    948                 #print msg
    949                 asaplog.push( msg )
    950                 print_log( 'ERROR' )
    951             else:
    952                 raise TypeError(msg)
    953 
     875            raise TypeError(msg)
     876
     877    @print_log_dec
    954878    def set_dirframe(self, frame=""):
    955879        """\
     
    967891        """
    968892        varlist = vars()
    969         try:
    970             Scantable.set_dirframe(self, frame)
    971         except RuntimeError, msg:
    972             if rcParams['verbose']:
    973                 #print msg
    974                 print_log()
    975                 asaplog.push( str(msg) )
    976                 print_log( 'ERROR' )
    977             else:
    978                 raise
     893        Scantable.set_dirframe(self, frame)
    979894        self._add_history("set_dirframe", varlist)
    980895
     
    1013928        return abc, lbl
    1014929
     930    @print_log_dec
    1015931    def flag(self, mask=None, unflag=False):
    1016932        """\
     
    1027943        varlist = vars()
    1028944        mask = mask or []
    1029         try:
    1030             self._flag(mask, unflag)
    1031         except RuntimeError, msg:
    1032             if rcParams['verbose']:
    1033                 #print msg
    1034                 print_log()
    1035                 asaplog.push( str(msg) )
    1036                 print_log( 'ERROR' )
    1037                 return
    1038             else: raise
     945        self._flag(mask, unflag)
    1039946        self._add_history("flag", varlist)
    1040947
     948    @print_log_dec
    1041949    def flag_row(self, rows=[], unflag=False):
    1042950        """\
     
    1052960        """
    1053961        varlist = vars()
    1054         try:
    1055             self._flag_row(rows, unflag)
    1056         except RuntimeError, msg:
    1057             if rcParams['verbose']:
    1058                 print_log()
    1059                 asaplog.push( str(msg) )
    1060                 print_log('ERROR')
    1061                 return
    1062             else: raise
     962        self._flag_row(rows, unflag)
    1063963        self._add_history("flag_row", varlist)
    1064964
     965    @print_log_dec
    1065966    def clip(self, uthres=None, dthres=None, clipoutside=True, unflag=False):
    1066967        """\
     
    1080981        """
    1081982        varlist = vars()
    1082         try:
    1083             self._clip(uthres, dthres, clipoutside, unflag)
    1084         except RuntimeError, msg:
    1085             if rcParams['verbose']:
    1086                 print_log()
    1087                 asaplog.push(str(msg))
    1088                 print_log('ERROR')
    1089                 return
    1090             else: raise
     983        self._clip(uthres, dthres, clipoutside, unflag)
    1091984        self._add_history("clip", varlist)
    1092985
     
    11201013        if not (unit == "" or base.has_key(unit)):
    11211014            raise ValueError("%s is not a valid unit." % unit)
    1122         try:
    1123             if unit == "":
    1124                 s = scantable(self._math._lag_flag(self, start, end, "lags"))
    1125             else:
    1126                 s = scantable(self._math._lag_flag(self, start*base[unit],
    1127                                                    end*base[unit], "frequency"))
    1128         except RuntimeError, msg:
    1129             if rcParams['verbose']:
    1130                 #print msg
    1131                 print_log()
    1132                 asaplog.push( str(msg) )
    1133                 print_log( 'ERROR' )
    1134                 return
    1135             else: raise
     1015        if unit == "":
     1016            s = scantable(self._math._lag_flag(self, start, end, "lags"))
     1017        else:
     1018            s = scantable(self._math._lag_flag(self, start*base[unit],
     1019                                               end*base[unit], "frequency"))
    11361020        s._add_history("lag_flag", varlist)
    11371021        if insitu:
     
    11821066        data = self._getabcissa(row)
    11831067        u = self._getcoordinfo()[0]
    1184         if rcParams['verbose']:
    1185             if u == "": u = "channel"
    1186             msg = "The current mask window unit is %s" % u
    1187             i = self._check_ifs()
    1188             if not i:
    1189                 msg += "\nThis mask is only valid for IF=%d" % (self.getif(i))
    1190             asaplog.push(msg)
     1068        if u == "":
     1069            u = "channel"
     1070        msg = "The current mask window unit is %s" % u
     1071        i = self._check_ifs()
     1072        if not i:
     1073            msg += "\nThis mask is only valid for IF=%d" % (self.getif(i))
     1074        asaplog.push(msg)
    11911075        n = self.nchan()
    11921076        msk = _n_bools(n, False)
     
    12401124        data = self._getabcissa(row)
    12411125        u = self._getcoordinfo()[0]
    1242         if rcParams['verbose']:
    1243             if u == "": u = "channel"
    1244             msg = "The current mask window unit is %s" % u
    1245             i = self._check_ifs()
    1246             if not i:
    1247                 msg += "\nThis mask is only valid for IF=%d" % (self.getif(i))
    1248             asaplog.push(msg)
     1126        if u == "":
     1127            u = "channel"
     1128        msg = "The current mask window unit is %s" % u
     1129        i = self._check_ifs()
     1130        if not i:
     1131            msg += "\nThis mask is only valid for IF=%d" % (self.getif(i))
     1132        asaplog.push(msg)
    12491133        masklist=[]
    12501134        ist, ien = None, None
     
    14641348        Scantable.shift_refpix(self, delta)
    14651349
     1350    @print_log_dec
    14661351    def history(self, filename=None):
    14671352        """\
     
    15001385            else:
    15011386                msg = "Illegal file name '%s'." % (filename)
    1502                 if rcParams['verbose']:
    1503                     #print msg
    1504                     asaplog.push( msg )
    1505                     print_log( 'ERROR' )
    1506                 else:
    1507                     raise IOError(msg)
    1508         if rcParams['verbose']:
    1509             try:
    1510                 from IPython.genutils import page as pager
    1511             except ImportError:
    1512                 from pydoc import pager
    1513             pager(out)
    1514         else:
    1515             return out
    1516         return
     1387                raise IOError(msg)
     1388        return page(out)
    15171389    #
    15181390    # Maths business
     
    15581430        scanav = (scanav and 'SCAN') or 'NONE'
    15591431        scan = (self, )
    1560         try:
    1561             if align:
    1562                 scan = (self.freq_align(insitu=False), )
    1563             s = None
    1564             if weight.upper() == 'MEDIAN':
    1565                 s = scantable(self._math._averagechannel(scan[0], 'MEDIAN',
    1566                                                          scanav))
    1567             else:
    1568                 s = scantable(self._math._average(scan, mask, weight.upper(),
    1569                               scanav))
    1570         except RuntimeError, msg:
    1571             if rcParams['verbose']:
    1572                 #print msg
    1573                 print_log()
    1574                 asaplog.push( str(msg) )
    1575                 print_log( 'ERROR' )
    1576                 return
    1577             else: raise
     1432
     1433        if align:
     1434            scan = (self.freq_align(insitu=False), )
     1435        s = None
     1436        if weight.upper() == 'MEDIAN':
     1437            s = scantable(self._math._averagechannel(scan[0], 'MEDIAN',
     1438                                                     scanav))
     1439        else:
     1440            s = scantable(self._math._average(scan, mask, weight.upper(),
     1441                          scanav))
    15781442        s._add_history("average_time", varlist)
    15791443        return s
     
    18541718        """
    18551719        varlist = vars()
    1856         try:
    1857             s = scantable(self._math._convertpol(self, poltype))
    1858         except RuntimeError, msg:
    1859             if rcParams['verbose']:
    1860                 #print msg
    1861                 print_log()
    1862                 asaplog.push( str(msg) )
    1863                 print_log( 'ERROR' )
    1864                 return
    1865             else:
    1866                 raise
     1720        s = scantable(self._math._convertpol(self, poltype))
    18671721        s._add_history("convert_pol", varlist)
    18681722        return s
     
    20321886        except RuntimeError:
    20331887            msg = "The fit failed, possibly because it didn't converge."
    2034             if rcParams['verbose']:
    2035                 #print msg
    2036                 print_log()
    2037                 asaplog.push( str(msg) )
    2038                 print_log( 'ERROR' )
    2039                 return
    2040             else:
    2041                 raise RuntimeError(msg)
     1888            raise RuntimeError(msg)
    20421889
    20431890
     
    25502397        from asap.asapfit import asapfit
    25512398        fit = asapfit(self._getfit(row))
    2552         if rcParams['verbose']:
    2553             #print fit
    2554             asaplog.push( '%s' %(fit) )
    2555             return
    2556         else:
    2557             return fit.as_dict()
     2399        asaplog.push( '%s' %(fit) )
     2400        return fit.as_dict()
    25582401
    25592402    def flag_nans(self):
     
    26492492        return (sum(nchans)/len(nchans) == nchans[0])
    26502493
     2494    @print_log_dec
    26512495    def _fill(self, names, unit, average, getpt, antenna):
    26522496        first = True
     
    26572501            if not os.path.exists(name):
    26582502                msg = "File '%s' does not exists" % (name)
    2659                 if rcParams['verbose']:
    2660                     asaplog.push(msg)
    2661                     print_log( 'ERROR' )
    2662                     return
    26632503                raise IOError(msg)
    26642504            fullnames.append(name)
     
    26732513            msg = "Importing %s..." % (name)
    26742514            asaplog.push(msg, False)
    2675             print_log()
    26762515            r.open(name)# antenna, -1, -1, getpt)
    26772516            r.fill()
Note: See TracChangeset for help on using the changeset viewer.