Skip to content

Commit

Permalink
address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Nov 13, 2023
1 parent 7039b4f commit a02b5a3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions docs/uvdata_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1567,11 +1567,11 @@ various conventions (``'ant1<ant2'``, ``'ant2<ant1'``, ``'u<0'``, ``'u>0'``, ``'
>>> from pyuvdata.data import DATA_PATH
>>> uvfits_file = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
>>> uvd = UVData.from_file(uvfits_file, use_future_array_shapes=True)
>>> uvd.conjugate_bls(convention='ant1<ant2')
>>> uvd.conjugate_bls('ant1<ant2')
>>> print(np.min(uvd.ant_2_array - uvd.ant_1_array) >= 0)
True
>>> uvd2.conjugate_bls(convention='u<0', use_enu=False)
>>> uvd2.conjugate_bls('u<0', use_enu=False)
>>> print(np.max(uvd2.uvw_array[:, 0]) <= 0)
True
Expand Down
4 changes: 2 additions & 2 deletions pyuvdata/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ def test_redundancy_finder():
uvd.select(times=uvd.time_array[0])
uvd.unproject_phase(use_ant_pos=True)
# uvw_array is now equivalent to baseline positions
uvd.conjugate_bls(convention="ant1<ant2", use_enu=True)
uvd.conjugate_bls("ant1<ant2", use_enu=True)

tol = 0.05 # meters

Expand Down Expand Up @@ -2815,7 +2815,7 @@ def test_high_tolerance_redundancy_error():
uvd.select(times=uvd.time_array[0])
uvd.unproject_phase(use_ant_pos=True)
# uvw_array is now equivalent to baseline positions
uvd.conjugate_bls(convention="ant1<ant2", use_enu=True)
uvd.conjugate_bls("ant1<ant2", use_enu=True)
bl_positions = uvd.uvw_array

tol = 20.05 # meters
Expand Down
2 changes: 1 addition & 1 deletion pyuvdata/uvdata/miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ def write_miriad(
)

# Miriad requires j>i which we call ant1<ant2
self.conjugate_bls(convention="ant1<ant2")
self.conjugate_bls("ant1<ant2")

if run_check:
self.check(
Expand Down
2 changes: 1 addition & 1 deletion pyuvdata/uvdata/tests/test_miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ def test_multi_files(casa_uvfits, tmp_path):
testfile2 = os.path.join(tmp_path, "uv2")
# rename telescope to avoid name warning
uv_full.unproject_phase()
uv_full.conjugate_bls(convention="ant1<ant2")
uv_full.conjugate_bls("ant1<ant2")

uv1 = uv_full.copy()
uv2 = uv_full.copy()
Expand Down
42 changes: 21 additions & 21 deletions pyuvdata/uvdata/tests/test_uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,7 @@ def test_conjugate_bls(casa_uvfits, metadata_only, future_shapes):

# check everything swapped & conjugated when go to ant2<ant1
uv2 = uv1.copy()
uv2.conjugate_bls(convention="ant2<ant1")
uv2.conjugate_bls("ant2<ant1")
assert np.min(uv2.ant_1_array - uv2.ant_2_array) >= 0

assert np.allclose(uv1.ant_1_array, uv2.ant_2_array)
Expand Down Expand Up @@ -2929,13 +2929,13 @@ def test_conjugate_bls(casa_uvfits, metadata_only, future_shapes):
)

# check everything returned to original values with original convention
uv2.conjugate_bls(convention="ant1<ant2")
uv2.conjugate_bls("ant1<ant2")
assert uv1 == uv2

# conjugate a particular set of blts
blts_to_conjugate = np.arange(uv2.Nblts // 2)
blts_not_conjugated = np.arange(uv2.Nblts // 2, uv2.Nblts)
uv2.conjugate_bls(convention=blts_to_conjugate)
uv2.conjugate_bls(blts_to_conjugate)

assert np.allclose(
uv1.ant_1_array[blts_to_conjugate], uv2.ant_2_array[blts_to_conjugate]
Expand Down Expand Up @@ -3045,41 +3045,41 @@ def test_conjugate_bls(casa_uvfits, metadata_only, future_shapes):
)

# check uv half plane conventions
uv2.conjugate_bls(convention="u<0", use_enu=False)
uv2.conjugate_bls("u<0", use_enu=False)
assert np.max(uv2.uvw_array[:, 0]) <= 0

uv2.conjugate_bls(convention="u>0", use_enu=False)
uv2.conjugate_bls("u>0", use_enu=False)
assert np.min(uv2.uvw_array[:, 0]) >= 0

uv2.conjugate_bls(convention="v<0", use_enu=False)
uv2.conjugate_bls("v<0", use_enu=False)
assert np.max(uv2.uvw_array[:, 1]) <= 0

uv2.conjugate_bls(convention="v>0", use_enu=False)
uv2.conjugate_bls("v>0", use_enu=False)
assert np.min(uv2.uvw_array[:, 1]) >= 0

# unphase to drift to test using ENU positions
uv2.unproject_phase(use_ant_pos=True)
uv2.conjugate_bls(convention="u<0")
uv2.conjugate_bls("u<0")
assert np.max(uv2.uvw_array[:, 0]) <= 0

uv2.conjugate_bls(convention="u>0")
uv2.conjugate_bls("u>0")
assert np.min(uv2.uvw_array[:, 0]) >= 0

uv2.conjugate_bls(convention="v<0")
uv2.conjugate_bls("v<0")
assert np.max(uv2.uvw_array[:, 1]) <= 0

uv2.conjugate_bls(convention="v>0")
uv2.conjugate_bls("v>0")
assert np.min(uv2.uvw_array[:, 1]) >= 0

# test errors
with pytest.raises(ValueError, match="convention must be one of"):
uv2.conjugate_bls(convention="foo")
uv2.conjugate_bls("foo")

with pytest.raises(ValueError, match="If convention is an index array"):
uv2.conjugate_bls(convention=np.arange(5) - 1)
uv2.conjugate_bls(np.arange(5) - 1)

with pytest.raises(ValueError, match="If convention is an index array"):
uv2.conjugate_bls(convention=[uv2.Nblts])
uv2.conjugate_bls([uv2.Nblts])


@pytest.mark.filterwarnings("ignore:This method will be removed in version 3.0 when")
Expand Down Expand Up @@ -6261,7 +6261,7 @@ def test_get_antenna_redundancies(pyuvsim_redundant):
assert bl in uv0.baseline_array

# conjugate data differently
uv0.conjugate_bls(convention="ant1<ant2")
uv0.conjugate_bls("ant1<ant2")
new_red_gps, new_centers, new_lengths, conjs = uv0.get_redundancies(
use_antpos=True, include_autos=False, include_conjugates=True
)
Expand Down Expand Up @@ -6316,7 +6316,7 @@ def test_redundancy_contract_expand(
blt_inds_to_conj.extend(
list(np.nonzero(uv0.baseline_array == gp[0])[0])
)
uv0.conjugate_bls(convention=np.array(blt_inds_to_conj))
uv0.conjugate_bls(np.array(blt_inds_to_conj))

# Assign identical data to each redundant group, set up flagging.
# This must be done after reconjugation because reconjugation can alter the index
Expand Down Expand Up @@ -6353,7 +6353,7 @@ def test_redundancy_contract_expand(
if reconjugate:
# undo the conjugations to make uv3 have different conjugations than uv0 to test
# that we still get the same answer
uv3.conjugate_bls(convention=np.array(blt_inds_to_conj))
uv3.conjugate_bls(np.array(blt_inds_to_conj))

uv2 = uv0.compress_by_redundancy(method=method, tol=tol, inplace=False)
uv2.check()
Expand Down Expand Up @@ -6417,7 +6417,7 @@ def test_redundancy_contract_expand(
blts_to_conj = []
for bl in bls_to_conj:
blts_to_conj.extend(list(np.nonzero(uv3.baseline_array == bl)[0]))
uv3.conjugate_bls(convention=blts_to_conj)
uv3.conjugate_bls(blts_to_conj)

# now check for ones that are still not matching
unique_bls_3 = np.unique(uv3.baseline_array)
Expand Down Expand Up @@ -6807,7 +6807,7 @@ def test_quick_redundant_vs_redundant_test_array(pyuvsim_redundant):

uv.select(times=uv.time_array[0])
uv.unproject_phase()
uv.conjugate_bls(convention="u>0", use_enu=True)
uv.conjugate_bls("u>0", use_enu=True)
tol = 0.05
# a quick and dirty redundancy calculation
unique_bls, baseline_inds = np.unique(uv.baseline_array, return_index=True)
Expand Down Expand Up @@ -6846,7 +6846,7 @@ def test_redundancy_finder_when_nblts_not_nbls_times_ntimes(casa_uvfits):
"""Test the redundancy finder functions when Nblts != Nbls * Ntimes."""
tol = 1 # meter
uv = casa_uvfits
uv.conjugate_bls(convention="u>0", use_enu=True)
uv.conjugate_bls("u>0", use_enu=True)
# check that Nblts != Nbls * Ntimes
assert uv.Nblts != uv.Nbls * uv.Ntimes

Expand Down Expand Up @@ -11232,7 +11232,7 @@ def test_fix_phase(hera_uvh5, tmp_path, future_shapes, use_ant_pos, phase_frame)

uv_in_bad_copy = uv_in_bad.copy()
if file_type == "miriad":
uv_in_bad_copy.conjugate_bls(convention="ant1<ant2")
uv_in_bad_copy.conjugate_bls("ant1<ant2")
uv_in_bad_copy.reorder_blts()
uv_in_bad2.reorder_blts()
uv_in_bad2._update_phase_center_id(0, new_id=1)
Expand Down
10 changes: 4 additions & 6 deletions pyuvdata/uvdata/uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4660,7 +4660,7 @@ def antpairpol_iter(self, *, squeeze="default"):
for key in antpairpols:
yield (key, self.get_data(key, squeeze=squeeze))

def conjugate_bls(self, *, convention="ant1<ant2", use_enu=True, uvw_tol=0.0):
def conjugate_bls(self, convention="ant1<ant2", *, use_enu=True, uvw_tol=0.0):
"""
Conjugate baselines according to one of the supported conventions.

Expand Down Expand Up @@ -5032,9 +5032,7 @@ def reorder_blts(

if conj_convention is not None:
self.conjugate_bls(
convention=conj_convention,
use_enu=conj_convention_use_enu,
uvw_tol=uvw_tol,
conj_convention, use_enu=conj_convention_use_enu, uvw_tol=uvw_tol
)

if isinstance(order, str):
Expand Down Expand Up @@ -10073,7 +10071,7 @@ def get_redundancies(
numbers, antpos, tol=tol, include_autos=include_autos
)
if conjugate_bls:
self.conjugate_bls(convention="u>0", uvw_tol=tol)
self.conjugate_bls("u>0", uvw_tol=tol)

if include_conjugates:
result = result + (None,)
Expand Down Expand Up @@ -10346,7 +10344,7 @@ def inflate_by_redundancy(self, *, tol=1.0, blt_order="time", blt_minor_order=No
string specifying minor order along the blt axis (see `reorder_blts`)

"""
self.conjugate_bls(convention="u>0")
self.conjugate_bls("u>0")
red_gps, centers, lengths = self.get_redundancies(
tol=tol, use_antpos=True, conjugate_bls=True
)
Expand Down

0 comments on commit a02b5a3

Please sign in to comment.