Commit 49e5873a authored by Philipp Arras's avatar Philipp Arras
Browse files

Add test for mask feature of wgridder

parent 33b0c107
Pipeline #81148 passed with stages
in 17 minutes and 38 seconds
......@@ -39,7 +39,7 @@ def _l2error(a, b):
def explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, xpixsize, ypixsize,
apply_w):
apply_w, mask):
speedoflight = 299792458.
x, y = np.meshgrid(*[-ss/2 + np.arange(ss) for ss in [nxdirty, nydirty]],
indexing='ij')
......@@ -55,6 +55,8 @@ def explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, xpixsize, ypixsize,
n = 1.
for row in range(ms.shape[0]):
for chan in range(ms.shape[1]):
if mask is not None and mask[row, chan] == 0:
continue
phase = (freq[chan]/speedoflight *
(x*uvw[row, 0] + y*uvw[row, 1] - uvw[row, 2]*nm1))
if wgt is None:
......@@ -74,9 +76,10 @@ def explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, xpixsize, ypixsize,
@pmp("singleprec", (True, False))
@pmp("wstacking", (True, False))
@pmp("use_wgt", (True, False))
@pmp("use_mask", (False, True))
@pmp("nthreads", (1, 2, 7))
def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
singleprec, wstacking, use_wgt, nthreads):
singleprec, wstacking, use_wgt, nthreads, use_mask):
if singleprec and epsilon < 5e-5:
pytest.skip()
rng = np.random.default_rng(42)
......@@ -87,6 +90,7 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
uvw = (rng.random((nrow, 3))-0.5)/(pixsizey*f0/speedoflight)
ms = rng.random((nrow, nchan))-0.5 + 1j*(rng.random((nrow, nchan))-0.5)
wgt = rng.uniform(0.9, 1.1, (nrow, nchan)) if use_wgt else None
mask = (rng.uniform(0, 1, (nrow, nchan)) > 0.5).astype(np.uint8) if use_mask else None
dirty = rng.random((nxdirty, nydirty))-0.5
nu, nv = int(nxdirty*ofactor)+1, int(nydirty*ofactor)+1
if nu & 1:
......@@ -101,9 +105,9 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
if wgt is not None:
wgt = wgt.astype("f4")
dirty2 = ng.ms2dirty(uvw, freq, ms, wgt, nxdirty, nydirty, pixsizex,
pixsizey, nu, nv, epsilon, wstacking, nthreads, 0).astype("f8")
pixsizey, nu, nv, epsilon, wstacking, nthreads, 0, mask).astype("f8")
ms2 = ng.dirty2ms(uvw, freq, dirty, wgt, pixsizex, pixsizey, nu, nv, epsilon,
wstacking, nthreads+1, 0).astype("c16")
wstacking, nthreads+1, 0, mask).astype("c16")
ref = max(my_vdot(ms,ms).real, my_vdot(ms2,ms2).real,
my_vdot(dirty, dirty).real, my_vdot(dirty2, dirty2).real)
tol = 1e-5*ref if singleprec else 1e-11*ref
......@@ -119,9 +123,10 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
@pmp("singleprec", (False,))
@pmp("wstacking", (False, True))
@pmp("use_wgt", (True,))
@pmp("use_mask", (True,))
@pmp("nthreads", (1, 2, 7))
@pmp("fov", (1., 20.))
def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon, singleprec, wstacking, use_wgt, fov, nthreads):
def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon, singleprec, wstacking, use_wgt, use_mask, fov, nthreads):
if singleprec and epsilon < 5e-5:
pytest.skip()
rng = np.random.default_rng(42)
......@@ -132,6 +137,7 @@ def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
uvw = (rng.random((nrow, 3))-0.5)/(pixsizex*f0/speedoflight)
ms = rng.random((nrow, nchan))-0.5 + 1j*(rng.random((nrow, nchan))-0.5)
wgt = rng.uniform(0.9, 1.1, (nrow, 1)) if use_wgt else None
mask = (rng.uniform(0, 1, (nrow, nchan)) > 0.5).astype(np.uint8) if use_mask else None
wgt = np.broadcast_to(wgt, (nrow, nchan)) if use_wgt else None
nu, nv = int(nxdirty*ofactor)+1, int(nydirty*ofactor)+1
if nu & 1:
......@@ -145,6 +151,8 @@ def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
if wgt is not None:
wgt = wgt.astype("f4")
dirty = ng.ms2dirty(uvw, freq, ms, wgt, nxdirty, nydirty, pixsizex,
pixsizey, nu, nv, epsilon, wstacking, nthreads, 0).astype("f8")
ref = explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, pixsizex, pixsizey, wstacking)
pixsizey, nu, nv, epsilon, wstacking, nthreads,
0, mask).astype("f8")
ref = explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, pixsizex,
pixsizey, wstacking, mask)
assert_allclose(_l2error(dirty, ref), 0, atol=epsilon)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment