import sys import os import casac import string import inspect import pdb from parameter_check import * casapath=os.environ['AIPSPATH'] import asap as sd os.environ['AIPSPATH']=casapath def sdlist(infile=None,scanaverage=None,listfile=None): """ASAP SD listing task (prototype): Task Version 2007-03-06 STM Keyword arguments: infile -- name of input SD dataset scanaverage -- average integrations within scans options: (bool) True,False default: False example: if True, this happens in read-in For GBT, set False! listfile -- Name of output file for summary list default: '' (no output file) example: 'mysd_summary.txt' WARNING: output file will be overwritten DESCRIPTION: Task sdlist lists the scan summary of the dataset after importing as a scantable into ASAP. It will optionally output this summary as file. Note that if your PAGER environment variable is set to 'less' and you have set the 'verbose' ASAP environment variable to True (the default), then the screen version of the summary will page. You can disable this for sdlist by setting sd.rcParams['verbose']=False before running sdlist. Set it back afterwards if you want lots of information. """ a=inspect.stack() stacklevel=0 for k in range(len(a)): if (string.find(a[k][1], 'ipython console') > 0): stacklevel=k break myf=sys._getframe(stacklevel).f_globals myf['__last_taskname']='sdlist' tb=myf['tb'] im = myf['im'] qa = myf['qa'] me = myf['me'] sm = myf['sm'] ia = myf['ia'] cl = myf['cl'] pl = myf['pl'] rg = myf['rg'] default=myf['default'] plotxy=myf['plotxy'] ### ### #Handle globals or user over-ride of arguments # function_signature_defaults=dict(zip(sdlist.func_code.co_varnames,sdlist.func_defaults)) for item in function_signature_defaults.iteritems(): key,val = item keyVal = eval(key) if (keyVal == None): #user hasn't set it - use global/default pass else: #user has set it - use over-ride # sys._getframe(1).f_globals[key]=keyVal myf[key]=keyVal ### # #Add type/menu/range error checking here # if type(mask)==str: mask=[mask] # # LIST PARAMETER NAMES HERE arg_names=['infile','scanaverage','listfile'] # # Assign parameter values arg_values = [] for ptst in arg_names: stst = myf[ptst] if ( type(stst) == str ): # Strip off leading and trailing whitespace stst = stst.strip() myf[ptst] = stst sex = ptst+"='"+stst+"'" else: sex = ptst+"="+str(stst) exec(sex) arg_values = arg_values + [stst] # # LIST ALLOWED PARAMETER TYPES HERE arg_types=[str,bool,str] #parameter_printvalues(arg_names,arg_values,arg_types) # # Check allowed types and values try: parameter_checktype(arg_names,arg_values,arg_types) except TypeError, e: print "sdlist -- TypeError: ", e return except ValueError, e: print "sdlist -- OptionError: ", e return ### ### ### Now the actual task code ### try: # pdb.set_trace() #load the data with or without averaging s=sd.scantable(infile,scanaverage) if ( listfile == '' ): sum = s.summary() else: sum = s.summary(listfile) if ( sd.rcParams['verbose'] == 'False'): # print the summary to the screen manually print sum # Clean up scantable del s # DONE except TypeError, e: print "sdlist -- TypeError: ", e return except ValueError, e: print "sdlist -- OptionError: ", e return except Exception, instance: print '***Error***',instance return saveinputs=myf['saveinputs'] saveinputs('sdlist','sdlist.last') ###End of sdlist def sdlist_defaults(): a=inspect.stack() stacklevel=0 for k in range(len(a)): if (string.find(a[k][1], 'ipython console') > 0): stacklevel=k break myf=sys._getframe(stacklevel).f_globals myf['infile']='' myf['scanaverage']=False myf['listfile']='' def sdlist_description(key='sdlist'): desc={'sdlist': 'ASAP SD listing task\n', 'infile': 'name of input SD dataset', 'scanaverage': 'average integs within scans (True,False)', 'listfile': 'output file name', } return desc[key] ###End of task