Beispiel #1
0
def mkfield(a, b, c, g):
    '''
	Here I use uvmodel to subtract the model b from the uv-data-set a. 
	This also copies the gain over, subtracts the source and then undoes the gain. 
	'''
    # Step 0: We need to ensure that any previous selfcal calibration gets applied
    # to the uv-data-set a.
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = a
    uvcat.out = 'temp2.uv'
    tout = uvcat.snarf()
    acos.taskout(uvcat, tout, 'peel.txt')

    # Step 1: First we copy the calibration from g to the uv-data-set a:

    gpcopy = mirexec.TaskGPCopy()
    gpcopy.vis = g
    gpcopy.out = 'temp2.uv'
    tout = gpcopy.snarf()
    acos.taskout(gpcopy, tout, 'peel.txt')

    # Step 2: Use uvcat to apply the gains, creating a temporary uv-file.
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = 'temp2.uv'
    uvcat.out = 'temp3.uv'
    tout = uvcat.snarf()
    acos.taskout(uvcat, tout, 'peel.txt')

    # Step 3: Subtract the model pmod from the temporary uv-file.
    uvmodel = mirexec.TaskUVModel()
    uvmodel.vis = 'temp3.uv'
    uvmodel.out = 'temp4.uv'
    uvmodel.model = b
    uvmodel.options = 'subtract,mfs'
    tout = uvmodel.snarf()
    acos.taskout(uvmodel, tout, 'peel.txt')

    # Step 4: This is a hack: We use atnf-gpedit (agpedit) to copy and invert the gains from g.
    gpcopy.vis = g
    gpcopy.out = 'temp4.uv'
    tout = gpcopy.snarf()
    acos.taskout(gpcopy, tout, 'peel.txt')

    cmd = './agpedit vis=temp4.uv options=invert'
    os.system(cmd)

    # Step 5: We use uvcat to make the desired uv-data-set.
    uvcat.vis = 'temp4.uv'
    uvcat.out = c
    tout = uvcat.snarf()
    acos.taskout(uvcat, tout, 'peel.txt')

    # Step 6: Finally, I make a settings file for c:
    S = acos.settings(name=c)
    S.save()
    print "DONE"

    # Step 7: Cleanup temp.uv and temp3.uv temp4.uv
    os.system("rm -r temp*.uv")
Beispiel #2
0
def mkpeel(a, b, c):
    '''
	Here I use uvmodel to subtract the model b from the uv-data-set a. 
	'''
    print "UVMODEL: " + a + " - " + "uv(" + b + ") = " + c
    # Step 1: First we use uvcat to apply the calibration, just to make sure.
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = a
    uvcat.out = 'temp.uv'
    tout = uvcat.snarf()
    acos.taskout(uvcat, tout, 'peel.txt')

    # Step 2: We use the temp.uv file to subtract the model.
    uvmodel = mirexec.TaskUVModel()
    uvmodel.vis = 'temp.uv'
    uvmodel.model = b
    uvmodel.out = c
    uvmodel.options = 'subtract,mfs'
    tout = uvmodel.snarf()
    acos.taskout(uvmodel, tout, 'peel.txt')

    # Step 3: Finally, I'm going to make a settings file just for the peel.uv:
    S = acos.settings(name=c)
    S.save()

    # Step 4: Now to clean up the temp.uv files.
    os.system("rm -r temp*.uv")
Beispiel #3
0
def wgains(params):
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = params.vis
    uvcat.out = '.temp'
    tout = uvcat.snarf()
    shrun('rm -r ' + params.vis)
    shrun('mv .temp ' + params.vis)
Beispiel #4
0
def uvcatr(fname):
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = fname
    uvcat.out = fname + '.tmp'
    print 'Writing in Gains for ' + str(fname)
    uvcat.snarf()
    print 'Deleting Temp File'
    os.system('rm -r ' + fname)
    os.system('mv ' + fname + '.tmp ' + fname)
Beispiel #5
0
def cal2srcs(cals, srcs):
    '''
	Cals = 'cal1,cal2'
	Srcs = 'src1,src2'
	'''
    #cals = cals.split(',');
    #srcs = srcs.split(',');
    # uvcat on src files
    if os.path.exists(srcs[2]) == False:
        #try:
        #	with open(srcs[2]):
        #		isthere=True;
        #except IOError:
        #	isthere=False;
        #
        #if isthere==False:
        uvcat = mirexec.TaskUVCat()
        uvcat.vis = srcs[0] + ',' + srcs[1]
        uvcat.out = srcs[2]
        uvcat.options = 'unflagged'
        tout = uvcat.snarf()
        acos.taskout(uvcat, tout, 'cal2srcs.txt')

    # puthd on src
    puthd = mirexec.TaskPutHead()
    puthd.in_ = srcs[2] + '/restfreq'
    puthd.value = 1.420405752
    tout = puthd.snarf()
    acos.taskout(puthd, tout, 'cal2srcs.txt')

    puthd.in_ = srcs[2] + '/interval'
    puthd.value = 1.0
    puthd.type = 'double'
    tout = puthd.snarf()
    acos.taskout(puthd, tout, 'cal2srcs.txt')

    # gpcopy cal1 -> src
    gpcopy = mirexec.TaskGPCopy()
    gpcopy.vis = cals[0]
    gpcopy.out = srcs[2]
    tout = gpcopy.snarf()
    acos.taskout(gpcopy, tout, 'cal2srcs.txt')
Beispiel #6
0
def mkpuv():
    '''
	For a chan0, applies the gains and then subtracts all the sources
	to provide a uv file with the source to be peeled. 	
	'''
    # First, apply the current gains.
    uvcat = mirexec.TaskUVCat()
    uvcat.vis = S.vis
    uvcat.out = S.vis + '_sc'
    tout = uvcat.snarf()
    acos.taskout(uvcat, tout, 'uvcat.txt')

    # Second, subtract the model from the new uv-file
    uvmodel = mirexec.TaskUVModel()
    uvmodel.vis = S.vis + '_sc'
    #TODO: Need to include pmod in the settings file.
    uvmodel.model = 'fmod'
    uvmodel.options = 'subtract'
    uvmodel.out = 'puv'
    tout = uvmodel.snarf()
    acos.taskout(uvmodel, tout, 'uvmodel.txt')
Beispiel #7
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()
Beispiel #8
0
def wgains(params):
	uvcat = mirexec.TaskUVCat()