Skip to content

Commit

Permalink
fix warning filtering for current and future pyuvdata
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed May 15, 2024
1 parent 62709cc commit 8a92b92
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
2 changes: 2 additions & 0 deletions hera_qm/tests/test_firstcal_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import pytest

pytestmark = pytest.mark.filterwarnings(
# this top one can be removed when we require pyuvdata >= 3.0
"ignore:.*Using known values for HERA",
"ignore:.*using values from known telescopes for HERA",
"ignore:.*Increasing the bound and calling fit again may find a better value",
"ignore:.*Decreasing the bound and calling fit again may find a better value",

Expand Down
2 changes: 2 additions & 0 deletions hera_qm/tests/test_omnical_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import numpy as np

pytestmark = pytest.mark.filterwarnings(
# this top one can be removed when we require pyuvdata >= 3.0
"ignore:.*Using known values for HERA",
"ignore:.*using values from known telescopes for HERA",
)

@pytest.fixture(scope='function')
Expand Down
9 changes: 7 additions & 2 deletions hera_qm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
from pathlib import Path

pytestmark = pytest.mark.filterwarnings(
# this top one can be removed when we require pyuvdata >= 3.0
"ignore:.*Using known values for HERA",
"ignore:.*using values from known telescopes for HERA",
"ignore:The uvw_array does not match the expected values given the antenna positions.",
"ignore:telescope_location is not set. Using known values for HERA.",
"ignore:antenna_positions is not set. Using known values for HERA.",
)


def test_get_metrics_ArgumentParser_ant_metrics():
a = utils.get_metrics_ArgumentParser('ant_metrics')
# First try defaults - test a few of them
Expand Down Expand Up @@ -346,6 +348,9 @@ def test_apply_yaml_flags_uvdata(tmpdir, filein, flag_freqs, flag_times, flag_an



# this top one can be removed when we require pyuvdata >= 3.0
@pytest.mark.filterwarnings("ignore:Cannot preserve total_quality_array when")
@pytest.mark.filterwarnings("ignore:Changing number of antennas, but preserving")
@pytest.mark.parametrize(
"filein",
["a_priori_flags_integrations.yaml",
Expand Down
61 changes: 27 additions & 34 deletions hera_qm/tests/test_xrfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
test_uvh5_files[cnum] = os.path.join(DATA_PATH, uvf)

pytestmark = pytest.mark.filterwarnings(
"ignore:The uvw_array does not match the expected values given the antenna positions.",
# this top one can be removed when we require pyuvdata >= 3.0
"ignore:.*Using known values for HERA",
"ignore:.*using values from known telescopes for HERA",
"ignore:The uvw_array does not match the expected values given the antenna positions.",
)

rng = np.random.default_rng(0)
Expand Down Expand Up @@ -1111,6 +1113,7 @@ def test_unflag():
assert True


@pytest.mark.filterwarnings("ignore:instrument is not the same")
def test_flag_apply(
uvdata_miriad,
uvflag_flag_miriad,
Expand Down Expand Up @@ -1399,6 +1402,14 @@ def test_xrfi_run_step(tmpdir):
with pytest.raises(ValueError):
xrfi.xrfi_run_step(uv_files=ocal_file, calculate_uvf_apriori=True, run_filter=True, reinitialize=True, dtype='uvwhatever')



# TODO: check whether invalid value encountered in subtract warning is expected
@pytest.mark.filterwarnings("ignore:invalid value encountered in subtract:RuntimeWarning")
@pytest.mark.filterwarnings("ignore:Mean of empty slice:RuntimeWarning")
@pytest.mark.filterwarnings("ignore:Degrees of freedom <= 0 for slice:RuntimeWarning")
@pytest.mark.filterwarnings("ignore::astropy.utils.exceptions.AstropyUserWarning")
@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
def test_xrfi_run_yaml_flags(tmpdir):
# test xrfi_run with yaml pre-flagging.

Expand Down Expand Up @@ -1469,23 +1480,10 @@ def test_xrfi_run_yaml_flags(tmpdir):

# now test apriori flag file.
# test for different integrations modes (lsts, jds, integrations)
msg = ['This object is already a waterfall'] * 8 + [
"antenna_diameters are not set or are being overwritten. antenna_diameters "
"are set using values from known telescopes for HERA."
] * 2
for test_flag in [a_priori_flag_integrations, a_priori_flag_jds, a_priori_flag_lsts]:
with check_warnings(UserWarning, match=msg):
# TODO: check whether this warning is expected
warnings.filterwarnings("ignore", category=RuntimeWarning, message="invalid value encountered in subtract")
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Mean of empty slice")
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Degrees of freedom <= 0 for slice")

warnings.filterwarnings("ignore", category=AstropyUserWarning)

xrfi.xrfi_run(ocal_file, acal_file, model_file, raw_dfile,
a_priori_flag_yaml=test_flag, history='Just a test',
kt_size=3, throw_away_edges=False)

xrfi.xrfi_run(ocal_file, acal_file, model_file, raw_dfile,
a_priori_flag_yaml=test_flag, history='Just a test',
kt_size=3, throw_away_edges=False)

for ext, label in ext_labels.items():
# by default, only cross median filter / mean filter is not performed.
Expand Down Expand Up @@ -1513,7 +1511,6 @@ def test_xrfi_run_yaml_flags(tmpdir):
os.remove(out)

@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
@pytest.mark.filterwarnings("ignore:antenna_diameters are not set")
def test_xrfi_run(tmpdir):
# The warnings are because we use UVFlag.to_waterfall() on the total chisquareds
# This doesn't hurt anything, and lets us streamline the pipe
Expand Down Expand Up @@ -1817,8 +1814,7 @@ def test_xrfi_run(tmpdir):
os.remove(fname)

@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
@pytest.mark.filterwarnings("ignore:antenna_diameters are not set")
@pytest.mark.filterwarnings("ignore:x_orientation is not the same this object")
@pytest.mark.filterwarnings("ignore:x_orientation is not the same")
def test_xrfi_run_edgeflag(tmpdir):
# test that flags within kt_size are flagged.
# first try out a single file.
Expand Down Expand Up @@ -1888,7 +1884,7 @@ def test_xrfi_run_edgeflag(tmpdir):
if ext not in ['cross_metrics1', 'cross_flags1']:
out = os.path.join(outdir, '.'.join([fake_obs, ext, 'h5']))
assert os.path.exists(out)
uvf = UVFlag(out)
uvf = UVFlag(out, use_future_array_shapes=True)
if ext == 'flags2.h5':
# check that two within edges are flagged
assert np.all(uvf.flag_array[:2])
Expand Down Expand Up @@ -1927,7 +1923,7 @@ def test_xrfi_run_edgeflag(tmpdir):
xrfi.xrfi_run(ocal_files, acal_files, model_files, raw_dfiles, history='Just a test', kt_size=1)
flags2 = sorted(glob.glob(tmp_path + '/*.xrfi/*.HH.flags2.h5'))
assert len(flags2) == 3
uvf = UVFlag(flags2)
uvf = UVFlag(flags2, use_future_array_shapes=True)
# check that two within edges are flagged
assert np.all(uvf.flag_array[:1])
assert np.all(uvf.flag_array[-1:])
Expand All @@ -1937,8 +1933,7 @@ def test_xrfi_run_edgeflag(tmpdir):


@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
@pytest.mark.filterwarnings("ignore:antenna_diameters are not set")
@pytest.mark.filterwarnings("ignore:x_orientation is not the same this object")
@pytest.mark.filterwarnings("ignore:x_orientation is not the same")
def test_xrfi_run_multifile(tmpdir):
# test xrfi_run with multiple files
# The warnings are because we use UVFlag.to_waterfall() on the total chisquareds
Expand Down Expand Up @@ -2019,7 +2014,7 @@ def test_xrfi_run_multifile(tmpdir):
# by default, only cross median filter / mean filter is not performed.
out = os.path.join(outdir, '.'.join([fake_obs, ext, 'h5']))
assert os.path.exists(out)
uvf = UVFlag(out)
uvf = UVFlag(out, use_future_array_shapes=True)
assert uvf.label == label
# all of flags2 should be flagged with this kt_size.
if ext == 'flags2.h5':
Expand All @@ -2038,7 +2033,7 @@ def test_xrfi_run_multifile(tmpdir):
# by default, only cross median filter / mean filter is not performed.
out = os.path.join(outdir, '.'.join([fake_obs, ext, 'h5']))
assert os.path.exists(out)
uvf = UVFlag(out)
uvf = UVFlag(out, use_future_array_shapes=True)
assert uvf.label == label
# if we don't throw away the edges, then there shouldn't be flags
# at the edge.
Expand Down Expand Up @@ -2133,13 +2128,7 @@ def test_day_threshold_run_yaml(tmpdir):
model_file = os.path.join(tmp_path, fake_obses[0] + '.omni_vis.uvh5')
shutil.copyfile(test_uvh5_file, model_file)

# check warnings
msg = ['This object is already a waterfall'] * 8 + [
"antenna_diameters are not set or are being overwritten. antenna_diameters "
"are set using values from known telescopes for HERA."
] * 2
with check_warnings(UserWarning, match=msg):
xrfi.xrfi_run(ocal_file, acal_file, model_file, raw_dfile, history='Just a test', kt_size=3, throw_away_edges=False)
xrfi.xrfi_run(ocal_file, acal_file, model_file, raw_dfile, history='Just a test', kt_size=3, throw_away_edges=False)

# Need to adjust time arrays when duplicating files
uvd = UVData.from_file(data_files[0], use_future_array_shapes=True)
Expand Down Expand Up @@ -2174,6 +2163,7 @@ def test_day_threshold_run_yaml(tmpdir):
assert os.path.exists(calfile)

@pytest.mark.filterwarnings("ignore:All-NaN slice encountered")
@pytest.mark.filterwarnings("ignore:instrument is not the same")
def test_day_threshold_run_data_only(tmpdir):
# The warnings are because we use UVFlag.to_waterfall() on the total chisquareds
# This doesn't hurt anything, and lets us streamline the pipe
Expand Down Expand Up @@ -2228,7 +2218,6 @@ def test_day_threshold_run_data_only(tmpdir):


@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
@pytest.mark.filterwarnings("ignore:antenna_diameters are not set")
def test_day_threshold_run_cal_only(tmpdir):
# The warnings are because we use UVFlag.to_waterfall() on the total chisquareds
# This doesn't hurt anything, and lets us streamline the pipe
Expand Down Expand Up @@ -2298,6 +2287,8 @@ def test_day_threshold_run_cal_only(tmpdir):
calfile = os.path.join(tmp_path, fake_obs + '.flagged_abs.calfits')
assert os.path.exists(calfile)


@pytest.mark.filterwarnings("ignore:instrument is not the same")
def test_day_threshold_run_omnivis_only(tmpdir):
# The warnings are because we use UVFlag.to_waterfall() on the total chisquareds
# This doesn't hurt anything, and lets us streamline the pipe
Expand Down Expand Up @@ -2489,6 +2480,7 @@ def test_xrfi_h1c_run_indata_string_filename_not_string():
filename=3)


@pytest.mark.filterwarnings("ignore:writing default values for restfreq")
def test_xrfi_h1c_apply():
xrfi_path = os.path.join(DATA_PATH, 'test_output')
wf_file1 = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA.omni.calfits.g.flags.h5')
Expand Down Expand Up @@ -2664,6 +2656,7 @@ def test_threshold_wf_exceptions(uvflag_f):


@pytest.mark.filterwarnings("ignore:This object is already a waterfall")
@pytest.mark.filterwarnings("ignore:instrument is not the same")
def test_xrfi_h3c_idr2_1_run(tmp_path, uvcal_calfits):

dec_jds = ['40355', '41101', '41847', '42593', '43339', '44085', '44831']
Expand Down

0 comments on commit 8a92b92

Please sign in to comment.