Skip to content

Commit

Permalink
Merge pull request #52 from SpheMakh/not-craching
Browse files Browse the repository at this point in the history
Not craching
  • Loading branch information
SpheMakh authored Jan 18, 2019
2 parents a830567 + 3cceaef commit ff67cd3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Changes since 0.6.0

# 1.0.7
- Fix synthesis time when scan_legth is a scalar

# 1.0.8
- Add option to optimise observation start time
2 changes: 1 addition & 1 deletion simms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.7"
__version__ = "1.0.9"
13 changes: 7 additions & 6 deletions simms/casasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def makems(msname=None,label=None,tel='MeerKAT',pos=None,pos_type='CASA',
scan_length=0,dtime=10,
freq0=700e6,dfreq=50e6,nchan=1,
nbands=1,
start_time=None,
stokes='RR RL LR LL',
feed="perfect R L",
noise=0,
setlimits=False,
setlimits=False, # Deprecated
elevation_limit=None,
shadow_limit=None,
outdir=None,
coords='itrf',
lon_lat=None,
optimise_start=False,
date=None,
noup=False,
auto_corr=False,
scan_lag=0):
scan_lag=0): # Deprecated
""" Creates an empty measurement set using CASA simulate (sm) tool. """


Expand Down Expand Up @@ -152,7 +152,10 @@ def toFloat(val):

# set date to today (start of observation) if not set by user
# The actual start time will be set internally by CASA depending on when the field transits
use_ha = False
if optimise_start:
use_ha = True
else:
use_ha = False
if date in (None, "None"):
td = time.gmtime()
date = "UTC,{0:d}/{1:d}/{02:d}".format(td.tm_year, td.tm_mon, td.tm_mday)
Expand Down Expand Up @@ -180,8 +183,6 @@ def toFloat(val):
nscans = np.int( np.ceil( synthesis/scan_length[0] ) )
scan_length = scan_length*(nscans)

print sum(scan_length)/3600.0

if ndir>=1:
# if scan legth is not set, set it to equal the synthesis time
if nscans == 0:
Expand Down
24 changes: 15 additions & 9 deletions simms/simms.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def which_vla(name):

def create_empty_ms(msname=None,label=None,tel=None,pos=None,pos_type='casa',
ra='0h0m0s',dec='-30d0m0s',synthesis=4,scan_length=[0],dtime=10,freq0=700e6,
dfreq=50e6,nchan=1,stokes='XX XY YX YY',start_time=-2,setlimits=False,
dfreq=50e6,nchan=1,stokes='XX XY YX YY',setlimits=False,
elevation_limit=0,shadow_limit=0,outdir=None,nolog=False,
coords='itrf',lon_lat=None,noup=False,nbands=1,direction=[],date=None,
fromknown=False,feed="perfect X Y",scan_lag=0, auto_corr=False):
fromknown=False,feed="perfect X Y",scan_lag=0, auto_corr=False,
optimise_start=None):

"""
Uses the CASA simulate tool to create an empty measurement set. Requires
Expand Down Expand Up @@ -165,11 +166,11 @@ def toList_freq(item, nounits=False):
fmt = 'msname="%(msname)s", label="%(label)s", tel="%(tel)s", pos="%(pos)s", '\
'pos_type="%(pos_type)s", synthesis=%(synthesis).4g, '\
'scan_length=%(scan_length)s, dtime="%(dtime)s", freq0=%(freq0)s, dfreq=%(dfreq)s, '\
'nchan=%(nchan)s, stokes="%(stokes)s", start_time=%(start_time)s, setlimits=%(setlimits)s, '\
'nchan=%(nchan)s, stokes="%(stokes)s", setlimits=%(setlimits)s, '\
'elevation_limit=%(elevation_limit)f, shadow_limit=%(shadow_limit)f, '\
'coords="%(coords)s",lon_lat="%(lon_lat)s", noup=%(noup)s, nbands=%(nbands)d, '\
'direction=%(direction)s, outdir="%(outdir)s",date="%(date)s",fromknown=%(fromknown)s, '\
'feed="%(feed)s",scan_lag=%(scan_lag).4g,auto_corr=%(auto_corr)s'%locals()
'feed="%(feed)s",scan_lag=%(scan_lag).4g,auto_corr=%(auto_corr)s,optimise_start=%(optimise_start)s'%locals()

info("Simms >>: %s"%fmt)
casa_script.write('makems(%s)\nexit'%fmt)
Expand All @@ -192,6 +193,7 @@ def toList_freq(item, nounits=False):
stdout=subprocess.PIPE if not isinstance(sys.stdout,file) else sys.stdout,
shell=True)

failed = False
if process.stdout or process.stderr:
out,err = process.communicate()
sys.stdout.write(out)
Expand All @@ -201,6 +203,7 @@ def toList_freq(item, nounits=False):
process.wait()
if process.returncode:
print 'ERROR: simms.py returns errr code %d. %s'%(process.returncode, message)
failed = True

casa_script.close()
os.system('mv %s/%s . && rm -fr %s'%(tmpdir,logfile,tmpdir) )
Expand All @@ -221,7 +224,7 @@ def toList_freq(item, nounits=False):
std.write('\n %s ::: %s\n%s\n'%(ts," ".join(command),ran))
std.write("Parameters: %s\n"%fmt)

if os.path.exists(msname):
if os.path.exists(msname) and failed==False:
info("simms succeeded")
else:
raise CasapyError(message)
Expand Down Expand Up @@ -285,7 +288,7 @@ def main():
help='Integration time in seconds : default is 10s')
add('-ih','--init-ha',dest='init_ha',default=None,
help='Initial hour angle for observation. If not specified '
'we use -[scan_length/2]')
'we use -[scan_length/2]:: DEPRECATED')
add('-nc','--nchan',dest='nchan',default='1',
help='Number of frequency channels. Specify as comma separated list '
' (for multiple subbands); see also --freq0, --dfreq: default is 1')
Expand All @@ -305,8 +308,10 @@ def main():
help='Polarization : default is "perfect X Y" ')
add('-date','--date',dest='date',metavar="EPOCH,yyyy/mm/dd[/h:m:s]",
help='Date of observation. Example "UTC,2014/05/26" or "UTC,2014/05/26/12:12:12" : default is today')
add('-os','--optimise-start', action="store_true",
help='Modify observation start time to maximise source visibility.')
add('-slg','--scan-lag',default=0,type=float,
help="Lag time between scans. In hrs: default is 0")
help="Lag time between scans. In hrs: default is 0:: DEPRECATED")
add('-stl','--set-limits',dest='set_limits',action='store_true',
help='Set telescope limits; elevation and shadow limts : not the default')
add('-el','--elevation-limit',dest='elevation_limit',type=float,default=0,
Expand Down Expand Up @@ -373,8 +378,9 @@ def main():
simms(msname=args.name,label=args.label,tel=telescope,pos=antennas,feed=args.feed,
pos_type=_type,ra=args.ra,dec=args.dec,synthesis=args.synthesis,scan_length=args.scan_length,
dtime=args.dtime,freq0=args.freq0,dfreq=args.dfreq,nchan=args.nchan,
stokes=args.pol,start_time=args.init_ha,setlimits=args.set_limits,
stokes=args.pol,setlimits=args.set_limits,
elevation_limit=args.elevation_limit,shadow_limit=args.shadow_limit,
outdir=args.outdir,coords=cs,lon_lat=args.lon_lat,noup=args.noup,
direction=args.direction,nbands=args.nband,date=args.date,
fromknown=args.knownconfig,scan_lag=args.scan_lag,auto_corr=args.auto_corr)
fromknown=args.knownconfig,scan_lag=args.scan_lag,auto_corr=args.auto_corr,
optimise_start=args.optimise_start)

0 comments on commit ff67cd3

Please sign in to comment.