Skip to content

Commit

Permalink
refactor the selection on the blt axis out so it can be reused.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Mar 21, 2024
1 parent e59eb84 commit bc69f98
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 354 deletions.
42 changes: 16 additions & 26 deletions pyuvdata/uvdata/miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ def read_miriad(
# but that may not matter for many purposes.
return

history_update_string = " Downselected to specific "
n_selects = 0
selections = []

# select on ant_str if provided
if ant_str is not None:
Expand All @@ -801,8 +800,7 @@ def read_miriad(

aipy_extracts.uv_selector(uv, ant_str)
if ant_str != "all":
history_update_string += "antenna pairs"
n_selects += 1
selections.append("antenna pairs")

# select on antenna_nums and/or bls using aipy_extracts.uv_selector
if antenna_nums is not None or bls is not None:
Expand All @@ -821,8 +819,7 @@ def read_miriad(
# convert antenna numbers to string form required by
# aipy_extracts.uv_selector
antpair_str_list = ["_".join([str(a) for a in ap]) for ap in antpairs]
history_update_string += "antennas"
n_selects += 1
selections.append("antennas")

if bls is not None:
if isinstance(bls, tuple) and (len(bls) == 2 or len(bls) == 3):
Expand Down Expand Up @@ -866,7 +863,7 @@ def read_miriad(
if len(bl) == 3:
bl_pols.add(uvutils.conj_pol(bl[2]))

if n_selects > 0:
if len(selections) > 0:
# combine antpair_str_list and bl_str_list with an intersection
antpair_str_list = list(
set(antpair_str_list).intersection(bl_str_list)
Expand All @@ -877,11 +874,7 @@ def read_miriad(
if len(bl_pols) > 0:
polarizations = list(bl_pols)

if n_selects > 0:
history_update_string += ", baselines"
else:
history_update_string += "baselines"
n_selects += 1
selections.append("antenna pairs")

# convert antenna pair list to string form required by
# aipy_extracts.uv_selector
Expand Down Expand Up @@ -911,11 +904,8 @@ def read_miriad(
time_range_use = np.array(time_range) - uv["inttime"] / (24 * 3600.0) / 2

uv.select("time", time_range_use[0], time_range_use[1], include=True)
if n_selects > 0:
history_update_string += ", times"
else:
history_update_string += "times"
n_selects += 1

selections.append("times")

# select on polarizations
if polarizations is not None:
Expand Down Expand Up @@ -949,15 +939,15 @@ def read_miriad(
# check not empty
if len(pol_list) == 0:
raise ValueError("No polarizations in data matched input")
if n_selects > 0:
history_update_string += ", polarizations"
else:
history_update_string += "polarizations"
n_selects += 1

history_update_string += " using pyuvdata."
if n_selects > 0:
self.history += history_update_string
selections.append("polarizations")

if len(selections) > 0:
# build up history string from selections
self.history += (
" Downselected to specific "
+ ", ".join(selections)
+ " using pyuvdata."
)

data_accumulator = {}
pol_list = []
Expand Down
22 changes: 11 additions & 11 deletions pyuvdata/uvdata/tests/test_uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,9 @@ def test_select_phase_center_id_blts(carma_miriad):
uv_sum = uv1 + uv2 + uv3
assert uvutils._check_histories(
uv_obj.history
+ " Downselected to specific baseline-times, phase center IDs using pyuvdata. "
+ " Downselected to specific phase center IDs, baseline-times using pyuvdata. "
"Combined data along baseline-time axis using pyuvdata. "
"Combined data along baseline-time axis using pyuvdata. "
"Unique part of next object history follows. baseline-times",
"Combined data along baseline-time axis using pyuvdata. ",
uv_sum.history,
)
uv_sum.history = uv_obj.history
Expand Down Expand Up @@ -1655,7 +1654,7 @@ def test_select_bls(casa_uvfits):
assert pair in sorted_pairs_to_keep

assert uvutils._check_histories(
old_history + " Downselected to specific baselines using pyuvdata.",
old_history + " Downselected to specific antenna pairs using pyuvdata.",
uv_object2.history,
)

Expand Down Expand Up @@ -1684,7 +1683,7 @@ def test_select_bls(casa_uvfits):
assert pair in sorted_pairs_to_keep

assert uvutils._check_histories(
old_history + " Downselected to specific baselines using pyuvdata.",
old_history + " Downselected to specific antenna pairs using pyuvdata.",
uv_object3.history,
)

Expand Down Expand Up @@ -1724,7 +1723,7 @@ def test_select_bls(casa_uvfits):

assert uvutils._check_histories(
old_history
+ " Downselected to specific baselines, polarizations using pyuvdata.",
+ " Downselected to specific antenna pairs, polarizations using pyuvdata.",
uv_object2.history,
)

Expand Down Expand Up @@ -1752,7 +1751,7 @@ def test_select_bls(casa_uvfits):
assert pair in sorted_pairs_to_keep

assert uvutils._check_histories(
old_history + " Downselected to specific baselines using pyuvdata.",
old_history + " Downselected to specific antenna pairs using pyuvdata.",
uv_object2.history,
)

Expand Down Expand Up @@ -1791,12 +1790,13 @@ def test_select_bls(casa_uvfits):

with pytest.raises(
ValueError,
match="Cannot provide length-3 tuples and also specify polarizations.",
match="Cannot provide any length-3 tuples and also specify polarizations.",
):
uv_object.select(bls=(7, 1, "RR"), polarizations="RR")

with pytest.raises(
ValueError, match="The third element in each bl must be a polarization string"
ValueError,
match="The third element in a bl tuple must be a polarization string",
):
uv_object.select(bls=(7, 1, 7))

Expand Down Expand Up @@ -2745,7 +2745,7 @@ def test_select(casa_uvfits, future_shapes):
assert uvutils._check_histories(
old_history + " Downselected to "
"specific baseline-times, antennas, "
"baselines, times, frequencies, "
"antenna pairs, times, frequencies, "
"polarizations using pyuvdata.",
uv_object2.history,
)
Expand Down Expand Up @@ -2853,7 +2853,7 @@ def test_select_with_lst(casa_uvfits, future_shapes):
assert uvutils._check_histories(
old_history + " Downselected to "
"specific baseline-times, antennas, "
"baselines, lsts, frequencies, "
"antenna pairs, lsts, frequencies, "
"polarizations using pyuvdata.",
uv_object2.history,
)
Expand Down
Loading

0 comments on commit bc69f98

Please sign in to comment.