Source
xxxxxxxxxx
"""Test skymodel simulation: observation (INT) with ACA configuration file containing an extra column to indirectly exercise readantenna method of simutil"""
########################################################################
# test_task_simobserve.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.simulation.simobserve.html
#
#
##########################################################################
import os
import sys
import shutil
import numpy
import glob
import unittest
from casatools import ctsys, image, ms, msmetadata, quanta, atmosphere, table
from casatasks import simobserve
from casatasks.private.simutil import *
# CASA5 uses the global versions of these tools
_ia = image()
_ms = ms()
_msmd = msmetadata()
_qa = quanta()
_at = atmosphere()
#
# Unit test of simobserve task.
#
class simobserve_unittest_base(unittest.TestCase):
"""
Base class of simobserve unit test.
The class defines common variables and test methods.
"""
graphics = "file"
# Variables
datapath = ctsys.resolve('unittest/simobserve/')
thistask = "simobserve"
imkeys=['max','mean','min','npts','rms','blc','blcf','trc','trcf','sigma','sum','sumsq']
# relative and absolute tolerance
# (atol=0. means to ignore absolute tolerance)
rtol = 5.0e-3
atol = 0.
showcomp = False
teardown = True
# Test methods
def _check_file(self, name, msg=""):
isthere = os.path.exists(name)
if len(msg) == 0:
msg = "output file %s was not created because of the task failure"%(name)
self.assertEqual(isthere, True, msg=msg)
def _get_imstats(self, name):
self._check_file(name)
_ia.open(name)
stats = _ia.statistics(list=True, verbose=True)
_ia.close()
return stats
def _get_msstats(self, name, column, compval):
self._check_file(name)
_ms.open(name)
stats = _ms.statistics(column, compval)
_ms.close()
return stats[list(stats.keys())[0]]
def _check_imstats(self, name, ref, rtol=None, atol=None):
# ref: a dictionary of reference statistics or reference image name
# name: the name of image to compare statistics
refname = ""
if type(ref) == str:
refname = ("'%s'" % os.path.basename(ref))
# get statistics of reference image
ref = self._get_imstats(ref)