def check_param_reader(config_num): """ tests initialize_uvdata_from_params """ param_filename = param_filenames[config_num] hera_uv = UVData() hera_uv.read_uvfits(triangle_uvfits_file) time = Time(hera_uv.time_array[0], scale='utc', format='jd') sources = np.array([create_zenith_source(time, 'zensrc')]) beam0 = UVBeam() beam0.read_beamfits(herabeam_default) beam1 = pyuvsim.AnalyticBeam('tophat') beam2 = pyuvsim.AnalyticBeam('gaussian', sigma=0.02) beam_list = [beam0, beam1, beam2] beam_dict = {'ANT1': 0, 'ANT2': 1, 'ANT3': 2} expected_uvtask_list = pyuvsim.uvdata_to_task_list(hera_uv, sources, beam_list, beam_dict=beam_dict) # Check default configuration uv_obj, new_beam_list, new_beam_dict, beam_ids = pyuvsim.initialize_uvdata_from_params( param_filename) uvtask_list = pyuvsim.uvdata_to_task_list(uv_obj, sources, new_beam_list, beam_dict=new_beam_dict) # Tasks are not ordered in UVTask lists, so need to sort them. # This is enabled by the comparison operator in UVTask uvtask_list = sorted(uvtask_list) expected_uvtask_list = sorted(expected_uvtask_list) for ti in xrange(len(expected_uvtask_list)): print uvtask_list[ti].baseline.antenna1.beam_id, expected_uvtask_list[ ti].baseline.antenna1.beam_id print uvtask_list[ti].baseline.antenna2.beam_id, expected_uvtask_list[ ti].baseline.antenna2.beam_id print uvtask_list[ti].baseline.antenna1.number, expected_uvtask_list[ ti].baseline.antenna1.number print uvtask_list[ti].baseline.antenna2.number, expected_uvtask_list[ ti].baseline.antenna2.number print uvtask_list[ti].baseline.antenna1.name, expected_uvtask_list[ ti].baseline.antenna1.name print uvtask_list[ti].baseline.antenna2.name, expected_uvtask_list[ ti].baseline.antenna2.name print uvtask_list[ti].freq - expected_uvtask_list[ti].freq print uvtask_list[ti].time - expected_uvtask_list[ti].time print uvtask_list[ti].uvdata_index, expected_uvtask_list[ ti].uvdata_index print '\n' nt.assert_true(uvtask_list == expected_uvtask_list)
def test_comparison(): """ Beam __eq__ method """ beam1 = pyuvsim.AnalyticBeam('uniform') beam2 = pyuvsim.AnalyticBeam('gaussian', sigma=0.02) beam2.type = 'undefined' not_beam = UVData() assert beam1 != not_beam assert beam2 != beam1
def test_achromatic_gaussian_beam(heratext_posfreq): sigma_rad = Angle('5d').to_value('rad') beam = pyuvsim.AnalyticBeam('gaussian', sigma=sigma_rad) beam.peak_normalize() beam.interpolation_function = 'az_za_simple' az_vals, za_vals, freq_vals = heratext_posfreq nsrcs = az_vals.size n_freqs = freq_vals.size interpolated_beam, interp_basis_vector = beam.interp( az_array=np.array(az_vals), za_array=np.array(za_vals), freq_array=np.array(freq_vals)) expected_data = np.zeros((2, 1, 2, n_freqs, nsrcs), dtype=np.float) interp_zas = np.zeros((n_freqs, nsrcs), dtype=np.float) for f_ind in range(n_freqs): interp_zas[f_ind, :] = np.array(za_vals) gaussian_vals = np.exp(-(interp_zas**2) / (2 * sigma_rad**2)) expected_data[1, 0, 0, :, :] = gaussian_vals expected_data[0, 0, 1, :, :] = gaussian_vals assert np.allclose(interpolated_beam, expected_data)
def test_diameter_to_sigma(): # The integrals of an Airy power beam and a Gaussian power beam, within # the first Airy null, should be close if the Gaussian width is set to the Airy width. diameter_m = 25.0 abm = pyuvsim.AnalyticBeam('airy', diameter=diameter_m) gbm = pyuvsim.AnalyticBeam('gaussian', diameter=diameter_m) Nfreqs = 20 freq_vals = np.linspace(100e6, 130e6, Nfreqs) lams = c_ms / freq_vals N = 250 Npix = 501 zmax = np.radians(40) # Degrees zas = np.linspace(-zmax, zmax, Npix) azs = np.array([0.0] * (N + 1) + [np.pi] * N) shape = ( 2, 1, 2, Nfreqs, ) + azs.shape airy_vals, interp_basis_vector = abm.interp(az_array=azs.flatten(), za_array=zas.flatten(), freq_array=freq_vals) gauss_vals, interp_basis_vector = gbm.interp(az_array=azs.flatten(), za_array=zas.flatten(), freq_array=freq_vals) airy_vals = airy_vals.reshape(shape) gauss_vals = gauss_vals.reshape(shape) airy_vals = airy_vals[0, 0, 0] * airy_vals[0, 0, 1] gauss_vals = gauss_vals[0, 0, 0] * gauss_vals[ 0, 0, 1] # Remove pol/spw/feed axes. Make power beam. for fi in range(Nfreqs): null = 1.22 * lams[fi] / diameter_m inds = np.where(np.abs(zas) < null) # Assert integral of power beams within the first Airy null are close assert np.isclose(np.sum(airy_vals[fi, inds]), np.sum(gauss_vals[fi, inds]), rtol=1e-2)
def test_power_analytic_beam(): # Check that power beam evaluation matches electric field amp**2 for analytic beams. freqs = np.arange(120e6, 160e6, 4e6) Npix = 1000 diam = 14.0 az = np.zeros(Npix) za = np.linspace(0, np.pi / 2., Npix) for b in ['gaussian', 'uniform', 'airy']: eb = pyuvsim.AnalyticBeam(b, diameter=diam) pb = pyuvsim.AnalyticBeam(b, diameter=diam) pb.efield_to_power() evals = eb.interp(az, za, freqs)[0][0, 0, 1] pvals = pb.interp(az, za, freqs)[0][0, 0, 0] assert np.allclose(evals**2, pvals) # Ensure uniform beam works pb = pyuvsim.AnalyticBeam('uniform') pb.efield_to_power() pb.interp(az, za, freqs)
def test_gaussbeam_values(): """ Make the long-line point sources up to 10 degrees from zenith. Obtain visibilities Confirm that the values match the expected beam values at those zenith angles. """ sigma = 0.05 hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) array_location = EarthLocation.from_geocentric( hera_uv.telescope_location[0], hera_uv.telescope_location[1], hera_uv.telescope_location[2], unit='m') freq = hera_uv.freq_array[0, 0] * units.Hz time = Time(hera_uv.time_array[0], scale='utc', format='jd') catalog, mock_keywords = pyuvsim.create_mock_catalog( time=time, arrangement='long-line', Nsrcs=41, max_za=10., array_location=array_location) beam = pyuvsim.AnalyticBeam('gaussian', sigma=sigma) array = pyuvsim.Telescope('telescope_name', array_location, [beam]) # Need a dummy baseline for this test. antenna1 = pyuvsim.Antenna('ant1', 1, np.array([0, 0, 0]), 0) antenna2 = pyuvsim.Antenna('ant2', 2, np.array([107, 0, 0]), 0) baseline = pyuvsim.Baseline(antenna1, antenna2) coherencies = [] zenith_angles = [] for src in catalog: task = pyuvsim.UVTask(src, time, freq, baseline, array) engine = pyuvsim.UVEngine(task) engine.apply_beam() # task.source.az_za_calc(time, array_location) zenith_angles.append(task.source.az_za[1]) # In radians. coherencies.append( np.real(engine.apparent_coherency[0, 0]).astype( float)) # All four components should be identical coherencies = np.array(coherencies) zenith_angles = np.array(zenith_angles) # Confirm the coherency values (ie., brightnesses) match the beam values. beam_values = np.exp(-(zenith_angles)**2 / (2 * beam.sigma**2)) nt.assert_true(np.all(beam_values**2 == coherencies))
def test_gaussbeam_values(): """ Make the long-line point sources up to 10 degrees from zenith. Confirm that the coherencies match the expected beam values at those zenith angles. """ sigma = 0.05 hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) array_location = EarthLocation.from_geocentric(*hera_uv.telescope_location, unit='m') freq = hera_uv.freq_array[0, 0] * units.Hz time = Time(hera_uv.time_array[0], scale='utc', format='jd') catalog, mock_keywords = pyuvsim.create_mock_catalog( time=time, arrangement='long-line', Nsrcs=41, min_alt=80., array_location=array_location) catalog.update_positions(time, array_location) beam = pyuvsim.AnalyticBeam('gaussian', sigma=sigma) array = pyuvsim.Telescope('telescope_name', array_location, [beam]) # Need a dummy baseline for this test. antenna1 = pyuvsim.Antenna('ant1', 1, np.array([0, 0, 0]), 0) antenna2 = pyuvsim.Antenna('ant2', 2, np.array([107, 0, 0]), 0) baseline = pyuvsim.Baseline(antenna1, antenna2) task = pyuvsim.UVTask(catalog, time, freq, baseline, array) engine = pyuvsim.UVEngine(task) engine.apply_beam() altitudes = task.sources.alt_az[0] # In radians. # All four components should be identical if isinstance(engine.apparent_coherency, units.Quantity): coherency_use = engine.apparent_coherency.to_value("Jy") else: coherency_use = engine.apparent_coherency coherencies = np.real(coherency_use[0, 0] + coherency_use[1, 1]).astype(float) zenith_angles, _ = simutils.altaz_to_zenithangle_azimuth( altitudes, np.zeros_like(np.array(altitudes))) # Confirm the coherency values (ie., brightnesses) match the beam values. beam_values = np.exp(-(zenith_angles)**2 / (2 * beam.sigma**2)) assert np.all(beam_values**2 == coherencies)
def test_beamerrs(): """ Error cases. """ with pytest.raises(ValueError, match='type not recognized'): pyuvsim.AnalyticBeam('unsupported_type') beam = pyuvsim.AnalyticBeam('gaussian') az, za = np.random.uniform(0.0, np.pi, (2, 5)) freq_arr = np.linspace(1e8, 1.5e8, 10) with pytest.raises(ValueError, match='Dish diameter needed for gaussian beam'): beam.interp(az, za, freq_arr) beam.type = 'airy' with pytest.raises(ValueError, match='Dish diameter needed for airy beam'): beam.interp(az, za, freq_arr) beam.type = 'noninterpolable' with pytest.raises(ValueError, match='no interp for this type: noninterpolable'): beam.interp(az, za, freq_arr)
def beam_objs(): uvb = UVBeam() uvb.read_beamfits(herabeam_default) uvb.extra_keywords['beam_path'] = herabeam_default uvb2 = UVBeam() uvb2.read_beamfits(herabeam_default) uvb2.extra_keywords['beam_path'] = herabeam_default beams = [uvb, uvb2] beams.append(pyuvsim.AnalyticBeam('uniform')) diameter_m = 14. beams.append(pyuvsim.AnalyticBeam('airy', diameter=diameter_m)) sigma = 0.03 beams.append(pyuvsim.AnalyticBeam('gaussian', sigma=sigma)) ref_freq, alpha = 100e6, -0.5 beams.append( pyuvsim.AnalyticBeam('gaussian', sigma=sigma, ref_freq=ref_freq, spectral_index=alpha)) return beams
def test_gaussian_beam(): sigma_rad = Angle('5d').to('rad').value beam = pyuvsim.AnalyticBeam('gaussian', sigma=sigma_rad) beam.peak_normalize() beam.interpolation_function = 'az_za_simple' time = Time('2018-03-01 00:00:00', scale='utc') array_location = EarthLocation(lat='-30d43m17.5s', lon='21d25m41.9s', height=1073.) source_list, mock_keywords = pyuvsim.create_mock_catalog( time, 'hera_text', array_location=array_location) nsrcs = len(source_list) az_vals = [] za_vals = [] freq_vals = [] for src in source_list: src_coord = SkyCoord(ra=src.ra, dec=src.dec, frame='icrs', obstime=time, location=array_location) src_coord_altaz = src_coord.transform_to('altaz') az_vals.append(src_coord_altaz.az.to('rad').value) za_vals.append((Angle('90d') - src_coord_altaz.alt).to('rad').value) if len(freq_vals) > 0: if src.freq.to('Hz').value != freq_vals[0]: freq_vals.append(src.freq.to('Hz').value) else: freq_vals.append(src.freq.to('Hz').value) n_freqs = len(freq_vals) interpolated_beam, interp_basis_vector = beam.interp( az_array=np.array(az_vals), za_array=np.array(za_vals), freq_array=np.array(freq_vals)) expected_data = np.zeros((2, 1, 2, n_freqs, nsrcs), dtype=np.float) interp_zas = np.zeros((n_freqs, nsrcs), dtype=np.float) for f_ind in range(n_freqs): interp_zas[f_ind, :] = np.array(za_vals) gaussian_vals = np.exp(-(interp_zas**2) / (2 * sigma_rad**2)) expected_data[1, 0, 0, :, :] = gaussian_vals expected_data[0, 0, 1, :, :] = gaussian_vals expected_data[1, 0, 1, :, :] = gaussian_vals expected_data[0, 0, 0, :, :] = gaussian_vals nt.assert_true(np.allclose(interpolated_beam, expected_data))
def test_chromatic_gaussian(): """ test_chromatic_gaussian Defining a gaussian beam with a spectral index and reference frequency. Check that beam width follows prescribed power law. """ freqs = np.arange(120e6, 160e6, 4e6) Nfreqs = len(freqs) Npix = 1000 alpha = -1.5 sigma = np.radians(15.0) az = np.zeros(Npix) za = np.linspace(0, np.pi / 2., Npix) # Error if trying to define chromatic beam without a reference frequency with pytest.raises( ValueError, match= 'ref_freq must be set for nonzero gaussian beam spectral index'): pyuvsim.AnalyticBeam('gaussian', sigma=sigma, spectral_index=alpha) A = pyuvsim.AnalyticBeam('gaussian', sigma=sigma, ref_freq=freqs[0], spectral_index=alpha) # Get the widths at each frequency. vals, _ = A.interp(az, za, freqs) vals = vals[0, 0, 1] for fi in range(Nfreqs): hwhm = za[np.argmin(np.abs(vals[fi] - 0.5))] sig_f = sigma * (freqs[fi] / freqs[0])**alpha assert np.isclose(sig_f, 2 * hwhm / 2.355, atol=1e-3)
def test_uniform_beam(heratext_posfreq): beam = pyuvsim.AnalyticBeam('uniform') beam.peak_normalize() beam.interpolation_function = 'az_za_simple' az_vals, za_vals, freqs = heratext_posfreq nsrcs = az_vals.size n_freqs = freqs.size interpolated_beam, interp_basis_vector = beam.interp(az_array=az_vals, za_array=za_vals, freq_array=freqs) expected_data = np.zeros((2, 1, 2, n_freqs, nsrcs), dtype=np.float) expected_data[1, 0, 0, :, :] = 1 expected_data[0, 0, 1, :, :] = 1 assert np.allclose(interpolated_beam, expected_data)
def test_uv_beam_widths(): # Check that the width of the Airy disk beam in UV space corresponds with the dish diameter. diameter_m = 25.0 beam = pyuvsim.AnalyticBeam('airy', diameter=diameter_m) beam.peak_normalize() beam.interpolation_function = 'az_za_simple' Nfreqs = 20 freq_vals = np.linspace(100e6, 130e6, Nfreqs) lams = c_ms / freq_vals N = 250 Npix = 500 zmax = np.radians(90) # Degrees arr = np.arange(-N, N) x, y = np.meshgrid(arr, arr) r = np.sqrt(x**2 + y**2) / float(N) zas = r * zmax azs = np.arctan2(y, x) interpolated_beam, interp_basis_vector = beam.interp( az_array=np.array(azs), za_array=np.array(zas), freq_array=np.array(freq_vals)) ebeam = interpolated_beam[0, 0, 1, :, :] ebeam = ebeam.reshape(Nfreqs, Npix, Npix) beam_kern = np.fft.fft2(ebeam, axes=(1, 2)) beam_kern = np.fft.fftshift(beam_kern, axes=(1, 2)) for i, bk in enumerate(beam_kern): # Cutoff at half a % of the maximum value in Fourier space. thresh = np.max(np.abs(bk)) * 0.005 points = np.sum(np.abs(bk) >= thresh) upix = 1 / (2 * np.sin(zmax) ) # 2*sin(zmax) = fov extent projected onto the xy plane area = np.sum(points) * upix**2 kern_radius = np.sqrt(area / np.pi) assert np.isclose(diameter_m / lams[i], kern_radius, rtol=0.5)
def test_airy_beam_values(heratext_posfreq): diameter_m = 14. beam = pyuvsim.AnalyticBeam('airy', diameter=diameter_m) beam.peak_normalize() beam.interpolation_function = 'az_za_simple' az_vals, za_vals, freq_vals = heratext_posfreq interpolated_beam, interp_basis_vector = beam.interp(az_array=az_vals, za_array=za_vals, freq_array=freq_vals) expected_data = np.zeros((2, 1, 2, 1, az_vals.size), dtype=np.float) za_grid, f_grid = np.meshgrid(za_vals, freq_vals) xvals = diameter_m / 2. * np.sin(za_grid) * 2. * np.pi * f_grid / c_ms airy_values = np.zeros_like(xvals) nz = xvals != 0. ze = xvals == 0. airy_values[nz] = 2. * j1(xvals[nz]) / xvals[nz] airy_values[ze] = 1. expected_data[1, 0, 0, :, :] = airy_values expected_data[0, 0, 1, :, :] = airy_values assert np.allclose(interpolated_beam, expected_data)
def test_offzenith_source_multibl_uvfits(): """Test single off-zenith source using test uvdata file. Calculate visibilities for a baseline triangle. """ hera_uv = UVData() hera_uv.read_uvfits( longbl_uvfits_file, ant_str='cross' ) # consists of a right triangle of baselines with w term hera_uv.unphase_to_drift() src_az = Angle('90.0d') src_alt = Angle('85.0d') src_za = Angle('90.0d') - src_alt src_l = np.sin(src_az.rad) * np.sin(src_za.rad) src_m = np.cos(src_az.rad) * np.sin(src_za.rad) src_n = np.cos(src_za.rad) time = Time(hera_uv.time_array[0], scale='utc', format='jd') array_location = EarthLocation.from_geocentric( hera_uv.telescope_location[0], hera_uv.telescope_location[1], hera_uv.telescope_location[2], unit='m') freq = hera_uv.freq_array[0, 0] * units.Hz # get antennas positions into ENU antpos, ants = hera_uv.get_ENU_antpos() antenna1 = pyuvsim.Antenna('ant1', ants[0], np.array(antpos[0, :]), 0) antenna2 = pyuvsim.Antenna('ant2', ants[1], np.array(antpos[1, :]), 0) antenna3 = pyuvsim.Antenna('ant3', ants[2], np.array(antpos[2, :]), 0) # setup the things that don't come from pyuvdata: # make a source off zenith time.location = array_location source = create_offzenith_source(time, 'offzensrc', az=src_az, alt=src_alt) # 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 = pyuvsim.AnalyticBeam('tophat') beam_list = [beam] baselines = [ pyuvsim.Baseline(antenna2, antenna1), pyuvsim.Baseline(antenna3, antenna1), pyuvsim.Baseline(antenna3, antenna2) ] array = pyuvsim.Telescope('telescope_name', array_location, beam_list) tasks = [pyuvsim.UVTask(source, time, freq, bl, array) for bl in baselines] visibilities = [] uvws = [] for t in tasks: engine = pyuvsim.UVEngine(t) visibilities.append(engine.make_visibility()) uvws.append(t.baseline.uvw) uvws = np.array(uvws) # analytically calculate visibilities beam.peak_normalize() beam.interpolation_function = 'az_za_simple' interpolated_beam, interp_basis_vector = beam.interp( az_array=np.array([src_az.rad]), za_array=np.array([src_za.rad]), freq_array=np.array([freq.to('Hz').value])) jones = np.zeros((2, 2), dtype=np.complex64) jones[0, 0] = interpolated_beam[1, 0, 0, 0, 0] jones[1, 1] = interpolated_beam[0, 0, 1, 0, 0] jones[1, 0] = interpolated_beam[1, 0, 1, 0, 0] jones[0, 1] = interpolated_beam[0, 0, 0, 0, 0] uvw_wavelength_array = hera_uv.uvw_array[ 0:hera_uv.Nbls] * units.m / const.c * freq.to('1/s') visibilities_analytic = [] for u, v, w in uvw_wavelength_array: vis = 0.5 * np.dot( jones, np.conj(jones).T) * np.exp(2j * np.pi * (u * src_l + v * src_m + w * src_n)) visibilities_analytic.append( np.array([vis[0, 0], vis[1, 1], vis[1, 0], vis[0, 1]])) print('pyuvsim uvws: ', np.around(uvws)) print('file uvws: ', np.around(hera_uv.uvw_array[0:hera_uv.Nbls])) print('Difference: ', uvws - hera_uv.uvw_array[0:hera_uv.Nbls]) # the file used different phasing code than the test uses -- increase the tolerance nt.assert_true( np.allclose(uvws, hera_uv.uvw_array[0:hera_uv.Nbls], atol=1e-4)) print('Analytic visibility', visibilities_analytic) print('Calculated visibility', visibilities) print(np.array(visibilities) - np.array(visibilities_analytic)) # the file used different phasing code than the test uses -- increase the tolerance nt.assert_true(np.allclose(visibilities, visibilities_analytic, atol=1e-4))
for filename in args.file_in: if rank == 0: print("Reading:", os.path.basename(filename)) input_uv = UVData() input_uv.read_uvfits(filename, read_data=False) time0 = input_uv.time_array[0] input_uv.read_uvfits(filename, freq_chans=0, times=time0) # beam = UVBeam() # beam.read_cst_beam(beam_files, beam_type='efield', frequency=[150e6], # 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 = pyuvsim.AnalyticBeam('gaussian', sigma=0.0222) beam_list = [beam] extra_keywords = { 'obs_param_file': 'uvfits_file=' + os.path.basename(filename), 'telescope_config_file': beam.type, 'antenna_location_file': os.path.basename(filename) } input_uv.extra_keywords = extra_keywords mock_keywords = {} mock_keywords['save'] = args.save_catalog mock_keywords['max_za'] = args.save_catalog mock_keywords['arrangement'] = args.mock_arrangement uvdata_out = pyuvsim.uvsim.run_uvsim(input_uv, beam_list=beam_list,
def test_param_reader(): pytest.importorskip('mpi4py') # Reading in various configuration files param_filename = os.path.join(SIM_DATA_PATH, "test_config", "param_10time_10chan_0.yaml") hera_uv = UVData() hera_uv.read_uvfits(triangle_uvfits_file) hera_uv.unphase_to_drift() hera_uv.telescope_name = 'HERA' time = Time(hera_uv.time_array[0], scale='utc', format='jd') sources, _ = pyuvsim.create_mock_catalog(time, arrangement='zenith', return_data=True) beam0 = UVBeam() beam0.read_beamfits(herabeam_default) beam0.extra_keywords['beam_path'] = herabeam_default beam1 = pyuvsim.AnalyticBeam('uniform') beam2 = pyuvsim.AnalyticBeam('gaussian', sigma=0.02) beam3 = pyuvsim.AnalyticBeam('airy', diameter=14.6) beam_list = pyuvsim.BeamList([beam0, beam1, beam2, beam3]) # To fill out other parameters in the UVBeam. beam_list.set_str_mode() beam_list.set_obj_mode() beam_dict = {'ANT1': 0, 'ANT2': 1, 'ANT3': 2, 'ANT4': 3} # Error conditions: params_bad = pyuvsim.simsetup._config_str_to_dict(param_filename) bak_params_bad = copy.deepcopy(params_bad) # Missing config file info params_bad['config_path'] = os.path.join( SIM_DATA_PATH, 'nonexistent_directory', 'nonexistent_file' ) with pytest.raises(ValueError, match="nonexistent_directory is not a directory"): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) params_bad['config_path'] = os.path.join(SIM_DATA_PATH, "test_config") params_bad['telescope']['array_layout'] = 'nonexistent_file' with pytest.raises(ValueError, match="nonexistent_file from yaml does not exist"): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) params_bad['telescope']['telescope_config_name'] = 'nonexistent_file' with pytest.raises(ValueError, match="telescope_config_name file from yaml does not exist"): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) # Missing beam keywords params_bad = copy.deepcopy(bak_params_bad) params_bad['config_path'] = os.path.join(SIM_DATA_PATH, "test_config") params_bad = copy.deepcopy(bak_params_bad) params_bad['telescope']['telescope_config_name'] = os.path.join( SIM_DATA_PATH, 'test_config', '28m_triangle_10time_10chan_gaussnoshape.yaml' ) with pytest.raises(KeyError, match="Missing shape parameter for gaussian beam"): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) params_bad['telescope']['telescope_config_name'] = os.path.join( SIM_DATA_PATH, 'test_config', '28m_triangle_10time_10chan_nodiameter.yaml' ) with pytest.raises(KeyError, match="Missing diameter for airy beam."): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) params_bad['telescope']['telescope_config_name'] = os.path.join( SIM_DATA_PATH, 'test_config', '28m_triangle_10time_10chan_nofile.yaml' ) with pytest.raises(ValueError, match="Undefined beam model"): pyuvsim.simsetup.initialize_uvdata_from_params(params_bad) # Check default configuration uv_obj, new_beam_list, new_beam_dict = pyuvsim.initialize_uvdata_from_params(param_filename) new_beam_list.set_obj_mode() pyuvsim.simsetup._complete_uvdata(uv_obj, inplace=True) with open(param_filename, 'r') as fhandle: param_dict = yaml.safe_load(fhandle) expected_ofilepath = pyuvsim.utils.write_uvdata( uv_obj, param_dict, return_filename=True, dryrun=True ) assert './sim_results.uvfits' == expected_ofilepath # Spoof attributes that won't match. uv_obj.antenna_names = uv_obj.antenna_names.tolist() uv_obj.antenna_diameters = hera_uv.antenna_diameters uv_obj.history = hera_uv.history uvfits_required_extra = [ "_antenna_positions", "_gst0", "_rdate", "_earth_omega", "_dut1", "_timesys", ] for attr in uvfits_required_extra: param = getattr(uv_obj, attr) if param.value is None: param.value = param.spoof_val setattr(uv_obj, attr, param) assert new_beam_dict == beam_dict assert new_beam_list == beam_list assert uv_obj == hera_uv