示例#1
0
def generate_sky_model_y_hybrid(baselines,del_bl,num_bl,fits_file):
    """
    y is a vector of the visibilities at different baselines
    """
    healmap = a.map.Map(fromfits=fits_file)
    px_array = n.arange(healmap.npix()) # gets an array of healpix pixel indices
    rx,ry,rz = n.array(healmap.px2crd(px_array,ncrd=3)) # finds the topocentric coords for each healpix pixel
    phi,theta = n.array(healmap.px2crd(px_array,ncrd=2)) # phi,theta in math coords
    print px_array.shape
    true_sky = healmap.map.map

    beamsig_largebm = 10/(2*n.pi*del_bl*(num_bl-1))                                                            
    beamsig_smallbm = 10/(2*n.pi*del_bl)
    amp_largebm = uf.gaussian(beamsig_largebm,n.zeros_like(theta),phi)
    amp_smallbm = uf.gaussian(beamsig_smallbm,n.zeros_like(theta),phi)

    #smallbm_inds = (int(n.floor(num_bl/2)),int(n.floor(num_bl/2)))
    smallbm_ind = int(n.floor(num_bl/2))*(num_bl+1)+1

    dOmega = 4*n.pi/px_array.shape[0]

    visibilities = n.zeros(baselines.shape[0],dtype='complex')
    print baselines.shape[0]
    for kk in range(baselines.shape[0]):
        #print kk
        bx,by,bz = baselines[kk]
        if kk==smallbm_ind: amp = amp_smallbm                                                             
        else: amp = amp_largebm
        Vis = amp*true_sky*n.exp(2j*n.pi*(bx*rx+by*ry+bz*rz))*dOmega
        visibilities[kk] = n.sum(Vis)
    return visibilities
示例#2
0
def generate_sky_model_y(baselines,beamsig,gsm_map=None,gsm_data_file=None):
    """
    y is a vector of the visibilities at different baselines
    """
    if gsm_data_file!=None:
        healmap = a.map.Map(fromfits=gsm_data_file)
    elif gsm_map==None:
        return None
    
    px_array = n.arange(healmap.npix()) # gets an array of healpix pixel indices
    rx,ry,rz = n.array(healmap.px2crd(px_array,ncrd=3)) # finds the topocentric coords for each healpix pixel
    phi,theta = n.array(healmap.px2crd(px_array,ncrd=2)) # phi,theta in math coords
    print px_array.shape
    true_sky = healmap.map.map
    amp = uf.gaussian(beamsig,n.zeros_like(theta),phi)
    dOmega = 4*n.pi/px_array.shape[0]

    visibilities = n.zeros(baselines.shape[0],dtype='complex')
    print baselines.shape[0]
    for kk in range(baselines.shape[0]):
        print kk
        bx,by,bz = baselines[kk]
        Vis = amp*true_sky*n.exp(2j*n.pi*(bx*rx+by*ry+bz*rz))*dOmega
        visibilities[kk] = n.sum(Vis)
    return visibilities
示例#3
0
def generate_sky_model_y(baselines,
                         beam_sig,
                         gsm_map=None,
                         gsm_data_file=None):
    """
    y is a vector of the visibilities at different baselines
    """
    if gsm_data_file != None:
        healmap = a.map.Map(fromfits=gsm_data_file)
    elif gsm_map != None:
        healmap = a.map.Map()
        healmap.set_map(gsm_map)
    else:
        return None

    px_array = n.arange(
        healmap.npix())  # gets an array of healpix pixel indices
    rx, ry, rz = n.array(healmap.px2crd(
        px_array,
        ncrd=3))  # finds the topocentric coords for each healpix pixel
    phi, theta = n.array(healmap.px2crd(px_array,
                                        ncrd=2))  # phi,theta in math coords
    true_sky = healmap.map.map
    amp = uf.gaussian(beam_sig, n.zeros_like(theta), phi)
    dOmega = 4 * n.pi / px_array.shape[0]

    visibilities = n.zeros(baselines.shape[0], dtype='complex')
    for kk in range(baselines.shape[0]):
        bx, by, bz = baselines[kk]
        Vis = amp * true_sky * n.exp(2j * n.pi *
                                     (bx * rx + by * ry + bz * rz)) * dOmega
        visibilities[kk] = n.sum(Vis)
    return visibilities
示例#4
0
def get_coeffs_lm_fewer_baselines(aa,baselines,l,m,freqs = n.array([.1,]),savefolderpath=None,beamsig=None):
    """
    This function calculates the coefficients in front of the lm spherical
    harmonic for the antenna array described in the calfile. The coefficients 
    are determined by the integral of A(l,m)Y(l,m)exp[-i2pi(ul+vm)]dldm.

    However, this function only loops over the baselines of the antennas with
    respect to the origin. 
    """
    im = a.img.Img(size=200, res=.5) #make an image of the sky to get sky coords
    tx,ty,tz = im.get_top(center=(200,200)) #get coords of the zenith?
    valid = n.logical_not(tx.mask)
    tx,ty,tz = tx.flatten(),ty.flatten(),tz.flatten()
    theta = n.arctan(ty/tx) # using math convention of theta=[0,2pi], phi=[0,pi]
    phi = n.arccos(n.sqrt(1-tx*tx-ty*ty))
    #n.set_printoptions(threshold='nan')
    #print theta,phi
    #quit()

    #beam response for an antenna pointing at (tx,ty,tz) with a polarization in x direction
    #amp = A(theta) in notes
    if beamsig==None:
        amp = aa[0].bm_response((tx,ty,tz),pol='x')**2
    else:
        amp = uf.gaussian(beamsig,n.zeros_like(theta),phi) 
    na = len(aa.ants) # number of antennas
    #coefficient array: rows baselines; cols frequencies
    coeffs = n.zeros([(na*na-na)/2,len(freqs)],dtype=n.complex)
    # compute normalization for spherical harmonics
    Ynorm = special.sph_harm(0,0,0,0)
    # loop through all baselines
    for jj in range(baselines.shape[0]):
        bx,by,bz = baselines[jj]
        kk=0
        for fq in freqs: #loop over frequencies
            phs = n.exp(-2j*n.pi*fq * (bx*tx+by*ty+bz*tz)) #fringe pattern
            Y = n.array(special.sph_harm(m,l,theta,phi))/Ynorm #using math convention of theta=[0,2pi], phi=[0,pi]
            Y.shape = phs.shape = amp.shape = im.uv.shape
            amp = n.where(valid, amp, 0)
            phs = n.where(valid, phs, 0)
            Y = n.where(valid, Y, 0) 
            # n.set_printoptions(threshold='nan')
            # print Y
            # quit() 
            dc_response = n.sum(amp*Y*phs)/n.sum(amp) #this integrates the amplitude * fringe pattern; units mK?
            print 'dc = ',dc_response
            jy_response = n.real(dc_response * 100 / C.pspec.jy2T(fq)) # jy2T converts flux density in jansky to temp in mK
            print '\t',fq, dc_response, jy_response
            coeffs[jj,kk] = dc_response
            kk+=1
    if savefolderpath!=None: n.savez_compressed('{0}{1}_data_l_{1}_m_{2}'.format(savefolderpath,calfile,l,m),baselines=baselines,frequencies=freqs,coeffs=coeffs)
    return baselines,freqs,coeffs
示例#5
0
# define parameters related to calculation 
maxl = 10
_,beam_sig,del_bl,num_bl,fq = sys.argv
beam_sig=float(beam_sig); del_bl=float(del_bl);num_bl=int(num_bl);fq=float(fq)

savekey = 'grid_del_bl_{0:.2f}_num_bl_{1}_beam_sig_{2:.2f}_fq_{3:.2f}'.format(del_bl,num_bl,beam_sig,fq)

im = a.img.Img(size=200, res=.5) #make an image of the sky to get sky coords
tx,ty,tz = im.get_top(center=(200,200)) #get coords of the zenith?
dOmega = get_dOmega(tx,ty)
valid = n.logical_not(tx.mask)
tx,ty,tz = tx.flatten(),ty.flatten(),tz.flatten()
theta = n.arctan(ty/tx) # using math convention of theta=[0,2pi], phi=[0,pi]
phi = n.arccos(n.sqrt(1-tx*tx-ty*ty))
amp = uf.gaussian(beam_sig,n.zeros_like(theta),phi)

baselines = agg.make_pos_array(del_bl,num_bl)

num0,num1 = len(baselines),(maxl+1)*(maxl+1)
print "num baselines = {0}\n num lms = {1}".format(num0,num1)
lms = n.zeros([num1,2])
ii=0
for ll in range(maxl+1):
	for mm in range(-ll,ll+1):
		lms[ii] = n.array([ll,mm])
		ii+=1
matrix = n.zeros([num0,num1],dtype=n.complex)
assignment_matrix = n.arange(n.prod(matrix.shape)).reshape(matrix.shape)

# define parameters related to task-mastering
示例#6
0
dOmega = 4 * n.pi / px_array.shape[0]
phi, theta = n.array(healmap.px2crd(px_array, ncrd=2))
#print 'theta max = ',max(theta)
#print 'phi max = ',max(phi)

_, del_bl, num_bl = sys.argv
del_bl = float(del_bl)
num_bl = int(num_bl)

beamsig_largebm = 10 / (2 * n.pi * del_bl * (num_bl - 1))  #1.0
beamsig_smallbm = 10 / (2 * n.pi * del_bl)  #0.25
smallbm_inds = (int(n.floor(num_bl / 2)), int(n.floor(num_bl / 2)))

savekey = 'hybrid_del_bl_{0:.2f}_num_bl_{1}'.format(del_bl, num_bl)

amp_largebm = uf.gaussian(beamsig_largebm, n.zeros_like(theta), phi)
amp_smallbm = uf.gaussian(beamsig_smallbm, n.zeros_like(theta), phi)
baselines = agg.make_pos_array(del_bl, num_bl)

# define matrix to be calculated
num = len(baselines)
matrix = n.zeros([num, num], dtype=n.complex)
# define parameters related to task-mastering
numToDo = 50  #XXX num*(num+1)/2
print 'numToDo = ', numToDo
assn_inds = []
for ii in range(num + 1):
    for jj in range(ii + 1):
        assn_inds.append((ii, jj))
num_sent = 0  # this functions both as a record of how many assignments have
# been sent and as a tag marking which matrix entry was calculated
示例#7
0
global Rdata; Rdata = healmap.map.map
global dOmega; dOmega = 4*n.pi/px_array.shape[0]
phi,theta = n.array(healmap.px2crd(px_array,ncrd=2))
#print 'theta max = ',max(theta)
#print 'phi max = ',max(phi)

_,del_bl,num_bl = sys.argv
del_bl=float(del_bl);num_bl=int(num_bl)

beamsig_largebm = 10/(2*n.pi*del_bl*(num_bl-1)) #1.0                                         
beamsig_smallbm = 10/(2*n.pi*del_bl) #0.25          
smallbm_inds = (int(n.floor(num_bl/2)),int(n.floor(num_bl/2)))

savekey = 'hybrid_del_bl_{0:.2f}_num_bl_{1}'.format(del_bl,num_bl)

amp_largebm = uf.gaussian(beamsig_largebm,n.zeros_like(theta),phi)
amp_smallbm = uf.gaussian(beamsig_smallbm,n.zeros_like(theta),phi)
baselines = agg.make_pos_array(del_bl,num_bl)

# define matrix to be calculated
num = len(baselines)
matrix = n.zeros([num,num],dtype=n.complex)
# define parameters related to task-mastering
numToDo = 50 #XXX num*(num+1)/2
print 'numToDo = ',numToDo
assn_inds = []
for ii in range(num+1):
    for jj in range(ii+1):
        assn_inds.append((ii,jj))
num_sent = 0 # this functions both as a record of how many assignments have 
             # been sent and as a tag marking which matrix entry was calculated
示例#8
0
if __name__ == '__main__':
    nside = int(sys.argv[1])
    npix = 12 * nside * nside
    inputMapFname = sys.argv[2]
    outputMapFname = sys.argv[3]
    beam_sig = 1.57 * 0.15 / 0.12 * 0.4

    beamMap = ap.map.Map(nside)
    directionVects_xyz = beamMap.map.px2crd(np.array([i for i in range(npix)]))
    directionVects_xyz = np.array(directionVects_xyz).T
    directionVects_thetas = beamMap.map.px2crd(np.array(
        [i for i in range(npix)]),
                                               ncrd=2)[0]

    primaryBeam = uf.gaussian(beam_sig, np.zeros(npix), directionVects_thetas)
    totalBeamArea = np.sum(primaryBeam)

    inputMap = ap.map.Map(fromfits=inputMapFname)
    inputASCII = inputMap.map.get_map()
    simpleAverage = np.sum(inputASCII) / npix
    inputASCII *= primaryBeam
    inputMap.map.set_map(inputASCII)
    inputMap.to_fits(outputMapFname)

    integratedMonopoleResponse = np.sum(inputASCII)
    singleDipoleExtraction = integratedMonopoleResponse / totalBeamArea

    print "simple extraction gives:", singleDipoleExtraction
    print "simple averaging gives:", simpleAverage
示例#9
0
def get_coeffs_lm_fewer_baselines(aa,
                                  baselines,
                                  l,
                                  m,
                                  freqs=n.array([
                                      .1,
                                  ]),
                                  savefolderpath=None,
                                  beamsig=None):
    """
    This function calculates the coefficients in front of the lm spherical
    harmonic for the antenna array described in the calfile. The coefficients 
    are determined by the integral of A(l,m)Y(l,m)exp[-i2pi(ul+vm)]dldm.

    However, this function only loops over the baselines of the antennas with
    respect to the origin. 
    """
    im = a.img.Img(size=200,
                   res=.5)  #make an image of the sky to get sky coords
    tx, ty, tz = im.get_top(center=(200, 200))  #get coords of the zenith?
    valid = n.logical_not(tx.mask)
    tx, ty, tz = tx.flatten(), ty.flatten(), tz.flatten()
    theta = n.arctan(ty /
                     tx)  # using math convention of theta=[0,2pi], phi=[0,pi]
    phi = n.arccos(n.sqrt(1 - tx * tx - ty * ty))
    #n.set_printoptions(threshold='nan')
    #print theta,phi
    #quit()

    #beam response for an antenna pointing at (tx,ty,tz) with a polarization in x direction
    #amp = A(theta) in notes
    if beamsig == None:
        amp = aa[0].bm_response((tx, ty, tz), pol='x')**2
    else:
        amp = uf.gaussian(beamsig, n.zeros_like(theta), phi)
    na = len(aa.ants)  # number of antennas
    #coefficient array: rows baselines; cols frequencies
    coeffs = n.zeros([(na * na - na) / 2, len(freqs)], dtype=n.complex)
    # compute normalization for spherical harmonics
    Ynorm = special.sph_harm(0, 0, 0, 0)
    # loop through all baselines
    for jj in range(baselines.shape[0]):
        bx, by, bz = baselines[jj]
        kk = 0
        for fq in freqs:  #loop over frequencies
            phs = n.exp(-2j * n.pi * fq *
                        (bx * tx + by * ty + bz * tz))  #fringe pattern
            Y = n.array(
                special.sph_harm(m, l, theta, phi)
            ) / Ynorm  #using math convention of theta=[0,2pi], phi=[0,pi]
            Y.shape = phs.shape = amp.shape = im.uv.shape
            amp = n.where(valid, amp, 0)
            phs = n.where(valid, phs, 0)
            Y = n.where(valid, Y, 0)
            # n.set_printoptions(threshold='nan')
            # print Y
            # quit()
            dc_response = n.sum(amp * Y * phs) / n.sum(
                amp
            )  #this integrates the amplitude * fringe pattern; units mK?
            print 'dc = ', dc_response
            jy_response = n.real(
                dc_response * 100 / C.pspec.jy2T(fq)
            )  # jy2T converts flux density in jansky to temp in mK
            print '\t', fq, dc_response, jy_response
            coeffs[jj, kk] = dc_response
            kk += 1
    if savefolderpath != None:
        n.savez_compressed('{0}{1}_data_l_{1}_m_{2}'.format(
            savefolderpath, calfile, l, m),
                           baselines=baselines,
                           frequencies=freqs,
                           coeffs=coeffs)
    return baselines, freqs, coeffs
示例#10
0
import basic_amp_aa_grid_gauss as agg


if __name__=='__main__': 
    nside = int(sys.argv[1])
    npix = 12 * nside * nside
    inputMapFname = sys.argv[2]
    outputMapFname = sys.argv[3]
    beam_sig = 1.57 * 0.15 / 0.12 * 0.4

    beamMap = ap.map.Map(nside)
    directionVects_xyz = beamMap.map.px2crd(np.array([i for i in range(npix)]))
    directionVects_xyz = np.array(directionVects_xyz).T
    directionVects_thetas = beamMap.map.px2crd(np.array([i for i in range(npix)]),ncrd=2)[0]

    primaryBeam = uf.gaussian(beam_sig,np.zeros(npix),directionVects_thetas)
    totalBeamArea = np.sum(primaryBeam)

    inputMap = ap.map.Map(fromfits=inputMapFname)
    inputASCII = inputMap.map.get_map()
    simpleAverage = np.sum(inputASCII) / npix
    inputASCII *= primaryBeam
    inputMap.map.set_map(inputASCII)
    inputMap.to_fits(outputMapFname)

    integratedMonopoleResponse = np.sum(inputASCII)
    singleDipoleExtraction = integratedMonopoleResponse / totalBeamArea

    print "simple extraction gives:",singleDipoleExtraction
    print "simple averaging gives:",simpleAverage