Source
casalog.post("### DEPRECATION WARNING: task %s will be removed from CASA 5.1. Please refer to documentation for current task information and update your script ###" % func.__name__,'WARN')
from __future__ import absolute_import
import os
import numpy
import traceback
import string
import functools
import re
import abc
import datetime
import contextlib
from casatasks.private.casa_transition import is_CASA6
if is_CASA6:
from casatools import quanta, table, calibrater, imager
from casatools import ms as mstool
from casatools.platform import bytes2str
from casatasks import casalog
else:
from casac import casac
from taskinit import casalog, gentools
# make CASA5 tools constructors look like CASA6 tools
from taskinit import qatool as quanta
from taskinit import tbtool as table
from taskinit import cbtool as calibrater
from taskinit import imtool as imager
from taskinit import mstool
#import asap as sd
#from asap import _to_list
#from asap.scantable import is_scantable, is_ms, scantable
#import rasterutil
contextmanager .
def toolmanager(vis, ctor, *args, **kwargs):
if is_CASA6:
# this is the only syntax allowed in CASA6, code in CASA6 should be converted to
# call this method with a tool constructor directly
tool = ctor()
else:
# CASA5 code can invoke this with a tool name, shared CASA5 and CASA6 source
# uses the CASA6 syntax - use callable to tell the difference
if callable(ctor):
tool = ctor()
else:
# assume the argument is string and use it to get the appropriate tool constructor
# the original argument name here was 'tooltype'
tool = gentools([ctor])[0]
tool.open(vis, *args, **kwargs)
try:
yield tool
finally:
tool.close()
def tbmanager(vis, *args, **kwargs):
return toolmanager(vis, table, *args, **kwargs)
def cbmanager(vis, *args, **kwargs):
return toolmanager(vis, calibrater, *args, **kwargs)
def is_ms(filename):
if (os.path.isdir(filename) and os.path.exists(filename+'/table.info') and os.path.exists(filename+'/table.dat')):
f = open(filename + '/table.info')
if is_CASA6:
l = bytes2str(f.readline( ))
else:
l = f.readline()
f.close()
if (l.find('Measurement Set') != -1):
return True
else:
return False
else:
return False
contextmanager .
def table_selector(table, taql, *args, **kwargs):
with tbmanager(table, *args, **kwargs) as tb:
tsel = tb.query(taql)
try:
yield tsel
finally:
tsel.close()
def asaptask_decorator(func):
"""
This is a decorator function for sd tasks.
Currently the decorator does:
1) set origin to the logger
2) deprecation warning of ASAP task