Source
#"""
#Helper functions for the vishead task that might also be useful outside it,
#when working with measurement sets as tables.
#"""
from __future__ import absolute_import
import os
from casatasks.private.casa_transition import is_CASA6
if is_CASA6:
from casatools import table, quanta
_tb = table( )
_qa = quanta( )
# basestring is use in the CASA5 code, now use str and hide it a bit from any other basestring
# this is really a python3 difference
_basestring = str
else:
from taskinit import *
_tb = tb
_qa = qa
# basestring is use in the CASA5 code, fudge that here and hide it a bit from any other basestring
# this is really a python3 difference
_basestring = basestring
def getput_keyw(mode, vis, key, hdindex, hdvalue='', hdref=None):
table = vis + '/' + key[0]
col = key[1]
_tb.open(table, nomodify = (mode == 'get'))
colinfo = _tb.getcolkeywords(col)
if mode == 'get':
try:
i = int(hdindex)
if i < 0:
# allowed by python, but...
raise Exception("Illegal index " + str(i))
value = _tb.getcell(col, i) # throws exception if index too large
except (ValueError, TypeError): # This is almost certainly from
if(_tb.isvarcol(col)): # int('') or int(None). Default
value = _tb.getvarcol(col) # to returning the full column.
else:
value = _tb.getcol(col)
elif mode == 'put':
if(_tb.isvarcol(col)):
_tb.close()
raise Exception("vishead does not yet read/write variably sized columns")
else:
#TODO: Apply colinfo and hdref.
i = None
try:
i = int(hdindex)
except (ValueError, TypeError):
i = None # hdindex is not convertable to an int.
if isinstance(i, int):
# Get full column, change one element, write it back. Not