diff --git a/CHANGELOG.md b/CHANGELOG.md index b31d6df78..c9addfc6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Changed +- When reading MWAX correlator files , `remove_coarse_band` now defaults to +`False` if DERIPPLE is on. Otherwise it defaults to `True`. +- If the user has set `remove_coarse_band=True` when DERIPPLE is on, a warning is +raised, and no pfb shape is removed. ### Added - A NotImplementedError to `mwa_corr_fits.py` that is thrown when trying to read diff --git a/src/pyuvdata/uvdata/mwa_corr_fits.py b/src/pyuvdata/uvdata/mwa_corr_fits.py index 768b5dc38..85d35eafd 100644 --- a/src/pyuvdata/uvdata/mwa_corr_fits.py +++ b/src/pyuvdata/uvdata/mwa_corr_fits.py @@ -1513,7 +1513,7 @@ def read_mwa_corr_fits( keep_all_metadata=True, use_aoflagger_flags=None, remove_dig_gains=True, - remove_coarse_band=True, + remove_coarse_band=None, correct_cable_len=True, correct_van_vleck=False, cheby_approx=True, @@ -1745,6 +1745,29 @@ def read_mwa_corr_fits( if key not in self.extra_keywords: self.extra_keywords[key] = value + if remove_coarse_band is None: + if ( + "DERIPPLE" in self.extra_keywords + and self.extra_keywords["DERIPPLE"] == 1 + ): + remove_coarse_band = False + else: + remove_coarse_band = True + elif ( + remove_coarse_band is True + and "DERIPPLE" in self.extra_keywords + and self.extra_keywords["DERIPPLE"] == 1 + ): + # turn off pfb correction if it was corrected in the correlator + warnings.warn( + "No coarse band shape will be removed from this data " + "because DERIPPLE is on.", + stacklevel=2, + ) + remove_coarse_band = False + else: + pass + # set parameters from other parameters self.telescope.Nants = len(self.telescope.antenna_numbers) self.Nants_data = len(self.telescope.antenna_numbers) diff --git a/tests/uvdata/test_mwa_corr_fits.py b/tests/uvdata/test_mwa_corr_fits.py index 86731fee4..4ead3baca 100644 --- a/tests/uvdata/test_mwa_corr_fits.py +++ b/tests/uvdata/test_mwa_corr_fits.py @@ -1711,3 +1711,43 @@ def test_fringe_stopping_error(tmp_path): NotImplementedError, match="This data has had fringe stopping applied. " ): UVData.from_file([test_metafits, fetch_data("mwax_2021_raw_gpubox")]) + + +@pytest.mark.filterwarnings("ignore:some coarse channel files were not submitted") +@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only") +def test_deripple_on_warns_and_passes(tmp_path): + test_metafits = str(tmp_path / "1131733552_dr.metafits") + with fits.open(fetch_data("mwax_2021_metafits")) as meta: + meta[0].header["DERIPPLE"] = 1 + meta.writeto(test_metafits) + with pytest.warns(UserWarning, match="No coarse band shape will be removed"): + uvd = UVData.from_file( + [test_metafits, fetch_data("mwax_2021_raw_gpubox")], remove_coarse_band=True + ) + assert "Divided out pfb coarse channel bandpass" not in uvd.history + + +@pytest.mark.filterwarnings("ignore:some coarse channel files were not submitted") +@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only") +def test_deripple_remove_coarse_band_none(tmp_path): + test_metafits = str(tmp_path / "1131733551_dr.metafits") + with fits.open(fetch_data("mwax_2021_metafits")) as meta: + meta[0].header["DERIPPLE"] = 1 + meta.writeto(test_metafits) + uvd = UVData.from_file( + [test_metafits, fetch_data("mwax_2021_raw_gpubox")], remove_coarse_band=None + ) + assert "Divided out pfb coarse channel bandpass" not in uvd.history + + +@pytest.mark.filterwarnings("ignore:some coarse channel files were not submitted") +@pytest.mark.filterwarnings("ignore:Fixing auto-correlations to be be real-only") +def test_deripple_off_does_nothing(tmp_path): + test_metafits = str(tmp_path / "1131733550_dr.metafits") + with fits.open(fetch_data("mwax_2021_metafits")) as meta: + meta[0].header["DERIPPLE"] = 0 + meta.writeto(test_metafits) + uvd = UVData.from_file( + [test_metafits, fetch_data("mwax_2021_raw_gpubox")], remove_coarse_band=True + ) + assert "Divided out pfb coarse channel bandpass" in uvd.history