Exemplo n.º 1
0
def test_run_paramdict_uvsim():
    # Running a simulation from parameter dictionary.

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

    pyuvsim.run_uvsim(params, return_uv=True)
Exemplo n.º 2
0
def test_run_gleam_uvsim(spectral_type):
    params = pyuvsim.simsetup._config_str_to_dict(
        os.path.join(SIM_DATA_PATH, 'test_config',
                     'param_1time_1src_testgleam.yaml'))
    params["sources"]["spectral_type"] = spectral_type
    params["sources"].pop("min_flux")
    params["sources"].pop("max_flux")

    pyuvsim.run_uvsim(params, return_uv=True)
Exemplo n.º 3
0
def test_run_uvsim():
    hera_uv = UVData()
    hera_uv.read_uvfits(EW_uvfits_file)

    beam = UVBeam()
    beam.read_cst_beam(beam_files,
                       beam_type='efield',
                       frequency=[100e6, 123e6],
                       telescope_name='HERA',
                       feed_name='PAPER',
                       feed_version='0.1',
                       feed_pol=['x'],
                       model_name='E-field pattern - Rigging height 4.9m',
                       model_version='1.0')

    beam_list = [beam]
    mock_keywords = {"Nsrcs": 3}
    uv_out = pyuvsim.run_uvsim(hera_uv,
                               beam_list,
                               catalog_file=None,
                               mock_keywords=mock_keywords,
                               uvdata_file=EW_uvfits_file)
    if rank == 0:
        nt.assert_true(
            np.allclose(uv_out.data_array, hera_uv.data_array, atol=5e-3))
Exemplo n.º 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)
Exemplo n.º 5
0
def test_analytic_diffuse(model, tmpdir):
    # Generate the given model and simulate for a few baselines.
    # Import from analytic_diffuse  (consider moving to rasg_affiliates?)
    pytest.importorskip('analytic_diffuse')
    pytest.importorskip('astropy_healpix')
    import analytic_diffuse

    modname = model
    use_w = False
    params = {}
    if model == 'quaddome':
        modname = 'polydome'
        params['n'] = 2
    elif model == 'monopole-nonflat':
        modname = 'monopole'
        use_w = True
        params[
            'order'] = 30  # Expansion order for the non-flat monopole solution.

    # Making configuration files for this simulation.
    template_path = os.path.join(SIM_DATA_PATH, 'test_config',
                                 'obsparam_diffuse_sky.yaml')
    obspar_path = str(tmpdir.join('obsparam_diffuse_sky.yaml'))
    layout_path = str(tmpdir.join('threeant_layout.csv'))
    herauniform_path = str(tmpdir.join('hera_uniform.yaml'))

    teleconfig = {
        'beam_paths': {
            0: 'uniform'
        },
        'telescope_location': "(-30.72153, 21.42830, 1073.0)",
        'telescope_name': 'HERA'
    }
    if not use_w:
        antpos_enu = np.array([[0, 0, 0], [0, 3, 0], [5, 0, 0]], dtype=float)
    else:
        antpos_enu = np.array([[0, 0, 0], [0, 3, 0], [0, 3, 5]], dtype=float)

    pyuvsim.simsetup._write_layout_csv(layout_path, antpos_enu,
                                       np.arange(3).astype(str), np.arange(3))
    with open(herauniform_path, 'w') as ofile:
        yaml.dump(teleconfig, ofile, default_flow_style=False)

    with open(template_path, 'r') as yfile:
        obspar = yaml.safe_load(yfile)
    obspar['telescope']['array_layout'] = layout_path
    obspar['telescope']['telescope_config_name'] = herauniform_path
    obspar['sources']['diffuse_model'] = modname
    obspar['sources'].update(params)
    obspar['filing']['outfile_name'] = 'diffuse_sim.uvh5'
    obspar['filing']['output_format'] = 'uvh5'
    obspar['filing']['outdir'] = str(tmpdir)

    with open(obspar_path, 'w') as ofile:
        yaml.dump(obspar, ofile, default_flow_style=False)

    uv_out = pyuvsim.run_uvsim(obspar_path, return_uv=True)
    # Convert from Jy to K sr
    dat = uv_out.data_array[:, 0, 0, 0] * jy_to_ksr(uv_out.freq_array[0,
                                                                      0]).value
    # Evaluate the solution and compare to visibilities.
    soln = analytic_diffuse.get_solution(modname)
    uvw_lam = uv_out.uvw_array * uv_out.freq_array[0, 0] / c_ms
    ana = soln(uvw_lam, **params)
    assert np.allclose(ana / 2, dat, atol=1e-2)