Changeset 1612 for branches/alma


Ignore:
Timestamp:
08/05/09 17:48:43 (15 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-729, CAS-1147

Ready to Release: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

I have changed that almost all log messages are output to casapy.log,
not to the terminal window. After this change, asap becomes to depend on casapy
and is not running in standalone, because asap have to import taskinit module
to access casalogger.


Location:
branches/alma/python
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/__init__.py

    r1605 r1612  
    212212        tup = line.split(':',1)
    213213        if len(tup) !=2:
    214             print ('Illegal line #%d\n\t%s\n\tin file "%s"' % (cnt, line, fname))
     214            #print ('Illegal line #%d\n\t%s\n\tin file "%s"' % (cnt, line, fname))
     215            casalog.post('Illegal line #%d\n\t%s\n\tin file "%s"' % (cnt, line, fname), 'WARN')
    215216            continue
    216217
     
    218219        key = key.strip()
    219220        if not defaultParams.has_key(key):
    220             print ('Bad key "%s" on line %d in %s' % (key, cnt, fname))
     221            #print ('Bad key "%s" on line %d in %s' % (key, cnt, fname))
     222            casalog.post('Bad key "%s" on line %d in %s' % (key, cnt, fname), 'WARN')
    221223            continue
    222224
     
    228230        try: cval = converter(val)   # try to convert to proper type or raise
    229231        except ValueError, msg:
    230             print ('Bad val "%s" on line #%d\n\t"%s"\n\tin file "%s"\n\t%s' % (val, cnt, line, fname, msg))
     232            #print ('Bad val "%s" on line #%d\n\t"%s"\n\tin file "%s"\n\t%s' % (val, cnt, line, fname, msg))
     233            casalog.post('Bad val "%s" on line #%d\n\t"%s"\n\tin file "%s"\n\t%s' % (val, cnt, line, fname, msg), 'WARN')
    231234            continue
    232235        else:
     
    343346
    344347# Logging
     348from taskinit import *
    345349from asap._asap import Log as _asaplog
    346350global asaplog
     
    353357def print_log():
    354358    log = asaplog.pop()
    355     if len(log) and rcParams['verbose']: print log
     359    #if len(log) and rcParams['verbose']: print log
     360    if len(log) and rcParams['verbose']: casalog.post( log )
    356361    return
    357362
     
    389394        del gui
    390395    except ImportError:
    391         print "Matplotlib not installed. No plotting available"
     396        #print "Matplotlib not installed. No plotting available"
     397        casalog.post( "Matplotlib not installed. No plotting available", 'WARN' )
    392398
    393399__date__ = '$Date$'.split()[1]
  • branches/alma/python/asapfitter.py

    r1603 r1612  
    44from asap import _n_bools
    55from asap import mask_and
     6from taskinit import *
    67
    78class fitter:
     
    5960            msg = "Please give a correct scan"
    6061            if rcParams['verbose']:
    61                 print msg
     62                #print msg
     63                casalog.post( msg, 'WARN' )
    6264                return
    6365            else:
     
    105107            msg = "Invalid function type."
    106108            if rcParams['verbose']:
    107                 print msg
     109                #print msg
     110                casalog.post( msg, 'WARN' )
    108111                return
    109112            else:
     
    134137            msg = "Fitter not yet initialised. Please set data & fit function"
    135138            if rcParams['verbose']:
    136                 print msg
     139                #print msg
     140                casalog.post( msg, 'WARN' )
    137141                return
    138142            else:
     
    170174        except RuntimeError, msg:
    171175            if rcParams['verbose']:
    172                 print msg
     176                #print msg
     177                casalog.post( msg, 'WARN' )
    173178            else:
    174179                raise
     
    228233            msg = "Please specify a fitting function first."
    229234            if rcParams['verbose']:
    230                 print msg
     235                #print msg
     236                casalog.post( msg, 'WARN' )
    231237                return
    232238            else:
     
    270276            msg = "Function only operates on Gaussian components."
    271277            if rcParams['verbose']:
    272                 print msg
     278                #print msg
     279                casalog.post( msg, 'WARN' )
    273280                return
    274281            else:
     
    281288            msg = "Please select a valid  component."
    282289            if rcParams['verbose']:
    283                 print msg
     290                #print msg
     291                casalog.post( msg, 'WARN' )
    284292                return
    285293            else:
     
    322330            msg = "Not yet fitted."
    323331            if rcParams['verbose']:
    324                 print msg
     332                #print msg
     333                casalog.post( msg, 'WARN' )
    325334                return
    326335            else:
     
    345354            msg = "Not yet fitted."
    346355            if rcParams['verbose']:
    347                 print msg
     356                #print msg
     357                casalog.post( msg, 'WARN' )
    348358                return
    349359            else:
     
    375385        fpars = self._format_pars(cpars, cfixed, errors and cerrs, area)
    376386        if rcParams['verbose']:
    377             print fpars
     387            #print fpars
     388            casalog.post( fpars )
    378389        return {'params':cpars, 'fixed':cfixed, 'formatted': fpars,
    379390                'errors':cerrs}
     
    416427        fixed = self.fitter.getfixedparameters()
    417428        if rcParams['verbose']:
    418             print self._format_pars(pars,fixed,None)
     429            #print self._format_pars(pars,fixed,None)
     430            casalog.post( self._format_pars(pars,fixed,None) )
    419431        return pars
    420432
     
    426438            msg = "Not yet fitted."
    427439            if rcParams['verbose']:
    428                 print msg
     440                #print msg
     441                casalog.post( msg, 'WARN' )
    429442                return
    430443            else:
     
    439452            msg = "Not yet fitted."
    440453            if rcParams['verbose']:
    441                 print msg
     454                #print msg
     455                casalog.post( msg, 'WARN' )
    442456                return
    443457            else:
     
    445459        ch2 = self.fitter.getchi2()
    446460        if rcParams['verbose']:
    447             print 'Chi^2 = %3.3f' % (ch2)
     461            #print 'Chi^2 = %3.3f' % (ch2)
     462            casalog.post( 'Chi^2 = %3.3f' % (ch2) )
    448463        return ch2
    449464
     
    455470            msg = "Not yet fitted."
    456471            if rcParams['verbose']:
    457                 print msg
     472                #print msg
     473                casalog.post( msg, 'WARN' )
    458474                return
    459475            else:
     
    468484            msg = "Not yet fitted."
    469485            if rcParams['verbose']:
    470                 print msg
     486                #print msg
     487                casalog.post( msg, 'WARN' )
    471488                return
    472489            else:
     
    476493            msg = "Not a scantable"
    477494            if rcParams['verbose']:
    478                 print msg
     495                #print msg
     496                casalog.post( msg, 'WARN' )
    479497                return
    480498            else:
     
    594612            msg = "Data is not a scantable"
    595613            if rcParams['verbose']:
    596                 print msg
     614                #print msg
     615                casalog.post( msg, 'WARN' )
    597616                return
    598617            else:
  • branches/alma/python/asaplotbase.py

    r1603 r1612  
    2222    from matplotlib.transforms import blend_xy_sep_transform  as blended_transform_factory
    2323
     24from taskinit import *
     25
    2426if int(matplotlib.__version__.split(".")[1]) < 87:
    25     print "Warning: matplotlib version < 0.87. This might cause errors. Please upgrade."
     27    #print "Warning: matplotlib version < 0.87. This might cause errors. Please upgrade."
     28    casalog.post( "matplotlib version < 0.87. This might cause errors. Please upgrade.", 'WARN' )
    2629
    2730#class MyFormatter(OldScalarFormatter):
     
    449452                    print 'Written file %s' % (fname)
    450453            except IOError, msg:
    451                 print 'Failed to save %s: Error msg was\n\n%s' % (fname, err)
     454                #print 'Failed to save %s: Error msg was\n\n%s' % (fname, err)
     455                casalog.post( 'Failed to save %s: Error msg was\n\n%s' % (fname, err), 'WARN' )
    452456                return
    453457        else:
    454             print "Invalid image type. Valid types are:"
    455             print "'ps', 'eps', 'png'"
     458            #print "Invalid image type. Valid types are:"
     459            #print "'ps', 'eps', 'png'"
     460            casalog.post( "Invalid image type. Valid types are:", 'WARN' )
     461            casalog.post( "'ps', 'eps', 'png'", 'WARN' )
    456462
    457463
  • branches/alma/python/asapmath.py

    r1446 r1612  
    33from asap import print_log
    44from asap import selector
     5from taskinit import *
    56
    67def average_time(*args, **kwargs):
     
    6667            msg = "Please give a list of scantables"
    6768            if rcParams['verbose']:
    68                 print msg
     69                #print msg
     70                casalog.post( msg, 'WARN' )
    6971                return
    7072            else:
     
    184186        msg = "The input data appear to contain no position-switch mode data."
    185187        if rcParams['verbose']:
    186             print msg
     188            #print msg
     189            casalog.post( msg, 'WARN' )
    187190            return
    188191        else:
     
    192195        msg = "No data was found with given scan numbers!"
    193196        if rcParams['verbose']:
    194             print msg
     197            #print msg
     198            casalog.post( msg, 'WARN' )
    195199            return
    196200        else:
     
    201205        msg = "mismatch in numbers of CAL on/off scans. Cannot calibrate. Check the scan numbers."
    202206        if rcParams['verbose']:
    203             print msg
     207            #print msg
     208            casalog.post( msg, 'WARN' )
    204209            return
    205210        else:
     
    211216        msg = "mismatch in numbers of on/off scans. Cannot calibrate. Check the scan numbers."
    212217        if rcParams['verbose']:
    213             print msg
     218            #print msg
     219            casalog.post( msg, 'WARN' )
    214220            return
    215221        else:
     
    221227            msg = "Need to supply a valid tau to use the supplied Tsys"
    222228            if rcParams['verbose']:
    223                 print msg
     229                #print msg
     230                casalog.post( msg, 'WARN' )
    224231                return
    225232            else:
     
    267274        msg = "The input data appear to contain no Nod observing mode data."
    268275        if rcParams['verbose']:
    269             print msg
     276            #print msg
     277            casalog.post( msg, 'WARN' )
    270278            return
    271279        else:
     
    304312            msg = "Need to supply a valid tau to use the supplied Tsys"
    305313            if rcParams['verbose']:
    306                 print msg
     314                #print msg
     315                casalog.post( msg, 'WARN' )
    307316                return
    308317            else:
     
    369378                       as well as the data
    370379    """
    371     print "simple_math is deprecated use +=/* instead."
     380    #print "simple_math is deprecated use +=/* instead."
     381    casalog.post( "simple_math is deprecated use +=/* instead.", 'WARN' )
    372382
    373383def merge(*args):
     
    398408            msg = "Please give a list of scantables"
    399409            if rcParams['verbose']:
    400                 print msg
     410                #print msg
     411                casalog.post( msg, 'WARN' )
    401412                return
    402413            else:
  • branches/alma/python/asapplotter.py

    r1562 r1612  
    11from asap import rcParams, print_log, selector
     2from taskinit import *
    23import matplotlib.axes
    34import re
     
    7475            msg = "Input is not a scantable"
    7576            if rcParams['verbose']:
    76                 print msg
     77                #print msg
     78                casalog.post( msg, 'WARN' )
    7779                return
    7880            raise TypeError(msg)
     
    169171               not self.set_stacking(stacking):
    170172            if rcParams['verbose']:
    171                 print msg
     173                #print msg
     174                casalog.post( msg, 'WARN' )
    172175                return
    173176            else:
     
    522525            msg = "Can only set mask after a first call to plot()"
    523526            if rcParams['verbose']:
    524                 print msg
     527                #print msg
     528                casalog.post( msg, 'WARN' )
    525529                return
    526530            else:
     
    888892            msg = "Input is not a scantable"
    889893            if rcParams['verbose']:
    890                 print msg
     894                #print msg
     895                casalog.post( msg, 'WARN' )
    891896                return
    892897            raise TypeError(msg)
  • branches/alma/python/linecatalog.py

    r1603 r1612  
    99from asap import rcParams
    1010import os
     11from taskinit import *
    1112
    1213class linecatalog(lcbase):
     
    3031            msg = "File '%s' not found" % fpath
    3132            if rcParams['verbose']:
    32                 print msg
     33                #print msg
     34                casalog.post( msg, 'WARN' )
    3335                return
    3436            else:
     
    9799                msg = "File %s exists." % name
    98100                if rcParams['verbose']:
    99                     print msg
     101                    #print msg
     102                    casalog.post( msg, 'WARN' )
    100103                    return
    101104                else:
  • branches/alma/python/scantable.py

    r1603 r1612  
    66from asap import linecatalog
    77from asap import _n_bools, mask_not, mask_and, mask_or
     8from taskinit import *
    89
    910class scantable(Scantable):
     
    5556                    if rcParams['verbose']:
    5657                        asaplog.push(s)
    57                         print asaplog.pop().strip()
     58                        #print asaplog.pop().strip()
     59                        print_log()
    5860                        return
    5961                    raise IOError(s)
     
    7274                              "asap table." % (filename)
    7375                        if rcParams['verbose']:
    74                             print msg
     76                            #print msg
     77                            casalog.post( msg, 'WARN' )
    7578                            return
    7679                        else:
     
    120123                msg = "File %s exists." % name
    121124                if rcParams['verbose']:
    122                     print msg
     125                    #print msg
     126                    casalog.post( msg, 'WARN' )
    123127                    return
    124128                else:
     
    159163        if not _is_valid(scanid):
    160164            if rcParams['verbose']:
    161                 print "Please specify a scanno to drop from the scantable"
     165                #print "Please specify a scanno to drop from the scantable"
     166                casalog.post( "Please specify a scanno to drop from the scantable", 'WARN' )
    162167                return
    163168            else:
     
    171176        except ValueError:
    172177            if rcParams['verbose']:
    173                 print "Couldn't find any match."
     178                #print "Couldn't find any match."
     179                casalog.post( "Couldn't find any match.", 'WARN' )
    174180                return
    175181            else: raise
     
    184190        except RuntimeError:
    185191            if rcParams['verbose']:
    186                 print "Couldn't find any match."
     192                #print "Couldn't find any match."
     193                casalog.post( "Couldn't find any match.", 'WARN' )
    187194            else:
    188195                raise
     
    209216        if scanid is None:
    210217            if rcParams['verbose']:
    211                 print "Please specify a scan no or name to " \
    212                       "retrieve from the scantable"
     218                #print "Please specify a scan no or name to " \
     219                #      "retrieve from the scantable"
     220                casalog.post( "Please specify a scan no or name to retrieve from the scantable", 'WARN' )
    213221                return
    214222            else:
     
    239247                msg = "Illegal scanid type, use 'int' or 'list' if ints."
    240248                if rcParams['verbose']:
    241                     print msg
     249                    #print msg
     250                    casalog.post( msg, 'WARN' )
    242251                else:
    243252                    raise TypeError(msg)
    244253        except RuntimeError:
    245             if rcParams['verbose']: print "Couldn't find any match."
     254            if rcParams['verbose']:
     255                #print "Couldn't find any match."
     256                casalog.post( "Couldn't find any match.", 'WARN' )
    246257            else: raise
    247258
     
    272283                msg = "Illegal file name '%s'." % (filename)
    273284                if rcParams['verbose']:
    274                     print msg
     285                    #print msg
     286                    casalog.post( msg, 'WARN' )
    275287                else:
    276288                    raise IOError(msg)
     
    430442
    431443        if rcParams['verbose']:
    432             print "--------------------------------------------------"
    433             print " ", stat, statunit
    434             print "--------------------------------------------------"
    435             print out
     444            tmpfile='/tmp/tmp_casapy_asap_scantable_stats'
     445            f=open(tmpfile,'w')
     446            print >> f, "--------------------------------------------------"
     447            print >> f, " ", stat, statunit
     448            print >> f, "--------------------------------------------------"
     449            print >> f, out
     450            f.close()
     451            f=open(tmpfile,'r')
     452            x=f.readlines()
     453            f.close()
     454            for xx in x:
     455                casalog.post( xx )
    436456        #else:
    437457            #retval = { 'axesnames': ['scanno', 'beamno', 'ifno', 'polno', 'cycleno'],
     
    513533            out +=  "--------------------------------------------------\n"
    514534        if rcParams['verbose']:
    515             print "--------------------------------------------------"
    516             print " %s" % (label)
    517             print "--------------------------------------------------"
    518             print out
     535            #print "--------------------------------------------------"
     536            #print " %s" % (label)
     537            #print "--------------------------------------------------"
     538            #print out
     539            casalog.post( "--------------------------------------------------" )
     540            casalog.post( " %s" % (label) )
     541            casalog.post( "--------------------------------------------------" )
     542            casalog.post( out )
    519543        # disabled because the vector seems more useful
    520544        #retval = {'axesnames': axesnames, 'axes': axes, 'data': outvec}
     
    703727            msg  = "Please specify a valid freq type. Valid types are:\n", valid
    704728            if rcParams['verbose']:
    705                 print msg
     729                #print msg
     730                casalog.post( msg, 'WARN' )
    706731            else:
    707732                raise TypeError(msg)
     
    722747        except RuntimeError, msg:
    723748            if rcParams['verbose']:
    724                 print msg
     749                #print msg
     750                casalog.post( msg, 'WARN' )
    725751            else:
    726752                raise
     
    768794        except RuntimeError, msg:
    769795            if rcParams['verbose']:
    770                 print msg
     796                #print msg
     797                casalog.post( msg, 'WARN' )
    771798                return
    772799            else: raise
     
    799826        except RuntimeError, msg:
    800827            if rcParams['verbose']:
    801                 print msg
     828                #print msg
     829                casalog.post( msg, 'WARN' )
    802830                return
    803831            else: raise
     
    11181146                msg = "Illegal file name '%s'." % (filename)
    11191147                if rcParams['verbose']:
    1120                     print msg
     1148                    #print msg
     1149                    casalog.post( msg, 'WARN' )
    11211150                else:
    11221151                    raise IOError(msg)
     
    11761205        except RuntimeError, msg:
    11771206            if rcParams['verbose']:
    1178                 print msg
     1207                #print msg
     1208                casalog.post( msg, 'WARN' )
    11791209                return
    11801210            else: raise
     
    14001430        except RuntimeError, msg:
    14011431            if rcParams['verbose']:
    1402                 print msg
     1432                #print msg
     1433                casalog.post( msg, 'WARN' )
    14031434                return
    14041435            else:
     
    14771508            msg = "The fit failed, possibly because it didn't converge."
    14781509            if rcParams['verbose']:
    1479                 print msg
     1510                #print msg
     1511                casalog.post( msg, 'WARN' )
    14801512                return
    14811513            else:
     
    19221954        fit = asapfit(self._getfit(row))
    19231955        if rcParams['verbose']:
    1924             print fit
     1956            #print fit
     1957            casalog.post( '%s' %(fit) )
    19251958            return
    19261959        else:
     
    20292062                if rcParams['verbose']:
    20302063                    asaplog.push(msg)
    2031                     print asaplog.pop().strip()
     2064                    #print asaplog.pop().strip()
     2065                    casalog.post( asaplog.pop().strip(), 'WARN' )
    20322066                    return
    20332067                raise IOError(msg)
Note: See TracChangeset for help on using the changeset viewer.