Source
'FLAG_CATEGORY', 'FLAG_ROW', 'INTERVAL', 'OBSERVATION_ID',
##########################################################################
# test_tool_table.py
#
# Copyright (C) 2022
# 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.table.html
#
# Methods tested in this script
# getcellslice
##########################################################################
import shutil
import unittest
import itertools
import os, stat
import numpy as np
from uuid import uuid4
from casatools import table, ctsys, image
import math
##########################################################################
ms_name = 'n08c1_swap1.ms'
orig_ms_path = ctsys.resolve( f'unittest/table/{ms_name}' )
print( f'table tool tests will use {orig_ms_path}' )
class TableBase(unittest.TestCase):
"setup common to all tests"
def setUpClass(cls):
cls.scratch_path = str(uuid4( ))
cls.ms_path = os.path.join(cls.scratch_path,ms_name)
def remove_readonly(func, path, _):
"Clear the readonly bit and reattempt the removal"
os.chmod(path, stat.S_IWRITE)
func(path)
def setUp(self):
self.tb = table( )
self.ia = image()
if os.path.exists(self.scratch_path):
shutil.rmtree( self.scratch_path, onerror=self.remove_readonly )
if not os.path.exists(self.scratch_path):
os.makedirs(self.scratch_path)
shutil.copytree( orig_ms_path, self.ms_path )
self.tb.open(self.ms_path,nomodify=False)
self.rows = self.tb.row( )
def tearDown(self):
self.rows.done( )
self.tb.close( )
self.tb.done( )
self.ia.done()
if os.path.exists(self.scratch_path):
shutil.rmtree( self.scratch_path, onerror=self.remove_readonly )
class TableRowTest(TableBase):
def test_get(self):
"""Test get function"""
### fetch single row
row = self.rows.get(21)
### check values
self.assertTrue(np.isclose(np.abs(np.sum(row['DATA'])),0.8696193426581154))
def test_shape( self ):
"""Test for valid data shape"""
### fetch single row
row = self.rows.get(21)
### check shape
self.assertTrue(row['DATA'].shape == (4, 32))
def test_put(self):
"""Test put function"""
### fetch single row