Skip to content

Commit

Permalink
Add an error if parameters are not properly passed to flag_init method
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Oct 30, 2024
1 parent 82f8875 commit ca32d4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/pyuvdata/uvdata/mwa_corr_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def correct_cable_length(self, cable_lens, ant_1_inds, ant_2_inds):
def flag_init(
self,
num_fine_chan,
*,
edge_width=80e3,
start_flag=2.0,
end_flag=0.0,
Expand All @@ -551,6 +552,9 @@ def flag_init(
Parameters
----------
num_fine_chans : int
Number of fine channels in each data file (number of fine channels
per coarse channel).
edge_width: float
The width to flag on the edge of each coarse channel, in hz. Set to
0 for no edge flagging.
Expand All @@ -565,7 +569,8 @@ def flag_init(
freq_inds : array_like of int, optional
Frequency indices that were kept if frequency selection was done.
n_orig_freq : int, optional
Number of original frequencies if frequency selection was done.
Number of original frequencies if frequency selection was done. Must
be passed if freq_inds is not None.
Raises
------
Expand All @@ -576,6 +581,8 @@ def flag_init(
(0 also acceptable).
If end_flag is not an integer multiple of the integration time
(0 also acceptable).
AssertionError
If freq_inds is not None and n_orig_freq is None.
"""
if (edge_width % self.channel_width[0]) > 0:
Expand All @@ -594,6 +601,11 @@ def flag_init(
"integration_time of the data or zero."
)

if freq_inds is not None and n_orig_freq is None:
raise AssertionError(
"If freq_inds is not None, n_orig_freq must be passed."
)

num_ch_flag = int(edge_width / self.channel_width[0])
num_start_flag = int(start_flag / self.integration_time[0])
num_end_flag = int(end_flag / self.integration_time[0])
Expand Down Expand Up @@ -680,7 +692,8 @@ def _read_fits_file(
file_nums : array
List of included file numbers ordered by coarse channel
num_fine_chans : int
Number of fine channels in each data file
Number of fine channels in each data file (number of fine channels
per coarse channel).
int_time : float
The integration time of each observation.
map_inds : array
Expand Down
16 changes: 16 additions & 0 deletions tests/uvdata/test_mwa_corr_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,22 @@ def test_flag_init_errors(flag_file_init, err_type, read_kwargs, err_msg):
uv.read(flag_file_init, **read_kwargs)


@pytest.mark.filterwarnings(
"ignore:coarse channels are not contiguous for this observation"
)
@pytest.mark.filterwarnings("ignore:some coarse channel files were not submitted")
def test_flag_init_error_freq_sel(flag_file_init):
from pyuvdata.uvdata.mwa_corr_fits import MWACorrFITS

mwa_obj = MWACorrFITS()
mwa_obj.read_mwa_corr_fits(flag_file_init, flag_init=False)

with pytest.raises(
AssertionError, match="If freq_inds is not None, n_orig_freq must be passed."
):
mwa_obj.flag_init(32, freq_inds=np.arange(10), n_orig_freq=None)


def test_read_metadata_only(tmp_path):
"""Test reading an MWA corr fits file as metadata only."""
uvd = UVData()
Expand Down

0 comments on commit ca32d4c

Please sign in to comment.