Source
xxxxxxxxxx
region = "ellipse [[0:0:0, 0.0.0], [10arcmin, 5arcmin], 45deg]\n- ellipse [[0:0:0, 0.0.0], [7arcmin, 2arcmin], 45deg]"
##########################################################################
# test_tool_regionmanager.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/latest/api/tt/casatools.regionmanager.html
#
#
##########################################################################
import os
import shutil
import numpy
import unittest
from casatools import ctsys, quanta, imagemetadata, table
from casatools import regionmanager as rgtool
from casatools import image as iatool
_qa = quanta()
_imd = imagemetadata()
datapath = ctsys.resolve('unittest/rgtool/')
def deep_equality(a, b):
if (type(a) != type(b)):
print("types don't match, a is a " + str(type(a)) + " b is a " + str(type(b)))
return False
if (type(a) == dict):
if (a.keys() != b.keys()):
print("keys don't match, a is " + str(a.keys()) + " b is " + str(b.keys()))
return False
for k in a.keys():
if (
k == "telescope" or k == "observer"
or k == "telescopeposition"
):
continue
elif (not deep_equality(a[k], b[k])):
print("dictionary member inequality a[" + str(k) \
+ "] is " + str(a[k]) + " b[" + str(k) + "] is " + str(b[k]))
return False
return True
if (type(a) == float):
if not (a == b or abs((a-b)/a) <= 1e-6):
print("float mismatch, a is " + str(a) + ", b is " + str(b))
return a == b or abs((a-b)/a) <= 1e-6
if (type(a) == numpy.ndarray):
if (a.shape != b.shape):
print("shape mismatch a is " + str(a.shape) + " b is " + str(b.shape))
return False
x = a.tolist()
y = b.tolist()
for i in range(len(x)):
if (not deep_equality(x[i], y[i])):
print("array element mismatch, x is " + str(x[i]) + " y is " + str(y[i]))
return False
return True
return a == b
# Tests for regionmanager.frombcs
class rg_frombcs_test(unittest.TestCase):
image = "imregion.fits"
image_nospec = "imregion_nospec.fits"
image_dironly = "imregion_dironly.fits"
box1 = 1.24795026
box2 = 0.782552901
box3 = 1.24794616
box4 = 0.782555814
box5 = 1.24794206
box6 = 0.782558727
box7 = 1.24793797
box8 = 0.782561641
box9 = 1.2479338718038551
box10 = 0.78256455381109313
box11 = 1.2479297756405987
box12 = 0.78256746696533663
chan0 = 4.73510000e+09
chan4 = 6.33510000e+09