Last active
August 29, 2015 14:14
-
-
Save SpheMakh/90ae62873fde116ca3b7 to your computer and use it in GitHub Desktop.
Intro to Pyxis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Author
SpheMakh
commented
Feb 19, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment