Skip to content

Commit

Permalink
Making requested changes following review
Browse files Browse the repository at this point in the history
  • Loading branch information
kartographer committed Feb 13, 2024
1 parent 943b2b9 commit aa4bd2f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 32 deletions.
32 changes: 21 additions & 11 deletions pyuvdata/uvdata/mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ def _init_from_mir_parser(
spdx_dict = {}
spw_dict = {}
for spdx in set(spdx_list):
# We need to do a some extra handling here, because a single correlator
# can produce multiple spectral windows (e.g., LSB/USB). The scheme below
# will negate the corr band number if LSB, will set the corr band number to
# 255 if the values arise from the pseudo-wideband values, and will add 512
# if the pols are split-tuned. This scheme, while a little funky, guarantees
# that each unique freq range has its own spectral window number.
spw_id = 255 if (spdx[0] == 0) else spdx[0]
spw_id *= (-1) ** (1 + spdx[1])
spw_id += 512 if (pol_split_tuning and spdx[2] == 1) else 0

data_mask = np.array([spdx == item for item in spdx_list])

# Grab values, get them into appropriate types
Expand All @@ -430,24 +440,16 @@ def _init_from_mir_parser(
):
if not np.allclose(val, mir_data.sp_data[item][data_mask]):
warnings.warn(
"Discrepancy in %s for win %i sb %i pol %i." % (item, *spdx)
"Discrepancy in %s for win %i sb %i pol %i. Values of "
"`freq_array` and `channel_width` should be checked for "
"channels corresponding to spw_id %i." % (item, *spdx, spw_id)
)

# Get the data in the right units and dtype
spw_fsky = float(spw_fsky * 1e9) # GHz -> Hz
spw_fres = float(spw_fres * 1e6) # MHz -> Hz
spw_nchan = int(spw_nchan)

# We need to do a some extra handling here, because a single correlator
# can produce multiple spectral windows (e.g., LSB/USB). The scheme below
# will negate the corr band number if LSB, will set the corr band number to
# 255 if the values arise from the pseudo-wideband values, and will add 512
# if the pols are split-tuned. This scheme, while a little funky, guarantees
# that each unique freq range has its own spectral window number.
spw_id = 255 if (spdx[0] == 0) else spdx[0]
spw_id *= (-1) ** (1 + spdx[1])
spw_id += 512 if (pol_split_tuning and spdx[2] == 1) else 0

# Populate the channel width array
channel_width = abs(spw_fres) + np.zeros(spw_nchan, dtype=np.float64)

Expand Down Expand Up @@ -675,6 +677,14 @@ def _init_from_mir_parser(
# If this check fails, it means that there's something off w/ the lst values
# (to a larger degree than expected), and we'll pass them back to the user,
# who can inspect them directly and decide what to do.
warnings.warn(
"> 25 ms errors detected reading in LST values from MIR data. "
"This typically signifies a minor metadata recording error (which can "
"be mitigated by calling the `set_lsts_from_time_array` method with "
"`update_vis=False`), though additional errors about uvw-position "
"accuracy may signal more significant issues with metadata accuracy "
"that could have substantial impact on downstream analysis."
)
self.lst_array = lst_array

self.polarization_array = polarization_array
Expand Down
6 changes: 4 additions & 2 deletions pyuvdata/uvdata/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ def sma_mir_main():
testfile = os.path.join(DATA_PATH, "sma_test.mir")
with uvtest.check_warnings(
UserWarning,
match="The lst_array is not self-consistent with the time_array and telescope "
"location. Consider recomputing with the `set_lsts_from_time_array` method.",
match=[
"> 25 ms errors detected reading in LST values from MIR data. ",
"The lst_array is not self-consistent with the time_array and telescope ",
],
):
uv_object.read(testfile, use_future_array_shapes=True)
uv_object.set_lsts_from_time_array()
Expand Down
56 changes: 42 additions & 14 deletions pyuvdata/uvdata/tests/test_mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def sma_mir_filt_main():
uv_object = UVData()
with uvtest.check_warnings(
UserWarning,
match="The lst_array is not self-consistent with the time_array and telescope "
"location. Consider recomputing with the `set_lsts_from_time_array` method.",
match=[
"> 25 ms errors detected reading in LST values from MIR data. ",
"The lst_array is not self-consistent with the time_array and telescope ",
],
):
uv_object.read(
sma_mir_test_file,
Expand Down Expand Up @@ -265,10 +267,9 @@ def test_mir_partial_read(sma_mir):
match=[
"Warning: a select on read keyword is set that is not supported by "
"read_mir. This select will be done after reading the file.",
"The lst_array is not self-consistent with the time_array and telescope "
"location. Consider recomputing with the `set_lsts_from_time_array` method",
"The lst_array is not self-consistent with the time_array and telescope "
"location. Consider recomputing with the `set_lsts_from_time_array` method",
"> 25 ms errors detected reading in LST values from MIR data. ",
"The lst_array is not self-consistent with the time_array and telescope ",
"The lst_array is not self-consistent with the time_array and telescope ",
],
):
uv3 = UVData.from_file(
Expand Down Expand Up @@ -303,8 +304,10 @@ def test_multi_nchan_spw_read(tmp_path):
uv_in = UVData()
with uvtest.check_warnings(
UserWarning,
match="The lst_array is not self-consistent with the time_array and telescope "
"location. Consider recomputing with the `set_lsts_from_time_array` method.",
match=[
"> 25 ms errors detected reading in LST values from MIR data. ",
"The lst_array is not self-consistent with the time_array and telescope ",
],
):
uv_in.read_mir(sma_mir_test_file, corrchunk=[0, 1, 2, 3, 4])
uv_in.set_lsts_from_time_array()
Expand All @@ -315,6 +318,7 @@ def test_multi_nchan_spw_read(tmp_path):


@pytest.mark.filterwarnings("ignore:The lst_array is not self-consistent with the.")
@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_read_mir_write_ms_flex_pol(mir_data, tmp_path):
"""
Mir to MS loopback test with flex-pol.
Expand Down Expand Up @@ -393,7 +397,13 @@ def test_inconsistent_sp_records(mir_data, sma_mir):

mir_uv = UVData()
mir_obj = Mir()
with uvtest.check_warnings(UserWarning, "Per-spectral window metadata differ."):
with uvtest.check_warnings(
UserWarning,
match=[
"Per-spectral window metadata differ.",
"> 25 ms errors detected reading in LST values",
],
):
mir_obj._init_from_mir_parser(mir_data)
mir_uv._convert_from_filetype(mir_obj)
mir_uv.use_future_array_shapes()
Expand All @@ -411,7 +421,13 @@ def test_inconsistent_bl_records(mir_data, sma_mir):
mir_data.load_data()
mir_uv = UVData()
mir_obj = Mir()
with uvtest.check_warnings(UserWarning, "Per-baseline metadata differ."):
with uvtest.check_warnings(
UserWarning,
match=[
"> 25 ms errors detected reading in LST values",
"Per-baseline metadata differ.",
],
):
mir_obj._init_from_mir_parser(mir_data)
mir_uv._convert_from_filetype(mir_obj)
mir_uv.use_future_array_shapes()
Expand All @@ -420,6 +436,7 @@ def test_inconsistent_bl_records(mir_data, sma_mir):
assert mir_uv == sma_mir


@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_multi_ipol(mir_data, sma_mir):
"""
Test that the MIR object does the right thing when different polarization types
Expand Down Expand Up @@ -621,6 +638,7 @@ def test_flex_pol_spw_all_flag(sma_mir_filt):
assert np.all(sma_mir_filt.flex_spw_polarization_array == -5)


@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_bad_sphid(mir_data):
"""
Test what bad values for sphid in sp_data result in an error.
Expand All @@ -636,6 +654,7 @@ def test_bad_sphid(mir_data):
assert str(err.value).startswith("'Mismatch between keys in vis_data and sphid")


@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_bad_pol_code(mir_data):
"""
Test that an extra (unused) pol code doesn't produce an error. Note that we want
Expand All @@ -652,6 +671,7 @@ def test_bad_pol_code(mir_data):


@pytest.mark.filterwarnings("ignore:The lst_array is not self-consistent")
@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_rechunk_on_read():
"""Test that rechunking on read works as expected."""
uv_data = UVData.from_file(
Expand All @@ -664,6 +684,7 @@ def test_rechunk_on_read():


@pytest.mark.filterwarnings("ignore:The lst_array is not self-consistent")
@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
@pytest.mark.parametrize(
"select_kwargs",
[
Expand All @@ -688,6 +709,7 @@ def test_select_on_read(select_kwargs, sma_mir):
assert sma_mir == uv_data


@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_non_icrs_coord_read(mir_data):
# When fed a non-J2000 coordinate, we want to convert that so that it can easily
mir_uv = UVData()
Expand All @@ -714,6 +736,7 @@ def test_non_icrs_coord_read(mir_data):
)


@pytest.mark.filterwarnings("ignore:> 25 ms errors detected reading in LST values")
def test_dedoppler_data(mir_data, sma_mir):
mir_uv = UVData()
mir_obj = Mir()
Expand Down Expand Up @@ -763,14 +786,16 @@ def test_source_pos_change_warning(mir_data, tmp_path):
):
mir_copy.__iadd__(mir_data, force=True, merge=False)

print(mir_copy.auto_data)

# Muck the ra coord
mir_copy.in_data["rar"] = [0, 1]
mir_obj = Mir()

with uvtest.check_warnings(
UserWarning, "Position for 3c84 changes by more than an arcminute."
UserWarning,
[
"> 25 ms errors detected reading in LST values",
"Position for 3c84 changes by more than an arcminute.",
],
):
mir_obj._init_from_mir_parser(mir_copy)

Expand All @@ -797,5 +822,8 @@ def test_spw_consistency_warning(mir_data):
mir_data.bl_data._data["ant2rx"][:] = 0

mir_uv = Mir()
with uvtest.check_warnings(UserWarning, match="Discrepancy in fres"):
with uvtest.check_warnings(
UserWarning,
match=["Discrepancy in fres", "> 25 ms errors detected reading in LST values"],
):
mir_uv._init_from_mir_parser(mir_data)
21 changes: 16 additions & 5 deletions pyuvdata/uvdata/tests/test_uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11987,11 +11987,22 @@ def test_set_nsamples_wrong_shape_error(hera_uvh5):
["zen.2458661.23480.HH.uvh5", ""],
[
"sma_test.mir",
(
"The lst_array is not self-consistent with the time_array and telescope"
" location. Consider recomputing with the `set_lsts_from_time_array`"
" method"
),
[
(
"The lst_array is not self-consistent with the time_array and "
"telescope location. Consider recomputing with the "
"`set_lsts_from_time_array` method"
),
(
"> 25 ms errors detected reading in LST values from MIR data. "
"This typically signifies a minor metadata recording error (which "
"can be mitigated by calling the `set_lsts_from_time_array` method "
"with `update_vis=False`), though additional errors about "
"uvw-position accuracy may signal more significant issues with "
"metadata accuracy that could have substantial impact on "
"downstream analysis."
),
],
],
[
"carma_miriad",
Expand Down

0 comments on commit aa4bd2f

Please sign in to comment.