def oldpartition(vis, outputvis, createmms, separationaxis, numsubms, datacolumn, calmsselection, calmsname, calfield, calscan, calintent, field, spw, antenna, timebin, combine, timerange, scan, scanintent, array, uvrange, observation ): """Create a multi visibility set from an existing visibility set: Keyword arguments: vis -- Name of input visibility file (MS) default: none; example: vis='ngc5921.ms' outputvis -- Name of output visibility file (MS) default: none; example: outputvis='ngc5921_src.ms' createmms -- Boolean flag if we're creating Multi MS default: True separationaxis -- what axis do we intend to split on. default = 'scan' Options: 'scan','spw','both' numsubms -- Number of sub-MSs to create. default: 64 datacolumn -- Which data column to split out default='corrected'; example: datacolumn='data' Options: 'data', 'corrected', 'model', 'all', 'float_data', 'lag_data', 'float_data,data', and 'lag_data,data'. note: 'all' = whichever of the above that are present. calmsselection -- Method by which to create a separate Calibration ms default = 'none' options: 'none','auto','manual' calmsname -- Name of output calibration visibility file (MS) default: none; example: outputvis='ngc5921_CAL.ms' calfield -- Field selection for calibration MS. default: '' calscans -- Scan selection for calibration MS. default: '' calintent -- Scan intent selection for calibration MS. default: '' field -- Field name default: field = '' means use all sources field = 1 # will get field_id=1 (if you give it an integer, it will retrieve the source with that index) field = '1328+307' specifies source '1328+307'. Minimum match can be used, egs field = '13*' will retrieve '1328+307' if it is unique or exists. Source names with imbedded blanks cannot be included. spw -- Spectral window index identifier default=-1 (all); example: spw=1 antenna -- antenna names default '' (all), antenna = '3 & 7' gives one baseline with antennaid = 3,7. timebin -- Interval width for time averaging. default: '0s' or '-1s' (no averaging) example: timebin='30s' combine -- Data descriptors that time averaging can ignore: scan, and/or state Default '' (none) timerange -- Time range default='' means all times. examples: timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' timerange='< YYYY/MM/DD/HH:MM:SS.sss' timerange='> YYYY/MM/DD/HH:MM:SS.sss' timerange='< ddd/HH:MM:SS.sss' timerange='> ddd/HH:MM:SS.sss' scan -- Scan numbers to select. default '' (all). scanintent -- Select based on the scan intent. default '' (all) array -- (Sub)array IDs to select. default '' (all). uvrange -- uv distance range to select. default '' (all). observation -- observation ID(s) to select. default '' (all). """ #retval = True casalog.origin('partition') # Start by going through and checking all the parameters if not isinstance(vis, str) or not os.path.exists(vis): raise ValueError, \ 'Visibility data set (%s) not found - please verify the name' % \ vis # SMC: The outputvis must be given # NOTE: added print statement because the exception msgs are # not being printed at this moment. if not outputvis or outputvis.isspace(): print 'Please specify outputvis' raise ValueError, 'Please specify outputvis' outputvis = outputvis.rstrip('/') if outputvis != '' and os.path.exists(outputvis): print 'Output MS %s already exists - will not overwrite.'%outputvis raise ValueError, "Output MS %s already exists - will not overwrite."%\ outputvis if isinstance(antenna,list): antenna = ', '.join([str(ant) for ant in antenna]) if isinstance(spw, list): spw = ','.join([str(s) for s in spw]) elif isinstance(spw,int): spw = str(spw) # Accept digits without units ...assume seconds timebin = qa.convert(qa.quantity(timebin), 's')['value'] timebin = str(timebin) + 's' if timebin == '0s': timebin= '-1s' if hasattr(combine, '_iter_'): combine = ', '.join(combine) if calmsselection in ['auto','manual']: if os.path.exists(calmsname): raise ValueError, ("Output calibration MS %s already exists "+\ "will not overwrite." ) % calmsname if createmms or not \ ((calmsselection in ['auto','manual']) ^ (outputvis != '')): # This means we are creating more than a single MS do it in parallel ph = PartitionHelper(locals()) ph.go() # Create a backup of the flags that are in the MMS casalog.origin('partition') casalog.post('Create a backup of the flags that are in the MMS') fh.backupFlags(aflocal=None, msfile=outputvis, prename='partition') return # Create the msTool try: msTool = mstool() msTool.open(vis) msTool.partition(outputms=outputvis, field=field, spw=spw, baseline=antenna, subarray=array, timebin=timebin, time=timerange, whichcol=datacolumn, scan=scan, uvrange=uvrange, combine=combine, intent=scanintent, obs=str(observation)) msTool.close() except Exception, instance: casalog.post("*** Error \'%s\' captured in partition" % (instance),'WARN') msTool.close()
def flagdata(vis, mode, autocorr, # mode manual parameter inpfile, # mode list parameters reason, tbuff, spw, # data selection parameters field, antenna, uvrange, timerange, correlation, scan, intent, array, observation, feed, clipminmax, # mode clip parameters datacolumn, clipoutside, channelavg, chanbin, timeavg, timebin, clipzeros, quackinterval, # mode quack parameters quackmode, quackincrement, tolerance, # mode shadow parameter addantenna, lowerlimit, # mode elevation parameters upperlimit, ntime, # mode tfcrop combinescans, timecutoff, freqcutoff, timefit, freqfit, maxnpieces, flagdimension, usewindowstats, halfwin, extendflags, winsize, # rflag parameters timedev, freqdev, timedevscale, freqdevscale, spectralmax, spectralmin, extendpols, # mode extend growtime, growfreq, growaround, flagneartime, flagnearfreq, minrel, # mode summary maxrel, minabs, maxabs, spwchan, spwcorr, basecnt, fieldcnt, name, action, # run or not the tool display, flagbackup, savepars, # save the current parameters to FLAG_CMD or to a file cmdreason, # reason to save to flag cmd outfile, # output file to save flag commands overwrite, # overwrite the outfile file writeflags # HIDDEN parameter ): # # Task flagdata # Flags data from an MS or calibration table based on data selection in various ways casalog.origin('flagdata') if (action == 'none' or action=='' or action=='calculate'): flagbackup = False # SMC: moved the flagbackup to before initializing the cluster. # Note that with this change, a flag backup will be created even if # an error happens that prevents the flagger tool from running. if (mode != 'summary' and flagbackup): casalog.post('Backup original flags before applying new flags') fh.backupFlags(aflocal=None, msfile=vis, prename='flagdata') # Set flagbackup to False because only the controller # should create a backup flagbackup = False # Initialize the helper class orig_locals = copy.deepcopy(locals()) FHelper = FlagHelper() # Check if vis is a MS, MMS or cal table: # typevis = 1 --> cal table # typevis = 0 --> MS # typevis = 2 --> MMS iscal = False typevis = fh.isCalTable(vis) if typevis == 1: iscal = True # ***************** Input is MMS -- Parallel Processing *********************** if FHelper.isMPIEnabled() and typevis == 2 and action != '' and action != 'none': # Create a temporary input file with .tmp extension. # Use this file for all the processing from now on. if (isinstance(inpfile,str) and inpfile != '') or \ (isinstance(inpfile, list) and os.path.isfile(inpfile[0])): inpfile = FHelper.setupInputFile(inpfile) if inpfile != None: orig_locals['inpfile'] = inpfile if outfile != '': outfile = os.path.abspath(outfile) orig_locals['outfile'] = outfile if isinstance(addantenna, str) and addantenna != '': addantenna = os.path.abspath(addantenna) orig_locals['addantenna'] = addantenna if isinstance(timedev, str) and timedev != '': timedev = os.path.abspath(timedev) orig_locals['timedev'] = timedev if isinstance(freqdev, str) and freqdev != '': freqdev = os.path.abspath(freqdev) orig_locals['freqdev'] = freqdev FHelper.__init__(orig_locals) # For tests only # FHelper.bypassParallelProcessing(1) FHelper.setupCluster('flagdata') # (CAS-4119): Override summary minabs,maxabs,minrel,maxrel # so that it is done after consolidating the summaries # By-pass options to filter summary filterSummary = False if ((mode == 'summary') and ((minrel != 0.0) or (maxrel != 1.0) or (minabs != 0) or (maxabs != -1))): filterSummary = True myms = mstool() myms.open(vis) subMS_list = myms.getreferencedtables() myms.close() if (minrel != 0.0): minreal_dict = create_arg_dict(subMS_list,0.0) FHelper.override_arg('minrel',minreal_dict) if (maxrel != 1.0): maxrel_dict = create_arg_dict(subMS_list,1.0) FHelper.override_arg('maxrel',maxrel_dict) if (minabs != 0): minabs_dict = create_arg_dict(subMS_list,0) FHelper.override_arg('minabs',minabs_dict) if (maxabs != -1): maxabs_dict = create_arg_dict(subMS_list,-1) FHelper.override_arg('maxabs',maxabs_dict) # By-pass options to filter summary if savepars: myms = mstool() myms.open(vis) subMS_list = myms.getreferencedtables() myms.close() savepars_dict = create_arg_dict(subMS_list,False) FHelper.override_arg('savepars',savepars_dict) # Execute the parallel engines retVar = FHelper.go() # In async mode return the job ids if ParallelTaskHelper.getAsyncMode(): return retVar else: # Filter summary at MMS level if (mode == 'summary'): if filterSummary: retVar = filter_summary(retVar,minrel,maxrel,minabs,maxabs) return retVar # Save parameters at MMS level elif savepars: action = 'none' else: return retVar summary_stats={}; # ***************** Input is a normal MS/cal table **************** # Create local tools aflocal = casac.agentflagger() mslocal = mstool() try: # Verify the ntime value newtime = 0.0 if type(ntime) == float or type(ntime) == int: if ntime <= 0: raise Exception, 'Parameter ntime cannot be < = 0' else: # units are seconds newtime = float(ntime) elif type(ntime) == str: if ntime == 'scan': # iteration time step is a scan newtime = 0.0 else: # read the units from the string qtime = qa.quantity(ntime) if qtime['unit'] == 'min': # convert to seconds qtime = qa.convert(qtime, 's') elif qtime['unit'] == '': qtime['unit'] = 's' # check units if qtime['unit'] == 's': newtime = qtime['value'] else: casalog.post('Cannot convert units of ntime. Will use default 0.0s', 'WARN') casalog.post("New ntime is of type %s and value %s"%(type(newtime),newtime), 'DEBUG') # Open the MS and attach it to the tool if ((type(vis) == str) & (os.path.exists(vis))): aflocal.open(vis, newtime) else: raise Exception, 'Visibility data set not found - please verify the name' # Get the parameters for the mode agent_pars = {} # By default, write flags to the MS writeflags = True # Only the apply action writes to the MS # action=apply --> write to the MS # action=calculate --> do not write to the MS # action='' --> do not run the tool and do not write to the MS if action != 'apply': writeflags = False # Default mode if mode == '' or mode == 'manualflag': mode = 'manual' # Read in the list of commands # Make a dictionary of the input commands. Select by reason if requested flagcmd = {} if mode == 'list': casalog.post('List mode is active') doPadding = True try: # If tbuff is requested, read and Parse if tbuff == 0.0 or tbuff == [] or tbuff == None: doPadding = False if doPadding: casalog.post('Will apply time buffer padding') # inpfile is a file if isinstance(inpfile, str): inpfile = [inpfile] # read in the list and do a simple parsing to apply tbuff flaglist = fh.readAndParse(inpfile, tbuff) else: # inpfile is a file if isinstance(inpfile, str) and os.path.isfile(inpfile): flaglist = fh.readFile(inpfile) nlines = len(flaglist) casalog.post('Read %s command(s) from file: %s'%(nlines, inpfile)) # inpfile is a list of files elif isinstance(inpfile, list) and os.path.isfile(inpfile[0]): flaglist = fh.readFiles(inpfile) # Python list of strings elif isinstance(inpfile, list): flaglist = inpfile else: raise Exception, 'Unsupported input list of flag commands or input file does not exist' # Parse and create a dictionary flagcmd = fh.parseDictionary(flaglist, reason) # Validate the dictionary. # IMPORTANT: if any parameter changes its type, the following # function needs to be updated. The same if any new parameter is # added or removed from the task fh.evaluateFlagParameters(flagcmd,orig_locals) # List of flag commands in dictionary vrows = flagcmd.keys() casalog.post('%s'%flagcmd,'DEBUG1') except Exception, instance: casalog.post('%s'%instance,'ERROR') raise Exception, 'Error reading the input list. Make sure the syntax used in the list '\ 'follows the rules given in the inline help of the task.' casalog.post('Selected ' + str(vrows.__len__()) + ' commands from combined input list(s) ') elif mode == 'manual': agent_pars['autocorr'] = autocorr casalog.post('Manual mode is active')
def flagdata( vis, mode, autocorr, # mode manual parameter inpfile, # mode list parameters reason, tbuff, spw, # data selection parameters field, antenna, uvrange, timerange, correlation, scan, intent, array, observation, feed, clipminmax, # mode clip parameters datacolumn, clipoutside, channelavg, timeavg, timebin, clipzeros, quackinterval, # mode quack parameters quackmode, quackincrement, tolerance, # mode shadow parameter addantenna, lowerlimit, # mode elevation parameters upperlimit, ntime, # mode tfcrop combinescans, timecutoff, freqcutoff, timefit, freqfit, maxnpieces, flagdimension, usewindowstats, halfwin, extendflags, winsize, # rflag parameters timedev, freqdev, timedevscale, freqdevscale, spectralmax, spectralmin, extendpols, # mode extend growtime, growfreq, growaround, flagneartime, flagnearfreq, minrel, # mode summary maxrel, minabs, maxabs, spwchan, spwcorr, basecnt, fieldcnt, name, action, # run or not the tool display, flagbackup, savepars, # save the current parameters to FLAG_CMD or to a file cmdreason, # reason to save to flag cmd outfile, # output file to save flag commands writeflags # HIDDEN parameter ): # # Task flagdata # Flags data from an MS or calibration table based on data selection in various ways casalog.origin('flagdata') if (action == 'none' or action == '' or action == 'calculate'): flagbackup = False # SMC: moved the flagbackup to before initializing the cluster. # Note that with this change, a flag backup will be created even if # an error happens that prevents the flagger tool from running. if (mode != 'summary' and flagbackup): casalog.post('Backup original flags before applying new flags') fh.backupFlags(aflocal=None, msfile=vis, prename='flagdata') # Set flagbackup to False because only the controller # should create a backup flagbackup = False # Initialize the helper class orig_locals = locals() FHelper = FlagHelper() # Check if vis is a MS, MMS or cal table: # typevis = 1 --> cal table # typevis = 0 --> MS # typevis = 2 --> MMS iscal = False typevis = fh.isCalTable(vis) if typevis == 1: iscal = True # ***************** Input is MMS -- Parallel Processing *********************** if typevis == 2 and action != '' and action != 'none': # Create a temporary input file with .tmp extension. # Use this file for all the processing from now on. if (isinstance(inpfile,str) and inpfile != '') or \ (isinstance(inpfile, list) and os.path.isfile(inpfile[0])): inpfile = FHelper.setupInputFile(inpfile) if inpfile != None: orig_locals['inpfile'] = inpfile if outfile != '': outfile = os.path.abspath(outfile) orig_locals['outfile'] = outfile if isinstance(addantenna, str) and addantenna != '': addantenna = os.path.abspath(addantenna) orig_locals['addantenna'] = addantenna if isinstance(timedev, str) and timedev != '': timedev = os.path.abspath(timedev) orig_locals['timedev'] = timedev if isinstance(freqdev, str) and freqdev != '': freqdev = os.path.abspath(freqdev) orig_locals['freqdev'] = freqdev FHelper.__init__(orig_locals) # For tests only # FHelper.bypassParallelProcessing(1) FHelper.setupCluster('flagdata') # (CAS-4119): Override summary minabs,maxabs,minrel,maxrel # so that it is done after consolidating the summaries # By-pass options to filter summary filterSummary = False if ((mode == 'summary') and ((minrel != 0.0) or (maxrel != 1.0) or (minabs != 0) or (maxabs != -1))): filterSummary = True myms = mstool() myms.open(vis) subMS_list = myms.getreferencedtables() myms.close() if (minrel != 0.0): minreal_dict = create_arg_dict(subMS_list, 0.0) FHelper.override_arg('minrel', minreal_dict) if (maxrel != 1.0): maxrel_dict = create_arg_dict(subMS_list, 1.0) FHelper.override_arg('maxrel', maxrel_dict) if (minabs != 0): minabs_dict = create_arg_dict(subMS_list, 0) FHelper.override_arg('minabs', minabs_dict) if (maxabs != -1): maxabs_dict = create_arg_dict(subMS_list, -1) FHelper.override_arg('maxabs', maxabs_dict) # By-pass options to filter summary if savepars: myms = mstool() myms.open(vis) subMS_list = myms.getreferencedtables() myms.close() savepars_dict = create_arg_dict(subMS_list, False) FHelper.override_arg('savepars', savepars_dict) # Execute the parallel engines retVar = FHelper.go() # In async mode return the job ids if ParallelTaskHelper.getAsyncMode(): return retVar else: # Filter summary at MMS level if (mode == 'summary'): if filterSummary: retVar = filter_summary(retVar, minrel, maxrel, minabs, maxabs) return retVar # Save parameters at MMS level elif savepars: action = 'none' else: return retVar summary_stats = {} # if pCASA.is_mms(vis): # pCASA.execute("flagdata", orig_locals) # return # ***************** Input is a normal MS/cal table **************** # Create local tools aflocal = casac.agentflagger() mslocal = mstool() try: # Verify the ntime value newtime = 0.0 if type(ntime) == float or type(ntime) == int: if ntime <= 0: raise Exception, 'Parameter ntime cannot be < = 0' else: # units are seconds newtime = float(ntime) elif type(ntime) == str: if ntime == 'scan': # iteration time step is a scan newtime = 0.0 else: # read the units from the string qtime = qa.quantity(ntime) if qtime['unit'] == 'min': # convert to seconds qtime = qa.convert(qtime, 's') elif qtime['unit'] == '': qtime['unit'] = 's' # check units if qtime['unit'] == 's': newtime = qtime['value'] else: casalog.post( 'Cannot convert units of ntime. Will use default 0.0s', 'WARN') casalog.post( "New ntime is of type %s and value %s" % (type(newtime), newtime), 'DEBUG') # Open the MS and attach it to the tool if ((type(vis) == str) & (os.path.exists(vis))): aflocal.open(vis, newtime) else: raise Exception, 'Visibility data set not found - please verify the name' # Get the parameters for the mode agent_pars = {} # By default, write flags to the MS writeflags = True # Only the apply action writes to the MS # action=apply --> write to the MS # action=calculate --> do not write to the MS # action='' --> do not run the tool and do not write to the MS if action != 'apply': writeflags = False # Default mode if mode == '' or mode == 'manualflag': mode = 'manual' # Read in the list of commands # Make a dictionary of the input commands. Select by reason if requested flagcmd = {} if mode == 'list': casalog.post('List mode is active') doPadding = True try: # If tbuff is requested, read and Parse if tbuff == 0.0 or tbuff == [] or tbuff == None: doPadding = False if doPadding: casalog.post('Will apply time buffer padding') # inpfile is a file if isinstance(inpfile, str): inpfile = [inpfile] # read in the list and do a simple parsing to apply tbuff flaglist = fh.readAndParse(inpfile, tbuff) else: # inpfile is a file if isinstance(inpfile, str) and os.path.isfile(inpfile): flaglist = fh.readFile(inpfile) nlines = len(flaglist) casalog.post('Read %s command(s) from file: %s' % (nlines, inpfile)) # inpfile is a list of files elif isinstance(inpfile, list) and os.path.isfile( inpfile[0]): flaglist = fh.readFiles(inpfile) # Python list of strings elif isinstance(inpfile, list): flaglist = inpfile else: raise Exception, 'Unsupported input list of flag commands or input file does not exist' # Parse and create a dictionary flagcmd = fh.parseDictionary(flaglist, reason) # Validate the dictionary. # IMPORTANT: if any parameter changes its type, the following # function needs to be updated. The same if any new parameter is # added or removed from the task fh.evaluateFlagParameters(flagcmd, orig_locals) # List of flag commands in dictionary vrows = flagcmd.keys() casalog.post('%s' % flagcmd, 'DEBUG1') except Exception, instance: casalog.post('%s' % instance, 'ERROR') raise Exception, 'Error reading the input list. Make sure the syntax used in the list '\ 'follows the rules given in the inline help of the task.' casalog.post('Selected ' + str(vrows.__len__()) + ' commands from combined input list(s) ') elif mode == 'manual': agent_pars['autocorr'] = autocorr casalog.post('Manual mode is active')
# Get a cluster pdh.setupCluster(thistask='partition') # Execute the jobs using simple_cluster try: pdh.go() pdh.bypassParallelProcessing(0) except Exception, instance: casalog.post('%s'%instance,'ERROR') return False # Create a backup of the flags that are in the MMS casalog.origin('partition') if flagbackup and os.path.exists(outputvis): casalog.post('Create a backup of the flags that are in the MMS') fh.backupFlags(aflocal=None, msfile=outputvis, prename='partition') return True # Create local copies of the MSTransform and ms tools mtlocal = casac.mstransformer() mslocal = mstool() try: # Gather all the parameters in a dictionary. config = {} config = pdh.setupParameters(inputms=vis, outputms=outputvis, field=field, spw=spw, array=array, scan=scan, antenna=antenna, correlation=correlation, uvrange=uvrange,timerange=timerange, intent=intent, observation=str(observation),
def applycal( vis=None, field=None, spw=None, intent=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, msselect=None, docallib=None, callib=None, gaintable=None, gainfield=None, interp=None, spwmap=None, calwt=None, parang=None, applymode=None, flagbackup=None, ): # Python script casalog.origin('applycal') # Take care of the trivial parallelization if ParallelTaskHelper.isParallelMS(vis): # Back up the flags, if requested (and if necessary) if flagbackup and applymode != 'calonly' and applymode != 'trial': fh.backupFlags(aflocal=None, msfile=vis, prename='applycal') flagbackup = False # To be safe convert file names to absolute paths. gaintable = ParallelTaskHelper.findAbsPath(gaintable) helper = ParallelTaskHelper('applycal', locals()) ret = helper.go() if ParallelTaskHelper.getAsyncMode(): return ret else: return try: mycb = cbtool() if (type(vis) == str) & os.path.exists(vis): # add CORRECTED_DATA column mycb.open(filename=vis, compress=False, addcorr=True, addmodel=False) else: raise Exception, \ 'Visibility data set not found - please verify the name' # enforce default if unspecified if applymode == '': applymode = 'calflag' # Back up the flags, if requested (and if necessary) if flagbackup and applymode != 'calonly' and applymode \ != 'trial': fh.backupFlags(aflocal=None, msfile=vis, prename='applycal') # Do data selection according to selectdata if selectdata: # pass all data selection parameters in as specified mycb.selectvis( time=timerange, spw=spw, scan=scan, field=field, intent=intent, observation=str(observation), baseline=antenna, uvrange=uvrange, chanmode='none', msselect=msselect, ) else: # selectdata=F, so time,scan,baseline,uvrange,msselect='' # using spw and field specifications only mycb.selectvis( time='', spw=spw, scan='', field=field, intent=intent, observation='', baseline='', uvrange='', chanmode='none', msselect='', ) # Arrange applies.... if docallib: # by cal library from file # parsing using c++ parser thiscallib=mycb.parsecallibfile(callib) mycb.setcallib(thiscallib) else: # by traditional parameters ngaintab = 0 if gaintable != ['']: ngaintab = len(gaintable) ncalwt = len(calwt) if ncalwt == 1: calwt = [calwt[0] for i in range(ngaintab)] ngainfld = len(gainfield) nspwmap = len(spwmap) ninterp = len(interp) # handle list of list issues with spwmap if nspwmap > 0: if type(spwmap[0]) != list: # first element not a list, only one spwmap specified # make it a list of list spwmap = [spwmap] nspwmap = 1 for igt in range(ngaintab): if gaintable[igt] != '': # field selection is null unless specified thisgainfield = '' if igt < ngainfld: thisgainfield = gainfield[igt] # spwmap is null unless specifed thisspwmap = [-1] if igt < nspwmap: thisspwmap = spwmap[igt] # interp is 'linear' unless specified thisinterp = 'linear' if igt < ninterp: if interp[igt] == '': interp[igt] = thisinterp thisinterp = interp[igt] mycb.setapply( t=0.0, table=gaintable[igt], field=thisgainfield, calwt=calwt[igt], spwmap=thisspwmap, interp=thisinterp, ) # ...and now the specialized terms # Apply parallactic angle, if requested if parang: mycb.setapply(type='P') mycb.correct(applymode) # report what the flags did reportflags(mycb.activityrec()) mycb.close() # write history try: param_names = \ applycal.func_code.co_varnames[:applycal.func_code.co_argcount] param_vals = [eval(p) for p in param_names] write_history( mstool(), vis, 'applycal', param_names, param_vals, casalog, ) except Exception, instance: casalog.post("*** Error \'%s\' updating HISTORY" % instance, 'WARN') except Exception, instance: print '*** Error ***', instance mycb.close() casalog.post("Error in applycal: %s" % str(instance), "SEVERE") raise Exception, "Error in applycal: "+str(instance)
def applycal( vis=None, field=None, spw=None, intent=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, msselect=None, docallib=None, callib=None, gaintable=None, gainfield=None, interp=None, spwmap=None, calwt=None, parang=None, applymode=None, flagbackup=None, ): # Python script casalog.origin("applycal") # Take care of the trivial parallelization if ParallelTaskHelper.isParallelMS(vis): # Back up the flags, if requested (and if necessary) if flagbackup and applymode != "calonly" and applymode != "trial": fh.backupFlags(aflocal=None, msfile=vis, prename="applycal") flagbackup = False # To be safe convert file names to absolute paths. gaintable = ParallelTaskHelper.findAbsPath(gaintable) helper = ParallelTaskHelper("applycal", locals()) ret = helper.go() if ParallelTaskHelper.getAsyncMode(): return ret else: return try: mycb = cbtool() if (type(vis) == str) & os.path.exists(vis): # add CORRECTED_DATA column mycb.open(filename=vis, compress=False, addcorr=True, addmodel=False) else: raise Exception, "Visibility data set not found - please verify the name" # enforce default if unspecified if applymode == "": applymode = "calflag" # Back up the flags, if requested (and if necessary) if flagbackup and applymode != "calonly" and applymode != "trial": fh.backupFlags(aflocal=None, msfile=vis, prename="applycal") # Do data selection according to selectdata if selectdata: # pass all data selection parameters in as specified mycb.selectvis( time=timerange, spw=spw, scan=scan, field=field, intent=intent, observation=str(observation), baseline=antenna, uvrange=uvrange, chanmode="none", msselect=msselect, ) else: # selectdata=F, so time,scan,baseline,uvrange,msselect='' # using spw and field specifications only mycb.selectvis( time="", spw=spw, scan="", field=field, intent=intent, observation="", baseline="", uvrange="", chanmode="none", msselect="", ) # Arrange applies.... if docallib: # by cal library from file mycallib = callibrary() mycallib.read(callib) mycb.setcallib(mycallib.cld) else: # by traditional parameters ngaintab = 0 if gaintable != [""]: ngaintab = len(gaintable) ncalwt = len(calwt) if ncalwt == 1: calwt = [calwt[0] for i in range(ngaintab)] ngainfld = len(gainfield) nspwmap = len(spwmap) ninterp = len(interp) # handle list of list issues with spwmap if nspwmap > 0: if type(spwmap[0]) != list: # first element not a list, only one spwmap specified # make it a list of list spwmap = [spwmap] nspwmap = 1 for igt in range(ngaintab): if gaintable[igt] != "": # field selection is null unless specified thisgainfield = "" if igt < ngainfld: thisgainfield = gainfield[igt] # spwmap is null unless specifed thisspwmap = [-1] if igt < nspwmap: thisspwmap = spwmap[igt] # interp is 'linear' unless specified thisinterp = "linear" if igt < ninterp: if interp[igt] == "": interp[igt] = thisinterp thisinterp = interp[igt] mycb.setapply( t=0.0, table=gaintable[igt], field=thisgainfield, calwt=calwt[igt], spwmap=thisspwmap, interp=thisinterp, ) # ...and now the specialized terms # Apply parallactic angle, if requested if parang: mycb.setapply(type="P") mycb.correct(applymode) # report what the flags did reportflags(mycb.activityrec()) mycb.close() # write history try: param_names = applycal.func_code.co_varnames[: applycal.func_code.co_argcount] param_vals = [eval(p) for p in param_names] write_history(mstool(), vis, "applycal", param_names, param_vals, casalog) except Exception, instance: casalog.post("*** Error '%s' updating HISTORY" % instance, "WARN") except Exception, instance: print "*** Error ***", instance mycb.close() casalog.post("Error in applycal: %s" % str(instance), "SEVERE") raise Exception, "Error in applycal: " + str(instance)
# Get a cluster pdh.setupCluster(thistask='partition') # Execute the jobs using cluster try: pdh.go() pdh.bypassParallelProcessing(0) except Exception, instance: casalog.post('%s' % instance, 'ERROR') return False # Create a backup of the flags that are in the MMS casalog.origin('partition') if flagbackup and os.path.exists(outputvis): casalog.post('Create a backup of the flags that are in the MMS') fh.backupFlags(aflocal=None, msfile=outputvis, prename='partition') return True # Create local copies of the MSTransform and ms tools mtlocal = casac.mstransformer() mslocal = mstool() try: # Gather all the parameters in a dictionary. config = {} config = pdh.setupParameters(inputms=vis, outputms=outputvis, field=field, spw=spw,
def statwt(vis, selectdata, field, spw, intent, array, observation, combine, timebin, slidetimebin, chanbin, minsamp, statalg, fence, center, lside, zscore, maxiter, excludechans, wtrange, flagbackup, preview, datacolumn): casalog.origin('statwt') if not selectdata: # CAS-10761, requirement provided by Urvashi if field or spw or intent or array or observation: casalog.post( "selectdata=False, any explicitly set data " + "selection parameters will be ignored", "WARN") field = "" spw = "" intent = "" array = "" observation = "" try: if (flagbackup): if (preview): casalog.post( "Running in preview mode. No flags will be " + "modified, so existing flags will not be backed up.") else: casalog.post('Backup original flags before applying new flags') flaghelper.backupFlags(aflocal=None, msfile=vis, prename='statwt') myms = mstool() myms.open(vis, nomodify=preview) sel = {} sel['spw'] = spw #sel['time'] = timerange sel['field'] = field #sel['baseline'] = antenna #sel['scan'] = scan sel['scanintent'] = intent #sel['polarization'] = correlation #sel['uvdist'] = uvrange sel['observation'] = str(observation) sel['array'] = array #sel['feed'] = feed # Select the data. Only-parse is set to false. myms.msselect(sel, False) rval = None rval = myms.statwt(combine=combine, timebin=timebin, slidetimebin=slidetimebin, chanbin=chanbin, minsamp=minsamp, statalg=statalg, fence=fence, center=center, lside=lside, zscore=zscore, maxiter=maxiter, excludechans=excludechans, wtrange=wtrange, preview=preview, datacolumn=datacolumn) # Write to HISTORY of MS if rval != None and preview == False: # Write history to MS try: param_names = statwt.func_code.co_varnames[:statwt.func_code. co_argcount] param_vals = [eval(p) for p in param_names] write_history(mstool(), vis, 'statwt', param_names, param_vals, casalog) except Exception, instance: casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN') return rval