Skip to content

Commit a0db278

Browse files
bhazeltonjpober
authored andcommitted
more test coverage
1 parent 4716506 commit a0db278

File tree

2 files changed

+82
-37
lines changed

2 files changed

+82
-37
lines changed

tests/test_analytic_beam.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from pyuvdata import AiryBeam, GaussianBeam, ShortDipoleBeam, UniformBeam, UVBeam
1313
from pyuvdata.analytic_beam import AnalyticBeam, UnpolarizedAnalyticBeam
1414
from pyuvdata.testing import check_warnings
15-
from pyuvdata.utils.plotting import get_az_za_grid, plot_beam_arrays
1615

1716

1817
def test_airy_beam_values(az_za_deg_grid):
@@ -713,39 +712,3 @@ def test_plotting(
713712
norm_kwargs=norm_kwargs,
714713
savefile=savefile,
715714
)
716-
717-
718-
def test_plot_arrays(tmp_path):
719-
pytest.importorskip("matplotlib")
720-
import matplotlib
721-
722-
matplotlib.use("Agg") # Must be before importing matplotlib.pyplot or pylab!
723-
724-
dipole_beam = ShortDipoleBeam()
725-
726-
az_grid, za_grid = get_az_za_grid()
727-
az_array, za_array = np.meshgrid(az_grid, za_grid)
728-
729-
beam_vals = dipole_beam.efield_eval(
730-
az_array=az_array.flatten(),
731-
za_array=za_array.flatten(),
732-
freq_array=np.asarray(np.asarray([100e6])),
733-
)
734-
beam_vals = beam_vals.reshape(2, 2, za_grid.size, az_grid.size)
735-
736-
feed_labels = np.degrees(dipole_beam.feed_angle).astype(str)
737-
feed_labels[np.isclose(dipole_beam.feed_angle, 0)] = "N/S"
738-
feed_labels[np.isclose(dipole_beam.feed_angle, np.pi / 2)] = "E/W"
739-
740-
savefile = str(tmp_path / "test.png")
741-
742-
plot_beam_arrays(
743-
beam_vals,
744-
az_array,
745-
za_array,
746-
complex_type="real",
747-
feedpol_label=feed_labels,
748-
beam_type_label="E-field",
749-
beam_name="short dipole",
750-
savefile=savefile,
751-
)

tests/utils/test_plotting.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (c) 2024 Radio Astronomy Software Group
2+
# Licensed under the 2-clause BSD License
3+
4+
import numpy as np
5+
import pytest
6+
7+
from pyuvdata import ShortDipoleBeam
8+
from pyuvdata.utils.plotting import get_az_za_grid, plot_beam_arrays
9+
10+
11+
def test_plot_arrays(tmp_path):
12+
pytest.importorskip("matplotlib")
13+
import matplotlib
14+
15+
matplotlib.use("Agg") # Must be before importing matplotlib.pyplot or pylab!
16+
17+
dipole_beam = ShortDipoleBeam()
18+
19+
az_grid, za_grid = get_az_za_grid()
20+
az_array, za_array = np.meshgrid(az_grid, za_grid)
21+
22+
beam_vals = dipole_beam.efield_eval(
23+
az_array=az_array.flatten(),
24+
za_array=za_array.flatten(),
25+
freq_array=np.asarray(np.asarray([100e6])),
26+
)
27+
beam_vals = beam_vals.reshape(2, 2, za_grid.size, az_grid.size)
28+
29+
savefile = str(tmp_path / "test.png")
30+
31+
plot_beam_arrays(
32+
beam_vals,
33+
az_array,
34+
za_array,
35+
complex_type="real",
36+
beam_type_label="E-field",
37+
beam_name="short dipole",
38+
savefile=savefile,
39+
)
40+
41+
42+
def test_plot_arrays_errors():
43+
pytest.importorskip("matplotlib")
44+
import matplotlib
45+
46+
matplotlib.use("Agg") # Must be before importing matplotlib.pyplot or pylab!
47+
48+
dipole_beam = ShortDipoleBeam()
49+
50+
az_grid, za_grid = get_az_za_grid()
51+
az_array, za_array = np.meshgrid(az_grid, za_grid)
52+
53+
beam_vals = dipole_beam.efield_eval(
54+
az_array=az_array.flatten(),
55+
za_array=za_array.flatten(),
56+
freq_array=np.asarray(np.asarray([100e6])),
57+
)
58+
59+
with pytest.raises(
60+
ValueError,
61+
match="az_array and za_array must be shaped like the last dimension "
62+
"of beam_vals for irregular beam_vals",
63+
):
64+
plot_beam_arrays(beam_vals[:, :, 0], az_array, za_array)
65+
66+
beam_vals = beam_vals.reshape(2, 2, za_grid.size, az_grid.size)
67+
68+
with pytest.raises(ValueError, match="beam_vals must be 3 or 4 dimensional."):
69+
plot_beam_arrays(beam_vals[0, 0], az_array, za_array)
70+
71+
with pytest.raises(
72+
ValueError,
73+
match="feedpol_label must have the same number of elements as the 1st",
74+
):
75+
plot_beam_arrays(beam_vals, az_array, za_array, feedpol_label=["foo"])
76+
77+
with pytest.raises(
78+
ValueError,
79+
match="az_array and za_array must be shaped like the last 2 dimensions "
80+
"of beam_vals for regularly gridded beam_vals",
81+
):
82+
plot_beam_arrays(beam_vals, az_array[0], za_array)

0 commit comments

Comments
 (0)