# v.1.0, 1/24/2011 - mkrauss@nrao.edu (Miriam Krauss)
#=====================================================================
# This is a streamlined, but still human-dependent, script. To use,
# run "execfile('wideband_proc_dist.py')". General plan would be:
#
# -> run importData
# -> inspect results and flag as needed
# -> run calibData
# -> inspect; flag again as needed
# -> run calibData
# -> run applyCalib
# -> inspect; flag further if needed
# -> run calibData
# -> run applyCalib
#=====================================================================
import os, time
#=====================================================================
# importData: runs importevla to convert sdm to ms; writes out listobs
# information to a file; imports and applies online flags; makes a
# plot of these flags and saves flag versions from before and after;
# plots antenna distribution; flags shadowed and zero-amplitude data;
# splits the data with requested averaging; makes a set of plots for
# initial data inspection. Sends an email when it's all done with
# information about where it's written html files, etc.
#
# sdmName = name of input sdm directory
# dataDir = where sdm directory lives
# outName = root for filenames, etc.
# scanList = scans to import (default is all)
# refAnt = reference antenna to use
# timeAve = number of seconds to use for time-averaging, e.g. '3s'
# spwCopy = range of SPWs to split out, e.g. '2~17'; need to work around gaincurve bug
# plotField = name of source for which to make initial plots
# baseBand = list of spw strings to plot together e.g. ['18~25', '26~33']
# plotPoln = string for polarizations to be plotted
def importData(sdmName, dataDir, outName, scanList, refAnt, timeAve, spwCopy,
plotField, plotScan, baseBand, plotPoln):
msName = outName + '.ms'
aveName = '%s.%s' % (outName, timeAve)
msAve = aveName + '.ms'
# Make a time string for later use:
timeArr = time.localtime()
timeStr = '%4.0f-%02.0f-%02.0f.%02.0f:%02.0f' % (timeArr[0], timeArr[1], timeArr[2], timeArr[3], timeArr[4])
#=====================================================================
# Import the data; do not immediately apply online flags. Will make a
# flag command table for these, as well as shadow and zero flags,
# after import and data-checking.
casalog.post("Importing %s to MS format..." % (dataDir+'/'+sdmName))
timeImportStart = time.time()
importevla2(asdm=dataDir+'/'+sdmName, vis=msName, scans=scanList, applyflags=False)
timeImportEnd = time.time()
timeImportTotal = timeImportEnd - timeImportStart
casalog.post("Importing data took %0.2f seconds (%0.2f minutes)" % (timeImportTotal, timeImportTotal/60))
# Plot the weather table:
foo = plotwx(msName)
# Set logger to pipe to a different file so a text version of listobs
# exists, then switch back:
logOrig = casalog.logfile()
casalog.setlogfile('%s_listobs.txt' % outName)
listobs(msName)
casalog.setlogfile(logOrig)
# Import the online flags, make plots, apply flags, and save a flag
# version:
casalog.post("Importing and applying online flags...")
timeOnlineFlagStart = time.time()
from readflags import readflags, plotflags, useflags
myFlags = readflags(dataDir+'/'+sdmName, tbuff=1.5)
plotName = outName + '_onlineFlags.png'
plotflags(myFlags)
pl.savefig(plotName)
useflags(msName, myFlags)
flagmanager(vis=msName, mode='save', versionname='flags.online', \
comment='Flag save after only online flags applied')
timeOnlineFlagEnd = time.time()
timeOnlineFlagTotal = timeOnlineFlagEnd - timeOnlineFlagStart
casalog.post("Applying online flags took %0.2f seconds (%0.2f minutes)" % (timeOnlineFlagTotal, timeOnlineFlagTotal/60))
# Plot antenna distribution
plotants(vis=msName, figfile=outName+'_antdist.png')
# Make flagcmd command list for zero and shadow flags; save flags:
casalog.post("Flagging zeros and shadowed data...")
timeFlagStart = time.time()
## flagcmd(vis=msName, mode='cmd',
## command=["mode='shadow'",
## "mode='clip' cliprange='0~1E-10' clipexpr='ABS_RR'",
## "mode='clip' cliprange='0~1E-10' clipexpr='ABS_LL'"],
## flagbackup=False)
flagdata(vis=msName, mode='shadow', flagbackup=False)
flagdata(vis=msName, mode='manualflag', clipminmax=[0.0, 1E-10], \
clipoutside=False, clipcolumn='DATA', \
clipexpr=['ABS RR','ABS LL','ABS RL','ABS LR'], flagbackup=False)
flagmanager(vis=msName, mode='save', versionname='flags.shadow.zeros', \
comment='Flag save after online, shadow, and zero flags applied')
timeFlagEnd = time.time()
timeFlagTotal = timeFlagEnd - timeFlagStart
casalog.post("Applying zero and shadow flags took %0.2f seconds (%0.2f minutes)" % (timeFlagTotal, timeFlagTotal/60))
## Split the data, with requested averaging:
casalog.post("Splitting data to average...")
timeSplitStart = time.time()
split(vis=msName, outputvis=msAve, datacolumn='data', timebin=timeAve, spw=spwCopy, \
keepflags=False)
timeSplitEnd = time.time()
timeSplitTotal = timeSplitEnd - timeSplitStart
casalog.post("Splitting data to time-average took %0.2f seconds (%0.2f minutes)" % (timeSplitTotal, timeSplitTotal/60))
# Initial inspection, using plotms, plotting calibrators' amplitude &
# phase vs. frequency for baselines to reference antenna:
casalog.post("Plotting data...")
timePlotStart = time.time()
# Need to get antennas first, since plotms will hang if it comes
# across an antenna without data:
## NEED TO MODIFY THIS SO THAT IT ONLY FINDS ANTENNAS THAT ACTUALLY
## HAVE DATA!
tb.open(msAve + '/ANTENNA')
antArr = tb.getcol('NAME')
tb.close
plotDir = aveName+'.importData.'+timeStr+'.plots'
os.system('mkdir '+plotDir)
for i in range(0, len(baseBand)):
spwStr = baseBand[i]
html = open(plotDir+'/field_%s.amp-phase_v_freq.spw%s.html' % (plotField, spwStr), 'w')
htmlHead = '''
Phase/amplitude vs. freq for '''+msAve+''', '''+plotField+''', spw '''+spwStr+'''
Amplitude vs. Frequency: |
Phase vs. Frequency: |
'''
html.write(htmlHead)
for j in range(0, len(antArr)):
plotMade = False
if antArr[j] == refAnt:
continue
antStr = '%s&%s' % (antArr[j], refAnt)
plotNameAmp = plotDir + '/' + antStr + '.spw' + spwStr + '.freq.amp.png'
plotNamePh = plotDir + '/' + antStr + '.spw' + spwStr + '.freq.phase.png'
htmlNameAmp = antStr + '.spw' + spwStr + '.freq.amp.png'
htmlNamePh = antStr + '.spw' + spwStr + '.freq.phase.png'
htmlStr = '''
%s: |
|
''' % (antStr, htmlNameAmp, htmlNameAmp, htmlNamePh, htmlNamePh)
html.write(htmlStr)
# Make amp vs. freq plots:
plotms(vis=msAve, xaxis='freq', yaxis='amp', selectdata=True, \
field=plotField, spw=spwStr, antenna=antStr, avgtime='5s', \
plotfile=plotNameAmp, correlation=plotPoln, scan=plotScan)
while (plotMade == False):
time.sleep(2)
print "Testing for plot %s..." % plotNameAmp
plotMade = os.path.isfile(plotNameAmp)
print "Plot not found."
plotMade = False
# Make phase vs. freq plots:
plotms(vis=msAve, xaxis='freq', yaxis='phase', selectdata=True, \
field=plotField, spw=spwStr, antenna=antStr, avgtime='5s', \
plotfile=plotNamePh, correlation=plotPoln, scan=plotScan )
while (plotMade == False):
time.sleep(2)
print "Testing for plot %s..." % plotNamePh
plotMade = os.path.isfile(plotNamePh)
print "Plot not found."
htmlTail = '''
'''
html.write(htmlTail)
html.close()
timePlotEnd = time.time()
timePlotTotal = timePlotEnd - timePlotStart
casalog.post("Plotting data took %0.2f seconds (%0.2f minutes)" % (timePlotTotal, timePlotTotal/60))
#=====================================================================
# Copy plots to web space:
os.system('cp -rp '+plotDir+' /path/to/web/space')
#=====================================================================
# Save the log with a more understandable name:
logOrig = casalog.logfile()
logName = outName+'.importData.'+timeStr+'.log'
os.system('cp %s %s' % (logOrig, logName))
#=====================================================================
# Send an email notification:
subject = 'Data imported: %s' % sdmName
os.system('echo "Data for %s have been imported, time-averaged, and plotted; see http://www.mywebsite.edu/%s" > tempmail' % (sdmName,plotDir))
os.system('cat tempmail | mail -s "%s" email@email.edu' % subject)
os.system('rm tempmail')
#=====================================================================
#=====================================================================
# calibData: given an input ms, and a list of fields to use for flux,
# bandpass, and gain calibration, will perform standard calibration
# and make plots for inspection.
#
# msName = name of ms to be calibrated
# fluxSrc = name of flux calibrator, e.g. '3C48'
# fluxFields = list of field IDs for flux calibrator, e.g. [2,3,4]
# bpassFields = same, for bandpass calibrator(s)
# gainFields = same, for gain calibrator(s)
# band = letter designation for the band, for setjy. Note that
# currently, this script is set up to only do one band at a time.
# refAnt = desired reference antenna
# bpassPhInt = '3s', e.g.; solution interval for initial phase cal
# bpassPhChan = '28~32', e.g.; channels to use for initial phase cal
# gainPhInt = '3s', e.g.; solution interval for phase determination
# gainAmpInt = '60s', e.g.; solution interval for amplitude determination
# gainChan = '4~58', e.g.; channel range to use for gain solutions
# baseBand = array of spw strings to plot together (oft. basebands),
# e.g. ['2~9', '10~17']
# plotPoln = string for polarizations to be plotted
def calibData(msName, fluxSrc, fluxFields, bpassFields, gainFields, band,
spwCalib, refAnt, bpassPhInt, bpassPhChan, bpassScan,
gainPhInt, gainAmpInt, gainChan, baseBand, plotPoln):
#=====================================================================
# Set up useful bits for later
# Get local time and set up plot directory
timeArr = time.localtime()
timeStr = '%4.0f-%02.0f-%02.0f.%02.0f:%02.0f' % (timeArr[0], timeArr[1], timeArr[2], timeArr[3], timeArr[4])
plotDir = msName + '.calibData.' + timeStr+'.plots'
os.system('mkdir ' + plotDir)
# Get antenna information
tb.open(msName + '/ANTENNA')
antArr = tb.getcol('NAME')
tb.close
# Check that there is a flux calibrator image to use
casaPath = os.environ.get('CASAPATH').split()[0]
modImageDir = '%s/data/nrao/VLA/CalModels/%s_%s.im' % (casaPath, fluxSrc, band)
if not os.path.isdir(modImageDir):
casalog.post("ERROR: The calibrator model image directory not present at "+modImageDir, priority='ERROR')
return
#=====================================================================
# Determine needed opacity corrections, per spw:
tauMS = opacitycalc(vis=msName)
#=====================================================================
# setjy for flux calibrator:
for i in fluxFields:
srcStr = str(i)
setjy(vis=msName, field=srcStr, modimage=modImageDir, \
scalebychan=True, standard='Perley-Butler 2010')
#=====================================================================
# Bandpass calibration:
bpassFields = list(bpassFields)
bpassStr = ''
for s in range(0, len(bpassFields)):
bpassStr = str(bpassFields[s]) + ',' + bpassStr
bpassStr = str.rstrip(bpassStr,',') # remove trailing comma
bpassPh = msName + '.' + bpassPhInt + '.bcal.phase'
bpassTab = msName + '.bcal'
# Since solutions are being appended, need to delete any pre-
# existing files.
os.system('rm -rf ' + bpassPh)
os.system('rm -rf ' + bpassTab)
# Loop through spectral windows to create initial phase solutions:
for n in spwCalib:
zVal = tauMS[n]
bpassSpwStr = '%i:%s' % (n, bpassPhChan)
gaincal(vis=msName, caltable=bpassPh, field=bpassStr, \
selectdata=True, spw=bpassSpwStr, gaintype='G', \
solint=bpassPhInt, calmode='p', refant=refAnt, \
append=True, gaincurve=True, opacity=zVal,
scan=bpassScan)
# Loop through spectral windows to create bandpass solutions:
for i in spwCalib:
zVal = tauMS[i]
bpassSpwStr = '%i' % i
bandpass(vis=msName, caltable=bpassTab, gaintable=[bpassPh], \
field=bpassStr, spw=bpassSpwStr, solint='inf', refant=refAnt, \
combine='scan,field', solnorm=True, selectdata=True, \
append=True, gaincurve=True, opacity=zVal, \
scan=bpassScan)
#=====================================================================
# Gain calibration:
gainFields = list(gainFields)
gainStr = ''
for s in range(0, len(gainFields)):
gainStr = str(gainFields[s]) + ',' + gainStr
gainStr = str.rstrip(gainStr,',') # remove trailing comma
gainPh = msName + '.' + gainPhInt + '.gain.phase'
gainPhAmp = msName + '.' + gainAmpInt + '.gain.phase.amp'
# Since solutions are being appended, need to delete any pre-
# existing files.
os.system('rm -rf ' + gainPh)
os.system('rm -rf ' + gainPhAmp)
# Loop through spectral windows to create phase-only solutions:
for n in spwCalib:
zVal = tauMS[n]
gainSpwStr = '%i:%s' % (n, gainChan)
gaincal(vis=msName, caltable=gainPh, field=gainStr, \
selectdata=False, spw=gainSpwStr, interp='nearest', \
solint=gainPhInt, calmode='p', refant=refAnt, \
gaintable=[bpassTab], minsnr=3.0, minblperant=3, \
append=True, gaincurve=True, opacity=zVal)
# Loop through spectral windows to create phase+amplitude solutions:
for n in spwCalib:
zVal = tauMS[n]
gainSpwStr = '%i:%s' % (n, gainChan)
gaincal(vis=msName, caltable=gainPhAmp, field=gainStr, \
selectdata=False, spw=gainSpwStr, interp='nearest', \
solint=gainAmpInt, calmode='ap', refant=refAnt, \
gaintable=[bpassTab, gainPh], minsnr=3.0, \
minblperant=3, append=True, gaincurve=True, opacity=zVal)
#=====================================================================
# Flux scaling:
# Only scale flux if there are sources other than the flux calibrator
if (fluxFields != gainFields):
fluxStr = ''
for s in range(0, len(fluxFields)):
fluxStr = str(fluxFields[s]) + ',' + fluxStr
fluxStr = str.rstrip(fluxStr,',') # remove trailing comma
fluxTab = msName + '.' + gainAmpInt + '.fscale.phase.amp'
# To keep record of flux-scaled values, switch log files temporarily:
logOrig = casalog.logfile()
casalog.setlogfile('%s.fluxval.txt' % fluxTab)
os.system('rm -rf ' + fluxTab)
cb.open(msName)
scaledFlux = cb.fluxscale(tablein=gainPhAmp, tableout=fluxTab,
reference=fluxStr, transfer=gainStr);
cb.close();
casalog.setlogfile(logOrig)
#=====================================================================
# Plot solutions and make web pages
# Phase solutions
html = open(plotDir+'/field_%s.bpphase.html' % (bpassStr), 'w')
htmlHead = '''
Initial phase vs. time for '''+msName+''', '''+bpassStr+'''
'''
html.write(htmlHead)
for j in range(0, len(antArr)):
antStr = '%s' % antArr[j]
htmlNamePh = antStr + '.time.phase.png'
plotNamePh = plotDir + '/' + htmlNamePh
htmlStr = '''
%s: |
''' % (antStr, htmlNamePh, htmlNamePh)
html.write(htmlStr)
# Make phase vs. time plots:
plotcal(caltable=bpassPh, xaxis='time', yaxis='phase', \
field=bpassStr, antenna=antStr, \
showgui=False, figfile=plotNamePh, \
plotrange=[-1,-1,-180,180])
htmlTail = '''
'''
html.write(htmlTail)
html.close()
# Bandpass solutions, one per baseband per antenna:
for i in range(0, len(baseBand)):
html = open(plotDir+'/field_%s.bandpass.spw%s.html' % (bpassStr, baseBand[i]), 'w')
htmlHead = '''
Bandpass phase/amplitude vs. freq for '''+msName+''', '''+bpassStr+''', band '''+baseBand[i]+'''
'''
html.write(htmlHead)
for j in range(0, len(antArr)):
antStr = '%s' % antArr[j]
htmlNameAmp = antStr + '.spw' + baseBand[i] + '.freq.amp.png'
htmlNamePh = antStr + '.spw' + baseBand[i] + '.freq.phase.png'
plotNameAmp = plotDir + '/' + htmlNameAmp
plotNamePh = plotDir + '/' + htmlNamePh
htmlStr = '''
%s: |
|
''' % (antStr, htmlNameAmp, htmlNameAmp, htmlNamePh, htmlNamePh)
html.write(htmlStr)
# Make amp vs. freq plots:
plotcal(caltable=bpassTab, xaxis='freq', yaxis='amp', \
field=bpassStr, antenna=antStr, spw=baseBand[i], \
showgui=False, figfile=plotNameAmp)
# Make phase vs. freq plots:
plotcal(caltable=bpassTab, xaxis='freq', yaxis='phase', \
field=bpassStr, antenna=antStr, spw=baseBand[i], \
showgui=False, figfile=plotNamePh, \
plotrange=[-1,-1,-180,180])
htmlTail = '''
'''
html.write(htmlTail)
html.close()
# Make plots of gain solutions, one per baseband per antenna:
for i in range(0, len(baseBand)):
html = open(plotDir+'/field_%s.gain.spw%s.html' % (gainStr, baseBand[i]), 'w')
htmlHead = '''
Gain phase/amplitude vs. freq for '''+msName+''', '''+gainStr+''', band '''+baseBand[i]+'''
'''
html.write(htmlHead)
for j in range(0, len(antArr)):
antStr = '%s' % antArr[j]
htmlNameAmp = antStr + '.spw' + baseBand[i] + '.time.amp.png'
htmlNamePh = antStr + '.spw' + baseBand[i] + '.time.phase.png'
plotNameAmp = plotDir + '/' + htmlNameAmp
plotNamePh = plotDir + '/' + htmlNamePh
htmlStr = '''
%s: |
|
''' % (antStr, htmlNameAmp, htmlNameAmp, htmlNamePh, htmlNamePh)
html.write(htmlStr)
# Make amp vs. freq plots:
plotcal(caltable=gainPhAmp, xaxis='time', yaxis='amp', \
field=gainStr, antenna=antStr, spw=baseBand[i], \
showgui=False, figfile=plotNameAmp)
# Make phase vs. freq plots:
plotcal(caltable=gainPh, xaxis='time', yaxis='phase', \
field=gainStr, antenna=antStr, spw=baseBand[i], \
showgui=False, figfile=plotNamePh, \
plotrange=[-1,-1,-180,180])
htmlTail = '''
'''
html.write(htmlTail)
html.close()
# Only plot flux table if there are sources other than the flux calibrator
if (fluxFields != gainFields):
# Make flux-scaled amp vs. freq plots:
for i in range(0, len(baseBand)):
html = open(plotDir+'/field_%s.fscale.gain.spw%s.html' % (gainStr, baseBand[i]), 'w')
htmlHead = '''
Gain phase/flux-scaled amplitude vs. freq for '''+msName+''', '''+gainStr+''', band '''+baseBand[i]+'''
'''
html.write(htmlHead)
for j in range(0, len(antArr)):
antStr = '%s' % antArr[j]
htmlNameAmp = antStr + '.spw' + baseBand[i] + '.time.amp.fscale.png'
htmlNamePh = antStr + '.spw' + baseBand[i] + '.time.phase.png'
plotNameAmp = plotDir + '/' + htmlNameAmp
htmlStr = '''
%s: |
|
''' % (antStr, htmlNameAmp, htmlNameAmp, htmlNamePh, htmlNamePh)
html.write(htmlStr)
plotcal(caltable=fluxTab, xaxis='time', yaxis='amp', \
field=gainStr, antenna=antStr, spw=baseBand[i], \
showgui=False, figfile=plotNameAmp)
htmlTail = '''
'''
html.write(htmlTail)
html.close()
#=====================================================================
# Copy plots to web space:
os.system('cp -rp '+plotDir+' /path/to/webspace')
#=====================================================================
# Give the log a more understandable name:
logOrig = casalog.logfile()
logName = msName+'.calibData.'+timeStr+'.log'
os.system('cp %s %s' % (logOrig, logName))
#=====================================================================
# Send an email notification:
subject = 'Data calibrated: %s' % msName
os.system('echo "Data for %s have been calibrated and plotted; see http://www.mywebspace/%s" > tempmail' % (msName,plotDir))
os.system('cat tempmail | mail -s "%s" myemailaddress' % subject)
os.system('rm tempmail')
#=====================================================================
#=====================================================================
# applyCalib: apply requested calibration products to an MS, and make
# a set of plots to evaluate data quality. Plots will only be made
# for requested sources, and will include phase vs. amplitude and
# amplitude vs. baseline. Time-averaging with requested length will
# be used to create plots. Note that this is only "self-cal" type
# calibration, used on cal sources and to evaluate data quality.
#
# msName = name of file to be calibrated
# clearPrev = run clearcal to clear prior calibration?
# calField = fields to calibrate, e.g. [2,3,4]
# calChan = channels to calibrate, e.g. '4~58'
# fluxFields = name(s) of flux calibrator(s) for setjy, e.g. [3,4]
# calTable = list of tables to apply
# calInterp = list of interpolation methods to use
# plotField = list of field(s) to plot, e.g. [1,2]
# timeBin = time binning to use for plots, e.g. '5'
# chanBin = channel binning to use for plots, e.g. '5'
# plotPoln = string for polarizations to be plotted
def applyCalib(msName, clearPrev, calField, calChan, fluxFields, fluxSrc, band,
spwCalib, calTable, calInterp, plotField, timeBin, chanBin, plotPoln):
#=====================================================================
# Clear prior calibration, if requested:
if clearPrev == True:
clearcal(vis=msName)
#=====================================================================
# Determine needed opacity corrections, per spw:
tauMS = opacitycalc(vis=msName)
## Check that there is a flux calibrator image to use
casaPath = os.environ.get('CASAPATH').split()[0]
modImageDir = '%s/data/nrao/VLA/CalModels/%s_%s.im' % (casaPath, fluxSrc, band)
if not os.path.isdir(modImageDir):
casalog.post("ERROR: The calibrator model image directory not present at "+modImageDir, priority='ERROR')
return
## setjy for flux calibrator:
for i in fluxFields:
srcStr = str(i)
setjy(vis=msName, field=srcStr, modimage=modImageDir, \
scalebychan=True, standard='Perley-Butler 2010')
## Apply calibration, per spw:
timeArr = time.localtime()
timeStr = '%4.0f-%02.0f-%02.0f.%02.0f:%02.0f' % (timeArr[0], timeArr[1], timeArr[2], timeArr[3], timeArr[4])
flagStr = 'preCalib_'+timeStr
flagComm = 'Flag save before calibration on '+timeStr
# Save a version of the flags before applying calibration:
flagmanager(vis=msName, mode='save', versionname=flagStr, \
comment=flagComm)
for i in range(0, len(calField)):
if (i == 0):
calFieldStr = str(calField[i])
else:
calFieldStr = calFieldStr + ',' + str(calField[i])
for n in spwCalib:
spwStr = str(n)+':'+calChan
zVal = tauMS[n]
applycal(vis=msName, spw=spwStr, field=calFieldStr, selectdata=False, \
interp=calInterp, gaintable=calTable, gaincurve=True, \
opacity=zVal, calwt=False)
## applycal(vis=msName, spw=spwStr, field=calField, selectdata=False, \
## interp=calInterp, gaintable=calTable, gaincurve=False, \
## opacity=zVal, calwt=False)
#=====================================================================
# Make plots of calibrated data, one per spw of each phase vs. amp and
# amp vs. baseline:
plotDir = msName+'.applyCalib.'+timeStr+'.plots'
os.system('mkdir '+plotDir)
# Loop over fields and spws:
for i in range(0, len(plotField)):
plotStr = str(plotField[i])
html = open(plotDir+'/field_%s.html' % plotStr, 'w')
htmlHead = '''
Calibrated phase vs. amp and amp vs. baseline for '''+msName+''', field '''+plotStr+'''
Phase vs. Amplitude: |
Amplitude vs. Baseline: |
'''
html.write(htmlHead)
for s in spwCalib:
spwStr = str(s)+':'+calChan
plotMade = False
htmlAmpPh = 'field_'+plotStr+'.spw'+spwStr+'.amp.phase.png'
htmlAmpBl = 'field_'+plotStr+'.spw'+spwStr+'.amp.bl.png'
plotAmpPh = plotDir+'/'+htmlAmpPh
plotAmpBl = plotDir+'/'+htmlAmpBl
htmlStr = '''
spw%s: |
|
''' % (spwStr, htmlAmpPh, htmlAmpPh, htmlAmpBl, htmlAmpBl)
html.write(htmlStr)
# Make phase vs. amp plots:
plotms(vis=msName, xaxis='phase', yaxis='amp', selectdata=True, \
field=plotStr, spw=spwStr, avgtime=timeBin, \
avgchannel=chanBin, \
plotfile=plotAmpPh, correlation=plotPoln, \
xdatacolumn='corrected', ydatacolumn='corrected')
while (plotMade == False):
time.sleep(2)
print "Testing for plot %s..." % plotAmpPh
plotMade = os.path.isfile(plotAmpPh)
print "Plot not found."
plotMade = False
# Make amp vs. baseline plots:
plotms(vis=msName, xaxis='baseline', yaxis='amp', selectdata=True, \
field=plotStr, spw=spwStr, avgtime=timeBin, \
avgchannel=chanBin, \
plotfile=plotAmpBl, correlation=plotPoln, \
ydatacolumn='corrected')
while (plotMade == False):
time.sleep(2)
print "Testing for plot %s..." % plotAmpBl
plotMade = os.path.isfile(plotAmpBl)
print "Plot not found."
htmlTail = '''
'''
html.write(htmlTail)
html.close()
#=====================================================================
# Copy plots to web space:
os.system('cp -rp '+plotDir+' /path/to/webspace/')
#=====================================================================
# Give the log a more understandable name:
logOrig = casalog.logfile()
logName = msName+'.applyCal.'+timeStr+'.log'
os.system('cp %s %s' % (logOrig, logName))
#=====================================================================
# Send an email notification:
subject = 'Calibration applied, data plotted: %s' % msName
os.system('echo "Calibration applied to data in %s, and plots made; see http://mywebsite/%s" > tempmail' % (msName,plotDir))
os.system('cat tempmail | mail -s "%s" myemailaddress' % subject)
os.system('rm tempmail')