Source
xxxxxxxxxx
['POSITION', 1, [-4751589.52238021, 2791757.53976021, -3200482.25099623], 0.0001],
#########################################################################
# test_task_importmiriad.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.
#
# Features tested:
# 1) Is the import performed without raising exceptions
# 2) Do all expected tables exist
# 3) Can the MS be opened
# 4) Do the tables contain expected values
#
# Based on the requirements listed in casadocs found here:
# https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.data.importmiriad.html
#
##########################################################################
import os
import sys
import shutil
import unittest
from casatools import ctsys, table, ms
from casatasks import importmiriad
ctsys_resolve = ctsys.resolve
_tb = table( )
_ms = ms( )
stype = str
myname = 'importmiriad-unit-test'
# default dataset name
my_dataset_names = ['1934.uv']
# name of the resulting MS
msname = my_dataset_names[0].split('.')[0]+'.ms'
def checktable(thename, theexpectation, dataslice=[]):
global msname, myname
_tb.open(os.path.join(msname,thename))
if thename == "":
thename = "MAIN"
for mycell in theexpectation:
print(myname, ": comparing ", mycell)
if mycell[0]=="DATA" or mycell[0]=="CHAN_WIDTH" or mycell[0]=="CHAN_FREQ":
value = _tb.getcellslice(mycell[0], mycell[1],dataslice[0],dataslice[1],dataslice[2])
else:
value = _tb.getcell(mycell[0], mycell[1])
# see if value is array
try:
isarray = value.__len__
except:
# it's not an array
# zero tolerance?
if mycell[3] == 0:
in_agreement = (value == mycell[2])
else:
in_agreement = ( abs(value - mycell[2]) < mycell[3])
else:
if isinstance(value, stype):
in_agreement = value == mycell[2]
else:
# it's an array
# zero tolerance?
if mycell[3] == 0:
in_agreement = (value == mycell[2]).all()
else:
try:
in_agreement = (abs(value - mycell[2]) < mycell[3]).all()
except:
in_agreement = False
if not in_agreement:
print(myname, ": Error in MS subtable", thename, ":")
print(" column ", mycell[0], " row ", mycell[1], " contains ", value)
print(" expected value is ", mycell[2])
_tb.close()
return False
_tb.close()
print(myname, ": table ", thename, " as expected.")
return True