class TestBaselineAntnumMethods(object): """Setup for tests on antnum, baseline conversion.""" def setup(self): self.uv_object = UVData() self.uv_object.Nants_telescope = 128 self.uv_object2 = UVData() self.uv_object2.Nants_telescope = 2049 def teardown(self): """Test teardown: delete objects.""" del(self.uv_object) del(self.uv_object2) def test_baseline_to_antnums(self): """Test baseline to antnum conversion for 256 & larger conventions.""" nt.assert_equal(self.uv_object.baseline_to_antnums(67585), (0, 0)) nt.assert_raises(StandardError, self.uv_object2.baseline_to_antnums, 67585) def test_antnums_to_baselines(self): """Test antums to baseline conversion for 256 & larger conventions.""" nt.assert_equal(self.uv_object.antnums_to_baseline(0, 0), 67585) nt.assert_equal(self.uv_object.antnums_to_baseline(257, 256), 592130) # Check attempt256 nt.assert_equal(self.uv_object.antnums_to_baseline(0, 0, attempt256=True), 257) nt.assert_equal(self.uv_object.antnums_to_baseline(257, 256), 592130) nt.assert_true(uvtest.checkWarnings(self.uv_object.antnums_to_baseline, [257, 256], {'attempt256': True}, message='found > 256 antennas')) nt.assert_raises(StandardError, self.uv_object2.antnums_to_baseline, 0, 0)
def test_writePAPER(): """Test reading & writing PAPER Miriad file.""" UV = UVData() testfile = os.path.join(DATA_PATH, 'zen.2456865.60537.xy.uvcRREAA') write_file = os.path.join(DATA_PATH, 'test/outtest_miriad.uv') status = uvtest.checkWarnings(UV.read_miriad, [testfile], known_warning='miriad') UV.write_miriad(write_file, clobber=True) nt.assert_true(status) del(UV)
def setUp(self): """Setup for tests of basic methods.""" self.uv_object = UVData() self.testfile = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') uvtest.checkWarnings(self.uv_object.read_uvfits, [self.testfile], message='Telescope EVLA is not') self.uv_object2 = copy.deepcopy(self.uv_object)
class TestUVDataBasicMethods(object): def setUp(self): """Setup for tests of basic methods.""" self.uv_object = UVData() self.testfile = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') uvtest.checkWarnings(self.uv_object.read_uvfits, [self.testfile], message='Telescope EVLA is not') self.uv_object2 = copy.deepcopy(self.uv_object) def teardown(self): """Test teardown: delete objects.""" del(self.uv_object) del(self.uv_object2) def test_equality(self): """Basic equality test.""" nt.assert_equal(self.uv_object, self.uv_object) def test_check(self): """Test simple check function.""" nt.assert_true(self.uv_object.check()) def test_nants_data_telescope(self): self.uv_object.Nants_data = self.uv_object.Nants_telescope - 1 nt.assert_true(self.uv_object.check) self.uv_object.Nants_data = self.uv_object.Nants_telescope + 1 nt.assert_raises(ValueError, self.uv_object.check)
def test_ReadFHD_model(): """FHD to uvfits loopback test with model visibilities.""" fhd_uv = UVData() uvfits_uv = UVData() fhd_uv.read_fhd(testfiles, use_model=True) fhd_uv.write_uvfits(os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296_model.uvfits'), spoof_nonessential=True) uvfits_uv.read_uvfits(os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296_model.uvfits')) nt.assert_equal(fhd_uv, uvfits_uv) del(fhd_uv) del(uvfits_uv)
def test_phase_unphaseHERA(): """ Read in drift data, phase to an RA/DEC, unphase and check for object equality. """ testfile = os.path.join(DATA_PATH, 'hera_testfile') UV_raw = UVData() # Note the RA/DEC values in the raw file were calculated from the lat/long # in the file, which don't agree with our known_telescopes. # So for this test we use the lat/lon in the file. status = uvtest.checkWarnings(UV_raw.read_miriad, [testfile], {'correct_lat_lon': False}, known_warning='miriad') UV_phase = UVData() status = uvtest.checkWarnings(UV_phase.read_miriad, [testfile], {'correct_lat_lon': False}, known_warning='miriad') UV_phase.phase(0., 0., ephem.J2000) UV_phase.unphase_to_drift() nt.assert_equal(UV_raw, UV_phase) del(UV_phase) del(UV_raw)
def test_ReadUVFitsWriteMiriad(): """ read uvfits, write miriad test. Read in uvfits file, write out as miriad, read back in and check for object equality. """ uvfits_uv = UVData() miriad_uv = UVData() uvfits_file = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') testfile = os.path.join(DATA_PATH, 'test/outtest_miriad') read_status = uvtest.checkWarnings(uvfits_uv.read_uvfits, [uvfits_file], message='Telescope EVLA is not') uvfits_uv.write_miriad(testfile, clobber=True) miriad_read_status = uvtest.checkWarnings(miriad_uv.read_miriad, [testfile], message='Telescope EVLA is not') nt.assert_true(read_status) nt.assert_true(miriad_read_status) nt.assert_equal(miriad_uv, uvfits_uv) del(uvfits_uv) del(miriad_uv)
def test_readwriteread(): """ CASA tutorial uvfits loopback test. Read in uvfits file, write out new uvfits file, read back in and check for object equality. """ uv_in = UVData() uv_out = UVData() testfile = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') write_file = os.path.join(DATA_PATH, 'test/outtest_casa.uvfits') read_status = uvtest.checkWarnings(uv_in.read_uvfits, [testfile], message='Telescope EVLA is not') uv_in.write_uvfits(write_file) write_status = uvtest.checkWarnings(uv_out.read_uvfits, [write_file], message='Telescope EVLA is not') nt.assert_true(read_status) nt.assert_true(write_status) nt.assert_equal(uv_in, uv_out) del(uv_in) del(uv_out)
def test_ReadFHDWriteReadUVFits(): """ FHD to uvfits loopback test. Read in FHD files, write out as uvfits, read back in and check for object equality. """ fhd_uv = UVData() uvfits_uv = UVData() fhd_uv.read_fhd(testfiles) fhd_uv.write_uvfits(os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits'), spoof_nonessential=True) uvfits_uv.read_uvfits(os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits')) nt.assert_equal(fhd_uv, uvfits_uv) del(fhd_uv) del(uvfits_uv)
def setUp(self): """Setup for basic parameter, property and iterator tests.""" self.required_parameters = ['_data_array', '_nsample_array', '_flag_array', '_Ntimes', '_Nbls', '_Nblts', '_Nfreqs', '_Npols', '_Nspws', '_uvw_array', '_time_array', '_ant_1_array', '_ant_2_array', '_lst_array', '_baseline_array', '_freq_array', '_polarization_array', '_spw_array', '_integration_time', '_channel_width', '_object_name', '_telescope_name', '_instrument', '_telescope_location', '_history', '_vis_units', '_Nants_data', '_Nants_telescope', '_antenna_names', '_antenna_numbers', '_phase_type'] self.required_properties = ['data_array', 'nsample_array', 'flag_array', 'Ntimes', 'Nbls', 'Nblts', 'Nfreqs', 'Npols', 'Nspws', 'uvw_array', 'time_array', 'ant_1_array', 'ant_2_array', 'lst_array', 'baseline_array', 'freq_array', 'polarization_array', 'spw_array', 'integration_time', 'channel_width', 'object_name', 'telescope_name', 'instrument', 'telescope_location', 'history', 'vis_units', 'Nants_data', 'Nants_telescope', 'antenna_names', 'antenna_numbers', 'phase_type'] self.extra_parameters = ['_extra_keywords', '_antenna_positions', '_gst0', '_rdate', '_earth_omega', '_dut1', '_timesys', '_uvplane_reference_time', '_phase_center_ra', '_phase_center_dec', '_phase_center_epoch', '_zenith_ra', '_zenith_dec'] self.extra_properties = ['extra_keywords', 'antenna_positions', 'gst0', 'rdate', 'earth_omega', 'dut1', 'timesys', 'uvplane_reference_time', 'phase_center_ra', 'phase_center_dec', 'phase_center_epoch', 'zenith_ra', 'zenith_dec'] self.other_properties = ['telescope_location_lat_lon_alt', 'telescope_location_lat_lon_alt_degrees', 'phase_center_ra_degrees', 'phase_center_dec_degrees', 'zenith_ra_degrees', 'zenith_dec_degrees'] self.uv_object = UVData()
def test_readWriteReadMiriad(): """ PAPER file Miriad loopback test. Read in Miriad PAPER file, write out as new Miriad file, read back in and check for object equality. """ uv_in = UVData() uv_out = UVData() testfile = os.path.join(DATA_PATH, 'zen.2456865.60537.xy.uvcRREAA') write_file = os.path.join(DATA_PATH, 'test/outtest_miriad.uv') status = uvtest.checkWarnings(uv_in.read_miriad, [testfile], known_warning='miriad') uv_in.write_miriad(write_file, clobber=True) uv_out.read_miriad(write_file) nt.assert_true(status) nt.assert_equal(uv_in, uv_out) del(uv_in) del(uv_out)
def test_ReadMiriadWriteUVFits(): """ Miriad to uvfits loopback test. Read in Miriad files, write out as uvfits, read back in and check for object equality. """ miriad_uv = UVData() uvfits_uv = UVData() miriad_file = os.path.join(DATA_PATH, 'zen.2456865.60537.xy.uvcRREAA') testfile = os.path.join(DATA_PATH, 'test/outtest_miriad.uvfits') miriad_status = uvtest.checkWarnings(miriad_uv.read_miriad, [miriad_file], known_warning='miriad') miriad_uv.write_uvfits(testfile, spoof_nonessential=True, force_phase=True) uvfits_uv.read_uvfits(testfile) nt.assert_true(miriad_status) nt.assert_equal(miriad_uv, uvfits_uv) del(miriad_uv) del(uvfits_uv)
try: obs_min = args.obsid_range[0] obs_max = args.obsid_range[1] except: obs_min = min(file_dict.keys()) obs_max = max(file_dict.keys()) for k in file_dict.keys(): if k > obs_max or k < obs_min: file_dict.pop(k) for i, (k, v) in enumerate(file_dict.iteritems()): if args.dirty: print('converting dirty vis for obsid {}, ({} of {})'.format(k, i, len(file_dict))) uvfits_file = op.join(output_folder, str(k) + '.uvfits') this_uv = UVData() this_uv.read_fhd(v) this_uv.write_uvfits(uvfits_file, spoof_nonessential=True) del(this_uv) if args.model: print('converting model vis for obsid {}, ({} of {})'.format(k, i, len(file_dict))) uvfits_file = op.join(output_folder, str(k) + '_model.uvfits') this_uv = UVData() this_uv.read_fhd(v, use_model=True) this_uv.write_uvfits(uvfits_file, spoof_nonessential=True) del(this_uv)
#! /usr/bin/env python import argparse import os.path as op from uvdata import UVData parser = argparse.ArgumentParser() parser.add_argument('uvfits_read', help='name of a uvfits file to read in') parser.add_argument('uvfits_write', help='name of a uvfits file to write out') args = parser.parse_args() uvfits_file_in = args.uvfits_read if not op.isfile(uvfits_file_in): raise IOError('There is no file named {}'.format(args.uvfits_file_in)) uvfits_file_out = args.uvfits_write this_uv = UVData() this_uv.read_uvfits(uvfits_file_in) this_uv.write_uvfits(uvfits_file_out) del(this_uv)
""" Format the UVData object parameters into a sphinx rst file. """ from uvdata import UVData import numpy as np from astropy.time import Time UV = UVData() out = 'Parameters\n==============\n' out += ("These are the standard attributes of UVData objects.\n\nUnder the hood " "they are actually properties based on UVParameter objects.\n\nAngle type " "attributes also have convenience properties named the same thing \nwith " "'_degrees' appended through which you can get or set the value in " "degrees.\n\nSimilarly location type attributes (which are given in " "topocentric xyz coordinates) \nhave convenience properties named the " "same thing with '_lat_lon_alt' and \n'_lat_lon_alt_degrees' appended " "through which you can get or set the values using \nlatitude, longitude and " "altitude values in radians or degrees and meters.\n\n") out += 'Required\n----------------\n' out += ('These parameters are required to have a sensible UVData object and \n' 'are required for most kinds of uv data files.') out += "\n\n" for thing in UV.required(): obj = getattr(UV, thing) out += '**{name}**\n'.format(name=obj.name) out += ' {desc}\n'.format(desc=obj.description) out += "\n" out += 'Optional\n----------------\n' out += ('These parameters are defined by one or more file standard but are not '
def test_known_telescopes(): """Test known_telescopes method returns expected results.""" uv_object = UVData() known_telescopes = ['PAPER', 'HERA', 'MWA'] nt.assert_equal(known_telescopes.sort(), uv_object.known_telescopes().sort())
def setup(self): self.uv_object = UVData() self.uv_object.Nants_telescope = 128 self.uv_object2 = UVData() self.uv_object2.Nants_telescope = 2049
class TestUVDataInit(object): def setUp(self): """Setup for basic parameter, property and iterator tests.""" self.required_parameters = ['_data_array', '_nsample_array', '_flag_array', '_Ntimes', '_Nbls', '_Nblts', '_Nfreqs', '_Npols', '_Nspws', '_uvw_array', '_time_array', '_ant_1_array', '_ant_2_array', '_lst_array', '_baseline_array', '_freq_array', '_polarization_array', '_spw_array', '_integration_time', '_channel_width', '_object_name', '_telescope_name', '_instrument', '_telescope_location', '_history', '_vis_units', '_Nants_data', '_Nants_telescope', '_antenna_names', '_antenna_numbers', '_phase_type'] self.required_properties = ['data_array', 'nsample_array', 'flag_array', 'Ntimes', 'Nbls', 'Nblts', 'Nfreqs', 'Npols', 'Nspws', 'uvw_array', 'time_array', 'ant_1_array', 'ant_2_array', 'lst_array', 'baseline_array', 'freq_array', 'polarization_array', 'spw_array', 'integration_time', 'channel_width', 'object_name', 'telescope_name', 'instrument', 'telescope_location', 'history', 'vis_units', 'Nants_data', 'Nants_telescope', 'antenna_names', 'antenna_numbers', 'phase_type'] self.extra_parameters = ['_extra_keywords', '_antenna_positions', '_gst0', '_rdate', '_earth_omega', '_dut1', '_timesys', '_uvplane_reference_time', '_phase_center_ra', '_phase_center_dec', '_phase_center_epoch', '_zenith_ra', '_zenith_dec'] self.extra_properties = ['extra_keywords', 'antenna_positions', 'gst0', 'rdate', 'earth_omega', 'dut1', 'timesys', 'uvplane_reference_time', 'phase_center_ra', 'phase_center_dec', 'phase_center_epoch', 'zenith_ra', 'zenith_dec'] self.other_properties = ['telescope_location_lat_lon_alt', 'telescope_location_lat_lon_alt_degrees', 'phase_center_ra_degrees', 'phase_center_dec_degrees', 'zenith_ra_degrees', 'zenith_dec_degrees'] self.uv_object = UVData() def teardown(self): """Test teardown: delete object.""" del(self.uv_object) def test_parameter_iter(self): "Test expected parameters." all = [] for prop in self.uv_object: all.append(prop) for a in self.required_parameters + self.extra_parameters: nt.assert_true(a in all, msg='expected attribute ' + a + ' not returned in object iterator') def test_required_parameter_iter(self): "Test expected required parameters." required = [] for prop in self.uv_object.required(): required.append(prop) for a in self.required_parameters: nt.assert_true(a in required, msg='expected attribute ' + a + ' not returned in required iterator') def test_extra_parameter_iter(self): "Test expected optional parameters." extra = [] for prop in self.uv_object.extra(): extra.append(prop) for a in self.extra_parameters: nt.assert_true(a in extra, msg='expected attribute ' + a + ' not returned in extra iterator') def test_unexpected_attributes(self): "Test for extra attributes." expected_attributes = self.required_properties + \ self.extra_properties + self.other_properties attributes = [i for i in self.uv_object.__dict__.keys() if i[0] != '_'] for a in attributes: nt.assert_true(a in expected_attributes, msg='unexpected attribute ' + a + ' found in UVData') def test_properties(self): "Test that properties can be get and set properly." prop_dict = dict(zip(self.required_properties + self.extra_properties, self.required_parameters + self.extra_parameters)) for k, v in prop_dict.iteritems(): rand_num = np.random.rand() setattr(self.uv_object, k, rand_num) this_param = getattr(self.uv_object, v) try: nt.assert_equal(rand_num, this_param.value) except: print('setting {prop_name} to a random number failed'.format(prop_name=k)) raise(AssertionError)