def test_read_ms_read_uvfits(): """ Test that a uvdata object instantiated from an ms file created with CASA's importuvfits is equal to a uvdata object instantiated from the original uvfits file (tests equivalence with importuvfits in uvdata). Since the histories are different, this test sets both uvdata histories to identical empty strings before comparing them. """ ms_uv = UVData() uvfits_uv = UVData() ms_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.ms") uvfits_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits") uvtest.checkWarnings(uvfits_uv.read, [uvfits_file], message="Telescope EVLA is not") ms_uv.read(ms_file) # set histories to identical blank strings since we do not expect # them to be the same anyways. ms_uv.history = "" uvfits_uv.history = "" # the objects won't be equal because uvfits adds some optional parameters # and the ms sets default antenna diameters even though the uvfits file # doesn't have them assert uvfits_uv != ms_uv # they are equal if only required parameters are checked: assert uvfits_uv.__eq__(ms_uv, check_extra=False) # set those parameters to none to check that the rest of the objects match ms_uv.antenna_diameters = None for p in uvfits_uv.extra(): fits_param = getattr(uvfits_uv, p) ms_param = getattr(ms_uv, p) if fits_param.name in UVFITS.uvfits_required_extra and ms_param.value is None: fits_param.value = None setattr(uvfits_uv, p, fits_param) # extra keywords are also different, set both to empty dicts uvfits_uv.extra_keywords = {} ms_uv.extra_keywords = {} assert uvfits_uv == ms_uv del ms_uv del uvfits_uv
def test_multi_files(casa_uvfits, axis): """ Reading multiple files at once. """ uv_full = casa_uvfits.copy() uv_multi = UVData() testfile1 = os.path.join(DATA_PATH, "multi_1.ms") testfile2 = os.path.join(DATA_PATH, "multi_2.ms") filesread = [testfile1, testfile2] # test once as list and once as an array if axis is None: filesread = np.array(filesread) uv_multi.read(filesread, axis=axis) # Casa scrambles the history parameter. Replace for now. uv_multi.history = uv_full.history # the objects won't be equal because uvfits adds some optional parameters # and the ms sets default antenna diameters even though the uvfits file # doesn't have them assert uv_multi != uv_full # they are equal if only required parameters are checked: assert uv_multi.__eq__(uv_full, check_extra=False) # set those parameters to none to check that the rest of the objects match uv_multi.antenna_diameters = None for p in uv_full.extra(): fits_param = getattr(uv_full, p) ms_param = getattr(uv_multi, p) if fits_param.name in UVFITS.uvfits_required_extra and ms_param.value is None: fits_param.value = None setattr(uv_full, p, fits_param) # extra keywords are also different, set both to empty dicts uv_full.extra_keywords = {} uv_multi.extra_keywords = {} assert uv_multi == uv_full del uv_full del uv_multi
def test_multi_files(): """ Reading multiple files at once. """ uv_full = UVData() uv_multi = UVData() uvfits_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits") uvtest.checkWarnings(uv_full.read, [uvfits_file], message="Telescope EVLA is not") testfile1 = os.path.join(DATA_PATH, "multi_1.ms") testfile2 = os.path.join(DATA_PATH, "multi_2.ms") uv_multi.read(np.array([testfile1, testfile2])) # Casa scrambles the history parameter. Replace for now. uv_multi.history = uv_full.history # the objects won't be equal because uvfits adds some optional parameters # and the ms sets default antenna diameters even though the uvfits file # doesn't have them assert uv_multi != uv_full # they are equal if only required parameters are checked: assert uv_multi.__eq__(uv_full, check_extra=False) # set those parameters to none to check that the rest of the objects match uv_multi.antenna_diameters = None for p in uv_full.extra(): fits_param = getattr(uv_full, p) ms_param = getattr(uv_multi, p) if fits_param.name in UVFITS.uvfits_required_extra and ms_param.value is None: fits_param.value = None setattr(uv_full, p, fits_param) # extra keywords are also different, set both to empty dicts uv_full.extra_keywords = {} uv_multi.extra_keywords = {} assert uv_multi == uv_full del uv_full del uv_multi
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') 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) # these are not equal because miriad_uv still retains zenith_dec and # zenith_ra, which are not present in uvfits_uv nt.assert_false(miriad_uv == uvfits_uv) # they are equal if only required parameters are checked: nt.assert_true(miriad_uv.__eq__(uvfits_uv, check_extra=False)) # remove zenith_ra and zenith_dec to test that the rest of the objects are equal miriad_uv.zenith_ra = None miriad_uv.zenith_dec = None nt.assert_equal(miriad_uv, uvfits_uv) # check error if phase_type is wrong and force_phase not set uvtest.checkWarnings(miriad_uv.read_miriad, [miriad_file], known_warning='miriad') nt.assert_raises(ValueError, miriad_uv.write_uvfits, testfile, spoof_nonessential=True) miriad_uv.set_unknown_phase_type() nt.assert_raises(ValueError, miriad_uv.write_uvfits, testfile, spoof_nonessential=True) # check error if spoof_nonessential not set uvtest.checkWarnings(miriad_uv.read_miriad, [miriad_file], known_warning='miriad') nt.assert_raises(ValueError, miriad_uv.write_uvfits, testfile, force_phase=True) # check warning when correct_lat_lon is set to False uvtest.checkWarnings(miriad_uv.read_miriad, [miriad_file], {'correct_lat_lon': False}, message=[ 'Altitude is not present in Miriad file, ' 'using known location altitude' ]) # check that setting the phase_type to something wrong errors nt.assert_raises(ValueError, uvtest.checkWarnings, miriad_uv.read_miriad, [miriad_file], {'phase_type': 'phased'}) nt.assert_raises(ValueError, uvtest.checkWarnings, miriad_uv.read_miriad, [miriad_file], {'phase_type': 'foo'}) del (miriad_uv) del (uvfits_uv)