Source
'''mstransform: When there are no input SPECTRUM cols chan avg result is the same regardless of useWeightSpectrum because VI/VB fills a cte. weightSpectrum/sigmaSpectrum across channels'''
##########################################################################
# test_task_mstransform.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.
#
#
# Based on the requirements listed in casadocs found here:
# https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.mstransform.html
#
##########################################################################
import shutil
import unittest
import os
import numpy
import math
import sys
import filecmp
import glob
from casatools import ctsys, ms, table, msmetadata, agentflagger
from casatasks import applycal, cvel, cvel2, flagcmd, flagdata, importasdm, listpartition, listobs, mstransform, setjy, split
#from casatasks import importasdm ### tar files have been created to avoid the importasdm dependency
# Define the root for the data files
datapath = ctsys.resolve('unittest/mstransform/')
af_local = agentflagger()
msmd_local = msmetadata()
ms_local = ms()
tb_local = table()
from casatestutils import testhelper as th
def weighToSigma(weight):
if weight > sys.float_info.min:
return 1.0/math.sqrt(weight)
else:
return -1.0
def sigmaToWeight(sigma):
if sigma > sys.float_info.min:
return 1.0/math.pow(sigma,2)
else:
return 0.0
def check_eq(val, expval, tol=None):
"""Checks that val matches expval within tol."""
# print(val)
if type(val) == dict:
for k in val:
check_eq(val[k], expval[k], tol)
else:
try:
if tol and hasattr(val, '__rsub__'):
are_eq = abs(val - expval) < tol
else:
are_eq = val == expval
if hasattr(are_eq, 'all'):
are_eq = are_eq.all()
if not are_eq:
raise ValueError('!=')
except ValueError:
errmsg = "%r != %r" % (val, expval)
if (len(errmsg) > 66): # 66 = 78 - len('ValueError: ')
errmsg = "\n%r\n!=\n%r" % (val, expval)
raise ValueError(errmsg)
except Exception:
print("Error comparing", val, "to", expval)
raise
# Base class which defines setUp functions
# for importing different data sets
class test_base(unittest.TestCase):
vis = None
def setUp_ngc5921(cls):
# data set with spw=0, 63 channels in LSRK
test_base.vis = "ngc5921.ms"