Exemple #1
0
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)
Exemple #2
0
        # read in the observed visibilities
        obsdata = fits.open(file)

        # get the real and imaginary components
        data_real, data_imag, data_wgt = uvutil.visload(obsdata)
        
        #----------------------------------------------------------------------
        # Python version of UVMODEL
        # "Observe" the lensed emission with the SMA and write to a new file
        #----------------------------------------------------------------------
        # Python replace:
        nameindx = file.find('uvfits')
        name = file[0:nameindx-1]

        py_replace = uvmodel.replace(outfits, file)
        #py_real, py_imag, py_wgt = uvmodel.components(py_replace)
        #dreal = py_real - data_real
        #dimag = py_imag - data_imag
        #py_chi2 = py_wgt * (dreal ** 2 + dimag ** 2)
        #print name, 'py-replace ', py_chi2.sum(), py_wgt.sum()

        modelvisfile = name + '_pyreplace.uvfits'
        os.system('rm -rf ' + modelvisfile)
        py_replace.writeto(modelvisfile)

        # and convert to miriad format for imaging
        miriadmodelvisloc = name + '_pyreplace.miriad'
        os.system('rm -rf ' + miriadmodelvisloc)
        command = 'fits in=' + modelvisfile + ' op=uvin out=' + \
            miriadmodelvisloc
Exemple #3
0
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)
Exemple #4
0
def uvmcmcfitVis(model, data, simfile):
    #cmd = 'rm -rf ' + simfile
    #call(cmd, shell=True)
    uvmodel.replace(model, data, simfile, miriad=True)
Exemple #5
0
def uvmcmcfitVis(model, data, simfile):
    #cmd = 'rm -rf ' + simfile
    #call(cmd, shell=True)
    uvmodel.replace(model, data, simfile, miriad=True)