def wgains(lpars): ''' Write the gains into a new file. ''' mirout, mirerr = lib.mirrun(task='uvcat', vis=lpars.vis, out='.temp') #tout = uvcat.snarf() o, e = lib.shrun('rm -r '+lpars.vis) o, e = lib.shrun('mv .temp '+lpars.vis)
def selfcal_multi(settings): ''' Main module that controls the multi-threaded selfcal. selfcal_main(settings), where settings is grabbed from a config file through: settings = apercal.lib.settings('someconfigfile.txt') ''' logger = logging.getLogger('selfcal_multi') logger.setLevel(logging.DEBUG) # NOTE: The script parameters, spars, are grabbed here and used throughout the script. spars = settings.get('selfcal_multi') nt = 0 if lib.str2bool(spars.imall)!=False: print "Making Wide Band Image..." spars.line="" #NOTE: Increase the CLEAN depth by the nominal increase in sensitivity. spars.dc = float(spars.dc) * pl.sqrt(8.) #NOTE: Increase the BW spars.bw = float(spars.bw) * 8. for i in range(0,int(spars.nloops)): print "Loop=", str(i) iteri(spars, i=i+1) image_cycle(settings, spars, j=i+1) print "Completed Wide Band Image" sys.exit(0) spars.nloops = int(spars.nloops) THREADS = [] for v in spars.vis.split(','): # NOTE: Here we make the new directory and move to it. if lib.str2bool(spars.cleanup)!=False: o, e = lib.shrun("rm -r "+v+"/gains") o, e = lib.shrun("rm -r "+v+"_*") logger.info("Assigned Thread "+str(nt)+" for "+v) nt+=1 # NOTE: Now mpars only exists in this for loop, and is reserved for the # farming of the threads. It is a copy of spars #mpars = spars #mpars.vis = v #mpars.tag = v THREADS.append(selfcal_main(v, settings)) time.sleep(1) for T in THREADS: logger.info("Starting "+str(T)) T.start() for T in THREADS: time.sleep(1) logger.info("Joining "+ str(T)) T.join() logger.info("DONE.")
def invertr(settings, spars): ''' output = invertr(settings, spars) Runs MIRIAD's invert on spars.vis, using settings.get('image'). Returns the output from mirrun. ''' vis = spars.vis lpars = settings.get('image') #NOTE: Clean up o, e = lib.shrun('rm -r '+spars.map) o, e = lib.shrun('rm -r '+spars.beam) mirout, mirerr = lib.mirrun(task='invert', vis=vis, select=lpars.select, line=lpars.line, map = spars.map, beam=spars.beam, options=lpars.options, slop=lpars.slop, stokes=lpars.stokes, imsize=lpars.imsize, cell=lpars.cell, fwhm=lpars.fwhm, robust=lpars.robust) lib.exceptioner(mirout, mirerr) return mirout
def restor(lpars, mode='clean'): ''' output = restor(params, mode='clean') Uses the MIRIAD task restor to restor a model image, creating either an image or a residual. ''' if mode.upper()!="CLEAN": # Make the residual # Cleanup o, e = lib.shrun('rm -r '+lpars.residual) mirout, mirerr = lib.mirrun(task='restor', beam=lpars.beam, map=lpars.map, model=lpars.model, out=lpars.residual, mode='residual') else: # Make the image # Cleanup o, e = lib.shrun('rm -r '+lpars.image) mirout, mirerr = lib.mirrun(task='restor', beam=lpars.beam, map=lpars.map, model=lpars.model, out=lpars.image, mode=mode) return mirout
def make_mask(image, cutoff, mask): ''' output = make_mask(image, cutoff, mask) Uses the MIRIAD task MATHS to make a threshold mask. The input <image> is thresholded with cutoff, and a <mask> is created. ''' # Cleanup o, e = lib.shrun('rm -r '+mask) # NOTE: MATHS is stupid and doesn't know how to follow paths. So we have to make a symbolic # link to the images. lib.shrun('ln -s '+image) mirout, mirerr = lib.mirrun(task='maths', exp=os.path.split(image)[1], mask=os.path.split(image)[1]+".gt."+str(cutoff), out=mask) lib.exceptioner(mirout, mirerr) # Remove the symbolic link lib.shrun('rm '+os.path.split(image)[-1]) # Climb up back to the original path return mirout
def clean(lpars): ''' output = clean(lpars) Runs MIRIAD's clean, using standard settings. ''' #NOTE: Cleanup o, e = lib.shrun("rm -r "+lpars.model) if lpars.mask!=None: #NOTE: Use mask if provided. mirout, mirerr = lib.mirrun(task='clean', map=lpars.map, beam=lpars.beam, out=lpars.model, cutoff=lpars.cutoff, region="'mask("+lpars.mask+")'", niters=100000) lib.exceptioner(mirout, mirerr) else: #NOTE: Do a 'light' clean if no mask provided. mirout, mirerr = lib.mirrun(task='clean', map=lpars.map, beam=lpars.beam, out=lpars.model, cutoff=lpars.cutoff, niters=1000) lib.exceptioner(mirout, mirerr) return mirout
def make_nvss_lsm(params): #TODO: NVSS needs to be integrated here!!!! c = "python mk-nvss-lsm.py -i "+params.map+" -o "+params.lsm o, e = lib.shrun(c) tout = selfcal(params)