Example #1
0
def test_init():

    obs = '1061313128_99bl_1pol_half_time'
    testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs)
    file_type = 'uvfits'

    ss = SS()
    ss.read(testfile, flag_choice='original', diff=True)
    # Needs to be in time order for averaging comparison to work
    ss.reorder_blts(order='time')

    ins = INS(ss)

    # Mock the averaging method
    new_shape = [ss.Ntimes, ss.Nbls, ss.Nfreqs, ss.Npols]
    test_dat = np.mean(np.abs(ss.data_array).reshape(new_shape), axis=1)

    # Mock the weights array
    test_weights = np.sum(np.logical_not(
        ss.data_array.mask).reshape(new_shape),
                          axis=1)

    # Check that the data array averaged correctly
    # Weights are floating-point, which introdices itty bitty errors compared to masked average.
    assert np.all(np.isclose(test_dat, ins.metric_array, rtol=1e-6,
                             atol=1e-7)), "Averaging did not work as intended."
    # Check that the weights summed correctly
    assert np.all(
        test_weights == ins.weights_array), "Weights did not sum properly"
Example #2
0
def test_diff():
    obs = '1061313128_99bl_1pol_half_time'
    testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs)

    ss = SS()
    uv = UVData()

    # Read in two times and two baselines of data, so that the diff is obvious.
    uv.read(testfile, read_data=False)
    times = np.unique(uv.time_array)[:2]
    bls = [(0, 1), (0, 2)]
    uv.read(testfile, times=times, bls=bls)
    uv.reorder_blts(order='baseline')

    diff_dat = uv.data_array[1::2] - uv.data_array[::2]
    diff_flags = np.logical_or(uv.flag_array[::2], uv.flag_array[1::2])
    diff_times = 0.5 * (uv.time_array[::2] + uv.time_array[1::2])
    diff_nsamples = 0.5 * (uv.nsample_array[::2] + uv.nsample_array[1::2])
    diff_ints = uv.integration_time[::2] + uv.integration_time[1::2]
    diff_uvw = 0.5 * (uv.uvw_array[::2] + uv.uvw_array[1::2])

    with pytest.warns(
            UserWarning,
            match=
            "Reordering data array to baseline order to perform differencing."
    ):
        ss.read(testfile, diff=True, times=times, bls=bls)
    ss.reorder_blts(order='baseline')

    assert np.all(ss.data_array == diff_dat), "Data values are different!"
    assert np.all(ss.flag_array == diff_flags), "Flags are different!"
    assert np.all(ss.time_array == diff_times), "Times are different!"
    assert np.all(
        ss.nsample_array == diff_nsamples), "nsample_array is different!"
    assert np.all(
        ss.integration_time == diff_ints), "Integration times are different"
    assert np.all(ss.uvw_array == diff_uvw), "uvw_arrays disagree!"
    assert np.all(ss.ant_1_array == np.array([0, 0])), "ant_1_array disagrees!"
    assert np.all(ss.ant_2_array == np.array([1, 2])), "ant_2_array disagrees!"