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_yaml_to_tasks(): # params = yaml.safe_load(open(longbl_yaml_file)) params = yaml.safe_load(open(laptop_size_sim)) params['config_path'] = longbl_yaml_file # not sure why I need this input_uv, beam_list, beam_ids = \ pyuvsim.simsetup.initialize_uvdata_from_params(params) time = Time('2018-03-01 00:00:00', scale='utc') HERA_location = EarthLocation(lat='-30d43m17.5s', lon='21d25m41.9s', height=1073.) catalog, mock_keywords = pyuvsim.create_mock_catalog( time, arrangement='zenith', Nsrcs=10, array_location=HERA_location) print("Size of catalog:", sys.getsizeof(catalog), " bytes with ", len(catalog), "entries") uvtask_list = pyuvsim.uvdata_to_task_list(input_uv, catalog, beam_list) uvtask_pickle = pickle.dumps(uvtask_list) print("getsizeof(uvtask_pickle) = ", sys.getsizeof(uvtask_pickle), " bytes with ", len(uvtask_list), "entries") print("len(uvtask_pickle) = ", len(uvtask_pickle))
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))
def test_gather(): hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) time = Time(hera_uv.time_array[0], scale='utc', format='jd') sources = np.array([ create_zenith_source(time, 'src1') # create_zenith_source(time, 'src2'), # create_zenith_source(time, 'src3') ]) 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] uvtask_list = pyuvsim.uvdata_to_task_list(hera_uv, sources, beam_list) uv_out = pyuvsim.initialize_uvdata(uvtask_list, 'zenith_source', uvdata_file=EW_uvfits_file) for task in uvtask_list: engine = pyuvsim.UVEngine(task) task.visibility_vector = engine.make_visibility() uv_out = pyuvsim.serial_gather(uvtask_list, uv_out) nt.assert_true( np.allclose(uv_out.data_array, hera_uv.data_array, atol=5e-3))
def test_file_to_tasks(): hera_uv = UVData() hera_uv.read_uvfits(EW_uvfits_file) 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) tel_loc = EarthLocation.from_geocentric(*hera_uv.telescope_location, unit='m') 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] telescope = pyuvsim.Telescope(hera_uv.telescope_name, tel_loc, beam_list) ant_pos = hera_uv.antenna_positions + hera_uv.telescope_location ant_pos_enu = uvutils.ENU_from_ECEF( ant_pos.T, *hera_uv.telescope_location_lat_lon_alt).T expected_task_list = [] antenna_names = hera_uv.antenna_names antennas = [] for num, antname in enumerate(antenna_names): beam_id = 0 antennas.append( pyuvsim.Antenna(antname, num, ant_pos_enu[num], beam_id)) antennas1 = [] for antnum in hera_uv.ant_1_array: index = np.where(hera_uv.antenna_numbers == antnum)[0][0] antennas1.append(antennas[index]) antennas2 = [] for antnum in hera_uv.ant_2_array: index = np.where(hera_uv.antenna_numbers == antnum)[0][0] antennas2.append(antennas[index]) for idx, antenna1 in enumerate(antennas1): antenna2 = antennas2[idx] baseline = pyuvsim.Baseline(antenna1, antenna2) task = pyuvsim.UVTask(sources[0], time.jd, hera_uv.freq_array[0, 0], baseline, telescope) task.uvdata_index = (idx, 0, 0) expected_task_list.append(task) for idx, task in enumerate(uvtask_list): exp_task = expected_task_list[idx] nt.assert_equal(task, exp_task)