Пример #1
0
    def test_flag_apply(self):
        # test applying to UVData
        uv = UVData()
        uv.read_miriad(test_d_file)
        uv.flag_array = np.zeros_like(uv.flag_array, dtype=np.bool)
        uvf = UVFlag(uv, mode='flag')
        uvf.flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool)
        uvf.flag_array[:, :, 0, :] = True
        uvf2 = xrfi.flag_apply(uvf, uv, return_net_flags=True)
        nt.assert_true(np.allclose(uv.flag_array, uvf2.flag_array))

        # test applying to UVCal
        uv = UVCal()
        uv.read_calfits(test_c_file)
        uv.flag_array = np.zeros_like(uv.flag_array, dtype=np.bool)
        uvf = UVFlag(uv, mode='flag')
        uvf.flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool)
        uvf.flag_array[:, :, 0, :, :] = True
        uvf2 = xrfi.flag_apply(uvf, uv, return_net_flags=True)
        nt.assert_true(np.allclose(uv.flag_array, uvf2.flag_array))

        # test applying to waterfalls
        uv = UVData()
        uv.read_miriad(test_d_file)
        uv.flag_array = np.zeros_like(uv.flag_array, dtype=np.bool)
        uvf = UVFlag(uv, mode='flag', waterfall=True)
        uvf.flag_array[:, 0, :] = True
        xrfi.flag_apply(uvf, uv)
        nt.assert_true(np.allclose(uv.flag_array[:, :, 0, :], True))
        nt.assert_true(np.allclose(uv.flag_array[:, :, 1:, :], False))

        uv = UVCal()
        uv.read_calfits(test_c_file)
        uv.flag_array = np.zeros_like(uv.flag_array, dtype=np.bool)
        uvf = UVFlag(uv, mode='flag', waterfall=True)
        uvf.flag_array[:, 0, :] = True
        xrfi.flag_apply(uvf, uv)
        nt.assert_true(np.allclose(uv.flag_array[:, :, 0, :, :], True))
        nt.assert_true(np.allclose(uv.flag_array[:, :, 1:, :, :], False))

        # catch errors
        nt.assert_raises(ValueError, xrfi.flag_apply, uvf, 2)
        nt.assert_raises(ValueError, xrfi.flag_apply, 2, uv)
        uvf.mode = 'metric'
        nt.assert_raises(ValueError, xrfi.flag_apply, uvf, uv)
Пример #2
0
def test_clear_unused_attributes():
    uv = UVFlag(test_f_file)
    nt.assert_true(
        hasattr(uv, 'baseline_array') & hasattr(uv, 'ant_1_array')
        & hasattr(uv, 'ant_2_array'))
    uv.type = 'antenna'
    uv.clear_unused_attributes()
    nt.assert_false(
        hasattr(uv, 'baseline_array') | hasattr(uv, 'ant_1_array')
        | hasattr(uv, 'ant_2_array'))
    uv.mode = 'flag'
    nt.assert_true(hasattr(uv, 'metric_array'))
    uv.clear_unused_attributes()
    nt.assert_false(hasattr(uv, 'metric_array'))

    # Start over
    uv = UVFlag(test_f_file)
    uv.ant_array = np.array([4])
    uv.flag_array = np.array([5])
    uv.clear_unused_attributes()
    nt.assert_false(hasattr(uv, 'ant_array'))
    nt.assert_false(hasattr(uv, 'flag_array'))
Пример #3
0
def test_to_metric_unknown_mode():
    uvf = UVFlag(test_f_file)
    uvf.mode = 'foo'
    nt.assert_raises(ValueError, uvf.to_metric)