Source
xxxxxxxxxx
##########################################################################
# test_task_calstat.py
#
# Copyright (C) 2018
# Associated Universities, Inc. Washington DC, USA.
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
# License for more details.
#
# [Add the link to the JIRA ticket here once it exists]
#
# Based on the requirements listed in plone found here:
# https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.calstat.html
#
# Test_logreturn checks to make sure a logfile is generated and populated
# Test_dictreturn checks that the result is a python dict object containing keys specified in the documentation
# Test_takescal checks that a caltable is accepted and non-cal tables are rejected
# Test_axis checks that different axis vaules will provide different information
# Test_axisvals checks that the values for axis provided in the documentatin are accepted as valid values
# Test_datacolumn checks that different datacolumn values provide different information
#
##########################################################################
import sys
import os
import unittest
import shutil
import casatools
from casatasks import casalog, calstat
from casatools import table, ctsys
datapath = casatools.ctsys.resolve('unittest/calstat/ggtau.1mm.amp.gcal')
datapath_visibilities = casatools.ctsys.resolve('unittest/calstat/')
logpath = casalog.logfile()
contained = ['max', 'mean', 'medabsdevmed', 'median', 'min', 'npts', 'quartile', 'rms', 'stddev', 'sum', 'sumsq', 'var']
epsilon = 0.0001
class calstat_test(unittest.TestCase):
def setUp(self):
self.tb = table()
self.epsilon = 0.0001
self.caltables = ['ggtau.1mm.amp.gcal',
'ggtau.1mm.bpoly',
'ggtau.1mm.ph.gcal',
'ggtau.1mm.ph.gcal0',
'ggtau.3mm.amp.gcal',
'ggtau.3mm.bpoly',
'ggtau.3mm.ph.gcal',
'ggtau.3mm.ph.gcal0',
'ggtau.co.bpoly',
'ggtau.hco.bpoly']
def tearDown(self):
if os.path.exists('testlog.log'):
os.remove('testlog.log')
self.tb.done()
def test_logreturn(self):
'''logreturn test: Test that a logfile is written and populated with the expected information'''
casalog.setlogfile('testlog.log')
# Check that a logfile is populated and contains the correct infromation
calstat(datapath, axis='TIME')
for item in contained:
self.assertTrue( item in open('testlog.log').read(), msg='Fails to write required information to the log')
def test_dictreturn(self):
'''dictionary test: Test that calstat makes a python dict with the expected keys'''
# Check that type of returned object is a python dict
caldict = calstat(datapath)
self.assertTrue(isinstance(caldict, dict), msg='calstat does not return a python dict')
# Check that the dict contains the correct values
self.assertTrue(all (k in caldict['GAIN'] for k in contained), msg='Dictionalry does not contain all the correct values')
def test_takescal(self):
'''takes cal test: Test that calstat only takes cal tables'''
self.assertTrue(calstat(datapath), msg='calstat fails to take a caltable')
# No type checking for CASA 6, but some for CASA 5
with self.assertRaises(RuntimeError, msg='Fails to recognize non-caltable'):
calstat(datapath_visibilities)
def test_axis(self):