Skip to content

Commit

Permalink
fix weighting and polproducts test
Browse files Browse the repository at this point in the history
  • Loading branch information
landmanbester committed Aug 27, 2024
1 parent 15021cd commit 5eff059
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
25 changes: 24 additions & 1 deletion tests/test_polproducts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def test_polproducts(do_gains, ms_name):
from daskms import xds_from_ms, xds_from_table, xds_to_table
from daskms.experimental.zarr import xds_to_zarr
from africanus.constants import c as lightspeed
from ducc0.wgridder import dirty2vis
from ducc0.wgridder.experimental import dirty2vis
from pfb.utils.naming import xds_from_url
from pfb.operators.gridder import wgridder_conventions


test_dir = Path(ms_name).resolve().parent
Expand Down Expand Up @@ -72,6 +73,8 @@ def test_polproducts(do_gains, ms_name):
nx = npix
ny = npix

flip_u, flip_v, flip_w, x0, y0 = wgridder_conventions(0.0, 0.0)

print("Image size set to (%i, %i, %i)" % (nchan, nx, ny))

# first axis is Stokes
Expand All @@ -97,6 +100,11 @@ def test_polproducts(do_gains, ms_name):
dirty=model[0, c],
pixsize_x=cell_rad,
pixsize_y=cell_rad,
center_x=x0,
center_y=y0,
flip_u=flip_u,
flip_v=flip_v,
flip_w=flip_w,
epsilon=epsilon,
do_wgridding=True,
nthreads=8)
Expand All @@ -107,6 +115,11 @@ def test_polproducts(do_gains, ms_name):
dirty=model[1, c],
pixsize_x=cell_rad,
pixsize_y=cell_rad,
center_x=x0,
center_y=y0,
flip_u=flip_u,
flip_v=flip_v,
flip_w=flip_w,
epsilon=epsilon,
do_wgridding=True,
nthreads=8)
Expand All @@ -117,6 +130,11 @@ def test_polproducts(do_gains, ms_name):
dirty=model[2, c],
pixsize_x=cell_rad,
pixsize_y=cell_rad,
center_x=x0,
center_y=y0,
flip_u=flip_u,
flip_v=flip_v,
flip_w=flip_w,
epsilon=epsilon,
do_wgridding=True,
nthreads=8)
Expand All @@ -127,6 +145,11 @@ def test_polproducts(do_gains, ms_name):
dirty=model[3, c],
pixsize_x=cell_rad,
pixsize_y=cell_rad,
center_x=x0,
center_y=y0,
flip_u=flip_u,
flip_v=flip_v,
flip_w=flip_w,
epsilon=epsilon,
do_wgridding=True,
nthreads=8)
Expand Down
13 changes: 8 additions & 5 deletions tests/test_weighting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from pathlib import Path
from pfb.utils.weighting import _compute_counts
from pfb.operators.gridder import wgridder_conventions

pmp = pytest.mark.parametrize

Expand Down Expand Up @@ -57,12 +58,14 @@ def test_counts(ms_name):
ny = npix

print("Image size set to (%i, %i, %i)" % (nchan, nx, ny))


flip_u, flip_v, flip_w, x0, y0 = wgridder_conventions(0.0, 0.0)
usign = 1.0 if not flip_u else -1.0
vsign = 1.0 if not flip_v else -1.0
mask = np.ones((nrow, nchan), dtype=bool)
wgt = np.ones((nrow, nchan), dtype=uvw.dtype)
counts = _compute_counts(uvw, freq, mask, wgt, nx, ny, cell_rad, cell_rad,
dtype=np.float64, k=0, ngrid=2)
dtype=np.float64, k=0, ngrid=2,
usign=usign, vsign=vsign)
ku = np.sort(np.fft.fftfreq(nx, cell_rad))
# shift by half a pixel to get bin edges
kucell = ku[1] - ku[0]
Expand All @@ -74,8 +77,8 @@ def test_counts(ms_name):
kv -= kvcell/2
kv = np.append(kv, kv.max() + kvcell)
weights = np.ones((nrow*nchan), dtype=np.float64)
u = (uvw[:, 0:1] * freq[None, :]/lightspeed).ravel()
v = (uvw[:, 1:2] * freq[None, :]/lightspeed).ravel()
u = (usign*uvw[:, 0:1] * freq[None, :]/lightspeed).ravel()
v = (vsign*uvw[:, 1:2] * freq[None, :]/lightspeed).ravel()
counts2, _, _ = np.histogram2d(u, v, bins=[ku, kv], weights=weights)

assert_allclose(counts, counts2)

0 comments on commit 5eff059

Please sign in to comment.