コード例 #1
0
def plot_noise(kw,current_time):
    # store a plot of the psf
    outdir = '/tmp/ska_calculator/data/runs/' + current_time + '/'
    data = outdir + 'noise.im'
    data_fits = outdir + 'noise.fits'
    plotname = outdir + 'noise.png'

    #public_dir = 'ska_calculator/public/data/' + current_time + '/'
    public_dir = '/home/ec2-user/turbogears/ska-calculator/ska_calculator/public/data/' + current_time +'/'

    miriad.fits(In=data, out=data_fits, op='xyout')
    f=pyfits.open(data_fits)
    noise_data = f[0].data
    noise_data = noise_data[0,0,:,:]
    cdelt = f[0].header['cdelt1']*3600
    f.close()

    plt.figure(1, figsize=(8,6))
    plt.clf()  # clear the previous figure
    plt.subplot(1,1,1)
    midpoint = np.round(len(noise_data)/2)
    box_rad = 64
    box_min = midpoint-box_rad
    box_max = midpoint+box_rad
    extent_min = -box_rad * cdelt
    extent_max = box_rad * cdelt
    extent = [extent_min,extent_max,extent_min,extent_max]
    plt.imshow(noise_data[box_min:box_max,box_min:box_max], extent=extent,interpolation='nearest')
    plt.colorbar()
    plt.xlabel('arcsec', size=10)
    plt.ylabel('arcsec', size=10)
    plt.title('noise', size=12)
    plt.savefig(plotname)

    os.system('cp ' + plotname + ' ' + public_dir + '/.')
    os.system('cp ' + data_fits + ' ' + public_dir + '/.')

    return
コード例 #2
0
ファイル: miriad_tools.py プロジェクト: rajikalk/Scripts
def clean(v0, datadir='.'):

    curdir = os.getcwd()

    try:
        os.chdir(datadir)
        visdata = glob('./*.uvdata')
        if len(visdata) == 0:
            raise IOError("could not find %s" % visdata)
        elif len(visdata) > 1:
            raise IOError("Multiple visibility files found %i" %
                          (len(visdata)))

        visdata = visdata[0]
        source, void = os.path.splitext(visdata)

        #set C18O rest velocity
        void = miriad.puthd(_in=visdata + '/restfreq', value=219.560368)

        dv = 0.2
        Dv = 4.
        nchan = int(Dv / dv)
        #     v0 = 9.1 #km/s
        # cut out all but +/- 2 km/s from rest
        # velocity syntax is number of channels, first channel, channel spacing,
        #         channel width
        try:
            miriad.uvaver(vis=visdata,
                          line='velocity,%i,%.1f,%.1f,%.1f' %
                          (nchan, v0 - Dv / 2, dv, dv),
                          out=source + '.vcut.uv')
        except:
            pass

        # integrate (average) down to one channel
        # will make integrated intensity, but in wrong units
        # to get to integrated intensity, multiply by (n*dv)
        try:
            miriad.uvaver(vis=source + '.vcut.uv',
                          line='velocity,%i,%.1f,%.1f,%.1f' %
                          (1, v0 - Dv / 2, Dv, Dv),
                          out=source + '.aver.uv')
        except:
            pass

        os.system('rm -rf *.dirtymap* *.beam*')

        output = miriad.invert(vis=source + '.aver.uv',
                               map=source + '.dirtymap',
                               beam=source + '.beam',
                               cell=0.8,
                               imsize=100,
                               robust=1.0,
                               options='systemp,double')

        rms = float(
            re.findall("Theoretical rms noise: ([-+]?\d+[\.]?\d*[-+Ee]*\d*)",
                       output)[0])

        #clean the dirty map, just do a very basic clean for now
        #restore image
        os.system('rm -rf *.clean* *.cleanmap*')
        cleanoutput = miriad.clean(map=source + '.dirtymap',
                                   beam=source + '.beam',
                                   out=source + '.clean',
                                   cutoff=rms * 2,
                                   niters=10000,
                                   gain=0.05,
                                   options='positive')

        print(cleanoutput)

        miriad.restor(map=source + '.dirtymap',
                      beam=source + '.beam',
                      model=source + '.clean',
                      out=source + '.cleanmap')

        miriad.fits(_in=source + '.dirtymap',
                    op='xyout',
                    out=source + '.dirtymap.fits')
        miriad.fits(_in=source + '.beam',
                    op='xyout',
                    out=source + '.beam.fits')
        miriad.fits(_in=source + '.cleanmap',
                    op='xyout',
                    out=source + '.cleanmap.fits')
    finally:
        os.chdir(curdir)
コード例 #3
0
ファイル: miriad_tools.py プロジェクト: rajikalk/Scripts
def subtract(datadir='.', time=0):

    curdir = os.getcwd()

    try:
        os.chdir(datadir)

        visdata = glob('*.uvdata')
        if len(visdata) == 0:
            raise IOError("could not find %s" % visdata)
        elif len(visdata) > 1:
            raise IOError("Multiple visibility files found %i" %
                          (len(visdata)))

        visdata = visdata[0]
        source, void = os.path.splitext(visdata)

        cleanext = '.cleanmap' if time == 0 else '.sub%i.cleanmap' % (time - 1)

        if not os.path.exists('imfit_sub%i.txt' % time):
            os.system('rm sub%i.region' % time)
            miriad.cgcurs(_in=source + cleanext,
                          device='/xs',
                          options='wedge,cursor,region')
            os.system('mv cgcurs.region sub%i.region' % time)

            output = miriad.imfit(_in=source + cleanext,
                                  object='gaussian',
                                  region='@sub%i.region' % time)

            with open('imfit_sub%i.txt' % time, 'w') as f:
                f.write(output)
        else:
            output = open('imfit_sub%i.txt' % time, 'r').readlines()
            output = ''.join(output)

        print(output)

        imout, rms, beamMajor, beamMinor, beampa = read_imfit(output)

        # create zero image
        if not os.path.exists(source + '.zero'):
            miriad.maths(exp=source + cleanext + '*0', out=source + '.zero')

        os.system(
            'rm -r *sub%i.model* *sub%i.dirtymap* *sub%i.beam *sub%i.aver.uv' %
            (time, time, time, time))
        # make model gaussian
        miriad.imgen(_in=source + '.zero',
                     out=source + '.sub%i.model' % time,
                     object='gaussian',
                     spar='%f,%f,%f,%f,%f,%f' %
                     (imout['peak'], imout['x'], imout['y'], imout['dmaj'],
                      imout['dmin'], imout['dpa']))

        #convert to Jy/pixel
        factor = 0.8**2 / (2 * np.pi * beamMajor * beamMinor / 2.35482**2)
        print(1 / factor)
        miriad.maths(exp=source + '.sub%i.model*%f' % (time, factor),
                     out=source + '.sub%i.model.perpixel' % time)

        # convert model gaussian to uv space
        uvext = '.aver.uv' if time == 0 else '.sub%i.aver.uv' % (time - 1)
        miriad.uvmodel(vis=source + uvext,
                       model=source + '.sub%i.model.perpixel' % time,
                       options='subtract',
                       out=source + '.sub%i.aver.uv' % time)

        # create new dirty image with subtracted uv data
        miriad.invert(vis=source + '.sub%i.aver.uv' % time,
                      map=source + '.sub%i.dirtymap' % time,
                      beam=source + '.sub%i.beam' % time,
                      cell=0.8,
                      imsize=100,
                      robust=1.0,
                      options='systemp,double')

        miriad.fits(_in=source + '.sub%i.dirtymap' % time,
                    op='xyout',
                    out=source + '.sub%i.dirtymap.fits' % time)

    finally:
        os.chdir(curdir)
コード例 #4
0
def plot_psf(kw,current_time):
    # store a plot of the psf
    outdir = '/tmp/ska_calculator/data/runs/' + current_time + '/'
    psf = outdir + 'psf.im'
    #public_dir = 'ska_calculator/public/data/' + current_time + '/'
    public_dir = '/home/ec2-user/turbogears/ska-calculator/ska_calculator/public/data/' + current_time + '/'
    psf_fits = outdir + 'psf.fits'
    plotname = outdir + '/psf.png'
    
    
    if not os.path.exists(public_dir):
            os.makedirs(public_dir)


    print 'psf=', psf
    print 'public_dir=', public_dir

    miriad.fits(In=psf, out=psf_fits, op='xyout')
    f=pyfits.open(psf_fits)
    beam_data = f[0].data
    beam_data = beam_data[0,:,:]
    #beam_stat = beam_data[960:-960,960:-960]
    beam_stat = beam_data
    min_range = beam_stat.min()
    cdelt = f[0].header['cdelt1']*3600
    f.close()
    
    plt.figure(1, figsize=(8,6))
    plt.clf()  # clear the previous figure
    
    plt.subplot(1,1,1)
    midpoint = np.round(len(beam_data)/2)
    box_rad = 16
    box_min = midpoint-box_rad
    box_max = midpoint+box_rad
    extent_min = -box_rad * cdelt
    extent_max = box_rad * cdelt
    #extent = [-64*cdelt,64*cdelt,-64*cdelt,64*cdelt]
    #plt.imshow(beam_data[960:-960,960:-960], extent=extent,interpolation='nearest',vmin=min_range,vmax=-3*min_range)
    extent = [extent_min,extent_max,extent_min,extent_max]
    plt.imshow(beam_data[box_min:box_max,box_min:box_max], extent=extent,interpolation='nearest',vmin=min_range,vmax=-3*min_range)
    plt.colorbar()

    levels1=[0.1,0.2,0.5]
    levels2=[-0.05, -0.01]
    plt.contour(beam_data[box_min:box_max,box_min:box_max], levels1, hold='on', colors = 'k',origin='upper', extent=extent, aspect='auto')
    plt.contour(beam_data[box_min:box_max,box_min:box_max], levels2, hold='on', colors = 'w',origin='upper', extent=extent, aspect='auto')
    plt.xlabel('arcsec', size=10)
    plt.ylabel('arcsec', size=10)
    plt.title('Beam PSF', size=12)
    plt.savefig(plotname)

    #print 'BLAAAAAAAAAAAAAAAA$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'

    #print plotname
    #print public_dir
    #os.system('ls ' + public_dir)
    
    os.system('cp ' + plotname + ' ' + public_dir + '/.')
    os.system('cp ' + psf_fits + ' ' + public_dir + '/.')
    
    #os.system('ls -l ' + public_dir)

    return
コード例 #5
0
    refant = int(line['refant'])

    ## -- Common data preparation -- ##
    for name in names:

        # Convert to MIRIAD UVFITS format
        in_file = in_path + '/' + obsid + '/' + name + '.fits'
        out_file = in_path + '/' + obsid + '/' + name + '.uv'
        if not os.path.exists(out_file):
            fits_input = {
                'In': in_file,
                'op': 'uvin',
                'out': out_file,
                'velocity': 'lsr'
            }
            miriad.fits(**fits_input)

        # Flag auto correlations
        in_file = in_path + '/' + obsid + '/' + name + '.uv'
        uvflag_input = {'vis': in_file, 'select': 'auto', 'flagval': 'flag'}
        miriad.uvflag(**uvflag_input)

        # Additional flags
        if os.path.exists(in_path + '/' + obsid + '/uvflag.txt'):
            flags = ascii.read(in_path + '/' + obsid + '/uvflag.txt',
                               format='commented_header',
                               comment='#')
            for flag in flags:
                uvflag_input = {
                    'vis': in_file,
                    'select': str(flag['select']),