示例#1
0
def test_mock_diffuse_maps(model, hera_loc, apollo_loc, location):
    analytic_diffuse = pytest.importorskip('analytic_diffuse')
    pytest.importorskip('astropy_healpix')
    if location == 'earth':
        loc = hera_loc
    else:
        loc = apollo_loc
    modname, modkwargs = model
    map_nside = 128
    t0 = Time.now()
    cat, kwds = pyuvsim.simsetup.create_mock_catalog(
        t0, arrangement='diffuse', array_location=loc,
        diffuse_model=modname, map_nside=map_nside,
        diffuse_params=modkwargs
    )

    cat.update_positions(t0, loc)

    modfunc = analytic_diffuse.get_model(modname)
    alt, az = cat.alt_az
    za = np.pi / 2 - alt

    vals = modfunc(az, za, **modkwargs)

    assert cat.nside == map_nside
    assert np.allclose(cat.stokes[0].to_value("K"), vals)
示例#2
0
def test_mock_diffuse_maps_errors():
    analytic_diffuse = pyuvsim.simsetup.analytic_diffuse
    astropy_healpix = pyuvsim.simsetup.astropy_healpix
    if (analytic_diffuse is not None) and (astropy_healpix is not None):

        # Error cases:
        with pytest.raises(ValueError, match="Diffuse arrangement selected"):
            pyuvsim.simsetup.create_mock_catalog(Time.now(), arrangement='diffuse')

        with pytest.warns(UserWarning, match="No nside chosen"):
            pyuvsim.simsetup.create_mock_catalog(
                Time.now(), arrangement='diffuse', diffuse_model='monopole'
            )

    else:
        with pytest.raises(ValueError, match="analytic_diffuse and astropy_healpix"):
            pyuvsim.simsetup.create_mock_catalog(Time.now(), arrangement='diffuse')
示例#3
0
def test_mock_catalog_moon():
    # A mock catalog made with a MoonLocation.
    pytest.importorskip('lunarsky')
    import lunarsky
    from pyuvsim.astropy_interface import Time

    time = Time.now()
    loc = lunarsky.MoonLocation.from_selenodetic(24.433333333, 0.687500000)
    mmock, mkwds = pyuvsim.simsetup.create_mock_catalog(time, 'hera_text', array_location=loc)
    eloc = EarthLocation.from_geodetic(24.433, 0.6875)
    emock, ekwds = pyuvsim.simsetup.create_mock_catalog(time, 'hera_text', array_location=eloc)

    assert mkwds['world'] == 'moon'
    assert ekwds['world'] == 'earth'

    # Simple check that the given lat/lon were interpreted differently in each call.
    assert mmock != emock
示例#4
0
def test_zenith_spectral_sim(spectral_type, tmpdir):
    # Make a power law source at zenith in three ways.
    # Confirm that simulated visibilities match expectation.

    params = pyuvsim.simsetup._config_str_to_dict(
        os.path.join(SIM_DATA_PATH, 'test_config',
                     'param_1time_1src_testcat.yaml'))

    alpha = -0.5
    ref_freq = 111e6
    Nfreqs = 20
    freqs = np.linspace(110e6, 115e6, Nfreqs)
    freq_params = pyuvsim.simsetup.freq_array_to_params(freqs)
    freqs = pyuvsim.simsetup.parse_frequency_params(freq_params)['freq_array'][
        0, :]
    freqs *= units.Hz
    spectrum = (freqs.value / ref_freq)**alpha

    source, kwds = pyuvsim.create_mock_catalog(Time.now(),
                                               arrangement='zenith',
                                               Nsrcs=1)
    source.spectral_type = spectral_type
    if spectral_type == 'spectral_index':
        source.reference_frequency = np.array([ref_freq]) * units.Hz
        source.spectral_index = np.array([alpha])
    else:
        source.Nfreqs = Nfreqs
        source.freq_array = freqs
        source.stokes = np.repeat(source.stokes, Nfreqs, axis=1)
        source.stokes[0, :, 0] *= spectrum
        source.coherency_radec = stokes_to_coherency(source.stokes)

    catpath = str(tmpdir.join('spectral_test_catalog.txt'))
    source.write_text_catalog(catpath)
    params['sources'] = {"catalog": catpath}
    params['filing']['outdir'] = str(tmpdir)
    params['freq'] = freq_params
    params['time']['start_time'] = kwds['time']
    params['select'] = {'antenna_nums': [1, 2]}

    uv_out = pyuvsim.run_uvsim(params, return_uv=True)

    for ii in range(uv_out.Nbls):
        assert np.allclose(uv_out.data_array[ii, 0, :, 0], spectrum / 2)
示例#5
0
def test_skymodeldata_with_quantity_stokes(unit, cat_with_some_pols):
    # Support for upcoming pyradiosky change setting SkyModel.stokes
    # to an astropy Quantity.
    if unit == 'Jy':
        sky = cat_with_some_pols
    else:
        pytest.importorskip('analytic_diffuse')
        sky, _ = pyuvsim.simsetup.create_mock_catalog(
            Time.now(), arrangement='diffuse', diffuse_model='monopole', map_nside=16
        )
    if not isinstance(sky.stokes, units.Quantity):
        sky.stokes *= units.Unit(unit)

    smd = pyuvsim.simsetup.SkyModelData(sky)
    assert np.all(sky.stokes.to_value(unit)[0] == smd.stokes_I)
    assert smd.flux_unit == unit

    sky2 = smd.get_skymodel()
    if units.Quantity != pyradiosky.SkyModel()._stokes.expected_type:
        sky.stokes = sky.stokes.to_value(unit)
    assert sky2 == sky
示例#6
0
def fake_tasks():
    sky = pyradiosky.SkyModel('src',
                              Longitude('10d'),
                              Latitude('5d'),
                              np.array([1, 0, 0, 0]) * units.Jy,
                              'spectral_index',
                              reference_frequency=np.array([100e6]) * units.Hz,
                              spectral_index=np.array([-0.74]))
    n_tasks = 30
    t0 = Time.now()
    freq = 50 * units.Hz
    objs = [
        pyuvsim.UVTask(sky, t0, freq, None, None, freq_i=ii)
        for ii in range(n_tasks)
    ]
    for ti, task in enumerate(objs):
        task.visibility_vector = np.random.uniform(
            0, 3) + np.random.uniform(0, 3) * 1j
        task.uvdata_index = (ti, 0, 0)
        task.sources = 1  # Replace with something easier to compare later.
        objs[ti] = task

    return objs