示例#1
0
 def test_default_cparam(self):
     '''Flagcmd: flag CPARAM data column'''
     flist = ["mode='clip' clipzeros=True datacolumn='CPARAM'"]
     flagcmd(vis=self.vis, inpmode='list', inpfile=flist,
             flagbackup=False)
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'], 11078, 'Should use CPARAM as the default column')
示例#2
0
 def test_compatibility(self):
     myinput = "observation='1' mode='manualflag'"
     filename = create_input(myinput)
     
     flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=False,
             flagbackup=False)
     test_eq(flagdata(vis=self.vis, mode='summary'), 2882778, 28500)
示例#3
0
 def test_clip_one_list(self):
     '''Flagcmd: Flag one solution using one command in a list'''
     flist = ["mode='clip' clipminmax=[0,3] correlation='REAL_Sol1' datacolumn='CPARAM'"]
     flagcmd(vis=self.vis, inpmode='list', inpfile=flist)
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'], 309388)
     self.assertEqual(res['correlation']['Sol2']['flagged'], 0)
示例#4
0
 def test_CAS4819(self):
     '''flagcmd: CAS-4819, Flag commands from three files'''
     self.setUp_ngc5921()
     # creat first input file
     myinput = "scan='1'\n"\
             "scan='2'\n"\
             "scan='3'"
     filename1 = 'list7a.txt'
     create_input1(myinput, filename1)
     
     # Create second input file
     myinput = "scan='5'\n"\
             "scan='6'\n"\
             "scan='7'"        
     filename2 = 'list7b.txt'
     create_input1(myinput, filename2)
     
      # Create third input file
     myinput = "scan='4' mode='clip' clipminmax=[0,4]" 
     filename3 = 'list7c.txt'
     create_input1(myinput, filename3)
    
     flagcmd(vis=self.vis, inpmode='list', inpfile=[filename1,filename2,filename3],
              flagbackup=False, action='apply')
     
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['scan']['1']['flagged'], 568134)
     self.assertEqual(res['scan']['2']['flagged'], 238140)
     self.assertEqual(res['scan']['3']['flagged'], 762048)
     self.assertEqual(res['scan']['4']['flagged'], 6696)
     self.assertEqual(res['scan']['5']['flagged'], 142884)
     self.assertEqual(res['scan']['6']['flagged'], 857304)
     self.assertEqual(res['scan']['7']['flagged'], 190512)
     self.assertEqual(res['total'],2854278)
     self.assertEqual(res['flagged'],2765718)
示例#5
0
 def test_list_reason1(self):
     '''flagcmd: select by reason from two files'''
     self.setUp_ngc5921()
     # creat first input file
     myinput = "scan='1' spw='0:10~20' reason='NONE'\n"\
             "scan='2' reason='EVEN'\n"\
             "scan='3' reason='ODD'"
     filename1 = 'reasonfile1.txt'
     create_input1(myinput, filename1)
     
     # Create second input file
     myinput = "scan='5' reason='ODD'\n"\
             "scan='6' reason='EVEN'\n"\
             "scan='7' reason='ODD'"        
     filename2 = 'reasonfile2.txt'
     create_input1(myinput, filename2)
     
     # Apply flag cmds on ODD reason
     flagcmd(vis=self.vis, inpmode='list', inpfile=[filename1,filename2], reason='ODD',
              flagbackup=False, action='apply')
     
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['scan']['3']['flagged'], 762048)
     self.assertEqual(res['scan']['5']['flagged'], 142884)
     self.assertEqual(res['scan']['6']['flagged'], 0)
     self.assertEqual(res['scan']['7']['flagged'], 190512)
     self.assertEqual(res['flagged'], 762048+142884+190512)
示例#6
0
 def test_xml2(self):
     '''flagcmd: list xml file and save in outfile'''
     
     # The MS only contains clip and shadow commands
     
     # Apply the shadow command
     flagcmd(vis=self.vis, action='apply', reason='SHADOW', flagbackup=False)
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'], 240640)
示例#7
0
 def test_cal_observation(self):
     '''Flagcmd: flag an observation from an old cal table format'''
     # Note: this cal table does not have an observation column. 
     # The column and sub-table should be added and the flagging
     # should happen after this.
     flagcmd(vis=self.vis, inpmode='list', inpfile=["observation='0'"], flagbackup=False)
     res=flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'],1248000)
     self.assertEqual(res['total'],1248000)
示例#8
0
 def test_manual_field_selection_for_bpass(self):
     """Flagcmd:: Manually flag a bpass-based CalTable using field selection"""
     
     flagcmd(vis=self.vis, inpmode='list', inpfile=["field='3C286_A'"], flagbackup=False)
     summary=flagdata(vis=self.vis, mode='summary')
     
     self.assertEqual(summary['field']['3C286_A']['flagged'], 499200.0)
     self.assertEqual(summary['field']['3C286_B']['flagged'], 0)
     self.assertEqual(summary['field']['3C286_C']['flagged'], 0)
     self.assertEqual(summary['field']['3C286_D']['flagged'], 0)
示例#9
0
 def test_action_plot_table(self):
     '''flagcmd: Test action=plot, nothing plotted'''
     outplot = 'noplot.png'
     flagcmd(vis=self.vis, inpmode='list', 
         inpfile=["intent='CAL*POINT*' field=''","scan='5'"], 
         action='list', savepars=True)
     
     flagcmd(vis=self.vis, inpmode='table', useapplied=True, action='plot',
             plotfile=outplot)
     
     self.assertTrue(os.path.exists(outplot),'Plot file was not created')
示例#10
0
 def test_action_plot_list(self):
     '''flagcmd: Test action=plot to plot 4 antennas and no timerange'''
     outplot = 'fourplot.png'
     cmds = ["antenna='ea01' reason='none'",
             "antenna='ea11' reason='no_reason'",
             "antenna='ea19' reason='none'",
             "antenna='ea24' reason='other'"]
     
     flagcmd(vis=self.vis, inpmode='list', inpfile=cmds, action='plot',plotfile=outplot)
             
     self.assertTrue(os.path.exists(outplot),'Plot file was not created')
示例#11
0
    def test_apply4(self):
        '''importevla: Save online flags to FLAG_CMD and file; do not apply'''

        # Use default msname and outfile
        msname = 'xosro4.ms'
        cmdfile = msname.replace('.ms', '_cmd.txt')
        if os.path.exists(msname):
            os.system('rm -rf ' + msname)
        if os.path.exists(cmdfile):
            os.system('rm -rf ' + cmdfile)

        importevla(asdm=self.asdm,
                   vis=msname,
                   scans='2',
                   online=True,
                   shadow=False,
                   flagzero=False,
                   applyflags=False,
                   savecmds=True,
                   flagbackup=False)

        # No flags were applied
        res = flagdata(vis=msname, mode='summary')
        self.assertEqual(res['flagged'], 0)

        # Apply only row 213 using flagcmd
        # The command in row 213 is the following:
        # antenna='ea06' timerange='2012/02/22/22:30:55.200~2012/02/22/22:35:08.199'
        # spw='EVLA_X#A0C0#0' correlation='LL,LR,RL
        flagcmd(vis=msname, action='apply', tablerows=213)

        # Check flags. RR should no be flagged
        res = flagdata(vis=msname, mode='summary')
        self.assertEqual(res['correlation']['RR']['flagged'], 0,
                         'RR should not be flagged')
        self.assertEqual(res['correlation']['LL']['flagged'], 29440)
        self.assertEqual(res['correlation']['LR']['flagged'], 29440)
        self.assertEqual(res['correlation']['RL']['flagged'], 29440)
        self.assertEqual(res['antenna']['ea06']['flagged'], 88320)
        self.assertEqual(res['antenna']['ea07']['flagged'], 3840,
                         'Only a few baselines should be flagged')
        self.assertEqual(res['antenna']['ea08']['flagged'], 3840,
                         'Only a few baselines should be flagged')

        # Check output file existence
        self.assertTrue(os.path.exists(cmdfile))

        # Check file content
        ff = open(cmdfile, 'r')
        cmdlist = ff.readlines()
        ncmds = cmdlist.__len__()
        ff.close()
        self.assertEqual(ncmds, 214,
                         'Only Online cmds should have been saved to file')
示例#12
0
 def test_MS_flagcmds(self):
     """Flagcmd:: Save flags to MS and apply to cal table"""
     self.setUp_data4rflag()
     msfile = self.vis
     flagcmd(vis=msfile, action='clear', clearall=True)
     flagdata(vis=msfile, antenna='ea09', action='', savepars=True)
     
     self.setUp_bpass_case()
     flagcmd(vis=self.vis, inpfile=msfile, action='apply', flagbackup=False)
     summary=flagdata(vis=self.vis, mode='summary')
     self.assertEqual(summary['antenna']['ea09']['flagged'], 48000.0)
     self.assertEqual(summary['antenna']['ea10']['flagged'], 0.0)
示例#13
0
    def test_list_field_Selection_for_bpass(self):
        """Flagcmd:: Manually flag a bpass-based CalTable using file in list mode """
        
        myinput = "field='3C286_A'"
        filename = create_input(myinput)

        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, flagbackup=False)
        summary=flagdata(vis=self.vis, mode='summary')
        self.assertEqual(summary['field']['3C286_A']['flagged'], 499200.0)
        self.assertEqual(summary['field']['3C286_B']['flagged'], 0)
        self.assertEqual(summary['field']['3C286_C']['flagged'], 0)
        self.assertEqual(summary['field']['3C286_D']['flagged'], 0)
示例#14
0
 def test_cmd(self):
     '''flagcmd: inpmode=list with empty parameter'''
     
     # Test the correct parsing with empty parameter such as antenna=''
     flagcmd(vis=self.vis, inpmode='list', 
              inpfile=["intent='CAL*POINT*' field=''","scan='1,8' antenna=''","scan='10'"], 
              action='apply', savepars=False, flagbackup=False)
     res = flagdata(vis=self.vis,mode='summary')
     self.assertEqual(res['scan']['1']['flagged'], 192416)
     self.assertEqual(res['scan']['8']['flagged'], 39096)
     self.assertEqual(res['scan']['10']['flagged'], 39096)
     self.assertEqual(res['flagged'], 270608)
示例#15
0
    def test_apply4(self):
        """importevla: Save online flags to FLAG_CMD and file; do not apply"""

        # Use default msname and outfile
        msname = "xosro4.ms"
        cmdfile = msname.replace(".ms", "_cmd.txt")
        if os.path.exists(msname):
            os.system("rm -rf " + msname)
        if os.path.exists(cmdfile):
            os.system("rm -rf " + cmdfile)

        importevla(
            asdm=self.asdm,
            vis=msname,
            scans="2",
            online=True,
            shadow=False,
            flagzero=False,
            applyflags=False,
            savecmds=True,
            flagbackup=False,
        )

        # No flags were applied
        res = flagdata(vis=msname, mode="summary")
        self.assertEqual(res["flagged"], 0)

        # Apply only row 213 using flagcmd
        # The command in row 213 is the following:
        # antenna='ea06' timerange='2012/02/22/22:30:55.200~2012/02/22/22:35:08.199'
        # spw='EVLA_X#A0C0#0' correlation='LL,LR,RL
        flagcmd(vis=msname, action="apply", tablerows=213)

        # Check flags. RR should no be flagged
        res = flagdata(vis=msname, mode="summary")
        self.assertEqual(res["correlation"]["RR"]["flagged"], 0, "RR should not be flagged")
        self.assertEqual(res["correlation"]["LL"]["flagged"], 29440)
        self.assertEqual(res["correlation"]["LR"]["flagged"], 29440)
        self.assertEqual(res["correlation"]["RL"]["flagged"], 29440)
        self.assertEqual(res["antenna"]["ea06"]["flagged"], 88320)
        self.assertEqual(res["antenna"]["ea07"]["flagged"], 3840, "Only a few baselines should be flagged")
        self.assertEqual(res["antenna"]["ea08"]["flagged"], 3840, "Only a few baselines should be flagged")

        # Check output file existence
        self.assertTrue(os.path.exists(cmdfile))

        # Check file content
        ff = open(cmdfile, "r")
        cmdlist = ff.readlines()
        ncmds = cmdlist.__len__()
        ff.close()
        self.assertEqual(ncmds, 214, "Only Online cmds should have been saved to file")
示例#16
0
 def test_save_cal(self):
     '''Flagcmd: list flag cmds from MS and save to a file'''
     self.setUp_data4rflag()
     msfile = self.vis
     flagcmd(vis=msfile, action='clear', clearall=True)
     
     # Save cmds to FLAG_CMD table
     flagcmd(vis=msfile, inpmode='list', inpfile=["spw='1,3",
                                                  "mode='clip' clipminmax=[0,500] datacolumn='SNR'"], 
             action='list', savepars=True)
     
     self.setUp_bpass_case()
     flagcmds = 'calflags.txt'
     if os.path.exists(flagcmds):
         os.system('rm -rf '+flagcmds)
         
     # Apply to cal table and save to an external file
     flagcmd(vis=self.vis, inpmode='table', inpfile=msfile, savepars=True, outfile=flagcmds)
     self.assertTrue(os.path.exists(flagcmds))
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'], 246315)
     
     # Apply from list in file and compare
     flagdata(vis=self.vis, mode='unflag')
     flagcmd(vis=self.vis, inpmode='list', inpfile=flagcmds, action='apply')
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['flagged'], 246315)
示例#17
0
    def test_umanualflag(self):
        '''flagcmd: unapply manual agent'''
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)

        # Flag using manual agent
        myinput = "scan='1'"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)

        # Flag using the quack agent
        myinput = "scan='1~3' mode=quack quackinterval=1.0"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)
        
        # Unapply the manual line
        flagcmd(vis=self.vis, action='unapply', useapplied=True, tablerows=0, savepars=False)
        result = flagdata(vis=self.vis,mode='summary',scan='1,2,3')
        
        # scan 1 should be fully unflagged
        self.assertEqual(result['scan']['1']['flagged'], 0)
        self.assertEqual(result['scan']['2']['flagged'], 47628)
        self.assertEqual(result['scan']['3']['flagged'], 47628)
        self.assertEqual(result['flagged'], 47628+47628)
示例#18
0
    def test_uquack(self):
        '''flagcmd: unapply quack agent'''
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)

        # Flag using the quack agent
        myinput = "scan='1~3' mode=quack quackinterval=1.0"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)
        result = flagdata(vis=self.vis,mode='summary')
        quack_flags = result['scan']['1']['flagged']

        # Flag using manual agent
        myinput = "scan='1'"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)
        result = flagdata(vis=self.vis,mode='summary')
        scan1_flags = result['scan']['1']['flagged']

        # Unapply only the quack line
        flagcmd(vis=self.vis, action='unapply', useapplied=True, tablerows=0, savepars=True)
        result = flagdata(vis=self.vis,mode='summary')
        manual_flags = result['scan']['1']['flagged']
        
        # Only the manual flags should be there
#         self.assertEqual(result['flagged'], 568134, 'Expected 568134 flags, found %s'%result['flagged'])
#         self.assertEqual(result['total'], 568134,'Expected total 568134, found %s'%result['total'])
        # CAS-5377. New unapply action
        self.assertEqual(result['scan']['3']['flagged'], 0)
        self.assertEqual(manual_flags,scan1_flags - quack_flags)
示例#19
0
 def test_cal_time_field(self):
     '''Flagcmd: clip a timerange from a field'''
     # this timerange corresponds to field 3C286_D
     flags = "mode='clip' timerange='>14:58:33.6' clipzeros=True clipminmax=[0.,0.4]"\
             " datacolumn='CPARAM'"
     
     # Apply the flags
     flagcmd(vis=self.vis, inpmode='list', inpfile=[flags], flagbackup=False)
     res=flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['field']['3C286_A']['flagged'],0)
     self.assertEqual(res['field']['3C286_B']['flagged'],0)
     self.assertEqual(res['field']['3C286_C']['flagged'],0)
     self.assertEqual(res['field']['3C286_D']['flagged'],2221)
     self.assertEqual(res['flagged'],2221)
示例#20
0
    def test_utfcrop(self):
        '''flagcmd: unapply tfcrop agent'''
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)

        # Flag using manual agent
        myinput = "scan='1'"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True)
        
        # Flag using tfcrop agent from file
        # Note : For this test, scan=4 gives identical flags on 32/64 bit machines,
        #           and one flag difference on a Mac (32)
        #           Other scans give differences at the 0.005% level.
        myinput = "scan='4' mode=tfcrop correlation='ABS_RR' extendflags=False"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)
        res = flagdata(vis=self.vis,mode='summary')
        self.assertEqual(res['scan']['1']['flagged'], 568134, 'Whole scan=1 should be flagged')
        #self.assertEqual(res['scan']['4']['flagged'], 1201, 'scan=4 should be partially flagged')
        self.assertTrue(res['scan']['4']['flagged']>= 1200 and res['scan']['4']['flagged']<= 1204, \
                        'scan=4 should be partially flagged')
        
        # Unapply only the tfcrop line
        flagcmd(vis=self.vis, action='unapply', useapplied=True, tablerows=1, savepars=False)
        result = flagdata(vis=self.vis,mode='summary',scan='4')
        self.assertEqual(result['flagged'], 0, 'Expected 0 flags, found %s'%result['flagged'])
        self.assertEqual(result['total'], 95256,'Expected total 95256, found %s'%result['total'])
示例#21
0
    def test_intent(self):
        '''flagcmd: test scan intent selection'''
        
        myinput = "intent='CAL*POINT*'\n"\
                "#scan=3,4"
        filename = create_input(myinput)
        
        # flag POINTING CALIBRATION scans and ignore comment line
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=False,
                flagbackup=False)
#         test_eq(flagdata(vis=self.vis,mode='summary', antenna='2'), 377280, 26200)
        res = flagdata(vis=self.vis,mode='summary')
#         self.assertEqual(res['scan']['1']['flagged'], 80184, 'Only scan 1 should be flagged')
#         self.assertEqual(res['scan']['4']['flagged'], 0, 'Scan 4 should not be flagged')
        self.assertEqual(res['scan']['1']['flagged'], 192416.0)
示例#22
0
 def test_unsupported_mode_in_list(self):
     '''Flagcmd: elevation and shadow are not supported in cal tables'''
     res = flagcmd(vis=self.vis, inpmode='list', inpfile=["mode='elevation'",
                                                          "spw='1'"])
     
     res = flagdata(vis=self.vis, mode='summary')
     self.assertEqual(res['spw']['1']['flagged'], 83200)
示例#23
0
    def test_rflagauto(self):
        """flagcmd:: Test of rflag with defaults
        """
        # (6) flagcmd AUTO. Should give same answers as test_flagdata[test_rflag1]
        flagdata(vis=self.vis,mode='unflag');
        flagcmd(vis=self.vis, inpmode='list', inpfile=['mode=rflag spw=9,10 extendflags=False'], 
                action='apply',
                flagbackup=False)
        res6 = flagdata(vis=self.vis, mode='summary')
        print "(6) Finished flagcmd test : auto : ", res6['flagged']

        #(7) flagdata AUTO (same as test_flagdata[test_rflag1])
        #flagdata(vis=self.vis,mode='unflag');
        #flagdata(vis=self.vis, mode='rflag', spw='9,10');
        #res7 = flagdata(vis=self.vis, mode='summary')
        #print "\n---------------------- Finished flagdata test : auto : ", res7['flagged']

        self.assertEqual(res6['flagged'], 42728.0)
示例#24
0
    def test_overwrite_false1(self):
        '''flagcmd: Use savepars and overwrite=False'''
        
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)
        
        # Create flag commands in file called flagcmd.txt
        myinput = "scan='4' mode='clip' correlation='ABS_RR' clipminmax=[0, 4]\n"
        filename = create_input(myinput)

        newfile = 'myflags.txt'                
        # Apply flags from filename and try to save in newfile
        # Overwrite=False shouldn't do anything as newfile doesn't exist
        flagcmd(vis=self.vis, action='apply', inpmode='list',inpfile=filename, savepars=True, outfile=newfile,
                flagbackup=False, overwrite=False)
        
        # newfile should contain what was in filename
        self.assertTrue(filecmp.cmp(filename, newfile, 1), 'Files should be the same')        
示例#25
0
    def test_apply4(self):
        '''importevla: Save online flags to FLAG_CMD and file; do not apply'''

        # Use default msname and outfile
        msname = 'xosro4.ms'
        cmdfile = msname.replace('.ms','_cmd.txt')
        if os.path.exists(msname):
            os.system('rm -rf '+msname)
        if os.path.exists(cmdfile):
            os.system('rm -rf '+cmdfile)
            
        importevla(asdm=self.asdm, vis=msname, scans='2',online=True, shadow=False, flagzero=False,
                    applyflags=False,savecmds=True, flagbackup=False)

        # No flags were applied
        res = flagdata(vis=msname, mode='summary')
        self.assertEqual(res['flagged'],0)
        
        # Apply only row 213 using flagcmd
        # The command in row 213 is the following:
        # antenna='ea06' timerange='2012/02/22/22:30:55.200~2012/02/22/22:35:08.199' 
        # spw='EVLA_X#A0C0#0' correlation='LL,LR,RL
        flagcmd(vis=msname, action='apply', tablerows=213)
        
        # Check flags. RR should no be flagged
        res = flagdata(vis=msname, mode='summary')
        self.assertEqual(res['correlation']['RR']['flagged'],0,'RR should not be flagged')
        self.assertEqual(res['correlation']['LL']['flagged'],29440)
        self.assertEqual(res['correlation']['LR']['flagged'],29440)
        self.assertEqual(res['correlation']['RL']['flagged'],29440)
        self.assertEqual(res['antenna']['ea06']['flagged'],88320)
        self.assertEqual(res['antenna']['ea07']['flagged'],3840,'Only a few baselines should be flagged')
        self.assertEqual(res['antenna']['ea08']['flagged'],3840,'Only a few baselines should be flagged')
        
        # Check output file existence       
        self.assertTrue(os.path.exists(cmdfile))
        
        # Check file content
        ff = open(cmdfile,'r')
        cmdlist = ff.readlines()
        ncmds = cmdlist.__len__()
        ff.close()
        self.assertEqual(ncmds, 214, 'Only Online cmds should have been saved to file')
示例#26
0
    def test_CAS2399(self):
        '''flagcmd: shadow by antennas not present in MS'''
        
        # Create antennafile in disk
        myinput = 'name=VLA01\n'+\
                'diameter=25.0\n'+\
                'position=[-1601144.96146691, -5041998.01971858, 3554864.76811967]\n'+\
                'name=VLA02\n'+\
                'diameter=25.0\n'+\
                'position=[-1601105.7664601889, -5042022.3917835914, 3554847.245159178]\n'+\
                'name=VLA09\n'+\
                'diameter=25.0\n'+\
                'position=[-1601197.2182404203, -5041974.3604805721, 3554875.1995636248]\n'+\
                'name=VLA10\n'+\
                'diameter=25.0\n'+\
                'position=[-1601227.3367843349,-5041975.7011900628,3554859.1642644769]\n'            

#        antfile = 'myants.txt'
#        if os.path.exists(antfile):
#            os.system('rm -rf myants.txt')

        filename = create_input(myinput)

        # Create command line
        myinput = ["mode='shadow' tolerance=0.0 addantenna='flagcmd.txt'"]
#        filename = 'cmdfile.txt'
#        if os.path.exists(filename):
#            os.system('rm -rf cmdfile.txt')
        
#        create_input(myinput, filename)
        
        # Flag
        flagcmd(vis=self.vis, action='clear', clearall=True)
#        flagcmd(vis=self.vis, action='apply', inpmode='list', inpfile=filename)
        flagcmd(vis=self.vis, action='apply', inpmode='list', inpfile=myinput, flagbackup=False)
        
        # Check flags
        res = flagdata(vis=self.vis, mode='summary')
        self.assertEqual(res['antenna']['VLA3']['flagged'], 3752)
        self.assertEqual(res['antenna']['VLA4']['flagged'], 1320)
        self.assertEqual(res['antenna']['VLA5']['flagged'], 1104)        
示例#27
0
    def test_action_plot_da(self):
        '''flagcmd: Test action=plot to plot page with DA antenna CAS-5187'''
        cmds = []
        for i in range(28):
            cmds.append("antenna='DA%03d' reason='none%d'" % (i, i % 5))

        r = flagcmd(vis=self.vis, inpmode='list', inpfile=cmds, action='plot',
                    plotfile='manyplot.png')
        self.assertIn('plotfiles', r)
        self.assertEqual(len(r['plotfiles']), 1)
        self.assertEqual(r['plotfiles'], ['manyplot.png'])
        self.assertTrue(os.path.exists('manyplot.png'))
示例#28
0
    def test_overwrite_false1(self):
        '''flagcmd: Use savepars and overwrite=False'''
        
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)
        
        # Create flag commands in file called flagcmd.txt
        myinput = "scan='4' mode='clip' correlation='ABS_RR' clipminmax=[0, 4]\n"
        filename = create_input(myinput)

        newfile = 'myflags.txt'  
        if os.path.exists("myflags.txt"):
            os.system('rm -rf myflags.txt')
                      
        # Apply flags from filename and try to save in newfile
        # Overwrite=False shouldn't do anything as newfile doesn't exist
        flagcmd(vis=self.vis, action='apply', inpmode='list',inpfile=filename, savepars=True, outfile=newfile,
                flagbackup=False, overwrite=False)
        
        # newfile should contain what was in filename
        self.assertTrue(filecmp.cmp(filename, newfile, 1), 'Files should be the same')        
示例#29
0
    def test_overwrite_false(self):
        '''flagcmd: Use savepars and overwrite=False'''
        
        # Create flag commands in file called flagcmd.txt
        myinput = "scan='4' mode='clip' correlation='ABS_RR' clipminmax=[0, 4]\n"
        filename = create_input(myinput)
        # Copy it to a new file
        newfile = 'newfile.txt'
        os.system('rm -rf '+newfile)
        os.system('cp '+filename+' '+newfile)

        # Create different flag command 
        myinput = "scan='1'\n"
        filename = create_input(myinput)
                
        # Apply flags from filename and try to save in newfile
        # Overwrite parameter should allow this
        flagcmd(vis=self.vis, action='apply', inpmode='list',inpfile=filename, savepars=True, outfile=newfile,
                flagbackup=False, overwrite=False)
        
        # newfile should contain what was in filename
        self.assertFalse(filecmp.cmp(filename, newfile, 1), 'Files should be different')        
示例#30
0
    def test_action_plot_large(self):
        '''flagcmd: Test action=plot to plot many antennas into multiple pages'''
        cmds = []
        for i in range(60):
            cmds.append("antenna='ea%03d' reason='none%d'" % (i, i % 5))

        r = flagcmd(vis=self.vis, inpmode='list', inpfile=cmds, action='plot',
                    plotfile='manyplot.png')
        self.assertIn('plotfiles', r)
        self.assertEqual(len(r['plotfiles']), 3)
        self.assertEqual(r['plotfiles'],
                         ['manyplot-001.png',
                          'manyplot-002.png','manyplot-003.png'])
        for f in r['plotfiles']:
            self.assertTrue(os.path.exists(f))
示例#31
0
    def test_unapply_clip_and_unset_flagrow(self):
        '''flagcmd: Check that FLAG_ROW is unset after un-applying a clip agent'''
        # Remove any cmd from table
        flagcmd(vis=self.vis, action='clear', clearall=True)

        # Flag using manual agent
        myinput = "scan='4'"
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=False)
        
        # Check FLAG_ROW is all set to true
        mytb = tbtool()
        mytb.open(self.vis)
        selectedtb = mytb.query('SCAN_NUMBER in [4]')
        FLAG_ROW = selectedtb.getcol('FLAG_ROW')
        mytb.close()        
        selectedtb.close()
        self.assertEqual(FLAG_ROW.sum(), FLAG_ROW.size)
        
        # Flag using tfcrop agent from file
        myinput = "scan='4' mode=clip "
        filename = create_input(myinput)
        flagcmd(vis=self.vis, inpmode='list', inpfile=filename, action='apply', savepars=True,
                flagbackup=False)
        
        # Check FLAG_ROW is all set to true
        mytb = tbtool()
        mytb.open(self.vis)
        selectedtb = mytb.query('SCAN_NUMBER in [4]')
        FLAG_ROW = selectedtb.getcol('FLAG_ROW')
        mytb.close()           
        selectedtb.close()
        self.assertEqual(FLAG_ROW.sum(), FLAG_ROW.size)
        
        # Unapply only the tfcrop line
        flagcmd(vis=self.vis, action='unapply', useapplied=True, tablerows=0, savepars=False)
       
        # Check FLAG_ROW is now all set to false
        mytb = tbtool()
        mytb.open(self.vis)
        selectedtb = mytb.query('SCAN_NUMBER in [4]')
        FLAG_ROW = selectedtb.getcol('FLAG_ROW')
        mytb.close()        
        selectedtb.close()
        self.assertEqual(FLAG_ROW.sum(), 0)
示例#32
0
 def test_action_list1(self):
      '''flagcmd: action=list with inpmode from a list'''
      flagcmd(vis=self.vis, action='clear', clearall=True)         
      cmd = ["spw='5~7'","spw='1'"]
      flagcmd(vis=self.vis, action='list', inpmode='list', inpfile=cmd, savepars=True)
      
      # Apply the flags
      flagcmd(vis=self.vis)
      
      res=flagdata(vis=self.vis, mode='summary')
      self.assertEqual(res['flagged'],1099776)  
示例#33
0
 def test_missing_corr(self):
     '''flagcmd: CAS-4234, non-existing correlation raise no error'''
     flagcmd(vis=self.vis, action='clear', clearall=True)
     
     flagcmd(vis=self.vis, inpmode='list', inpfile=["correlation='XX,RR,RL'"], action='list',
             savepars=True)
     
     flagcmd(vis=self.vis, action='apply', flagbackup=False)
     
     res = flagdata(vis=self.vis, mode='summary')
     
     self.assertEqual(res['flagged'], 208000+208000, 'Should only flag RR and RL and not fail')