Skip to content

Commit 9eeda90

Browse files
committed
TST: Add normalization test.
This requires further investigation with more extensive visibilities, since Luis reports deviations when using Gaussian-Sinc kernel (normalization not correct). To be continued.
1 parent 6c7c48a commit 9eeda90

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/fastimgproto/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12

23

34
def reset_progress_bar(progress_bar, total, description="Doing something"):
@@ -24,3 +25,22 @@ def reset_progress_bar(progress_bar, total, description="Doing something"):
2425
progress_bar.total=total
2526
progress_bar.desc=description
2627
return
28+
29+
30+
def values_close(c1, c2, tol=np.float_(1e-8)):
31+
"""
32+
Check if two complex values are almost the same.
33+
34+
(See also: `pytest.approx` - but it's unclear if that works for complex
35+
values.)
36+
37+
Args:
38+
c1 (complex): Value 1
39+
c2 (complex): Value 2
40+
tol (float): Largest tolerated difference
41+
42+
Returns:
43+
bool: True if `|(c1-c2)| < tol`
44+
"""
45+
diff_amp = np.absolute(c1 - c2)
46+
return diff_amp < tol

tests/test_imager.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import numpy as np
21
import astropy.units as u
2+
import numpy as np
33

44
import fastimgproto.gridder.conv_funcs as conv_funcs
55
from fastimgproto.imager import image_visibilities
6+
from fastimgproto.utils import values_close
67

78

89
def test_normalization():
9-
n_image = 16 # pixel co-ords -8 through 7.
10+
n_image = 16 * u.pix # pixel co-ords -8 through 7.
1011
support = 3
1112
uvw_pixel_coords = np.array([
1213
(-4., 0, 0),
@@ -22,15 +23,31 @@ def test_normalization():
2223
grid_pixel_width_lambda = 1.0 / (cell_size.to(u.rad) * n_image)
2324
uvw_lambda = uvw_pixel_coords * grid_pixel_width_lambda.value
2425

26+
kernel_func=conv_funcs.Gaussian(trunc=2.5)
27+
image, beam = image_visibilities(vis,
28+
vis_weights=vis_weights,
29+
uvw_lambda=uvw_lambda,
30+
image_size=n_image,
31+
cell_size=cell_size,
32+
kernel_func=kernel_func,
33+
kernel_support=3,
34+
35+
)
36+
37+
assert values_close(beam.max(), 1.0)
38+
assert values_close(image.max(), vis_amplitude)
39+
40+
# Now try with Sinc kernel:
41+
kernel_func=conv_funcs.Sinc(trunc=3.)
2542
image, beam = image_visibilities(vis,
2643
vis_weights=vis_weights,
2744
uvw_lambda=uvw_lambda,
28-
image_size=n_image * u.pix,
45+
image_size=n_image,
2946
cell_size=cell_size,
30-
kernel_func=conv_funcs.Gaussian(trunc=2.5),
47+
kernel_func=kernel_func,
3148
kernel_support=3,
3249

3350
)
3451

35-
assert beam.max() == 1.0
36-
assert image.max() == vis_amplitude
52+
assert values_close(beam.max(), 1.0)
53+
assert values_close(image.max(), vis_amplitude)

0 commit comments

Comments
 (0)