def test_freq_range(mwa_beam_1ppd): beam1 = mwa_beam_1ppd beam2 = UVBeam() # include all beam2.read_mwa_beam(filename, pixels_per_deg=1, freq_range=[100e6, 200e6]) assert beam1 == beam2 beam2.read_mwa_beam(filename, pixels_per_deg=1, freq_range=[100e6, 150e6]) beam1.select(freq_chans=[0, 1]) assert beam1.history != beam2.history beam1.history = beam2.history assert beam1 == beam2 with pytest.warns(UserWarning, match="Only one available frequency in freq_range"): beam1.read_mwa_beam(filename, pixels_per_deg=1, freq_range=[100e6, 130e6]) with pytest.raises(ValueError, match="No frequencies available in freq_range"): beam2.read_mwa_beam(filename, pixels_per_deg=1, freq_range=[100e6, 110e6]) with pytest.raises(ValueError, match="freq_range must have 2 elements."): beam2.read_mwa_beam(filename, pixels_per_deg=1, freq_range=[100e6])
def test_read_cst_write_read_fits_intensity(cst_power_1freq, tmp_path): # set up power beam beam_in = cst_power_1freq beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam.fits") write_file2 = str(tmp_path / "outtest_beam2.fits") beam_in.write_beamfits(write_file, clobber=True) # now replace 'power' with 'intensity' for btype fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header primary_hdr["BTYPE"] = "Intensity" hdunames = uvutils._fits_indexhdus(fname) bandpass_hdu = fname[hdunames["BANDPARM"]] prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, bandpass_hdu]) hdulist.writeto(write_file2, overwrite=True) hdulist.close() beam_out.read_beamfits(write_file2) assert beam_in == beam_out return
def test_read_write_mwa(mwa_beam_1ppd, tmp_path): """Basic read/write test.""" beam1 = mwa_beam_1ppd beam2 = UVBeam() beam1.read_mwa_beam(filename, pixels_per_deg=1) assert beam1.pixel_coordinate_system == "az_za" assert beam1.beam_type == "efield" assert beam1.data_array.shape == (2, 1, 2, 3, 91, 360) # this is entirely empirical, just to prevent unexpected changes. # The actual values have been validated through external tests against # the mwa_pb repo. assert np.isclose(np.max(np.abs(beam1.data_array)), 0.6823676193472403) assert "x" in beam1.feed_array assert "y" in beam1.feed_array assert beam1.x_orientation == "east" outfile_name = str(tmp_path / "mwa_beam_out.fits") beam1.write_beamfits(outfile_name, clobber=True) beam2.read_beamfits(outfile_name) assert beam1 == beam2
def make_cst_beam(beam_type, nfreq): """Make the default CST testing beam.""" extra_keywords = { "software": "CST 2016", "sim_type": "E-farfield", "layout": "1 antenna", "port_num": 1, } beam = UVBeam() beam.read_cst_beam( cst_files, beam_type=beam_type, frequency=[150e6, 123e6], telescope_name="HERA", feed_name="Dipole", feed_version="1.0", feed_pol=["x"], model_name="Dipole - Rigging height 4.9 m", model_version="1.0", x_orientation="east", reference_impedance=100, history=("Derived from https://github.com/Nicolas-Fagnoni/Simulations." "\nOnly 2 files included to keep test data volume low."), extra_keywords=extra_keywords, ) return beam
def test_bad_amps(): beam1 = UVBeam() amps = np.ones([2, 8]) with pytest.raises(ValueError) as cm: beam1.read_mwa_beam(filename, pixels_per_deg=1, amplitudes=amps) assert str(cm.value).startswith("amplitudes must be shape")
def test_read_cst_write_read_fits_change_freq_units(cst_power_1freq, tmp_path): # set up power beam beam_in = cst_power_1freq beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam.fits") write_file2 = str(tmp_path / "outtest_beam2.fits") beam_in.write_beamfits(write_file, clobber=True) # now change frequency units fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header primary_hdr["CUNIT3"] = "MHz" primary_hdr["CRVAL3"] = primary_hdr["CRVAL3"] / 1e6 primary_hdr["CDELT3"] = primary_hdr["CRVAL3"] / 1e6 hdunames = uvutils._fits_indexhdus(fname) bandpass_hdu = fname[hdunames["BANDPARM"]] prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, bandpass_hdu]) hdulist.writeto(write_file2, overwrite=True) hdulist.close() beam_out.read_beamfits(write_file2) assert beam_in == beam_out return
def test_read_power(cst_power_2freq): beam2 = UVBeam() beam1 = cst_power_2freq assert beam1.pixel_coordinate_system == "az_za" assert beam1.beam_type == "power" assert beam1.data_array.shape == (1, 1, 2, 2, 181, 360) assert np.max(beam1.data_array) == 8275.5409 assert np.allclose( beam1.data_array[:, :, 0, :, :, np.where(beam1.axis1_array == 0)[0]], beam1.data_array[:, :, 1, :, :, np.where(beam1.axis1_array == np.pi / 2.0)[0]], ) # test passing in other polarization beam2.read_cst_beam( np.array(cst_files), beam_type="power", frequency=np.array([150e6, 123e6]), feed_pol="y", telescope_name="TEST", feed_name="bob", feed_version="0.1", model_name="E-field pattern - Rigging height 4.9m", model_version="1.0", ) assert np.allclose(beam1.freq_array, beam2.freq_array) assert np.allclose(beam2.polarization_array, np.array([-6, -5])) assert np.allclose( beam1.data_array[:, :, 0, :, :, :], beam2.data_array[:, :, 0, :, :, :] )
def test_casa_beam(tmp_path, hera_beam_casa): # test reading in CASA power beam. Some header items are missing... beam_in = hera_beam_casa beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam.fits") expected_extra_keywords = [ "OBSERVER", "OBSDEC", "DATAMIN", "OBJECT", "INSTRUME", "DATAMAX", "OBSRA", "ORIGIN", "DATE-MAP", "DATE", "EQUINOX", "DATE-OBS", "COMMENT", ] assert expected_extra_keywords.sort() == list( beam_in.extra_keywords.keys()).sort() beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out
def test_read_cst_write_read_fits_power(cst_power_1freq, tmp_path): # redo for power beam beam_in = cst_power_1freq beam_out = UVBeam() # add optional parameters for testing purposes beam_in.extra_keywords = {"KEY1": "test_keyword"} beam_in.x_orientation = "east" beam_in.reference_impedance = 340.0 beam_in.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.loss_array = np.random.normal(50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_in.Nspws, beam_in.Nfreqs)) write_file = str(tmp_path / "outtest_beam.fits") beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out return
def test_read_power_single_freq(cst_power_1freq): # test single frequency beam2 = UVBeam() beam1 = cst_power_1freq assert beam1.freq_array == [150e6] assert beam1.pixel_coordinate_system == "az_za" assert beam1.beam_type == "power" assert beam1.data_array.shape == (1, 1, 2, 1, 181, 360) # test single frequency and not rotating the polarization with uvtest.check_warnings(UserWarning, "No frequency provided. Detected frequency is"): beam2.read_cst_beam( cst_files[0], beam_type="power", telescope_name="TEST", feed_name="bob", feed_version="0.1", model_name="E-field pattern - Rigging height 4.9m", model_version="1.0", rotate_pol=False, ) assert beam2.freq_array == [150e6] assert beam2.pixel_coordinate_system == "az_za" assert beam2.beam_type == "power" assert beam2.polarization_array == np.array([-5]) assert beam2.data_array.shape == (1, 1, 1, 1, 181, 360) assert np.allclose(beam1.data_array[:, :, 0, :, :, :], beam2.data_array)
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))
def test_read_yaml_errors(tmp_path): pytest.importorskip("yaml") # test error if required key is not present in yaml file import yaml test_yaml_file = str(tmp_path / "test_cst_settings.yaml") with open(cst_yaml_file, "r") as file: settings_dict = yaml.safe_load(file) settings_dict.pop("telescope_name") with open(test_yaml_file, "w") as outfile: yaml.dump(settings_dict, outfile, default_flow_style=False) beam1 = UVBeam() with pytest.raises( ValueError, match=( "telescope_name is a required key in CST settings files but is " "not present." ), ): beam1.read_cst_beam(test_yaml_file, beam_type="power") os.remove(test_yaml_file)
def test_read_cst_write_read_fits_efield(cst_efield_1freq, tmp_path): beam_in = cst_efield_1freq.copy() beam_out = UVBeam() # add optional parameters for testing purposes beam_in.extra_keywords = {"KEY1": "test_keyword"} beam_in.x_orientation = "east" beam_in.reference_impedance = 340.0 beam_in.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.loss_array = np.random.normal(50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_in.Nspws, beam_in.Nfreqs)) beam_in.interpolation_function = "az_za_simple" beam_in.freq_interp_kind = "linear" write_file = str(tmp_path / "outtest_beam.fits") beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out return
def test_writeread_healpix_no_corrdsys(cst_power_1freq_cut_healpix, tmp_path): beam_in = cst_power_1freq_cut_healpix beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam.fits") write_file2 = str(tmp_path / "outtest_beam2.fits") beam_in.write_beamfits(write_file, clobber=True) # now remove coordsys but leave ctype 1 fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header primary_hdr.pop("COORDSYS") hdunames = uvutils._fits_indexhdus(fname) hpx_hdu = fname[hdunames["HPX_INDS"]] bandpass_hdu = fname[hdunames["BANDPARM"]] prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, hpx_hdu, bandpass_hdu]) hdulist.writeto(write_file2, overwrite=True) hdulist.close() beam_out.read_beamfits(write_file2) assert beam_in == beam_out return
def test_writeread_healpix_power(cst_power_1freq_cut_healpix, tmp_path): # redo for power beam beam_in = cst_power_1freq_cut_healpix beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam_hpx.fits") # add optional parameters for testing purposes beam_in.extra_keywords = {"KEY1": "test_keyword"} beam_in.x_orientation = "east" beam_in.reference_impedance = 340.0 beam_in.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.loss_array = np.random.normal(50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_in.Nspws, beam_in.Nfreqs)) # check that data_array is complex assert np.iscomplexobj(np.real_if_close(beam_in.data_array, tol=10)) beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out return
def test_basisvec_hdu_errors(cst_efield_1freq, tmp_path, header_dict, error_msg): beam_in = cst_efield_1freq beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam.fits") write_file2 = str(tmp_path / "outtest_beam2.fits") # now change values for various items in basisvec hdu to not match primary hdu beam_in.write_beamfits(write_file, clobber=True) keyword = list(header_dict.keys())[0] # hacky treatment of CDELT b/c we need the object to be defined already if keyword == "CDELT1": new_val = np.diff(beam_in.axis1_array)[0] * 2 elif keyword == "CDELT2": new_val = np.diff(beam_in.axis2_array)[0] * 2 else: new_val = header_dict[keyword] fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header hdunames = uvutils._fits_indexhdus(fname) basisvec_hdu = fname[hdunames["BASISVEC"]] basisvec_hdr = basisvec_hdu.header basisvec_data = basisvec_hdu.data bandpass_hdu = fname[hdunames["BANDPARM"]] if "NAXIS" in keyword: ax_num = keyword.split("NAXIS")[1] if ax_num != "": ax_num = int(ax_num) ax_use = len(basisvec_data.shape) - ax_num new_arrays = np.split(basisvec_data, basisvec_hdr[keyword], axis=ax_use) basisvec_data = new_arrays[0] else: basisvec_data = np.split( basisvec_data, basisvec_hdr["NAXIS1"], axis=len(basisvec_data.shape) - 1, )[0] else: basisvec_hdr[keyword] = new_val prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) basisvec_hdu = fits.ImageHDU(data=basisvec_data, header=basisvec_hdr) hdulist = fits.HDUList([prihdu, basisvec_hdu, bandpass_hdu]) hdulist.writeto(write_file2, overwrite=True) hdulist.close() with pytest.raises(ValueError, match=error_msg): beam_out.read_beamfits(write_file2) return
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_writeread_healpix(cst_efield_1freq_cut_healpix, tmp_path): beam_in = cst_efield_1freq_cut_healpix.copy() beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam_hpx.fits") beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out return
def test_healpix_basisvec_hdu_errors(cst_efield_1freq_cut_healpix, tmp_path, header_dict, error_msg): beam_in = cst_efield_1freq_cut_healpix beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam_hpx.fits") write_file2 = str(tmp_path / "outtest_beam_hpx2.fits") beam_in.write_beamfits(write_file, clobber=True) # now change values for various items in basisvec hdu to not match primary hdu keyword = list(header_dict.keys())[0] new_val = header_dict[keyword] fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header hdunames = uvutils._fits_indexhdus(fname) basisvec_hdu = fname[hdunames["BASISVEC"]] basisvec_hdr = basisvec_hdu.header basisvec_data = basisvec_hdu.data hpx_hdu = fname[hdunames["HPX_INDS"]] bandpass_hdu = fname[hdunames["BANDPARM"]] if "NAXIS" in keyword: ax_num = keyword.split("NAXIS")[1] if ax_num != "": ax_num = int(ax_num) ax_use = len(basisvec_data.shape) - ax_num new_arrays = np.split(basisvec_data, basisvec_hdr[keyword], axis=ax_use) basisvec_data = new_arrays[0] else: basisvec_data = np.split( basisvec_data, basisvec_hdr["NAXIS1"], axis=len(basisvec_data.shape) - 1, )[0] else: basisvec_hdr[keyword] = new_val prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) basisvec_hdu = fits.ImageHDU(data=basisvec_data, header=basisvec_hdr) hdulist = fits.HDUList([prihdu, basisvec_hdu, hpx_hdu, bandpass_hdu]) hdulist.writeto(write_file2, overwrite=True) hdulist.close() with pytest.raises(ValueError, match=error_msg): beam_out.read_beamfits(write_file2) return
def test_extra_keywords_complex(tmp_path, hera_beam_casa): beam_in = hera_beam_casa beam_out = UVBeam() testfile = str(tmp_path / "outtest_beam.fits") # check handling of complex-like keywords beam_in.extra_keywords["complex1"] = np.complex64(5.3 + 1.2j) beam_in.extra_keywords["complex2"] = 6.9 + 4.6j beam_in.write_beamfits(testfile, clobber=True) beam_out.read_beamfits(testfile, run_check=False) assert beam_in == beam_out return
def test_extra_keywords_float(tmp_path, hera_beam_casa): beam_in = hera_beam_casa beam_out = UVBeam() testfile = str(tmp_path / "outtest_beam.fits") # check handling of float-like keywords beam_in.extra_keywords["float1"] = np.int64(5.3) beam_in.extra_keywords["float2"] = 6.9 beam_in.write_beamfits(testfile, clobber=True) beam_out.read_beamfits(testfile, run_check=False) assert beam_in == beam_out return
def test_extra_keywords_boolean(tmp_path, hera_beam_casa): beam_in = hera_beam_casa beam_out = UVBeam() testfile = str(tmp_path / "outtest_beam.fits") # check handling of boolean keywords beam_in.extra_keywords["bool"] = True beam_in.extra_keywords["bool2"] = False beam_in.write_beamfits(testfile, clobber=True) beam_out.read_beamfits(testfile, run_check=False) assert beam_in == beam_out return
def test_writeread_healpix(cst_efield_1freq_cut_healpix, tmp_path): beam_in = cst_efield_1freq_cut_healpix.copy() beam_out = UVBeam() write_file = str(tmp_path / "outtest_beam_hpx.fits") beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out # redo for power beam del beam_in beam_in = cst_efield_1freq_cut_healpix beam_in.efield_to_power() # add optional parameters for testing purposes beam_in.extra_keywords = {"KEY1": "test_keyword"} beam_in.x_orientation = "east" beam_in.reference_impedance = 340.0 beam_in.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.loss_array = np.random.normal(50.0, 5, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_in.Nspws, beam_in.Nfreqs)) beam_in.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_in.Nspws, beam_in.Nfreqs)) # check that data_array is complex assert np.iscomplexobj(np.real_if_close(beam_in.data_array, tol=10)) beam_in.write_beamfits(write_file, clobber=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out # now remove coordsys but leave ctype 1 fname = fits.open(write_file) data = fname[0].data primary_hdr = fname[0].header primary_hdr.pop("COORDSYS") hdunames = uvutils._fits_indexhdus(fname) hpx_hdu = fname[hdunames["HPX_INDS"]] bandpass_hdu = fname[hdunames["BANDPARM"]] prihdu = fits.PrimaryHDU(data=data, header=primary_hdr) hdulist = fits.HDUList([prihdu, hpx_hdu, bandpass_hdu]) hdulist.writeto(write_file, overwrite=True) beam_out.read_beamfits(write_file) assert beam_in == beam_out
def test_single_zenith_source_uvdata(): """Test single zenith source using test uvdata file.""" hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) 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 = hera_uv.antenna_positions[0:2, :] + hera_uv.telescope_location antpos = uvutils.ENU_from_ECEF(antpos.T, *hera_uv.telescope_location_lat_lon_alt).T antenna1 = pyuvsim.Antenna('ant1', 1, np.array(antpos[0, :]), 0) antenna2 = pyuvsim.Antenna('ant2', 2, np.array(antpos[1, :]), 0) # setup the things that don't come from pyuvdata: # make a source at zenith time.location = array_location source = create_zenith_source(time, 'zensrc') 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] baseline = pyuvsim.Baseline(antenna1, antenna2) array = pyuvsim.Telescope('telescope_name', array_location, beam_list) task = pyuvsim.UVTask(source, time, freq, baseline, array) engine = pyuvsim.UVEngine(task) visibility = engine.make_visibility() nt.assert_true(np.allclose(visibility, np.array([.5, .5, 0, 0]), atol=5e-3))
def test_dead_dipoles(): beam1 = UVBeam() delays = np.zeros((2, 16), dtype="int") delays[:, 0] = 32 uvtest.checkWarnings( beam1.read_mwa_beam, func_args=[filename], func_kwargs={ "pixels_per_deg": 1, "delays": delays }, message=("There are some terminated dipoles"), ) delay_str = ("[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], " "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]") gain_str = ("[[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, " "1.0, 1.0, 1.0, 1.0, 1.0], " "[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, " "1.0, 1.0, 1.0, 1.0]]") history_str = ("Sujito et al. full embedded element beam, derived from " "https://github.com/MWATelescope/mwa_pb/" + " delays set to " + delay_str + " gains set to " + gain_str + beam1.pyuvdata_version_str) assert uvutils._check_histories(history_str, beam1.history)
def test_read_power_single_freq(cst_power_1freq): # test single frequency beam2 = UVBeam() beam1 = cst_power_1freq assert beam1.freq_array == [150e6] assert beam1.pixel_coordinate_system == "az_za" assert beam1.beam_type == "power" assert beam1.data_array.shape == (1, 1, 2, 1, 181, 360) # test single frequency and not rotating the polarization uvtest.checkWarnings( beam2.read_cst_beam, [cst_files[0]], { "beam_type": "power", "telescope_name": "TEST", "feed_name": "bob", "feed_version": "0.1", "model_name": "E-field pattern - Rigging height 4.9m", "model_version": "1.0", "rotate_pol": False, }, message="No frequency provided. Detected frequency is", ) assert beam2.freq_array == [150e6] assert beam2.pixel_coordinate_system == "az_za" assert beam2.beam_type == "power" assert beam2.polarization_array == np.array([-5]) assert beam2.data_array.shape == (1, 1, 1, 1, 181, 360) assert np.allclose(beam1.data_array[:, :, 0, :, :, :], beam2.data_array)
def test_read_yaml_override(cst_efield_2freq): pytest.importorskip("yaml") beam1 = UVBeam() beam2 = UVBeam() extra_keywords = { "software": "CST 2016", "sim_type": "E-farfield", "layout": "1 antenna", "port_num": 1, } beam1 = cst_efield_2freq beam1.telescope_name = "test" with pytest.warns( UserWarning, match=( "The telescope_name keyword is set, overriding " "the value in the settings yaml file." ), ): beam2.read_cst_beam(cst_yaml_file, beam_type="efield", telescope_name="test"), assert beam1 == beam2 assert beam2.reference_impedance == 100 assert beam2.extra_keywords == extra_keywords
def hera_beam_casa(): beam_in = UVBeam() casa_file = os.path.join(DATA_PATH, "HERABEAM.FITS") beam_in.read_beamfits(casa_file, run_check=False) # fill in missing parameters beam_in.data_normalization = "peak" beam_in.feed_name = "casa_ideal" beam_in.feed_version = "v0" beam_in.model_name = "casa_airy" beam_in.model_version = "v0" # this file is actually in an orthoslant projection RA/DEC at zenith at a # particular time. # For now pretend it's in a zenith orthoslant projection beam_in.pixel_coordinate_system = "orthoslant_zenith" return beam_in
def test_read_yaml(cst_efield_2freq): pytest.importorskip("yaml") beam1 = UVBeam() beam2 = UVBeam() extra_keywords = { "software": "CST 2016", "sim_type": "E-farfield", "layout": "1 antenna", "port_num": 1, } beam1 = cst_efield_2freq beam2.read_cst_beam(cst_yaml_file, beam_type="efield") assert beam1 == beam2 assert beam2.reference_impedance == 100 assert beam2.extra_keywords == extra_keywords
def test_uvdata_init(): hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) hera_uv.unphase_to_drift(use_ant_pos=True) time = Time(hera_uv.time_array[0], scale='utc', format='jd') sources = np.array([create_zenith_source(time, 'zensrc')]) beam = UVBeam() beam.read_cst_beam(beam_files, beam_type='efield', frequency=[150e6, 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] uvtask_list = pyuvsim.uvdata_to_task_list(hera_uv, sources, beam_list) # for task in uvtask_list: # task.time = Time(task.time, format='jd') # task.freq = task.freq * units.Hz uvdata_out = pyuvsim.initialize_uvdata(uvtask_list, 'zenith_source', uvdata_file=EW_uvfits_file) hera_uv.data_array = np.zeros_like(hera_uv.data_array, dtype=np.complex) hera_uv.flag_array = np.zeros_like(hera_uv.data_array, dtype=bool) hera_uv.nsample_array = np.ones_like(hera_uv.data_array) hera_uv.history = (pyuvsim.get_version_string() + 'Sources from source list: zenith_source. ' 'Based on UVData file: ' + EW_uvfits_file + '. Npus = 1.' + hera_uv.pyuvdata_version_str) hera_uv.instrument = hera_uv.telescope_name enu_out = uvdata_out.get_ENU_antpos() enu_in = hera_uv.get_ENU_antpos() nt.assert_equal(hera_uv._antenna_positions, uvdata_out._antenna_positions) nt.assert_true(uvdata_out.__eq__(hera_uv, check_extra=False))