def mkuvfits(fin, fout): UV = pyuvdata.UVData() #Read file and rewrap phases. UV.read_miriad(fin, 'miriad') UV.phase_to_time(UV.time_array[0]) UV.write_uvfits(fout, 'uvfits') #Output to .ms directory casa.importuvfits(fout, fout + '.ms')
def makeVis(config, miriad=False, idtag=''): """ Make simulated visibilities given a model image and observed visibilities. Writes the visibilities to uvfits files. """ import uvmodel import os # get the uvfits files visfile = config['UVData'] #---------------------------------------------------------------------- # Python version of UVMODEL # "Observe" the lensed emission with the SMA and write to a new file #---------------------------------------------------------------------- # Python version of UVMODEL's "replace" subroutine: # is visfile a list of visibilities files? if not type(visfile) is list: visname, visext = os.path.splitext(visfile) if miriad: # We use miriad to do the imaging tag = '.miriad' DataMiriad = visname + tag if not os.path.exists(DataMiriad): print("Creating new miriad data file: " + DataMiriad) os.system('rm -rf ' + DataMiriad) command = 'fits op=uvin in=' + visfile + ' out=' + DataMiriad os.system(command) else: # We use CASA to do the imaging tag = '.ms' # check to see if the CASA ms exists try: from taskinit import tb tb.open(visname + tag) tb.close() print "Found an existing CASA ms file." except RuntimeError: print "No CASA ms file found, creating one from " + visname \ + ".uvfits file." from casa import importuvfits infile = visname + '.uvfits' outfile = visname + '.ms' importuvfits(fitsfile=infile, vis=outfile) visfile = visname + tag SBmapLoc = 'LensedSBmap.fits' modelvisfile = visname + '_model_' + idtag + tag os.system('rm -rf ' + modelvisfile) if miriad: SBmapMiriad = 'LensedSBmap' + tag os.system('rm -rf ' + SBmapMiriad) command = 'fits op=xyin in=' + SBmapLoc + ' out=' \ + SBmapMiriad os.system(command) command = 'uvmodel options=replace vis=' + visfile + \ ' model=' + SBmapMiriad + ' out=' + modelvisfile os.system(command + ' > uvmodeloutput.txt') #command = 'cp ' + visfile + '/wflags ' + modelvisfile #os.system(command) else: #print(visfile, modelvisfile) uvmodel.replace(SBmapLoc, visfile, modelvisfile, miriad=miriad) #print(visfile, modelvisfile) # Python version of UVMODEL's "subtract" subroutine: modelvisfile = visname + '_residual_' + idtag + tag os.system('rm -rf ' + modelvisfile) if miriad: SBmapMiriad = 'LensedSBmap' + tag os.system('rm -rf ' + SBmapMiriad) command = 'fits op=xyin in=' + SBmapLoc + ' out=' \ + SBmapMiriad os.system(command) os.system('rm -rf ' + modelvisfile) command = 'uvmodel options=subtract vis=' + visfile + \ ' model=' + SBmapMiriad + ' out=' + modelvisfile os.system(command) #command = 'cp ' + visfile + '/wflags ' + modelvisfile #os.system(command) else: #print(visfile, modelvisfile) uvmodel.subtract(SBmapLoc, visfile, modelvisfile, miriad=miriad) else: for i, ivisfile in enumerate(visfile): visname, visext = os.path.splitext(ivisfile) print(visname) if miriad: tag = '.uvfits' else: tag = '.ms' # check to see if the CASA ms exists try: from taskinit import tb tb.open(visname + tag) tb.close() print "Found an existing CASA ms file." except RuntimeError: print "No CASA ms file found, creating one from " + visname \ + ".uvfits file." from casa import importuvfits infile = visname + '.uvfits' outfile = visname + '.ms' importuvfits(fitsfile=infile, vis=outfile) SBmapLoc = 'LensedSBmap.fits' if miriad: SBmapMiriad = 'LensedSBmap.miriad' os.system('rm -rf ' + SBmapMiriad) command = 'fits op=xyin in=' + SBmapLoc + ' out=' \ + SBmapMiriad os.system(command) ivisfile = visname + '.miriad' modelivisfile = visname + '_model_' + idtag + '.miriad' os.system('rm -rf ' + modelivisfile) command = 'uvmodel options=replace vis=' + ivisfile + \ ' model=' + SBmapMiriad + ' out=' + modelivisfile os.system(command) #command = 'cp ' + ivisfile + '/wflags ' + modelivisfile #os.system(command) else: ivisfile = visname + tag modelivisfile = visname + '_model_' + idtag + tag os.system('rm -rf ' + modelivisfile) uvmodel.replace(SBmapLoc, ivisfile, modelivisfile, miriad=miriad) # Python version of UVMODEL's "subtract" subroutine: if miriad: SBmapMiriad = 'LensedSBmap.miriad' os.system('rm -rf ' + SBmapMiriad) command = 'fits op=xyin in=' + SBmapLoc + ' out=' \ + SBmapMiriad os.system(command) modelivisfile = visname + '_residual_' + idtag + '.miriad' os.system('rm -rf ' + modelivisfile) command = 'uvmodel options=subtract vis=' + ivisfile + \ ' model=' + SBmapMiriad + ' out=' + modelivisfile os.system(command) #command = 'cp ' + ivisfile + '/wflags ' + modelivisfile #os.system(command) else: modelivisfile = visname + '_residual_' + idtag + tag os.system('rm -rf ' + modelivisfile) uvmodel.subtract(SBmapLoc, ivisfile, modelivisfile, miriad=miriad)
#!/usr/bin/env /usr/lib64/casapy/bin/python """ CASA script for batch importing miriad files D.Jacobs 2010 """ import sys, os, optparse #Setup casa environment (AOC) sys.path.append('/usr/lib64/casapy/test/lib/python2.6') sys.path.append('/usr/lib64/casapy/test/lib/python2.6/site-packages') #setup miriad environment (AOC) MIRBIN = '/usr/local/miriad/linux64/bin/' os.environ['MIRCAT'] = '/usr/local/miriad/cat/' import casa o = optparse.OptionParser() o.set_usage('miriad2casams.py [options] *.uv') o.set_description(__doc__) opts, args = o.parse_args(sys.argv[1:]) for file in args: fitsfile = file + '.fits' visfile = file + '.ms' print(file + ' > ' + fitsfile) os.system(MIRBIN + 'fits in=' + file + ' op=uvout out=' + fitsfile + ' stokes=xx') print(fitsfile + ' > ' + visfile) casa.importuvfits(fitsfile=fitsfile, vis=visfile)
#!/usr/bin/env /usr/lib64/casapy/bin/python """ CASA script for batch importing miriad files D.Jacobs 2010 """ import sys, os, optparse #Setup casa environment (AOC) sys.path.append('/usr/lib64/casapy/test/lib/python2.6') sys.path.append('/usr/lib64/casapy/test/lib/python2.6/site-packages') #setup miriad environment (AOC) MIRBIN='/usr/local/miriad/linux64/bin/' os.environ['MIRCAT']='/usr/local/miriad/cat/' import casa o = optparse.OptionParser() o.set_usage('miriad2casams.py [options] *.uv') o.set_description(__doc__) opts,args = o.parse_args(sys.argv[1:]) for file in args: fitsfile = file+'.fits' visfile = file+'.ms' print(file+' > '+fitsfile) os.system(MIRBIN+'fits in='+file+' op=uvout out='+fitsfile+' stokes=xx') print(fitsfile+' > ' + visfile) casa.importuvfits(fitsfile=fitsfile,vis=visfile)