示例#1
0
def test_to_waterfall_waterfall():
    uvf = UVFlag(test_f_file)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall()
    uvtest.checkWarnings(uvf.to_waterfall, [], {},
                         nwarnings=1,
                         message='This object is already a waterfall')
示例#2
0
def test_to_waterfall_bl_flags_or():
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall(method='or')
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.mode == 'flag')
    nt.assert_true(uvf.flag_array.shape == (len(uvf.time_array),
                                            len(uvf.freq_array),
                                            len(uvf.polarization_array)))
    nt.assert_true(
        np.array_equal(uvf.weights_array, np.ones_like(uvf.flag_array,
                                                       np.float)))
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.weights_array[0, 0, 0, 0] = 0.2
    uvtest.checkWarnings(uvf.to_waterfall, [], {'method': 'or'},
                         nwarnings=1,
                         message='Currently weights are')
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.mode == 'flag')
    nt.assert_true(uvf.flag_array.shape == (len(uvf.time_array),
                                            len(uvf.freq_array),
                                            len(uvf.polarization_array)))
    nt.assert_true(
        np.array_equal(uvf.weights_array, np.ones_like(uvf.flag_array,
                                                       np.float)))
示例#3
0
def test_copy():
    uvf = UVFlag(test_f_file)
    uvf2 = uvf.copy()
    nt.assert_true(uvf == uvf2)
    # Make sure it's a copy and not just pointing to same object
    uvf.to_waterfall()
    nt.assert_false(uvf == uvf2)
示例#4
0
def test_to_waterfall_bl():
    uvf = UVFlag(test_f_file)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall()
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.metric_array.shape == (len(uvf.time_array),
                                              len(uvf.freq_array),
                                              len(uvf.polarization_array)))
    nt.assert_true(uvf.weights_array.shape == uvf.metric_array.shape)
示例#5
0
def test_to_waterfall_ant():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uvf = UVFlag(uvc)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall()
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.metric_array.shape == (len(uvf.time_array),
                                              len(uvf.freq_array),
                                              len(uvf.polarization_array)))
    nt.assert_true(uvf.weights_array.shape == uvf.metric_array.shape)
示例#6
0
def test_to_antenna_metric():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uvf = UVFlag(uvc)
    uvf.to_waterfall()
    uvf.metric_array[0, 10, 0] = 3.2  # Fill in time0, chan10
    uvf.metric_array[1, 15, 0] = 2.1  # Fill in time1, chan15
    uvf.to_antenna(uvc)
    nt.assert_true(np.all(uvf.ant_array == uvc.ant_array))
    nt.assert_true(np.all(uvf.time_array == uvc.time_array))
    nt.assert_true(np.all(uvf.metric_array[:, 0, 10, 0, 0] == 3.2))
    nt.assert_true(np.all(uvf.metric_array[:, 0, 15, 1, 0] == 2.1))
    nt.assert_true(
        np.isclose(uvf.metric_array.mean(),
                   (3.2 + 2.1) * uvc.Nants_data / uvf.metric_array.size))
示例#7
0
def test_to_antenna_flags():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uvf = UVFlag(uvc)
    uvf.to_waterfall()
    uvf.to_flag()
    uvf.flag_array[0, 10, 0] = True  # Flag time0, chan10
    uvf.flag_array[1, 15, 0] = True  # Flag time1, chan15
    uvf.to_antenna(uvc)
    nt.assert_true(np.all(uvf.ant_array == uvc.ant_array))
    nt.assert_true(np.all(uvf.time_array == uvc.time_array))
    nt.assert_true(np.all(uvf.flag_array[:, 0, 10, 0, 0]))
    nt.assert_true(np.all(uvf.flag_array[:, 0, 15, 1, 0]))
    nt.assert_true(uvf.flag_array.mean() == 2. * uvc.Nants_data /
                   uvf.flag_array.size)
示例#8
0
def test_to_antenna_errors():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uv = UVData()
    uv.read_miriad(test_d_file)
    uvf = UVFlag(test_f_file)
    uvf.to_waterfall()
    nt.assert_raises(ValueError, uvf.to_antenna,
                     7.3)  # invalid matching object
    uvf = UVFlag(uv)
    nt.assert_raises(ValueError, uvf.to_antenna,
                     uvc)  # Cannot pass in baseline type
    uvf = UVFlag(test_f_file)
    uvf.to_waterfall()
    uvf.polarization_array[0] = -4
    nt.assert_raises(ValueError, uvf.to_antenna, uvc)  # Mismatched pols
示例#9
0
def test_to_antenna_metric_force_pol():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uvc.select(jones=-5)
    uvf = UVFlag(uvc)
    uvf.to_waterfall()
    uvf.metric_array[0, 10, 0] = 3.2  # Fill in time0, chan10
    uvf.metric_array[1, 15, 0] = 2.1  # Fill in time1, chan15
    uvf.polarization_array[0] = -4
    uvf.to_antenna(uvc, force_pol=True)
    nt.assert_true(np.all(uvf.ant_array == uvc.ant_array))
    nt.assert_true(np.all(uvf.time_array == uvc.time_array))
    nt.assert_true(np.array_equal(uvf.polarization_array, uvc.jones_array))
    nt.assert_true(np.all(uvf.metric_array[:, 0, 10, 0, 0] == 3.2))
    nt.assert_true(np.all(uvf.metric_array[:, 0, 15, 1, 0] == 2.1))
    nt.assert_true(
        np.isclose(uvf.metric_array.mean(),
                   (3.2 + 2.1) * uvc.Nants_data / uvf.metric_array.size))
示例#10
0
def test_to_antenna_force_pol():
    uvc = UVCal()
    uvc.read_calfits(test_c_file)
    uvc.select(jones=-5)
    uvf = UVFlag(uvc)
    uvf.to_waterfall()
    uvf.to_flag()
    uvf.flag_array[0, 10, 0] = True  # Flag time0, chan10
    uvf.flag_array[1, 15, 0] = True  # Flag time1, chan15
    uvf.polarization_array[0] = -4  # Change pol, but force pol anyway
    uvf.to_antenna(uvc, force_pol=True)
    nt.assert_true(np.all(uvf.ant_array == uvc.ant_array))
    nt.assert_true(np.all(uvf.time_array == uvc.time_array))
    nt.assert_true(np.array_equal(uvf.polarization_array, uvc.jones_array))
    nt.assert_true(np.all(uvf.flag_array[:, 0, 10, 0, 0]))
    nt.assert_true(np.all(uvf.flag_array[:, 0, 15, 1, 0]))
    nt.assert_true(uvf.flag_array.mean() == 2 * uvc.Nants_data /
                   uvf.flag_array.size)
示例#11
0
def test_to_baseline_metric():
    uv = UVData()
    uv.read_miriad(test_d_file)
    uvf = UVFlag(uv)
    uvf.to_waterfall()
    uvf.metric_array[0, 10, 0] = 3.2  # Fill in time0, chan10
    uvf.metric_array[1, 15, 0] = 2.1  # Fill in time1, chan15
    uvf.to_baseline(uv)
    nt.assert_true(np.all(uvf.baseline_array == uv.baseline_array))
    nt.assert_true(np.all(uvf.time_array == uv.time_array))
    times = np.unique(uvf.time_array)
    ind = np.where(uvf.time_array == times[0])[0]
    nt0 = len(ind)
    nt.assert_true(np.all(uvf.metric_array[ind, 0, 10, 0] == 3.2))
    ind = np.where(uvf.time_array == times[1])[0]
    nt1 = len(ind)
    nt.assert_true(np.all(uvf.metric_array[ind, 0, 15, 0] == 2.1))
    nt.assert_true(
        np.isclose(uvf.metric_array.mean(),
                   (3.2 * nt0 + 2.1 * nt1) / uvf.metric_array.size))
示例#12
0
def test_to_baseline_flags():
    uv = UVData()
    uv.read_miriad(test_d_file)
    uvf = UVFlag(uv)
    uvf.to_waterfall()
    uvf.to_flag()
    uvf.flag_array[0, 10, 0] = True  # Flag time0, chan10
    uvf.flag_array[1, 15, 0] = True  # Flag time1, chan15
    uvf.to_baseline(uv)
    nt.assert_true(np.all(uvf.baseline_array == uv.baseline_array))
    nt.assert_true(np.all(uvf.time_array == uv.time_array))
    times = np.unique(uvf.time_array)
    ntrue = 0.0
    ind = np.where(uvf.time_array == times[0])[0]
    ntrue += len(ind)
    nt.assert_true(np.all(uvf.flag_array[ind, 0, 10, 0]))
    ind = np.where(uvf.time_array == times[1])[0]
    ntrue += len(ind)
    nt.assert_true(np.all(uvf.flag_array[ind, 0, 15, 0]))
    nt.assert_true(uvf.flag_array.mean() == ntrue / uvf.flag_array.size)
示例#13
0
def test_to_baseline_force_pol():
    uv = UVData()
    uv.read_miriad(test_d_file)
    uvf = UVFlag(uv)
    uvf.to_waterfall()
    uvf.to_flag()
    uvf.flag_array[0, 10, 0] = True  # Flag time0, chan10
    uvf.flag_array[1, 15, 0] = True  # Flag time1, chan15
    uvf.polarization_array[0] = -4  # Change pol, but force pol anyway
    uvf.to_baseline(uv, force_pol=True)
    nt.assert_true(np.all(uvf.baseline_array == uv.baseline_array))
    nt.assert_true(np.all(uvf.time_array == uv.time_array))
    nt.assert_true(
        np.array_equal(uvf.polarization_array, uv.polarization_array))
    times = np.unique(uvf.time_array)
    ntrue = 0.0
    ind = np.where(uvf.time_array == times[0])[0]
    ntrue += len(ind)
    nt.assert_true(np.all(uvf.flag_array[ind, 0, 10, 0]))
    ind = np.where(uvf.time_array == times[1])[0]
    ntrue += len(ind)
    nt.assert_true(np.all(uvf.flag_array[ind, 0, 15, 0]))
    nt.assert_true(uvf.flag_array.mean() == ntrue / uvf.flag_array.size)
示例#14
0
def test_to_waterfall_bl_multi_pol():
    uvf = UVFlag(test_f_file)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf2 = uvf.copy()
    uvf2.polarization_array[0] = -4
    uvf.__add__(uvf2, inplace=True,
                axis='pol')  # Concatenate to form multi-pol object
    uvf2 = uvf.copy()  # Keep a copy to run with keep_pol=False
    uvf.to_waterfall()
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.metric_array.shape == (len(uvf.time_array),
                                              len(uvf.freq_array),
                                              len(uvf.polarization_array)))
    nt.assert_true(uvf.weights_array.shape == uvf.metric_array.shape)
    nt.assert_true(len(uvf.polarization_array) == 2)
    # Repeat with keep_pol=False
    uvf2.to_waterfall(keep_pol=False)
    nt.assert_true(uvf2.type == 'waterfall')
    nt.assert_true(uvf2.metric_array.shape == (len(uvf2.time_array),
                                               len(uvf.freq_array), 1))
    nt.assert_true(uvf2.weights_array.shape == uvf2.metric_array.shape)
    nt.assert_true(len(uvf2.polarization_array) == 1)
    nt.assert_true(uvf2.polarization_array[0] == ','.join(
        map(str, uvf.polarization_array)))
示例#15
0
def test_antpair2ind_nonbaseline():
    uvf = UVFlag(test_f_file)
    uvf.to_waterfall()
    nt.assert_raises(ValueError, uvf.antpair2ind, 0, 3)
示例#16
0
 def test_uvflag_waterfall_error(self):
     uvf = UVFlag(test_f_file)
     uvf.to_waterfall()
     uvf.to_flag()
     nt.assert_raises(ValueError, xrfi.flag_xants, uvf, 0)