예제 #1
0
def test_phase_delay():
    from africanus.rime import phase_delay

    uvw = np.random.random(size=(100, 3))
    lm = np.random.random(size=(10, 2))
    frequency = np.linspace(.856e9, .856e9 * 2, 64, endpoint=True)

    from africanus.constants import minus_two_pi_over_c

    # Test complex phase at a particular index in the output
    uvw_i, lm_i, freq_i = 2, 3, 5

    u, v, w = [1, 2, 3]
    l, m = [0.1, 0.2]
    freq = 0.856e9

    # Set up values in the input
    uvw[uvw_i] = [u, v, w]
    lm[lm_i] = [l, m]
    frequency[freq_i] = freq

    # Compute complex phase
    complex_phase = phase_delay(uvw, lm, frequency)

    # Test singular value vs a point in the output
    n = np.sqrt(1.0 - l**2 - m**2) - 1.0
    phase = minus_two_pi_over_c * (u * l + v * m + w * n) * freq
    assert np.all(np.exp(1j * phase) == complex_phase[lm_i, uvw_i, freq_i])
def test_wsclean_predict(chunks):
    row = sum(chunks['rows'])
    src = sum(chunks['source'])
    chan = sum(chunks['channels'])

    rs = np.random.RandomState(42)
    source_sel = rs.randint(0, 2, src).astype(np.bool)
    source_type = np.where(source_sel, "POINT", "GAUSSIAN")

    gauss_shape = rs.normal(size=(src, 3))
    uvw = rs.normal(size=(row, 3))
    lm = rs.normal(size=(src, 2)) * 1e-5
    flux = rs.normal(size=src)
    coeffs = rs.normal(size=(src, 2))
    log_poly = rs.randint(0, 2, src, dtype=np.bool)
    flux[log_poly] = np.abs(flux[log_poly])
    coeffs[log_poly] = np.abs(coeffs[log_poly])
    freq = np.linspace(.856e9, 2 * .856e9, chan)
    ref_freq = np.full(src, freq[freq.shape[0] // 2])

    # WSClean visibilities
    vis = wsclean_predict(uvw, lm, source_type, flux, coeffs, log_poly,
                          ref_freq, gauss_shape, freq)

    # Compute it another way. Note the CASA coordinate convention
    # used by wsclean
    phase = phase_delay(lm, uvw, freq, convention='casa')
    spectrum = spectra(flux, coeffs, log_poly, ref_freq, freq)
    shape = gaussian(uvw, freq, gauss_shape)
    # point sources don't' contribute to the shape
    shape[source_sel] = 1.0
    np_vis = np.einsum("srf,srf,sf->rf", shape, phase, spectrum)[:, :, None]

    assert_almost_equal(np_vis, vis)