Source
import os, re
import string
from taskinit import casalog, mstool, qa, tbtool
from mstools import write_history
from update_spw import join_spws, subtract_spws
def uvcontsub3(vis, fitspw, combine, fitorder, field, spw,
scan, intent, correlation, observation):
"""Extract the line(s) of an MS."""
retval = True
casalog.origin('uvcontsub3')
myms = mstool()
mytb = tbtool()
# This one is redundant - it is already checked at the XML level.
if not ((type(vis) == str) and os.path.isdir(vis)):
casalog.post('Visibility data set not found - please verify the name', 'SEVERE')
return False
outputvis = vis + '.contsub'
if os.path.exists(outputvis):
casalog.post("Output MS " + outputvis + " already exists - will not overwrite.", 'SEVERE')
return False
if combine and combine.lower() != 'spw':
casalog.post("uvcontsub3 deliberately does not support combination by",
'SEVERE')
casalog.post("anything except spw.", 'SEVERE')
return False
# MSStateGram is picky ('CALIBRATE_WVR.REFERENCE, OBSERVE_TARGET_ON_SOURCE'
# doesn't work, but 'CALIBRATE_WVR.REFERENCE,OBSERVE_TARGET_ON_SOURCE'
# does), and I don't want to mess with bison now. A .upper() might be a
# good idea too, but the MS def'n v.2 does not say whether OBS_MODE should
# be case-insensitive.
intent = intent.replace(', ', ',')
if type(spw) == list:
spw = ','.join([str(s) for s in spw])
elif type(spw) == int:
spw = str(spw)
## if ':' in spw:
## casalog.post("uvcontsub3 does not yet support selection by channel for the output",
## 'SEVERE')
## casalog.post("Meanwhile, use split to select the desired channels", 'WARN')
## return False
if ';' in spw:
casalog.post("uvcontsub3 does not yet support writing multiple channel groups per output spw",
'SEVERE')
return False
mytb.open(vis + '/SPECTRAL_WINDOW')
allspw = '0~' + str(mytb.nrows() - 1)
mytb.close()
if 'spw' not in combine:
spwmfitspw = subtract_spws(spw, fitspw)
if spwmfitspw == 'UNKNOWN':
spwmfitspw = subtract_spws(allspw, fitspw)
if spwmfitspw:
raise Exception, "combine must include 'spw' when the fit is being applied to spws outside fitspw."