Skip to content

Commit

Permalink
Fix some things found in pyuvsim testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed May 8, 2024
1 parent 11ec7e5 commit 17c8d91
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
19 changes: 18 additions & 1 deletion pyuvdata/uvdata/initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def new_uvdata(
telescope name and location, x_orientation and antenna names, numbers
and positions.
antpairs : sequence of 2-tuples of int or 2D array of int, optional
Antenna pairs in the data. If an ndarray, must have shape (Nants, 2).
Antenna pairs in the data. If an ndarray, must have shape (N antpairs, 2).
These may be the *unique* antpairs of the data if
each antpair observes the same set of times, otherwise they should be an
Nblts-length array of each antpair at each time. It is recommended
Expand Down Expand Up @@ -522,8 +522,11 @@ def new_uvdata(
)

if antpairs is None:
bl_order = ("ant1", "ant2")
antpairs = list(combinations_with_replacement(telescope.antenna_numbers, 2))
do_blt_outer = True
else:
bl_order = None

(
nbls,
Expand All @@ -541,6 +544,19 @@ def new_uvdata(
time_axis_faster_than_bls=time_axis_faster_than_bls,
time_sized_arrays=(lst_array, integration_time),
)

if not do_blt_outer:
if time_array.size != antpairs.shape[0]:
raise ValueError("Length of time array must match the number of antpairs.")

if bl_order is not None and blts_are_rectangular:
if time_axis_faster_than_bls:
blt_order = ("time", "ant1")
else:
blt_order = ("ant1", "ant2")
else:
blt_order = None

baseline_array = get_baseline_params(
antenna_numbers=telescope.antenna_numbers, antpairs=antpairs
)
Expand Down Expand Up @@ -595,6 +611,7 @@ def new_uvdata(
obj.spw_array = spw_array
obj.flex_spw_id_array = flex_spw_id_array
obj.integration_time = integration_time
obj.blt_order = blt_order

set_phase_params(
obj,
Expand Down
29 changes: 29 additions & 0 deletions pyuvdata/uvdata/tests/test_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def test_lunar_simple_new_uvdata(lunar_simple_params: dict[str, Any], selenoid:
},
"instrument must be set on the Telescope object passed to `telescope`.",
],
[
{
"antpairs": np.array([(0, 1), (0, 2), (1, 2), (0, 3)]),
"do_blt_outer": False,
},
"Length of time array must match the number of antpairs.",
],
],
)
def test_bad_inputs(simplest_working_params: dict[str, Any], update_dict, err_msg):
Expand All @@ -138,6 +145,28 @@ def test_bad_inputs(simplest_working_params: dict[str, Any], update_dict, err_ms
UVData.new(**simplest_working_params)


@pytest.mark.parametrize(
["update_dict", "blt_order"],
[
[{}, ("ant1", "ant2")],
[{"time_axis_faster_than_bls": True}, ("time", "ant1")],
[
{
"antpairs": np.array([(0, 1), (0, 2), (1, 2), (0, 1)]),
"times": np.array([2459855, 2459855, 2459855.5, 2459855.5]),
"integration_time": np.full((4,), 12.0, dtype=float),
"do_blt_outer": False,
},
None,
],
],
)
def test_blt_order(simplest_working_params, update_dict, blt_order):
simplest_working_params.update(update_dict)
uvd = UVData.new(**simplest_working_params)
assert uvd.blt_order == blt_order


def test_bad_time_inputs(simplest_working_params: dict[str, Any]):
with pytest.raises(ValueError, match="time_array must be a numpy array"):
get_time_params(
Expand Down
4 changes: 3 additions & 1 deletion pyuvdata/uvdata/uvfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ def write_uvfits(
start_freq_array += [freq_array_use[chan_mask][0]]
# Need the array direction here since channel_width is always supposed
# to be > 0, but channels can be in decending freq order
freq_dir = np.sign(np.median(np.diff(freq_array_use[chan_mask])))
freq_dir = 1.0
if nchan_list[-1] > 1:
freq_dir = np.sign(np.median(np.diff(freq_array_use[chan_mask])))
delta_freq_array += [
np.median(self.channel_width[chan_mask]) * freq_dir
]
Expand Down

0 comments on commit 17c8d91

Please sign in to comment.