Skip to content

Instantly share code, notes, and snippets.

@SpheMakh
Last active August 29, 2015 14:14
Show Gist options
  • Save SpheMakh/90ae62873fde116ca3b7 to your computer and use it in GitHub Desktop.
Save SpheMakh/90ae62873fde116ca3b7 to your computer and use it in GitHub Desktop.
Intro to Pyxis
import Pyxis
# once Pyxis is loaded, ms,mqt, im, lsm, std,stefcal become available
import ms # ms module
import im # imager module
import mqt # meqtree-pipeliner wrap
import stefcal # self calibration module
from Pyxis.ModSupport import * # I will make a note whenever I use something from here
define("MS_REDO",True,"Remake MS if it already exists")
from simms import simms
simms = simms.simms()
def _simms(msname='$MS',observatory='$OBSERVATORY',antennas='$ANTENNAS',
synthesis=8,integration=30,freq0='1.4GHz',dfreq='50MHz',**kw):
""" Create empty MS """
# First lets evaluate the variables within the "$" construct.
msname,observatory,antennas = interpolate_locals('msname observatory antennas')
if not os.path.exists(msname) or MS_REDO:
info('Making empty MS ...')
simms(msname=msname,tel=observatory,freq0=freq0,dfreq=dfreq,
dtime=integration,synthesis=synthesis,pos=antennas,**kw)
v.MS = msname # update the super global variable MS
# creates DESTDIR if it doesn't exist
makedir(DESTDIR)
ms.plot_uvcov(save=II('${OUTFILE}_uvcov.png'),ms=.1)
# The parameters parsed via the string argument will form part of the doc string for _simms()
# Run pyxis help[_simms] to see how this works
document_globals(_simms,"MS OBSERVATORY ANTENNAS")
def simsky(msname="$MS",lsmname="$LSM",column="$COLUMN",
tdlconf="$TDLCONF",tdlesec="$SIMSEC",
noise=0,args=[],**kw):
"""
Simulates visibilities into a MS.
msname : MS name
lsmname : LSM name
column : Column to simulate visibilities into
tdlconf : Meqtrees TDL configuration profiles file (required to run MeqTrees pipeliner)
tdlsec : Section to execute in tdlconf
noise : Visibility noise to add to simulation.
args, kw : extra arguments to pass to the MeqTrees pipeliner
"""
msname,lsmname,column,tdlsec,tdlconf = interpolate_locals('msname lsmname column tdlsec tdlconf')
args = ["${ms.MS_TDL} ${lsm.LSM_TDL}"] + list(args)
options = {}
options['ms_sel.output_column'] = column
if noise:
options['noise_stddev'] = noise
options.update(kw) # extra keyword args get preference
mqt.run(TURBO_SIM,job='_tdl_job_1_simulate_MS',config=tdlconf,section=tdlsec,options=options,args=args)
document_globals(simsky,"MS LSM COLUMN SIMSEC TDLCONF TURBO_SIM")
def calibrate(msname='$MS',lsmname='$LSM',tdlconf='$TDLCONF',tdlsec='$CALSEC',
column='$COLUMN',do_dE=False,args=[],**kw):
""" Calibrate MS """
msname,lsmname,column,tdlconf,tdlsec = interpolate_locals('msname lsmname '
'column tdlconf tdlsec')
v.MS = msname
v.LSM = lsmname
args = ["${ms.MS_TDL} ${lsm.LSM_TDL}"] + list(args)
mqt.TDLCONFIG = tdlconf
v.LSM = lsmname
options = {}
if do_dE:
""" add dE opts into options dict"""
options.update(dict(diffgains=True))
options.update(kw)
stefcal.stefcal(msname,section=tdlsec,options=options,args=args)
document_globals(calibrate,"MS LSM COLUMN CALSEC TDLCONF")
def azishe(start=0,stop=4):
""" The is the driver function """
do_step = lambda step: step>=float(start) and step<=float(stop)
_simms(synthesis=8)
if do_step(0):
simsky(column='DATA')
ms.copycol(fromcol='DATA',tocol='CORRECTED_DATA')
im.lwimager.make_image(dirty=False,restore=True,restore_lsm=False)
if do_step(1):
calibrate()
if do_step(2):
calibrate(do_dE=True)
im.lwimager.make_image(dirty=False,restore=True,restore_lsm=True)
@SpheMakh
Copy link
Author

DESTDIR_Template = '${OUTDIR>/}plots-${MS:BASE}' # images will be sent to this directory
OUTFILE_Template = '${DESTDIR>/}${MS:BASE}${_s<STEP}${_<LABEL}' # prefix for output from pipeline
LOG = 'log-pyxis.txt'

LSM = 'bright2deg.lsm.html'
MS = 'kat7_8h30s.MS'
COLUMN = 'DATA'

define("MS_REDO",True,"Remake MS if it already exists")

define("OBSERVATORY","kat-7","Observatory")
define("ANTENNAS","KAT7_ANTENNAS","Antenna table")

CATTERY = mqt.CATTERY
TURBO_SIM = II('$CATTERY/Siamese/turbo-sim.py')
STEFCAL = II('$CATTERY/Calico/calico-stefcal.py')
define("TDLCONF","tdlconf.profiles","TDL configuration file")
define("SIMSEC","sim","Simulation section in TDL profile")
define("CALSEC","stefcal","Calibration section in TDL profile")

import im.lwimager # we will use LWIMAGER for imaging.

# the casa imager (clean task) and wsclean are also available via im.{casa,wsclean}
im.npix = 1024
im.cellsize = '30arcsec'
im.stokes = 'I'
im.niter = 1000
im.weight = 'uniform'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment