def test_watershed_flag_errors(self): # setup uv = UVData() uv.read_miriad(test_d_file) uvm = UVFlag(uv, history='I made this') uvf = UVFlag(uv, mode='flag') uvf2 = UVFlag(uv, mode='flag', waterfall=True) # pass in objects besides UVFlag nt.assert_raises(ValueError, xrfi.watershed_flag, 1, 2) nt.assert_raises(ValueError, xrfi.watershed_flag, uvm, 2) nt.assert_raises(ValueError, xrfi.watershed_flag, uvm, uvf2) # use a bogus average_method nt.assert_raises(KeyError, xrfi.watershed_flag, uvm, uvf, avg_method='blah') # set the UVFlag object to have a bogus type uvm.type = 'blah' nt.assert_raises(ValueError, xrfi.watershed_flag, uvm, uvf)
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'))
def test_flag(self): # setup uv = UVData() uv.read_miriad(test_d_file) uvm = UVFlag(uv, history='I made this') # initialize array with specific values uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[0, 0, 0, 0] = 7. uvf = xrfi.flag(uvm, nsig_p=6.) nt.assert_true(uvf.mode == 'flag') flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[0, 0, 0, 0] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test channel flagging in baseline type uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[:, :, 0, :] = 7. uvm.metric_array[:, :, 1, :] = 3. uvf = xrfi.flag(uvm, nsig_p=6., nsig_f=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[:, :, :2, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test time flagging in baseline type uvm.metric_array = np.zeros_like(uvm.metric_array) times = np.unique(uvm.time_array) inds1 = np.where(uvm.time_array == times[0])[0] inds2 = np.where(uvm.time_array == times[1])[0] uvm.metric_array[inds1, :, :, :] = 7. uvm.metric_array[inds2, :, :, :] = 3. uvf = xrfi.flag(uvm, nsig_p=6., nsig_t=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[inds1, :, :, :] = True flag_array[inds2, :, :, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test channel flagging in antenna type uv = UVCal() uv.read_calfits(test_c_file) uvm = UVFlag(uv, history='I made this') uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[:, :, 0, :, :] = 7. uvm.metric_array[:, :, 1, :, :] = 3. uvf = xrfi.flag(uvm, nsig_p=7., nsig_f=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[:, :, :2, :, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test time flagging in antenna type uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[:, :, :, 0, :] = 7. uvm.metric_array[:, :, :, 1, :] = 3. uvf = xrfi.flag(uvm, nsig_p=6., nsig_t=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[:, :, :, :2, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test channel flagging in waterfall type uv = UVData() uv.read_miriad(test_d_file) uvm = UVFlag(uv, history='I made this', waterfall=True) uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[:, 0, :] = 7. uvm.metric_array[:, 1, :] = 3. uvf = xrfi.flag(uvm, nsig_p=6., nsig_f=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[:, :2, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # test time flagging in waterfall type uvm.metric_array = np.zeros_like(uvm.metric_array) uvm.metric_array[0, :, :] = 7. uvm.metric_array[1, :, :] = 3. uvf = xrfi.flag(uvm, nsig_p=6., nsig_t=2.) flag_array = np.zeros_like(uvf.flag_array, dtype=np.bool) flag_array[:2, :, :] = True nt.assert_true(np.allclose(uvf.flag_array, flag_array)) # catch errors nt.assert_raises(ValueError, xrfi.flag, 2) nt.assert_raises(KeyError, xrfi.flag, uvm, avg_method='blah') uvm.type = 'blah' nt.assert_raises(ValueError, xrfi.flag, uvm)