Commit 65e64dfd authored by Philipp Arras's avatar Philipp Arras
Browse files

Add simple test

parent 4a97f909
import matplotlib.pyplot as plt
import nifty_gridder as ng
import numpy as np
np.random.seed(40)
ndirty, nrow = 512, 6 # breaks
# ndirty, nrow = 64, 1 # almost there
nchan, fov, epsilon = 1, 10, 1e-7
pixsize = fov*np.pi/180/ndirty
conf = ng.GridderConfig(nxdirty=ndirty,
nydirty=ndirty,
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)
bl = ng.Baselines(coord=uvw, freq=freq)
flags = np.zeros((nrow, nchan), dtype=np.bool)
idx = ng.getIndices(bl, conf, flags)
ms = np.random.rand(nrow, nchan) - 0.5 + 1j*(np.random.rand(nrow, nchan) - 0.5)
vis = bl.ms2vis(ms, idx)
uvw = bl.effectiveuvw(idx)
res1 = ng.vis2dirty_wstack(bl, conf, idx, vis).real
x, y = np.meshgrid(*[-ss/2 + np.arange(ss) for ss in [ndirty, ndirty]],
indexing='ij')
x *= conf.Pixsize_x()
y *= conf.Pixsize_y()
res0 = np.zeros((ndirty, ndirty))
eps = np.sqrt(x**2 + y**2)
s = np.sin(eps)
nm1 = -s*s/(1 + np.cos(eps))
n = nm1 + 1
for ii in idx:
phase = x*uvw[ii, 0] + y*uvw[ii, 1] + uvw[ii, 2]*nm1
res0 += (vis[ii]*np.exp(2j*np.pi*phase)).real
res0 /= n
plt.imshow(res0)
plt.colorbar()
plt.savefig('groundtruth.png')
plt.close()
plt.imshow(res1)
plt.colorbar()
plt.savefig('new.png')
plt.close()
plt.imshow(res1/res0)
plt.colorbar()
plt.savefig('ratio.png')
plt.close()
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