Commit 75ef2a80 authored by Philipp Arras's avatar Philipp Arras
Browse files

Simplify tests

parent af146c42
......@@ -6,6 +6,32 @@ from numpy.testing import assert_, assert_allclose, assert_array_almost_equal
pmp = pytest.mark.parametrize
def _init_gridder(nxdirty, nydirty, epsilon, nchan, nrow):
pixsize = np.pi/180/60/nxdirty
conf = ng.GridderConfig(nxdirty=nxdirty,
nydirty=nydirty,
epsilon=epsilon,
pixsize_x=pixsize,
pixsize_y=pixsize)
speedoflight, f0 = 3e8, 1e9
freq = f0 + np.arange(nchan)*(f0/nchan)
uvw = (np.random.rand(nrow, 3)-0.5)/(pixsize*f0/speedoflight)
uvw[:, 2] = 0.
baselines = ng.Baselines(coord=uvw, freq=freq)
flags = np.zeros((nrow, nchan), dtype=np.bool)
idx = ng.getIndices(baselines, conf, flags)
return baselines, conf, idx
def _wscreen(npix, dst, w):
dc = (np.linspace(start=-npix/2, stop=npix/2 - 1, num=npix)*dst)**2
ls = np.broadcast_to(dc, (dc.shape[0],)*2)
theta = np.sqrt(ls + ls.T)
n = np.cos(theta)
wscreen = np.exp(2*np.pi*1j*w*(n - 1))/n
return wscreen
@pmp("nxdirty", (128, 300))
@pmp("nydirty", (128, 250))
@pmp("nrow", (1, 10, 10000))
......@@ -13,28 +39,13 @@ pmp = pytest.mark.parametrize
@pmp("epsilon", (1e-2, 1e-7, 2e-13))
def test_adjointness(nxdirty, nydirty, nrow, nchan, epsilon):
np.random.seed(42)
f0 = 1e9 # rough observation frequency
pixsize = np.pi/180/60/nxdirty # assume 1 arcmin FOV
speedoflight = 3e8
freq = f0 + np.arange(nchan)*(f0/nchan)
uvw = (np.random.rand(nrow, 3)-0.5) / (pixsize*f0/speedoflight)
uvw[:, 2] = 0.
baselines = ng.Baselines(coord=uvw, freq=freq)
gconf = ng.GridderConfig(nxdirty=nxdirty, nydirty=nydirty,
epsilon=epsilon, pixsize_x=pixsize,
pixsize_y=pixsize)
flags = np.zeros((nrow, nchan), dtype=np.bool)
idx = ng.getIndices(baselines, gconf, flags)
bl, gconf, idx = _init_gridder(nxdirty, nydirty, epsilon, nchan, nrow)
ms = np.random.rand(nrow, nchan)-0.5 + 1j*(np.random.rand(nrow, nchan)-0.5)
vis = baselines.ms2vis(ms, idx)
grid = ng.vis2grid(baselines, gconf, idx, vis)
vis = bl.ms2vis(ms, idx)
grid = ng.vis2grid(bl, gconf, idx, vis)
dirty = gconf.grid2dirty(grid)
dirty2 = np.random.rand(*dirty.shape)-0.5
ms2 = baselines.vis2ms(ng.grid2vis(baselines, gconf, idx,
gconf.dirty2grid(dirty2)), idx)
ms2 = bl.vis2ms(ng.grid2vis(bl, gconf, idx, gconf.dirty2grid(dirty2)), idx)
assert_allclose(np.vdot(ms, ms2).real, np.vdot(dirty, dirty2))
......@@ -156,15 +167,6 @@ def test_pickling():
assert_(gc.Pixsize_y() == gc2.Pixsize_y())
def _wscreen(npix, dst, w):
dc = (np.linspace(start=-npix/2, stop=npix/2 - 1, num=npix)*dst)**2
ls = np.broadcast_to(dc, (dc.shape[0],)*2)
theta = np.sqrt(ls + ls.T)
n = np.cos(theta)
wscreen = np.exp(2*np.pi*1j*w*(n - 1))/n
return wscreen
@pmp('nx', [4, 18, 54])
@pmp('dx', [1., 0.13, 132])
@pmp('w', [0, 10, 8489])
......@@ -189,29 +191,19 @@ def test_wstacking(nx, dx, w):
@pmp("nrow", (1, 10, 10000))
@pmp("nchan", (1, 10, 100))
@pmp("epsilon", (1e-2, 1e-7, 2e-13))
def test_applyholo(nxdirty, nydirty, nrow, nchan, epsilon):
@pmp("weight", (True, False))
def test_applyholo(nxdirty, nydirty, nrow, nchan, epsilon, weight):
np.random.seed(42)
pixsize = np.pi/180/60/nxdirty
conf = ng.GridderConfig(nxdirty=nxdirty,
nydirty=nydirty,
epsilon=epsilon,
pixsize_x=pixsize,
pixsize_y=pixsize)
speedoflight = 3e8
f0 = 1e9
freq = f0 + np.arange(nchan)*(f0/nchan)
uvw = (np.random.rand(nrow, 3) - 0.5)/(pixsize*f0/speedoflight)
uvw[:, 2] = 0.
baselines = ng.Baselines(coord=uvw, freq=freq)
flags = np.zeros((nrow, nchan), dtype=np.bool)
idx = ng.getIndices(baselines, conf, flags)
ms = np.random.rand(nrow,
nchan) - 0.5 + 1j*(np.random.rand(nrow, nchan) - 0.5)
vis = baselines.ms2vis(ms, idx)
grid = ng.vis2grid_c(baselines, conf, idx, vis)
y0 = ng.apply_holo(baselines, conf, idx, grid)
y1 = ng.vis2grid_c(baselines, conf, idx,
ng.grid2vis_c(baselines, conf, idx, grid))
bl, conf, idx = _init_gridder(nxdirty, nydirty, epsilon, nchan, nrow)
ms = np.random.rand(nrow, nchan)-0.5 + 1j*(np.random.rand(nrow, nchan)-0.5)
vis = bl.ms2vis(ms, idx)
grid = ng.vis2grid_c(bl, conf, idx, vis)
wgt = None
if weight:
wgt = np.random.rand(*vis.shape)
y0 = ng.apply_holo(bl, conf, idx, grid, wgt)
y1 = ng.vis2grid_c(bl, conf, idx, ng.grid2vis_c(bl, conf, idx, grid, wgt),
wgt=wgt)
assert_allclose(y0, y1)
......@@ -225,23 +217,10 @@ def test_applyholo(nxdirty, nydirty, nrow, nchan, epsilon):
def test_correlations(nxdirty, nydirty, nrow, nchan, epsilon, du, dv):
# FIXME Include weights
np.random.seed(42)
pixsize = np.pi/180/60/nxdirty
conf = ng.GridderConfig(nxdirty=nxdirty,
nydirty=nydirty,
epsilon=epsilon,
pixsize_x=pixsize,
pixsize_y=pixsize)
bl, conf, idx = _init_gridder(nxdirty, nydirty, epsilon, nchan, nrow)
if conf.W() <= abs(du) or conf.W() <= dv:
return
speedoflight, f0 = 3e8, 1e9
freq = f0 + np.arange(nchan)*(f0/nchan)
uvw = (np.random.rand(nrow, 3) - 0.5)/(pixsize*f0/speedoflight)
uvw[:, 2] = 0.
baselines = ng.Baselines(coord=uvw, freq=freq)
flags = np.zeros((nrow, nchan), dtype=np.bool)
idx = ng.getIndices(baselines, conf, flags)
y0 = ng.get_correlations(baselines, conf, idx, du, dv)
y0 = ng.get_correlations(bl, conf, idx, du, dv)
pts = ((nxdirty, nydirty),
(nxdirty + 1, nydirty),
(nxdirty, nydirty//2),
......@@ -250,7 +229,7 @@ def test_correlations(nxdirty, nydirty, nrow, nchan, epsilon, du, dv):
for pp in pts:
grid = np.zeros((2*nxdirty, 2*nydirty))
grid[pp] = 1
y1 = ng.apply_holo(baselines, conf, idx, grid)
y1 = ng.apply_holo(bl, conf, idx, grid)
ind = (pp[0]+du) % (2*nxdirty), (pp[1]+dv) % (2*nydirty)
assert_allclose(y0[pp], y1[ind].real)
assert_allclose(np.zeros_like(y1), y1.imag)
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