######################################################################### # # Function to count statistics as a function of 'reason' # # Flag Zeros, and run TFCrop, gathering incremental summary statistics. # ######################################################################### def task_reason_stats(msname='',field='',spw='',writeflags=True): # Open the MS and select data af.open(msname=msname,ntime=100.0); af.selectdata(field=field, spw=spw); # Unflag (This is only for a demo) ag0 = {'apply':True, 'sequential':True, 'mode':'unflag'} af.parseagentparameters(ag0); # (1) Flag Zeros ag1 = {'apply':True,'sequential':True,'mode':'clip', 'clipzeros':True} af.parseagentparameters(ag1); # (2) Summary ag2 = {'apply':True,'sequential':True,'mode':'summary','name':'Zeros'} af.parseagentparameters(ag2); # (3) TFCrop ag3 = {'apply':True,'sequential':True,'mode':'tfcrop'} af.parseagentparameters(ag3); # (4) Summary ag4 = {'apply':True,'sequential':True,'mode':'summary', 'name':'TFCrop'} af.parseagentparameters(ag4); # Run all these agents, and get the combined-report. af.init(); summary_stats_list = af.run(writeflags=writeflags); af.done(); # Parse the output summary lists and extract only 'type==summary' ## Iterate through the list in the correct order. Do not follow default 'dictionary-key' ordering. summary_reps=[]; for rep in range(0,summary_stats_list['nreport']): repname = 'report'+str(rep); if(summary_stats_list[repname]['type']=='summary'): summary_reps.append(summary_stats_list[repname]); # Step through the summary list and print a few things. ## SUBTRACT flag counts from previous agents, because the counts are cumulative. for ind in range(0,len(summary_reps)): flagcount = summary_reps[ind]['flagged']; totalcount = summary_reps[ind]['total']; # From the second summary onwards, subtract counts from the previous one :) if ( ind > 0 ): flagcount = flagcount - summary_reps[ind-1]['flagged']; print "Summary ", ind , "(" , summary_reps[ind]['name'] , ") : Flagged : " , flagcount , " out of " , totalcount ; return summary_reps; ##############################################