Skip to content

Commit 18c971d

Browse files
committed
Add tests, update test data registry info for new test data
1 parent ce087fe commit 18c971d

6 files changed

Lines changed: 188 additions & 64 deletions

File tree

src/pyuvdata/data/test_data.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ mwa_cotter_phase_test2: visibility_data/MWA/1133866760_rephase.uvfits
4343
mwa_fhd: visibility_data/MWA/fhd_vis_data.tar.gz
4444
mwa_fhd_cal: calibration_solutions/MWA/fhd_cal_data.tar.gz
4545
mwa_full_EE: primary_beams/MWA/mwa_full_EE_test.h5
46+
mwa_jmatrix: primary_beams/MWA/JMatrix_3freq.fits
47+
mwa_zmatrix: primary_beams/MWA/ZMatrix_3freq.fits
4648
mwax_2021_metafits: visibility_data/MWA/mwa_corr_fits_testfiles/1320409688.metafits
4749
mwax_2021_raw_gpubox: visibility_data/MWA/mwa_corr_fits_testfiles/1320409688_20211108122750_mini_ch137_000.fits
4850
ovro_lwa: visibility_data/LWA/2018-03-21-01_26_33_0004384620257280_000000_downselected.ms.tar.gz

src/pyuvdata/data/test_data_registry.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ primary_beams/HERA/HERABEAM.FITS a28232d8f63af528afae7ca529856809d478db86b3b3b7d
6868
primary_beams/LWA/OVRO_LWA_x.ffe c69e5ac1afa638d2a80663ded0bf4d69c1273a55bc16b52e15e3d96209a3087e
6969
primary_beams/LWA/OVRO_LWA_y.ffe 3e2f165ac82c7f422815c7b9911ae61dc7ed43dff00556ffd59b58248a93119a
7070
primary_beams/MWA/mwa_full_EE_test.h5 9246b9e98dc99d4284e7865ebae221b43aaef64893830cad00587d265eef2bfe
71+
primary_beams/MWA/JMatrix_3freq.fits c1a0100a3c0a6999d32c393f0712cb9d86f6f4340376d4cfea9eba120c94b4c0
72+
primary_beams/MWA/ZMatrix_3freq.fits fe79c5601cab0d4cd82260860ad98f66e0dcf7098b51c5b51108d344a76654a6
7173
flagsets/HERA/zen.2457698.40355.xx.HH.uvcAA.testuvflag.h5 20ff14975bcedf5edd447e3c5db3456d9298846d7e5da5bb084c7b0662327875

src/pyuvdata/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pyuvdata.data import DATA_PATH
1313

1414
# set the data version. This should be updated when the test data are changed.
15-
data_version = "v0.0.4"
15+
data_version = "v0.0.5"
1616

1717
pup = pooch.create(
1818
# Use the default cache folder for the operating system

tests/uvbeam/conftest.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def phased_array_beam_1freq(phased_array_beam_2freq):
334334

335335

336336
@pytest.fixture(scope="module")
337-
def mwa_beam_1ppd_main():
337+
def mwa_fee_1ppd_main():
338338
beam = UVBeam()
339339
beam.read_mwa_beam(fetch_data("mwa_full_EE"), pixels_per_deg=1)
340340

@@ -343,8 +343,32 @@ def mwa_beam_1ppd_main():
343343

344344

345345
@pytest.fixture(scope="function")
346-
def mwa_beam_1ppd(mwa_beam_1ppd_main):
347-
beam = mwa_beam_1ppd_main.copy()
346+
def mwa_fee_1ppd(mwa_fee_1ppd_main):
347+
beam = mwa_fee_1ppd_main.copy()
348+
349+
yield beam
350+
del beam
351+
352+
353+
@pytest.fixture(scope="module")
354+
def mwa_aee_files():
355+
return {"jfile": fetch_data("mwa_jmatrix"), "zfile": fetch_data("mwa_zmatrix")}
356+
357+
358+
@pytest.fixture(scope="module")
359+
def mwa_aee_main(mwa_aee_files):
360+
beam = UVBeam()
361+
filename = mwa_aee_files["jfile"]
362+
zfile = mwa_aee_files["zfile"]
363+
beam.read_mwa_beam(filename, zfile=zfile)
364+
365+
yield beam
366+
del beam
367+
368+
369+
@pytest.fixture(scope="function")
370+
def mwa_aee(mwa_aee_main):
371+
beam = mwa_aee_main.copy()
348372

349373
yield beam
350374
del beam

tests/uvbeam/test_mwa_beam.py

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2019 Radio Astronomy Software Group
22
# Licensed under the 2-clause BSD License
3+
import copy
34

45
import numpy as np
56
import pytest
@@ -10,27 +11,52 @@
1011
from pyuvdata.uvbeam.mwa_beam import P1sin, P1sin_array
1112

1213

13-
def test_read_write_mwa(mwa_beam_1ppd, tmp_path):
14+
@pytest.fixture()
15+
def mwabeam_kwargs(mwa_aee_files):
16+
return {"fee": {"pixels_per_deg": 1}, "aee": {"zfile": mwa_aee_files["zfile"]}}
17+
18+
19+
@pytest.fixture()
20+
def uvbeam_kwargs(mwabeam_kwargs):
21+
uvbeam_kwargs = copy.deepcopy(mwabeam_kwargs)
22+
uvbeam_kwargs["aee"]["mwa_zfile"] = uvbeam_kwargs["aee"].pop("zfile")
23+
return uvbeam_kwargs
24+
25+
26+
@pytest.fixture()
27+
def beam_filenames(mwa_aee_files):
28+
return {"fee": fetch_data("mwa_full_EE"), "aee": mwa_aee_files["jfile"]}
29+
30+
31+
@pytest.mark.parametrize("model", ["fee", "aee"])
32+
def test_read_write_mwa(beam_filenames, mwabeam_kwargs, model, tmp_path):
1433
"""Basic read/write test."""
15-
beam1 = mwa_beam_1ppd
16-
beam2 = UVBeam()
1734

18-
beam1.read_mwa_beam(fetch_data("mwa_full_EE"), pixels_per_deg=1)
19-
assert beam1.filename == ["mwa_full_EE_test.h5"]
35+
filename = beam_filenames[model]
36+
kwargs = mwabeam_kwargs[model]
37+
38+
beam1 = UVBeam()
39+
beam2 = UVBeam()
40+
beam1.read_mwa_beam(filename, **kwargs)
41+
42+
if model == "fee":
43+
assert beam1.filename == ["mwa_full_EE_test.h5"]
44+
assert beam1.data_array.shape == (2, 2, 3, 91, 360)
45+
# this is entirely empirical, just to prevent unexpected changes.
46+
# The actual values have been validated through external tests against
47+
# the mwa_pb repo.
48+
assert np.isclose(
49+
np.max(np.abs(beam1.data_array)),
50+
0.6823676193472403,
51+
rtol=beam1._data_array.tols[0],
52+
atol=beam1._data_array.tols[1],
53+
)
54+
else:
55+
assert beam1.filename == ["JMatrix_3freq.fits", "ZMatrix_3freq.fits"]
56+
assert beam1.data_array.shape == (2, 2, 3, 31, 121)
2057

2158
assert beam1.pixel_coordinate_system == "az_za"
2259
assert beam1.beam_type == "efield"
23-
assert beam1.data_array.shape == (2, 2, 3, 91, 360)
24-
25-
# this is entirely empirical, just to prevent unexpected changes.
26-
# The actual values have been validated through external tests against
27-
# the mwa_pb repo.
28-
assert np.isclose(
29-
np.max(np.abs(beam1.data_array)),
30-
0.6823676193472403,
31-
rtol=beam1._data_array.tols[0],
32-
atol=beam1._data_array.tols[1],
33-
)
3460

3561
assert "x" in beam1.feed_array
3662
assert "y" in beam1.feed_array
@@ -45,8 +71,17 @@ def test_read_write_mwa(mwa_beam_1ppd, tmp_path):
4571

4672

4773
@pytest.mark.filterwarnings("ignore:There are some terminated dipoles")
48-
def test_mwa_orientation(mwa_beam_1ppd):
49-
power_beam = mwa_beam_1ppd.efield_to_power(inplace=False)
74+
@pytest.mark.parametrize("model", ["fee", "aee"])
75+
def test_mwa_orientation(mwa_fee_1ppd, mwa_aee, beam_filenames, uvbeam_kwargs, model):
76+
if model == "fee":
77+
ebeam = mwa_fee_1ppd
78+
near_hor_za = 80
79+
near_zen_za = 2
80+
else:
81+
ebeam = mwa_aee
82+
near_hor_za = 81
83+
near_zen_za = 3
84+
power_beam = ebeam.efield_to_power(inplace=False)
5085

5186
za_val = np.nonzero(np.isclose(power_beam.axis2_array, 15.0 * np.pi / 180))
5287

@@ -58,13 +93,13 @@ def test_mwa_orientation(mwa_beam_1ppd):
5893
== utils.polstr2num(
5994
"ee", x_orientation=power_beam.get_x_orientation_from_feeds()
6095
)
61-
)
96+
)[0]
6297
north_ind = np.nonzero(
6398
power_beam.polarization_array
6499
== utils.polstr2num(
65100
"nn", x_orientation=power_beam.get_x_orientation_from_feeds()
66101
)
67-
)
102+
)[0]
68103

69104
# check that the e/w dipole is more sensitive n/s
70105
assert (
@@ -85,11 +120,13 @@ def test_mwa_orientation(mwa_beam_1ppd):
85120
# single dipole
86121
delays = np.full((2, 16), 32, dtype=int)
87122
delays[:, 5] = 0
88-
efield_beam = UVBeam.from_file(
89-
fetch_data("mwa_full_EE"), pixels_per_deg=1, delays=delays
90-
)
91123

92-
za_val = np.nonzero(np.isclose(efield_beam.axis2_array, 80.0 * np.pi / 180))
124+
filename = beam_filenames[model]
125+
kwargs = uvbeam_kwargs[model]
126+
kwargs["delays"] = delays
127+
efield_beam = UVBeam.from_file(filename, **kwargs)
128+
129+
za_val = np.nonzero(np.isclose(efield_beam.axis2_array, near_hor_za * np.pi / 180))
93130

94131
max_az_response = np.max(np.abs(efield_beam.data_array[0, east_ind, 0, za_val, :]))
95132
max_za_response = np.max(np.abs(efield_beam.data_array[1, east_ind, 0, za_val, :]))
@@ -99,9 +136,10 @@ def test_mwa_orientation(mwa_beam_1ppd):
99136
max_za_response = np.max(np.abs(efield_beam.data_array[1, north_ind, 0, za_val, :]))
100137
assert max_az_response > max_za_response
101138

139+
# go back to zenith pointed full tile beam
102140
# check the sign of the responses are as expected close to zenith
103-
efield_beam = mwa_beam_1ppd
104-
za_val = np.nonzero(np.isclose(power_beam.axis2_array, 2.0 * np.pi / 180))
141+
efield_beam = ebeam
142+
za_val = np.nonzero(np.isclose(power_beam.axis2_array, near_zen_za * np.pi / 180))
105143

106144
# first check zenith angle aligned response
107145
assert efield_beam.data_array[1, east_ind, 0, za_val, east_az] > 0
@@ -127,17 +165,21 @@ def test_mwa_orientation(mwa_beam_1ppd):
127165
),
128166
],
129167
)
130-
def test_mwa_pointing(delay_set, az_val, za_range):
168+
@pytest.mark.parametrize("model", ["fee", "aee"])
169+
def test_mwa_pointing(
170+
delay_set, az_val, za_range, beam_filenames, uvbeam_kwargs, model
171+
):
131172
# Test that pointing the beam moves the peak in the right direction.
132173

133174
delays = np.empty((2, 16), dtype=int)
134175

135176
for pol in range(2):
136177
delays[pol] = delay_set
137178

138-
mwa_beam = UVBeam.from_file(
139-
fetch_data("mwa_full_EE"), pixels_per_deg=1, beam_type="efield", delays=delays
140-
)
179+
filename = beam_filenames[model]
180+
kwargs = uvbeam_kwargs[model]
181+
kwargs["delays"] = delays
182+
mwa_beam = UVBeam.from_file(filename, **kwargs)
141183
mwa_beam.efield_to_power(calc_cross_pols=False)
142184

143185
# set up zenith angle, azimuth and frequency arrays to evaluate with
@@ -189,8 +231,8 @@ def test_mwa_pointing(delay_set, az_val, za_range):
189231
assert np.rad2deg(za_array[max_nn_loc]) < za_range[1]
190232

191233

192-
def test_freq_range(mwa_beam_1ppd):
193-
beam1 = mwa_beam_1ppd
234+
def test_freq_range(mwa_fee_1ppd):
235+
beam1 = mwa_fee_1ppd
194236
beam2 = UVBeam()
195237

196238
# include all

0 commit comments

Comments
 (0)