コード例 #1
0
 def corrcheck(self, dataset):
     self.res = listobs(vis=dataset, listfile='listobs.txt')
     self.assertTrue('Corrs' in open('listobs.txt').read(),
                     msg='Corrs does not exist in a MS')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, correlation=1)
     else:
         self.assertFalse(
             listobs(vis=dataset, correlation=1),
             msg='An int was accepted when a string is required')
     # section that should not raise warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, correlation='XX')
     listobs(vis=dataset, correlation='XX,YY')
     self.assertFalse(
         'WARN' in open('testlog.log').read(),
         msg='not accepting proper input for correlation in a MS')
     # section that should raise warnings
     listobs(vis=dataset, correlation=['XX', 'YY'])
     self.assertTrue('incorrect data type' in open('testlog.log').read(),
                     msg='No warning for using a list was given')
     listobs(vis=dataset, correlation='RR')
     self.assertTrue('named RR' in open('testlog.log').read(),
                     msg='No warning for using a absent correlation')
コード例 #2
0
 def timerangecheck(self, dataset):
     #check valid entry
     self.assertTrue(listobs(vis=dataset, timerange='03:00:00~04:00:00'))
     # create temp log and check inputs that raise no warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, timerange='3:0:0~4:0:0,4:0:0~5:0:0')
     self.assertFalse('WARN' in open('testlog.log').read())
     # check that specific warnings are raised
     listobs(vis=dataset, timerange='abc')
     self.assertTrue(
         'Parse error at or near ' in open('testlog.log').read())
     listobs(vis=dataset, timerange=[])
     self.assertTrue('incorrect data type used for field time' in open(
         'testlog.log').read())
     listobs(vis=dataset, timerange='03:00:00-04:00:00')
     self.assertTrue('near char. 9 in string "03:00:00-04:00:00"' in open(
         'testlog.log').read())
     listobs(vis=dataset, timerange='3~4')
     self.assertTrue(
         'MSSelectionNullSelection' in open('testlog.log').read())
     # Check that passing an int fails
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, timerange=4)
     else:
         self.assertFalse(listobs(vis=dataset, timerange=4))
コード例 #3
0
 def antcheck(self, dataset):
     self.res = listobs(vis=dataset, listfile='listobs.txt')
     self.assertTrue('Antennas' in open('listobs.txt').read(),
                     msg='Antennas section does not exist in MS')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, antenna=0)
     else:
         self.assertFalse(
             listobs(vis=dataset, antenna=0),
             msg='Accepts an int as an argument when a string is required')
     # section that should not raise warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, antenna='0')
     listobs(vis=dataset, antenna='0,DV01')
     self.assertFalse('WARN' in open('testlog.log').read(),
                      msg='Proper inputs raised warnings')
     # section that should raise warnings
     listobs(vis=dataset, antenna='abc')
     self.assertTrue('Antenna Expression: No match found for token(s)'
                     in open('testlog.log').read(),
                     msg='No warning raise for invalid string')
     listobs(vis=dataset, antenna='3')
     self.assertTrue(
         'No match found for the antenna specificion [ID(s): [3]]'
         in open('testlog.log').read(),
         msg='No warning for ID out of range')
     # This one is marked as correct by the documentation, but CASA disagrees
     listobs(vis=dataset, antenna=['0,DV01'])
     self.assertTrue('incorrect data type used for field baseline'
                     in open('testlog.log').read(),
                     msg='Failed to recognize list as incorrect data type')
コード例 #4
0
 def spwcheck(self, dataset):
     self.res = listobs(vis=dataset, listfile='listobs.txt')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, spw=1)
     else:
         self.assertFalse(listobs(vis=dataset, spw=1),
                          msg='An int was given to spw (requires string)')
     self.assertTrue('SpwID' in open('listobs.txt').read(),
                     msg='Spw does not exist in a MS')
     # section that should raise no warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, spw='0')
     listobs(vis=dataset, spw='0,1')
     listobs(vis=dataset, spw='0~1')
     self.assertFalse('WARN' in open('testlog.log').read(),
                      msg='not accepting proper input for spw in a MS')
     # section that should raise warnings
     listobs(vis=dataset, spw='3')
     self.assertTrue('No match found for 3' in open('testlog.log').read(),
                     msg='fails to recognize out of range values')
     listobs(vis=dataset, spw='0')
     self.assertTrue('-1' in open('testlog.log').read(),
                     msg='Fails to recognize improper delimiter')
     listobs(vis=dataset, spw='abc')
     self.assertTrue('No match found for "abc"'
                     in open('testlog.log').read(),
                     msg='Fails to recognize improper string')
コード例 #5
0
 def fieldcheck(self, dataset):
     self.res = listobs(vis=dataset, listfile='listobs.txt')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, field=1)
     else:
         self.assertFalse(
             listobs(vis=dataset, field=1),
             msg='An int was given to the field (requires a string)')
     self.assertTrue('FldId' in open('listobs.txt').read(),
                     msg='Field Id does not exist in a MS')
     # section that should raise no warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, field='1')
     listobs(vis=dataset, field='0~2')
     listobs(vis=dataset, field='0,2')
     self.assertFalse('WARN' in open('testlog.log').read(),
                      msg='not accepting proper input for field in a MS')
     # section that should be raising warnings
     listobs(vis=dataset, field='0-2')
     self.assertTrue('No match found for name "0-2"'
                     in open('testlog.log').read(),
                     msg='Failed to identify improper delimiter')
     listobs(vis=dataset, field='abc')
     self.assertTrue('No match found for name "abc"'
                     in open('testlog.log').read(),
                     msg='Failed to identify improper string')
コード例 #6
0
    def scancheck(self, dataset):
        # Check that listobs runs and that the scan column exists
        self.res = listobs(vis=dataset, listfile='listobs.txt')
        self.assertTrue('Scan' in open('listobs.txt').read(),
                        msg='scan does not exist in output')
        # Check to see if a valid input and invalid input is returns the proper value (pass/fail)
        self.assertTrue(listobs(vis=dataset, scan='1'),
                        msg='Scan fails to select')
        if CASA6:
            with self.assertRaises(AssertionError):
                listobs(vis=dataset, scan=1)
        else:
            self.assertFalse(listobs(vis=dataset, scan=1),
                             msg='Scan incorrectly accepts an int')

        # Make temp log
        casalog.setlogfile('testlog.log')

        # test for certain warnings appearing in the log
        listobs(vis=dataset, scan='1,2')
        self.assertFalse('WARN' in open('testlog.log').read(),
                         msg='A warning is raised for multiple scans')
        listobs(vis=dataset, scan=['1', '2'])
        self.assertTrue('incorrect data type' in open('testlog.log').read(),
                        msg='fails to label incorrect data type')
        listobs(vis=dataset, scan='abc')
        self.assertTrue('Parse error' in open('testlog.log').read(),
                        msg='fails to recognize improper string')
コード例 #7
0
    def obscheck(self, dataset):
        self.assertTrue(listobs(vis=dataset, observation=0),
                        msg='Observation fails to accept Int for a MS')
        self.assertTrue(
            listobs(vis=dataset, observation='0'),
            msg='Observation fails to accept proper string for a MS')
        # These should raise warnings
        casalog.setlogfile('testlog.log')
        listobs(vis=dataset, observation='abc')
        self.assertTrue('Parse error' in open('testlog.log').read(),
                        msg='Listobs fails to identify improper string')
        listobs(vis=dataset, observation='10')
        self.assertTrue(('The selected table has zero rows')
                        in open('testlog.log').read(),
                        msg='Listobs fails to identify an empty table')

        self.res = listobs(vis=dataset, listfile='listobs.txt')
        self.assertTrue('ObservationID' in open('listobs.txt').read(),
                        msg='There is no Observation information')
コード例 #8
0
    def logreadfunc(self, dataset):
        casalog.setlogfile('testlog.log')
        listobs(vis=dataset)
        casalog.setlogfile(logpath)

        if sys.version_info[0] == 3:
            print('VERSION', ' ', sys.version_info)
            # Check that the file can be read in python session default encoding
            with open('testlog.log', 'r') as fout:
                list(map(bytes2str, fout.readlines()))
                print(list(map(bytes2str, fout.readlines())))

        else:
            # Check if the file can be decoded as ascii for python 2.7
            with open('testlog.log', 'r') as log:
                for data in log:
                    try:
                        data.decode('ASCII')
                    except:
                        self.fail()
コード例 #9
0
 def intentcheck(self, dataset):
     # Returns true with a valid input and false with an int
     self.assertTrue(listobs(
         vis=dataset,
         intent=
         'CALIBRATE_PHASE.ON_SOURCE,CALIBRATE_POINTING.ON_SOURCE,CALIBRATE_WVR.ON_SOURCE'
     ),
                     msg='Fails with valid input')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, intent=1)
     else:
         self.assertFalse(listobs(vis=dataset, intent=1),
                          msg='Accepts int when it should only accept str')
     # Test for the existence of the column scan intent
     self.res = listobs(vis=dataset, listfile='listobs.txt')
     self.assertTrue('ScanIntent' in open('listobs.txt').read(),
                     msg='There is no ScanIntent information for a MS')
     # These shouldn't raise any warnings
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset, intent='CALIBRATE_PHASE.ON_SOURCE')
     listobs(
         vis=dataset,
         intent=
         'CALIBRATE_PHASE.ON_SOURCE,CALIBRATE_POINTING.ON_SOURCE,CALIBRATE_WVR.ON_SOURCE'
     )
     self.assertFalse(
         'WARN' in open('testlog.log').read(),
         msg='There are warnings for inputs that should raise none')
     # These should raise a warning
     listobs(vis=dataset, intent=[])
     self.assertTrue('incorrect data type used for field scanintent'
                     in open('testlog.log').read(),
                     msg='Incorrect data type list accepted')
     listobs(vis=dataset, intent='abc')
     self.assertTrue('No match found for "abc"'
                     in open('testlog.log').read(),
                     msg='Invalid string accepted without warning')
コード例 #10
0
 def uvrangecheck(self, dataset):
     self.assertTrue(listobs(vis=dataset, uvrange='0~100klambda'),
                     msg='fails to read valid input for uvrange in a MS')
     if CASA6:
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, uvrange=0)
         with self.assertRaises(AssertionError):
             listobs(vis=dataset, uvrange=[1, 2])
     else:
         self.assertFalse(
             listobs(vis=dataset, uvrange=0),
             msg='Accepts an int when only str should be accepted')
         self.assertFalse(
             listobs(vis=dataset, uvrange=[1, 2]),
             msg='accepts an array of ints when only str should be accepted'
         )
     # Use temp log
     casalog.setlogfile('testlog.log')
     # shouldn't raise Warning
     listobs(vis=dataset, uvrange='0~100')
     listobs(vis=dataset, uvrange='0~100klambda')
     listobs(vis=dataset, uvrange='0~50,60~100')
     self.assertFalse('WARN' in open('testlog.log').read(),
                      msg='Warnings are raised for valid inputs')
     # should raise warnings
     listobs(vis=dataset, uvrange=['0~50', '60~100'])
     self.assertTrue('incorrect data type used for field uvdist'
                     in open('testlog.log').read(),
                     msg='Fails to raise warning for wrong data type')
     listobs(vis=dataset, uvrange='0-100')
     self.assertTrue('near char. 2 in string "0-100"'
                     in open('testlog.log').read(),
                     msg='Fails to raise warning for wrong delimiter')
     listobs(vis=dataset, uvrange='abc')
     self.assertTrue('near char. 1 in string "abc"'
                     in open('testlog.log').read(),
                     msg='Fails to raise warning for improper string')
コード例 #11
0
    def arraycheck(self, dataset):
        self.assertTrue(listobs(vis=dataset, array='0'),
                        msg='Listobs fails to recognize valid array in a MS')
        if CASA6:
            with self.assertRaises(AssertionError):
                listobs(vis=dataset, array=0)
        else:
            self.assertFalse(
                listobs(vis=dataset, array=0),
                msg='Listobs fails to recognize invalid data type in a MS')
        self.res = listobs(vis=dataset, listfile='listobs.txt')
        # These should raise warnings
        casalog.setlogfile('testlog.log')
        listobs(vis=dataset, array='abc')
        self.assertTrue(
            'Parse error' in open('testlog.log').read(),
            msg='Listobs fails to recognize invalid string in a MS')
        listobs(vis=dataset, array='10')
        self.assertTrue('The selected table has zero rows'
                        in open('testlog.log').read(),
                        msg='Listobs fails to recognize empty table from a MS')

        self.assertTrue('ArrayID' in open('listobs.txt').read(),
                        msg='There is no Array information for a MS')
コード例 #12
0
#Copyright (C) 2020 Inter-University Institute for Data Intensive Astronomy
#See processMeerKAT.py for license details.

#!/usr/bin/env python3
import sys
import os

# Adapt PYTHONPATH to include processMeerKAT
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(SCRIPT_DIR))

import bookkeeping
from selfcal_scripts.selfcal_part2 import find_outliers
from casatasks import casalog
logfile = casalog.logfile()
casalog.setlogfile(
    'logs/{SLURM_JOB_NAME}-{SLURM_JOB_ID}.casa'.format(**os.environ))

if __name__ == '__main__':

    args, params = bookkeeping.get_selfcal_params()
    find_outliers(**params, step='sky')
    bookkeeping.rename_logs(logfile)
コード例 #13
0
 def tearDown(self):
     # remove files and temp logs
     os.system('rm -rf ' + 'listobs*.txt')
     os.system('rm -rf testlog.log')
     casalog.setlogfile(str(logpath))
コード例 #14
0
 def logfilecontain(self, dataset):
     casalog.setlogfile('testlog.log')
     listobs(vis=dataset)
     self.assertTrue('listobs' in open('testlog.log').read(),
                     msg='logfile not populated by listobs command on a MS')