コード例 #1
0
ファイル: Simulate_PAPER.py プロジェクト: SaulAryehKohn/capo
blIndices = [(0, 103), (1, 4), (0, 101), (0, 62), (0, 100), (1, 13), (1, 70), (1, 56), (1, 71), (1, 59), (0, 97), (12, 43), (9, 71), (9, 59), (57, 64)]
conjugate = [(0,101), (0,62), (0,100), (0,97), (12,43), (57,64)]

aa = a.cal.get_aa(opts.cal, opts.sdf, opts.sfreq, opts.nchan)
freqs = aa.get_afreqs()
#Fixed coordinate calculations
healpixCoords = np.transpose(np.asarray(hp.pix2ang(NSIDE,np.arange(12*NSIDE**2))))
pixelRAs = healpixCoords[:,1]
pixelDecs = -healpixCoords[:,0] + np.pi/2
galCoords = SkyCoord(frame="icrs", ra=pixelRAs*u.rad, dec=pixelDecs*u.rad).transform_to("galactic")

for source in sourceFiles:
    outfilename = './SimulatedVisibilities/' + source.split('/')[-1].replace('zen',opts.prefix)
    if os.path.exists(outfilename) and not opts.overwrite:
        print '\n    ' + outfilename + ' exists...skipping.\n'; continue
    omni.to_npz(outfilename, {}, {}, {}, {}) #make the file so that other programs running simultaneously skip this one
    meta,_,_,_ = omni.from_npz(source)
    times = meta['jds']
    meta['SimulationOptions'] = opts.__dict__
    vismdl = {opts.pol: {blIndex: np.zeros((len(times), opts.nchan), dtype=complex) for blIndex in blIndices}}

    #Precalcualte the topocentric and AzAlt coordinates of all pixels for all times
    allPixelTops, allPixelAzAlts = [],[] 
    for time in times:
        aa.set_jultime(time)
        pixelEq = a.coord.radec2eq([pixelRAs,pixelDecs])
        pixelTop = a.coord.eq2top_m(-aa.sidereal_time(),aa.lat).dot(pixelEq)
        allPixelTops.append(pixelTop)
        allPixelAzAlts.append(a.coord.top2azalt(pixelTop))

    #Loop over channels, regenerating the beam and GSM at each channel
コード例 #2
0
ファイル: merge_omni_npz.py プロジェクト: nkern/capo
to calibrate xx,xy,yx,yy at once, even though we only used info
from the linear instrumental polarizations.

Assumes xx and yy npz files are in the same directory.
Returns 
"""
o = optparse.OptionParser()
o.set_usage('merge_omni_npz.py [options] /path/to/*xx.npz')
opts, args = o.parse_args(sys.argv[1:])


def merge_dicts(*dict_args):
    result = {}
    for dictionary in dict_args:
        result.update(dictionary)
    return result


for xx_npz in args:
    yy_npz = xx_npz.replace("xx", "yy")
    new_npz = xx_npz.replace("xx.", "")
    print "Reading %s %s" % (xx_npz, yy_npz)
    metax, gainsx, vismdlx, xtalkx = omni.from_npz(xx_npz)
    metay, gainsy, vismdly, xtalky = omni.from_npz(yy_npz)
    meta = merge_dicts(metax, metay)
    gains = merge_dicts(gainsx, gainsy)
    vismdl = merge_dicts(vismdlx, vismdly)
    xtalk = merge_dicts(xtalkx, xtalky)
    print "    => %s" % new_npz
    omni.to_npz(new_npz, meta, gains, vismdl, xtalk)
コード例 #3
0
a.scripting.add_standard_options(o,chan=True)
opts,args = o.parse_args(sys.argv[1:])
chan = int(opts.chan)

### Save Options ###
for filename in args:
    print filename,'-->',
    outfile = filename[:-4]+'.slice.npz'
    print outfile
    if os.path.exists(outfile): 
        print "     ... exists. skipping"
        continue
   
    meta,gains,vismdl,xtalk = from_npz(filename)
    slice_gains = {}
    slice_vismdl = {}
    slice_xtalk = {}
    for pol in gains:
        slice_gains[pol] = {}
        for ant,gain in gains[pol].iteritems():
            slice_gains[pol][ant] = n.array([g[chan] for g in gain])
    for pol in vismdl:
        slice_vismdl[pol] = {}
        for bl,vis in vismdl[pol].iteritems():
            slice_vismdl[pol][bl] = n.array([v[chan] for v in vis])
        slice_xtalk[pol] = {}
        for bl,xt in xtalk[pol].iteritems():
            slice_xtalk[pol][bl] = n.array(xt[chan])
    to_npz(outfile,meta,slice_gains,slice_vismdl,slice_xtalk)

コード例 #4
0
#Fixed coordinate calculations
healpixCoords = np.transpose(
    np.asarray(hp.pix2ang(NSIDE, np.arange(12 * NSIDE**2))))
pixelRAs = healpixCoords[:, 1]
pixelDecs = -healpixCoords[:, 0] + np.pi / 2
galCoords = SkyCoord(frame="icrs", ra=pixelRAs * u.rad,
                     dec=pixelDecs * u.rad).transform_to("galactic")

for source in sourceFiles:
    outfilename = './SimulatedVisibilities/' + source.split('/')[-1].replace(
        'zen', opts.prefix)
    if os.path.exists(outfilename) and not opts.overwrite:
        print '\n    ' + outfilename + ' exists...skipping.\n'
        continue
    omni.to_npz(
        outfilename, {}, {}, {}, {}
    )  #make the file so that other programs running simultaneously skip this one
    meta, _, _, _ = omni.from_npz(source)
    times = meta['jds']
    meta['SimulationOptions'] = opts.__dict__
    vismdl = {
        opts.pol: {
            blIndex: np.zeros((len(times), opts.nchan), dtype=complex)
            for blIndex in blIndices
        }
    }

    #Precalcualte the topocentric and AzAlt coordinates of all pixels for all times
    allPixelTops, allPixelAzAlts = [], []
    for time in times:
        aa.set_jultime(time)
コード例 #5
0
ファイル: merge_omni_npz.py プロジェクト: SaulAryehKohn/capo
a single npz file per decimal JD. This lets us use omni_apply.py
to calibrate xx,xy,yx,yy at once, even though we only used info
from the linear instrumental polarizations.

Assumes xx and yy npz files are in the same directory.
Returns 
"""
o = optparse.OptionParser()
o.set_usage('merge_omni_npz.py [options] /path/to/*xx.npz')
opts,args = o.parse_args(sys.argv[1:])

def merge_dicts(*dict_args):
    result = {}
    for dictionary in dict_args:
        result.update(dictionary)
    return result

for xx_npz in args:
    yy_npz = xx_npz.replace("xx","yy")
    new_npz = xx_npz.replace("xx.","")
    print "Reading %s %s"%(xx_npz,yy_npz)    
    metax,gainsx,vismdlx,xtalkx = omni.from_npz(xx_npz)
    metay,gainsy,vismdly,xtalky = omni.from_npz(yy_npz)    
    meta = merge_dicts(metax,metay)
    gains = merge_dicts(gainsx,gainsy)
    vismdl = merge_dicts(vismdlx,vismdly)
    xtalk = merge_dicts(xtalkx,xtalky)
    print "    => %s"%new_npz
    omni.to_npz(new_npz,meta,gains,vismdl,xtalk)

コード例 #6
0
            FWHM = 60.0 * np.pi/180.0 #* (.145 / freqs[chan])
            sigmaAngle = FWHM / (8*np.log(2))**.5
            sigmaTop = np.sin(sigmaAngle)
            pixelBeam = np.exp(-(pixelTop[0]**2+pixelTop[1]**2)/2/sigmaTop**2)
            #print pixelBeam
            #pixelBeam = 1.0

            #Loop over baselines
            for blIndex in blIndices:
                bl = np.round(aa.get_baseline(blIndex[0],blIndex[1]) * a.const.c / 1.5e12) / a.const.c * 1.5e12
                u = bl[0] * freqs[chan]
                #bl *= int(u)/u
                beamAndFringe = pixelBeam * np.exp(-2.0j*np.pi*freqs[chan] * np.dot(bl,pixelTop))
                visibility = np.sum(fluxes*beamAndFringe * freqs[chan]**spectralIndices) #* 4*np.pi / beamMap.npix() / convertJyToKFactor
                vismdl[opts.pol][blIndex][tIndex,chan] = visibility

    omni.to_npz(outfilename, meta, {}, vismdl, {})
    print '\nResults written to ' + outfilename + '\n'


#TODO: figure out the right way to store visibilities to put back into omni npz file









コード例 #7
0
ファイル: Simple_Simulate_PAPER.py プロジェクト: nkern/capo
                                                      allPixelAzAlts):
            # print '        JD = ' + str(time)
            aa.set_jultime(time)
            # pixelBeam = hp.get_interp_val(beamMap.map.map, np.pi/2-pixelAzAlt[1], pixelAzAlt[0])
            FWHM = 60.0 * np.pi / 180.0  #* (.145 / freqs[chan])
            sigmaAngle = FWHM / (8 * np.log(2))**.5
            sigmaTop = np.sin(sigmaAngle)
            pixelBeam = np.exp(-(pixelTop[0]**2 + pixelTop[1]**2) / 2 /
                               sigmaTop**2)
            #print pixelBeam
            #pixelBeam = 1.0

            #Loop over baselines
            for blIndex in blIndices:
                bl = np.round(
                    aa.get_baseline(blIndex[0], blIndex[1]) * a.const.c /
                    1.5e12) / a.const.c * 1.5e12
                u = bl[0] * freqs[chan]
                #bl *= int(u)/u
                beamAndFringe = pixelBeam * np.exp(
                    -2.0j * np.pi * freqs[chan] * np.dot(bl, pixelTop))
                visibility = np.sum(
                    fluxes * beamAndFringe * freqs[chan]**spectralIndices
                )  #* 4*np.pi / beamMap.npix() / convertJyToKFactor
                vismdl[opts.pol][blIndex][tIndex, chan] = visibility

    omni.to_npz(outfilename, meta, {}, vismdl, {})
    print '\nResults written to ' + outfilename + '\n'

#TODO: figure out the right way to store visibilities to put back into omni npz file