# Needed libraries to use import sys from parameter_check import * # Create a custom 'inp' command for your task - currently it has to be separate # from the existing value (this will be made easier in the future) def cinp(): """ Print out current input values for a specified task: """ # retrieve the global namespace myf=sys._getframe(1).f_globals # retrieve the global value of the parameters used in your task via: # parameter = myf['parameter'] vis=myf['vis'] verbose=myf['verbose'] # print out the inputs to your task print '' print 'example -- List the observations in a data set:' print '' print 'vis = "'+str(vis)+'"','\t: Name of input visibility file (MS)' print 'verbose = ',verbose,'\t: List each observation in addition to summary' # Save inputs def csaveinputs(outfile=''): """ Save current input values to file on disk for a specified task: outfile -- Output file for the task inputs default: taskname.saved; example: outfile=taskname.orion """ # as above; grab global namespace and values for used parameters myf=sys._getframe(1).f_globals vis=myf['vis'] verbose=myf['verbose'] if outfile=='': outfile='example.saved' taskparameterfile=open(outfile,'w') print >>taskparameterfile, 'vis = "'+str(vis)+'"' print >>taskparameterfile, 'verbose = ',verbose def example(vis=None,verbose=None): """List the observations in a dataset: Keyword arguments: vis -- Name of input visibility file (MS) default: ; example: vis='ngc5921.ms' verbose -- List each observation in addition to the summary default=False; example: verbose=True """ # All documentation that you would like goes between the triple double # quotes above - format it as you wold like to see it. # Get the global namespace myf=sys._getframe(1).f_globals # Retrieve the saveinputs command from global saveinputs=myf['saveinputs'] # Retrieve the tool(s) that you will use in your task # example is just a copy of 'listobs' which uses the 'ms' tool ms=myf['ms'] ### # Keep the following as is, change only the name of your task #Handle globals or user over-ride of arguments function_signature_defaults=dict(zip(example.func_code.co_varnames,example.func_defaults)) # ^^^^^^^ here and ^^^^^^^ here # Keep the following as is: 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: myf[key]=keyVal #user has set it - use over-ride # Put in the parameters that you have in your task vis=myf['vis'] verbose=myf['verbose'] # ### #Add type/menu/range error checking here arg_names=['vis','verbose'] arg_values=[vis,verbose] arg_types=[str,bool] #parameter_printvalues(arg_names,arg_values,arg_types) try: parameter_checktype(arg_names,arg_values,arg_types) except TypeError, e: print "example -- TypeError: ", e return ### #Python script ms.open(thems=vis) ms.summary(verbose=verbose) ms.close()