Skip to content

Commit 6771782

Browse files
committed
Convolutional gridding tests work
The tests on the aaf were not in step with the recent changes.
1 parent 714f881 commit 6771782

8 files changed

Lines changed: 82 additions & 81 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ reproject_image.fits
4444
temp.fits
4545
/tests/test_ftprocessor_results
4646
/.pydevproject
47+
/tests/test_results

‎arl/fourier_transforms/convolutional_gridding.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def anti_aliasing_transform(shape, oversampling=8, support=3, m=6, c=0.0):
7373

7474
# Calculate the gridding kernel by Fourier transform of the gcf
7575
kernel = kernel_oversample(gcf, shape[0], oversampling, oversampling)
76+
kernel = kernel / kernel.max()
7677
return gcf, kernel
7778

7879

@@ -95,7 +96,6 @@ def anti_aliasing_calculate(shape, oversampling=8, support=3):
9596
# 2D Prolate spheroidal angular function is separable
9697
ny, nx = shape
9798
nu = numpy.abs(2.0 * coordinates(nx))
98-
print(nu)
9999
gcf1d, _ = grdsf(nu)
100100
gcf = numpy.outer(gcf1d, gcf1d)
101101
gcf = gcf / gcf.max()

‎arl/fourier_transforms/ftprocessor.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def predict_2d(vis, model, params=None):
4949
nchan, npol, ny, nx = model.data.shape
5050
assert nx==ny, "Images must be square"
5151

52-
if kernelname == 'crocodile':
52+
if kernelname == 'transform':
5353
log.info("ftprocessor.predict_2d: predicting using transformed PSWF")
5454
gcf, kernel = anti_aliasing_transform((padding * ny, padding * nx), oversampling)
5555
else:
56-
log.info("ftprocessor.predict_2d: predicting using calculated PSWF")
56+
log.info("ftprocessor.predict_2d: predicting using calculated spheroidal function")
5757
gcf, kernel = anti_aliasing_calculate((padding * ny, padding * nx), oversampling)
5858

5959
uvgrid = fft((pad_mid(model.data, padding * nx) / gcf).astype(dtype=complex))
@@ -125,12 +125,12 @@ def invert_2d(vis, im, dopsf=False, params=None):
125125
support = get_parameter(params, "support", 3)
126126
nchan, npol, ny, nx = im.data.shape
127127
gcf = 1.0
128-
if kernelname == 'crocodile':
128+
if kernelname == 'transform':
129129
log.info("ftprocessor.invert_2d: Two-dimensional invert using transformed PSWF")
130130
# Make the gridding convolution function the size of the image
131131
gcf, kernel = anti_aliasing_transform((padding * ny, padding * nx), oversampling)
132132
else:
133-
log.info("ftprocessor.invert_2d: Two-dimensional invert using calculated PSWF")
133+
log.info("ftprocessor.invert_2d: Two-dimensional invert using calculated spheroidal function")
134134
gcf, kernel = anti_aliasing_calculate((padding * ny, padding * nx), oversampling, support)
135135

136136
cellsize = abs(im.wcs.wcs.cdelt[0]) * numpy.pi / 180.0

‎examples/arl/gridding.ipynb‎

Lines changed: 47 additions & 57 deletions
Large diffs are not rendered by default.

‎tests/test_convolutional_gridding.py‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from arl.fourier_transforms.fft_support import *
88
from arl.fourier_transforms.convolutional_gridding import w_kernel_function, kernel_oversample, \
9-
coordinates2, anti_aliasing_transform, fixed_kernel_degrid, fixed_kernel_grid
9+
coordinates2, anti_aliasing_transform, anti_aliasing_calculate, fixed_kernel_degrid, fixed_kernel_grid
1010

1111

1212
class TestConvolutionalGridding(unittest.TestCase):
@@ -16,13 +16,19 @@ def assertAlmostEqualScalar(self, a, result=1.0):
1616

1717
def _test_pattern(self, npixel):
1818
return coordinates2(npixel)[0] + coordinates2(npixel)[1] * 1j
19+
1920

20-
def test_anti_aliasing(self):
21-
for shape in [(4, 4), (5, 5), (4, 6), (7, 3)]:
22-
aaf = anti_aliasing_transform(shape, 0, 10)
23-
self.assertEqual(aaf.shape, shape)
24-
self.assertAlmostEqual(aaf[shape[0] // 2, shape[1] // 2], 1.0)
25-
21+
def test_anti_aliasing_transform(self):
22+
for shape in [(64, 64), (128, 128), (256, 256)]:
23+
_, aaf = anti_aliasing_transform(shape, 8)
24+
self.assertAlmostEqual(numpy.max(aaf[..., aaf.shape[1] // 2, aaf.shape[0] // 2]), 1.0)
25+
26+
27+
def test_anti_aliasing_calculate(self):
28+
for shape in [(64, 64), (128, 128), (256, 256)]:
29+
_, aaf = anti_aliasing_calculate(shape, 8)
30+
self.assertAlmostEqual(numpy.max(aaf[..., aaf.shape[1] // 2, aaf.shape[0] // 2]), 1.0)
31+
2632
def test_w_kernel_function(self):
2733
assert_allclose(w_kernel_function(5, 0.1, 0), 1.0)
2834
self.assertAlmostEqualScalar(w_kernel_function(5, 0.1, 100)[2, 2], 1)
@@ -71,17 +77,16 @@ def test_convolutional_grid(self):
7177
nchan = 1
7278
npol = 4
7379
uvgrid = numpy.zeros([nchan, npol, npixel, npixel], dtype='complex')
74-
aaf = anti_aliasing_transform(shape, 0, 10)
75-
# gcf has shape [kernel_oversampling, kernel_oversampling, npixel, npixel] The fractional
80+
gcf, kernel = anti_aliasing_transform((npixel, npixel), 8)
81+
# kernel has shape [kernel_oversampling, kernel_oversampling, npixel, npixel] The fractional
7682
# part of the coordinate maps onto the first two axes.
77-
gcf = kernel_oversample(aaf, npixel, kernel_oversampling, 32)
7883
# Make some uv coordinates with random locations
7984
uvcoords = numpy.array([[random.uniform(-0.25, 0.25), random.uniform(-0.25, 0.25)] for ivis in range(nvis)])
8085
# Make some visibilities, all complex unity
8186
vis = numpy.ones([nchan, npol, nvis], dtype='complex')
8287
visweights = numpy.ones([nchan, npol, nvis])
8388
uvscale = numpy.array([1.0])
84-
fixed_kernel_grid(gcf, uvgrid, uvcoords, uvscale, vis, visweights)
89+
fixed_kernel_grid(kernel, uvgrid, uvcoords, uvscale, vis, visweights)
8590

8691
def test_convolutional_degrid(self):
8792
shape = (7, 7)
@@ -91,15 +96,14 @@ def test_convolutional_degrid(self):
9196
nchan = 1
9297
npol = 4
9398
uvgrid = numpy.ones([nchan, npol, npixel, npixel], dtype='complex')
94-
aaf = anti_aliasing_transform(shape, 0, 10)
95-
gcf = kernel_oversample(aaf, npixel, kernel_oversampling, 32)
99+
gcf, kernel = anti_aliasing_transform((npixel, npixel), 8)
96100
# gcf has shape [kernel_oversampling, kernel_oversampling, npixel, npixel] The fractional
97101
# part of the coordinate maps onto the first two axes.
98102
# Make some uv coordinates with random locations
99103
uvcoords = numpy.array([[random.uniform(-0.25, 0.25), random.uniform(-0.25, 0.25)] for ivis in range(nvis)])
100104
# Degrid the visibilities
101105
uvscale = numpy.array([1.0])
102-
vis = fixed_kernel_degrid(gcf, uvgrid, uvcoords, uvscale)
106+
vis = fixed_kernel_degrid(kernel, uvgrid, uvcoords, uvscale)
103107
assert vis.shape[0] == nvis
104108
assert vis.shape[1] == nchan
105109
assert vis.shape[2] == npol

‎tests/test_ftprocessor.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _checkdirty(self, vis, name='test_invert_2d_dirty', invert=invert_2d):
4242
export_image_to_fits(psf, '%s/%s_%s_psf.fits' % (self.dir, name, self.params['kernel']))
4343

4444
def setUp(self):
45-
self.dir = './test_ftprocessor_results'
45+
self.dir = './test_results'
4646
os.makedirs(self.dir, exist_ok=True)
4747

4848
self.params = {'npixel': 512,

‎tests/test_image_operations.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
class TestImage(unittest.TestCase):
1515

1616
def setUp(self):
17+
18+
self.dir = './test_results'
19+
os.makedirs(self.dir, exist_ok=True)
20+
1721
self.m31image = create_test_image()
1822
self.cellsize = 180.0 * 0.0001 / numpy.pi
1923
self.m31image.wcs.wcs.cdelt[0] = -self.cellsize
@@ -33,7 +37,7 @@ def test_create_image_from_array(self):
3337
m31modelsum = add_image(self.m31image, m31model_by_array)
3438
log.debug(self.m31image.data.shape)
3539
log.debug(self.m31image.wcs)
36-
log.debug(export_image_to_fits(self.m31image, fitsfile='temp.fits'))
40+
log.debug(export_image_to_fits(self.m31image, fitsfile='%s/test_model.fits' % (self.dir)))
3741

3842
def test_rasterise(self):
3943

@@ -53,8 +57,8 @@ def test_reproject(self):
5357

5458
newshape=(1,1,int(256//1.5),int(256//1.5))
5559
newimage, footprint=reproject_image(self.m31image, newwcs, shape=newshape)
56-
export_image_to_fits(newimage, fitsfile='reproject_image.fits')
57-
export_image_to_fits(footprint, fitsfile='reproject_footprint.fits')
60+
export_image_to_fits(newimage, fitsfile='%s/reproject_image.fits' % (self.dir))
61+
export_image_to_fits(footprint, fitsfile='%s/reproject_footprint.fits' % (self.dir))
5862

5963
if __name__ == '__main__':
6064
log.setLevel(logging.DEBUG)

‎tests/test_parameters.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
class TestParameters(unittest.TestCase):
1313
def setUp(self):
14-
self.paramsfile = arl_path("tests/TestParameters.txt")
14+
self.dir = './test_results'
15+
os.makedirs(self.dir, exist_ok=True)
16+
self.paramsfile = "%s/TestParameters.txt" % (self.dir)
1517
self.parameters = {'npixel': 256, 'cellsize':0.1, 'predict':{'cellsize':0.2}, 'invert':{'spectral_mode':'mfs'}}
1618

1719
def test_exportimport(self):

0 commit comments

Comments
 (0)