11# Copyright (c) 2019 Radio Astronomy Software Group
22# Licensed under the 2-clause BSD License
3+ import copy
34
45import numpy as np
56import pytest
1011from 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