Skip to content

Commit

Permalink
Merge pull request #463 from HERA-Team/fix_pyuvdata_v3
Browse files Browse the repository at this point in the history
Updates for pyuvdata v3
  • Loading branch information
steven-murray authored Jun 14, 2024
2 parents 781549e + c601215 commit 6e86921
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
37 changes: 21 additions & 16 deletions hera_qm/tests/test_metrics_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import numpy as np
import os
import h5py
import pyuvdata.tests as uvtest
try:
from pyuvdata.testing import check_warnings
except ImportError:
# this can be removed once we require pyuvdata >= v3.0
from pyuvdata.tests import check_warnings

from hera_qm.data import DATA_PATH
from hera_qm import metrics_io
import hera_qm.tests as qmtest
Expand Down Expand Up @@ -195,7 +200,7 @@ def test_write_metric_warning_json():
warn_message = ["JSON-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility."]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
json_dict = metrics_io.write_metric_file(json_file, test_dict, overwrite=True)
Expand All @@ -212,7 +217,7 @@ def test_write_metric_warning_pickle():
warn_message = ["Pickle-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility."]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
pickle_dict = metrics_io.write_metric_file(
Expand Down Expand Up @@ -291,15 +296,15 @@ def test_write_then_load_metric_warning_json():
warn_message = ["JSON-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
metrics_io.write_metric_file(json_file, test_dict, overwrite=True)
assert os.path.exists(json_file)
# output_json = metrics_io.write_metric_file(json_file, test_dict)
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
json_dict = metrics_io.load_metric_file(json_file)
Expand All @@ -317,15 +322,15 @@ def test_write_then_load_metric_warning_pickle():
warn_message = ["Pickle-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
metrics_io.write_metric_file(pickle_file, test_dict, overwrite=True)
assert os.path.exists(pickle_file)
# output_json = metrics_io.write_metric_file(json_file, test_dict)
warn_message = ["Pickle-type files can still be read but are no longer "
"written by default.\n"]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
pickle_dict = metrics_io.load_metric_file(pickle_file)
Expand All @@ -343,7 +348,7 @@ def test_read_write_old_firstcal_json_files():
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
test_metrics = metrics_io.load_metric_file(json_infile)
Expand All @@ -368,7 +373,7 @@ def test_read_write_old_omnical_json_files():
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
test_metrics = metrics_io.load_metric_file(json_infile)
Expand Down Expand Up @@ -397,7 +402,7 @@ def test_read_write_new_ant_json_files():
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
test_metrics = metrics_io.load_metric_file(json_infile)
Expand Down Expand Up @@ -425,11 +430,11 @@ def test_read_old_all_string_ant_json_files():
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
test_metrics_old = metrics_io.load_metric_file(old_json_infile)
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
test_metrics_new = metrics_io.load_metric_file(new_json_infile)
Expand Down Expand Up @@ -482,13 +487,13 @@ def test_boolean_read_write_json():
warn_message = ["JSON-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
metrics_io.write_metric_file(test_file, test_dict, overwrite=True)
warn_message = ["JSON-type files can still be read but are no longer "
"written by default.\n"]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
json_dict = metrics_io.load_metric_file(test_file)
Expand All @@ -505,14 +510,14 @@ def test_boolean_read_write_pickle():
warn_message = ["Pickle-type files can still be written but are no longer "
"written by default.\n"
"Write to HDF5 format for future compatibility.", ]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
metrics_io.write_metric_file(test_file, test_dict)

warn_message = ["Pickle-type files can still be read but are no longer "
"written by default.\n"]
with uvtest.check_warnings(
with check_warnings(
PendingDeprecationWarning, match=warn_message, nwarnings=1
):
input_dict = metrics_io.load_metric_file(test_file)
Expand Down
18 changes: 11 additions & 7 deletions hera_qm/tests/test_xrfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import shutil
import hera_qm.xrfi as xrfi
import numpy as np
import pyuvdata.tests as uvtest
try:
from pyuvdata.testing import check_warnings
except ImportError:
# this can be removed once we require pyuvdata >= v3.0
from pyuvdata.tests import check_warnings

from pyuvdata import UVData
from pyuvdata import UVCal
import hera_qm.utils as utils
Expand All @@ -14,7 +19,6 @@
import glob
import hera_qm.ant_class as ant_class
from hera_cal import io
from pyuvdata.tests import check_warnings
from astropy.utils.exceptions import AstropyUserWarning
import warnings

Expand Down Expand Up @@ -361,7 +365,7 @@ def test_check_convolve_dims_3D():
def test_check_convolve_dims_1D():
size = 10
d = np.ones(size)
with uvtest.check_warnings(
with check_warnings(
UserWarning,
match=f"K1 value {size + 1} is larger than the data",
nwarnings=1
Expand All @@ -373,7 +377,7 @@ def test_check_convolve_dims_1D():
def test_check_convolve_dims_kernel_not_given():
size = 10
d = np.ones((size, size))
with uvtest.check_warnings(
with check_warnings(
UserWarning,
match=["No K1 input provided.", "No K2 input provided"],
nwarnings=2
Expand All @@ -386,7 +390,7 @@ def test_check_convolve_dims_kernel_not_given():
def test_check_convolve_dims_Kt_too_big():
size = 10
d = np.ones((size, size))
with uvtest.check_warnings(
with check_warnings(
UserWarning,
match=f"K1 value {size + 1} is larger than the data",
nwarnings=1,
Expand All @@ -399,7 +403,7 @@ def test_check_convolve_dims_Kt_too_big():
def test_check_convolve_dims_Kf_too_big():
size = 10
d = np.ones((size, size))
with uvtest.check_warnings(
with check_warnings(
UserWarning,
match=f"K2 value {size + 1} is larger than the data",
nwarnings=1,
Expand Down Expand Up @@ -632,7 +636,7 @@ def test_detrend_medfilt():
# run detrend medfilt
Kt = 101
Kf = 101
with uvtest.check_warnings(
with check_warnings(
UserWarning,
match=[
f"K1 value {Kt} is larger than the data",
Expand Down

0 comments on commit 6e86921

Please sign in to comment.