Ejemplo n.º 1
0
def exchan(vis, ch):
    uvaver = mirexec.TaskUVAver()
    uvaver.vis = vis
    uvaver.line = 'channel,1,' + str(ch) + ',1,1'
    uvaver.out = vis.replace('.uv', '_ch' + str(ch) + '.uv')
    tout = uvaver.snarf()
    acos.taskout(uvaver, tout, 'uvaver.txt')
    return uvaver.out
Ejemplo n.º 2
0
def specr(f, S):
    '''
	Uses uvaver to cut-out a spectral range. 
	'''
    uvaver = mirexec.TaskUVAver()
    uvaver.vis = f
    uvaver.line = S.line
    uvaver.out = '_tmp_specr'
    tout = uvaver.snarf()
    os.system('rm -r ' + f)
    os.system('mv _tmp_specr ' + f)
    acos.taskout(uvaver, tout, 'uvaver.txt')
Ejemplo n.º 3
0
def getuvspw():
    uvaver = mirexec.TaskUVAver()
    for f in S.uvfiles.split(','):
        print "Extracting " + str(S.line) + " from " + f
        # Now to extract the spectral range using uvaver
        uvaver.vis = f
        uvaver.line = S.line
        uvaver.out = f.replace(S.tag, S.retag)
        tout = uvaver.snarf()
        acos.taskout(uvaver, tout, 'uvaver')
        # Delete the old file
        cmd = 'rm -r ' + f
        os.system(cmd)
Ejemplo n.º 4
0
def splitspw(vis, spw):
	uvaver = mirexec.TaskUVAver()
	uvaver.stokes='ii'
	uvaver.vis = vis
	uvaver.select = 'window('+str(spw)+')'
	wvis = vis+'_spw'+str(spw)+'.uv'

	if os.path.isdir(wvis)==False:
		uvaver.out = wvis
		uvaver.line = 'channel,58,2,1,1'
		uvaver.snarf()
		pgflag(wvis, 'ii', '3,1,1,3,5,3') 
		pgflag(wvis, 'ii', '3,1,1,3,5,3') 
	else:
		pass
	return wvis

	print "SPLIT'd ", vis, " -> ", wvis
Ejemplo n.º 5
0
    def run(self):
        cleanup = []

        vises = self.vises

        if self.precat:
            cattmp = self.out.vvis('cat')
            cattmp.delete()
            mirexec.TaskUVCat(vis=vises, out=cattmp).run()
            vises = [cattmp]
            cleanup.append(cattmp)

        t = mirexec.TaskUVModel(vis=vises, model=self.model)
        setattr(t, _modeOptionMap[self.mode], True)
        t.set(flux=self.flux)
        t.set(**self.modelMisc)

        cmodel = []

        # We need to run one model task for each pol. Do so in
        # parallel unless self.serial is True. There are several steps
        # to execute serially for each pol, so instead of running the
        # MIRIAD tasks asynchronously, which would add a few extra
        # sync points to the processing, we actually spawn a couple of
        # threads, since it's not very complicated to do so.

        def doone(modeltask, pol, polcode):
            pv = self.out.vvis('mdl' + pol)
            pv.delete()
            modeltask.set(select=self.select + ['pol(%s)' % (pol * 2)],
                          out=pv).run()
            cleanup.append(pv)

            # If the user is modeling with a point-source model, UVMODEL
            # doesn't write any polarization information into the output
            # dataset, which causes UVCAL to not apply the polcode correction
            # (even though the default assumption is I pol, I believe).  So we
            # edit the dataset to insert polarization information
            # unconditionally. We append npol and pol UV variables because
            # UVCAL checks the presence of these UV variables when deciding if
            # its input has any polarization information. We also write header
            # items so that the values of the UV variables will be defined for
            # the entire UV stream via the override mechanism -- otherwise,
            # they'd remain undefined until the entire stream was finished!
            # Appending in this way means that we don't have to rewrite the
            # entire dataset just to stick a "pol = npol = 1" at its
            # beginning.

            phnd = pv.open('a')
            phnd.writeVarInt('npol', 1)
            phnd.writeVarInt('pol', util.POL_I)
            phnd.setScalarItem('npol', np.int32, 1)
            phnd.setScalarItem('pol', np.int32, util.POL_I)
            phnd.close()

            cv = self.out.vvis('cal' + pol)
            cv.delete()
            mirexec.TaskUVCal(vis=pv, out=cv, polcode=polcode).run()
            cmodel.append(cv)
            cleanup.append(cv)

        from threading import Thread
        from copy import deepcopy

        threads = []

        for pol, polcode in zip('xy', (-6, -7)):
            if self.serial:
                doone(deepcopy(t), pol, polcode)
            else:
                thread = Thread(target=doone, args=(deepcopy(t), pol, polcode))
                thread.start()
                threads.append(thread)

        for thread in threads:
            thread.join()

        # Done with the per-pol processing.

        if not self.touchup:
            mirexec.TaskUVCat(vis=sorted(str(v) for v in cmodel),
                              out=self.out).run()
        else:
            combined = self.out.vvis('comb')
            combined.delete()
            mirexec.TaskUVCat(vis=sorted(str(v) for v in cmodel),
                              out=combined).run()
            cleanup.append(combined)

            sortvis = self.out.vvis('sort')
            sortvis.delete()
            mirexec.TaskUVSort(vis=combined, out=sortvis).run()
            cleanup.append(sortvis)

            mirexec.TaskUVAver(vis=sortvis, interval=1e-6, out=self.out).run()

        if not self.preserve:
            for v in cleanup:
                v.delete()