Esempio n. 1
0
def test_offzenith_vis():
    # Construct a shell with a single point source a known position off from zenith.
    #   Similar to test_vis_calc, but set the pointing center 5deg off from the zenith and adjust analytic calculation

    freqs = [1.0e8]
    Nfreqs = 1
    fov = 60
    ant1_enu = np.array([10.0, 0, 0])
    ant2_enu = np.array([0.0, 140.6, 0])

    bl = observatory.Baseline(ant1_enu, ant2_enu)

    # Set pointing center to ra/dec = 0/0
    center = [0, 0]

    # Make a shell and place a 1 Jy/pix point source at ra/dec of 5/0
    Nside = 128
    Npix = Nside**2 * 12
    shell = np.zeros((Npix, Nfreqs))
    pix_area = 4 * np.pi / float(Npix)
    ind = hp.ang2pix(Nside, 5, 0.0, lonlat=True)
    shell[ind] = 1  # Jy/pix
    shell[ind] *= utils.jy2Tsr(freqs[0], bm=pix_area)  # K

    obs = observatory.Observatory(0, 0, array=[bl], freqs=freqs)
    obs.pointing_centers = [center]
    obs.times_jd = np.array([1])
    obs.set_fov(fov)
    obs.set_beam("uniform")

    sky = sky_model.SkyModel(Nside=Nside, freqs=np.array(freqs), data=shell)

    vis_calc, times, bls = obs.make_visibilities(sky)

    ra_deg, dec_deg = hp.pix2ang(Nside, ind, lonlat=True)

    src_az = np.radians(90.0)
    src_za = np.radians(ra_deg)

    src_l = np.sin(src_az) * np.sin(src_za)
    src_m = np.cos(src_az) * np.sin(src_za)
    src_n = np.cos(src_za)
    u, v, w = bl.get_uvw(freqs[0])

    vis_analytic = (1) * np.exp(2j * np.pi *
                                (u * src_l + v * src_m + w * src_n))

    print(vis_analytic)
    print(vis_calc)
    print(vis_calc[0, 0, 0] - vis_analytic)
    vis_calc = vis_calc[0, 0, 0]
    assert np.isclose(vis_calc.real, vis_analytic.real)
    assert np.isclose(vis_calc.imag, vis_analytic.imag)
Esempio n. 2
0
def test_vis_calc():
    """Construct a shell with a single point source at the zenith.

    Confirm against analytic calculation.
    """

    ant1_enu = np.array([0, 0, 0])
    ant2_enu = np.array([0.0, 14.6, 0])

    bl = observatory.Baseline(ant1_enu, ant2_enu)

    freqs = np.array([1e8])
    nfreqs = 1

    fov = 20  # Deg

    # Longitude/Latitude in degrees.

    nside = 32
    ind = 10
    center = list(hp.pix2ang(nside, ind, lonlat=True))
    centers = [center]
    npix = nside**2 * 12
    shell = np.zeros((npix, nfreqs))
    pix_area = 4 * np.pi / float(npix)
    shell[ind] = 1  # Jy/pix
    shell[ind] *= utils.jy2Tsr(freqs[0], bm=pix_area)  # K

    obs = observatory.Observatory(latitude, longitude, array=[bl], freqs=freqs)
    obs.pointing_centers = centers
    obs.times_jd = np.array([1])
    obs.set_fov(fov)
    obs.set_beam("uniform")

    sky = sky_model.SkyModel(Nside=nside,
                             freqs=freqs,
                             data=shell[np.newaxis, :, :])

    visibs, times, bls = obs.make_visibilities(sky)
    assert np.isclose(np.real(visibs),
                      1.0).all()  # Unit point source at zenith
Esempio n. 3
0
        raise ValueError("Input npz file needed.")
    f = np.load(args.infile)
    uvw = f['uvws']
    uvw = uvw[sel]
elif args.visfile is not None and args.infile is not None:
    raise ValueError("Cannot do both npz and uv input files at once.")
else:
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')
        uv.read(args.visfile)
        print("Using visibility file {}".format(args.visfile))
        uv.select(times=uv.time_array[0])  # Select first time only.
        dat = uv.data_array[:, 0, :, 0]
        lam = c_ms / uv.freq_array[0]

        dat_Tsr = dat * jy2Tsr(uv.freq_array[0], bm=1.0)
        uvw = np.repeat(uv.uvw_array[:, :, None], uv.Nfreqs, axis=2)
        uvw = np.swapaxes((uvw / lam), 1, 2)
        uvw = uvw.reshape((uv.Nbls * uv.Nfreqs, 3))
        dat_Tsr = dat_Tsr.flatten()
        uvw = uvw[sel]
        dat_Tsr = dat_Tsr[sel]
        if args.model is None:
            model, params = andiff.solutions.parse_filename(
                os.path.basename(args.visfile))
            args.model = model
            for k, v in params.items():
                if (hasattr(args, k)) and (getattr(args, k) is None):
                    setattr(args, k, v)
        outdict['dat_Tsr'] = dat_Tsr
Esempio n. 4
0
def test_pspec_amp():
    # Construct a flat-spectrum shell, simulate visibilities,
    #  confirm power spectrum amplitude.

    ant1_enu = np.array([0, 0, 0])
    ant2_enu = np.array([0.0, 14.6, 0])

    bl = observatory.Baseline(ant1_enu, ant2_enu)

    Ntimes = 20
    Nfreqs = 200
    freqs = np.linspace(100e6, 150e6, Nfreqs)

    fov = 50  # Deg

    # Longitude/Latitude in degrees.

    nside = 64

    obs = observatory.Observatory(latitude, longitude, array=[bl], freqs=freqs)
    t0 = Time("J2000").jd
    obs.times_jd = np.linspace(t0, t0 + 0.5, Ntimes)  # Half a day
    obs.set_pointings(obs.times_jd)

    obs.set_fov(fov)
    obs.set_beam("gaussian", gauss_width=7.37)

    skysig = 0.031

    sky = sky_model.SkyModel(Nside=nside, freqs=freqs, ref_chan=Nfreqs // 2)
    sky.make_flat_spectrum_shell(skysig, shared_memory=True)

    visibs, times, bls = obs.make_visibilities(sky, Nprocs=3)

    vis_jy = visibs[:, 0, :]  # (Nblts, Nskies, Nfreqs)
    vis_Ksr = utils.jy2Tsr(freqs) * vis_jy

    _vis = np.fft.ifft(vis_Ksr, axis=1)
    Nkpar = Nfreqs // 2
    _vis = _vis[:, :Nkpar]  # Keeping only positive k_par modes

    dspec_instr = np.abs(_vis)**2

    beam_sq_int = np.mean(
        obs.beam_sq_int(freqs, nside, obs.pointing_centers[0]))

    Bandwidth = freqs[-1] - freqs[0]
    scalar = cosmology.X2Y(
        sky.Z_array[sky.ref_chan]) * (Bandwidth / beam_sq_int)

    dspec_I = np.mean(dspec_instr * scalar, axis=0)

    # Theoretical pspec amp
    dnu = np.diff(freqs)[0]
    Z_sel = sky.Z_array[sky.ref_chan]
    amp_theor = skysig**2 * cosmology.comoving_voxel_volume(
        Z_sel, dnu, sky.pix_area_sr)

    tolerance = amp_theor / float(Ntimes)  # assuming independent fields
    print(amp_theor, np.mean(dspec_I))
    print(tolerance)
    assert np.isclose(amp_theor, np.mean(dspec_I), atol=2 *
                      tolerance)  # Close to within twice the sample variance