From 154b6ccf8f2ba567449137f3e20c9e81a8dadfbb Mon Sep 17 00:00:00 2001 From: Bryna Hazelton Date: Tue, 21 May 2024 13:26:13 -0700 Subject: [PATCH] Fix warning handling for pyuvdata v3.0 --- hera_qm/firstcal_metrics.py | 7 +- hera_qm/omnical_metrics.py | 11 +- hera_qm/tests/test_utils.py | 4 + hera_qm/tests/test_vis_metrics.py | 18 ++- hera_qm/tests/test_xrfi.py | 77 +++++++++---- hera_qm/utils.py | 6 +- hera_qm/xrfi.py | 176 ++++++++++++++++++++---------- 7 files changed, 205 insertions(+), 94 deletions(-) diff --git a/hera_qm/firstcal_metrics.py b/hera_qm/firstcal_metrics.py index df611f98..c77204d9 100644 --- a/hera_qm/firstcal_metrics.py +++ b/hera_qm/firstcal_metrics.py @@ -10,6 +10,7 @@ from . import utils, metrics_io import copy import os +import warnings try: from sklearn import gaussian_process as gp @@ -343,7 +344,11 @@ def __init__(self, calfits_files, use_gp=True): """ # Instantiate UVCal and read calfits self.UVC = UVCal() - self.UVC.read_calfits(calfits_files, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", "Future array shapes are now always used" + ) + self.UVC.read_calfits(calfits_files, use_future_array_shapes=True) if hasattr(self.UVC, "telescope"): x_orientation = self.UVC.telescope.x_orientation diff --git a/hera_qm/omnical_metrics.py b/hera_qm/omnical_metrics.py index f2628bbd..6161bb4e 100644 --- a/hera_qm/omnical_metrics.py +++ b/hera_qm/omnical_metrics.py @@ -176,10 +176,9 @@ def load_firstcal_gains(fc_file): uvc = UVCal() with warnings.catch_warnings(): warnings.filterwarnings( - "ignore", "The shapes of several attributes" + "ignore", "Future array shapes are now always used" ) - uvc.read_calfits(fc_file) - uvc.use_future_array_shapes() + uvc.read_calfits(fc_file, use_future_array_shapes=True) fc_gains = np.moveaxis(uvc.gain_array, 1, 2)[:, :, :, 0] d_nu = np.mean(uvc.freq_array[1:] - uvc.freq_array[:-1]) d_phi = np.abs(np.mean(np.angle(fc_gains)[:, :, 1:] - np.angle(fc_gains)[:, :, :-1], axis=2)) @@ -454,7 +453,11 @@ def __init__(self, omni_calfits, history=''): # Instantiate Data Object self.uv = UVCal() - self.uv.read_calfits(omni_calfits, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", "Future array shapes are now always used" + ) + self.uv.read_calfits(omni_calfits, use_future_array_shapes=True) # Get relevant metadata self.Nants = self.uv.Nants_data diff --git a/hera_qm/tests/test_utils.py b/hera_qm/tests/test_utils.py index fee624ce..c8681a39 100644 --- a/hera_qm/tests/test_utils.py +++ b/hera_qm/tests/test_utils.py @@ -262,6 +262,7 @@ def test_strip_extension_return_ext_extension(): root, ext = utils.strip_extension(path, return_ext=True) assert ext == path[-3:] +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.parametrize( "filein", ["a_priori_flags_integrations.yaml", @@ -351,6 +352,7 @@ 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.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.parametrize( "filein", ["a_priori_flags_integrations.yaml", @@ -417,6 +419,8 @@ def test_apply_yaml_flags_uvcal(filein): pytest.raises(NotImplementedError, utils.apply_yaml_flags, uvc, a_priori_flag_yaml=test_flag, throw_away_flagged_ants=True, ant_indices_only=False) + +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") def test_apply_yaml_flags_errors(): test_flag_jds = os.path.join(DATA_PATH, 'a_priori_flags_jds.yaml') test_c_file = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA.omni.calfits') diff --git a/hera_qm/tests/test_vis_metrics.py b/hera_qm/tests/test_vis_metrics.py index ab896a6d..b3ffc743 100644 --- a/hera_qm/tests/test_vis_metrics.py +++ b/hera_qm/tests/test_vis_metrics.py @@ -9,6 +9,7 @@ import os import copy import pytest +import warnings pytestmark = pytest.mark.filterwarnings( "ignore:The uvw_array does not match the expected values given the antenna positions.", @@ -18,7 +19,9 @@ def vismetrics_data(): data = UVData() filename = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA') - data.read_miriad(filename, use_future_array_shapes=True, check_autos=False) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + data.read_miriad(filename, use_future_array_shapes=True, check_autos=False) # massage the object to make it work with check_noise_variance data.select(antenna_nums=data.get_ants()[0:10]) @@ -75,11 +78,13 @@ def test_check_noise_variance_inttime_error(vismetrics_data): @pytest.fixture(scope='function') def uvd(): uvd = UVData() - uvd.read_miriad( - os.path.join(DATA_PATH, 'zen.2458002.47754.xx.HH.uvA'), - projected=False, use_future_array_shapes=True, - check_autos=False - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvd.read_miriad( + os.path.join(DATA_PATH, 'zen.2458002.47754.xx.HH.uvA'), + projected=False, use_future_array_shapes=True, + check_autos=False + ) return uvd def test_vis_bl_cov(uvd): @@ -147,6 +152,7 @@ def test_plot_bl_bl_scatter(uvd): plt.close('all') +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") def test_sequential_diff(): uvd = UVData() uvd.read_miriad(os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA'), use_future_array_shapes=True) diff --git a/hera_qm/tests/test_xrfi.py b/hera_qm/tests/test_xrfi.py index 6541e13d..444424c1 100644 --- a/hera_qm/tests/test_xrfi.py +++ b/hera_qm/tests/test_xrfi.py @@ -52,7 +52,9 @@ @pytest.fixture(scope="session") def uvdata_miriad_main(): - uv = UVData.from_file(test_d_file, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv = UVData.from_file(test_d_file, use_future_array_shapes=True) yield uv # clean up when done @@ -74,9 +76,11 @@ def uvdata_miriad(uvdata_miriad_main): @pytest.fixture(scope="session") def uvflag_metric_miriad_main(uvdata_miriad_main): - uvm = UVFlag( - uvdata_miriad_main, history='I made this', use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvm = UVFlag( + uvdata_miriad_main, history='I made this', use_future_array_shapes=True + ) yield uvm # clean up when done del uvm @@ -96,12 +100,14 @@ def uvflag_metric_miriad(uvflag_metric_miriad_main): @pytest.fixture(scope="session") def uvflag_metric_waterfall_miriad_main(uvdata_miriad_main): - uvm = UVFlag( - uvdata_miriad_main, - history='I made this', - waterfall=True, - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvm = UVFlag( + uvdata_miriad_main, + history='I made this', + waterfall=True, + use_future_array_shapes=True + ) yield uvm # clean up when done del uvm @@ -121,7 +127,9 @@ def uvflag_metric_waterfall_miriad(uvflag_metric_waterfall_miriad_main): @pytest.fixture(scope="session") def uvflag_flag_miriad_main(uvdata_miriad_main): - uvf = UVFlag(uvdata_miriad_main, mode='flag', use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf = UVFlag(uvdata_miriad_main, mode='flag', use_future_array_shapes=True) yield uvf # clean up when done del uvf @@ -141,12 +149,14 @@ def uvflag_flag_miriad(uvflag_flag_miriad_main): @pytest.fixture(scope="session") def uvflag_flag_waterfall_miriad_main(uvdata_miriad_main): - uvf = UVFlag( - uvdata_miriad_main, - mode='flag', - waterfall=True, - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf = UVFlag( + uvdata_miriad_main, + mode='flag', + waterfall=True, + use_future_array_shapes=True + ) yield uvf # clean up when done del uvf @@ -166,7 +176,9 @@ def uvflag_flag_waterfall_miriad(uvflag_flag_waterfall_miriad_main): @pytest.fixture(scope="session") def uvcal_calfits_main(): - uvc = UVCal.from_file(test_c_file, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvc = UVCal.from_file(test_c_file, use_future_array_shapes=True) yield uvc # clean up when done @@ -188,9 +200,11 @@ def uvcal_calfits(uvcal_calfits_main): @pytest.fixture(scope="session") def uvflag_metric_calfits_main(uvcal_calfits_main): - uvm = UVFlag( - uvcal_calfits_main, history='I made this', use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvm = UVFlag( + uvcal_calfits_main, history='I made this', use_future_array_shapes=True + ) yield uvm # clean up when done @@ -212,7 +226,9 @@ def uvflag_metric_calfits(uvflag_metric_calfits_main): @pytest.fixture(scope="session") def uvflag_flag_calfits_main(uvcal_calfits_main): - uvf = UVFlag(uvcal_calfits_main, mode='flag', use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf = UVFlag(uvcal_calfits_main, mode='flag', use_future_array_shapes=True) yield uvf # clean up when done @@ -234,7 +250,9 @@ def uvflag_flag_calfits(uvflag_flag_calfits_main): @pytest.fixture(scope="session") def uvflag_f_main(): - uvf = UVFlag(test_f_file, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf = UVFlag(test_f_file, use_future_array_shapes=True) yield uvf # clean up when done @@ -1042,7 +1060,8 @@ def test_flag( # test time flagging in baseline type # convert to current shapes for test coverage - uvm.use_current_array_shapes() + if hasattr(uvm, "use_current_array_shapes"): + uvm.use_current_array_shapes() uvm.metric_array = np.zeros_like(uvm.metric_array) times = np.unique(uvm.time_array) inds1 = np.where(uvm.time_array == times[0])[0] @@ -1113,6 +1132,7 @@ def test_unflag(): assert True +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:instrument is not the same") def test_flag_apply( uvdata_miriad, @@ -1405,6 +1425,7 @@ def test_xrfi_run_step(tmpdir): # TODO: check whether invalid value encountered in subtract warning is expected +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @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") @@ -1813,6 +1834,7 @@ def test_xrfi_run(tmpdir): for fname in [ocal_file, acal_file, model_file, raw_dfile]: os.remove(fname) +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:This object is already a waterfall") @pytest.mark.filterwarnings("ignore:x_orientation is not the same") def test_xrfi_run_edgeflag(tmpdir): @@ -1932,6 +1954,7 @@ def test_xrfi_run_edgeflag(tmpdir): +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:This object is already a waterfall") @pytest.mark.filterwarnings("ignore:x_orientation is not the same") def test_xrfi_run_multifile(tmpdir): @@ -2040,6 +2063,7 @@ def test_xrfi_run_multifile(tmpdir): if ext == 'flags2.h5': assert not np.all(uvf.flag_array) +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:This object is already a waterfall") def test_day_threshold_run(tmpdir): # The warnings are because we use UVFlag.to_waterfall() on the total chisquareds @@ -2110,6 +2134,7 @@ def test_day_threshold_run(tmpdir): assert os.path.exists(calfile) +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:This object is already a waterfall") def test_day_threshold_run_yaml(tmpdir): # The warnings are because we use UVFlag.to_waterfall() on the total chisquareds @@ -2164,6 +2189,7 @@ def test_day_threshold_run_yaml(tmpdir): @pytest.mark.filterwarnings("ignore:All-NaN slice encountered") @pytest.mark.filterwarnings("ignore:instrument is not the same") +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") 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 @@ -2217,6 +2243,7 @@ def test_day_threshold_run_data_only(tmpdir): assert os.path.exists(calfile) +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @pytest.mark.filterwarnings("ignore:This object is already a waterfall") def test_day_threshold_run_cal_only(tmpdir): # The warnings are because we use UVFlag.to_waterfall() on the total chisquareds @@ -2288,6 +2315,7 @@ def test_day_threshold_run_cal_only(tmpdir): assert os.path.exists(calfile) +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @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 @@ -2655,6 +2683,7 @@ def test_threshold_wf_exceptions(uvflag_f): pytest.raises(ValueError, xrfi.threshold_wf, 'foo') # not a UVFlag object +@pytest.mark.filterwarnings("ignore:Future array shapes are now always used") @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): diff --git a/hera_qm/utils.py b/hera_qm/utils.py index 24d50c08..85b2f0ef 100644 --- a/hera_qm/utils.py +++ b/hera_qm/utils.py @@ -734,7 +734,11 @@ def apply_yaml_flags(uv, a_priori_flag_yaml, lat_lon_alt_degrees=None, telescope raise NotImplementedError("uv must be a UVData, UVCal, or UVFlag object.") # this is a no-op if it's already using future shapes - uv.use_future_array_shapes() + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", "Future array shapes are now always used" + ) + uv.use_future_array_shapes() # if UVCal provided and lst_array is None, get lst_array from times. # If lat_lon_alt is not specified, try to infer it from the telescope name, which calfits files generally carry around diff --git a/hera_qm/xrfi.py b/hera_qm/xrfi.py index d13cddf5..13520abf 100644 --- a/hera_qm/xrfi.py +++ b/hera_qm/xrfi.py @@ -80,7 +80,9 @@ def flag_xants(uv, xants, inplace=True, run_check=True, uvo.to_flag(run_check=run_check, check_extra=check_extra, run_check_acceptability=run_check_acceptability) else: - uvo = UVFlag(uv, mode='flag', use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvo = UVFlag(uv, mode='flag', use_future_array_shapes=True) else: uvo = uv @@ -1059,7 +1061,10 @@ def flag(uvf_m, nsig_p=6., nsig_f=None, nsig_t=None, avg_method='quadmean', raise ValueError('uvf_m must be UVFlag instance with mode == "metric."') # use future array shapes - if not uvf_m.future_array_shapes: + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", "Future array shapes are now always used" + ) uvf_m.use_future_array_shapes() # initialize @@ -1253,16 +1258,20 @@ def flag_apply(uvf, uv, keep_existing=True, force_pol=False, history='', raise ValueError('Flags can only be applied to UVData or UVCal objects.') if not isinstance(uvf, (list, tuple, np.ndarray)): uvf = [uvf] - net_flags = UVFlag( - uv, - mode='flag', - copy_flags=keep_existing, - history=history, - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + net_flags = UVFlag( + uv, + mode='flag', + copy_flags=keep_existing, + history=history, + use_future_array_shapes=True + ) for uvf_i in uvf: if isinstance(uvf_i, str): - uvf_i = UVFlag(uvf_i, use_future_array_shapes=True) # Read file + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf_i = UVFlag(uvf_i, use_future_array_shapes=True) # Read file elif not isinstance(uvf_i, UVFlag): raise ValueError('Input to apply_flag must be UVFlag or path to UVFlag file.') if uvf_i.mode != 'flag': @@ -1401,7 +1410,9 @@ def calculate_metric(uv, algorithm, cal_mode='gain', run_check=True, alg_func = algorithm_dict[algorithm] except KeyError: raise KeyError('Algorithm not found in list of available functions.') - uvf = UVFlag(uv, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf = UVFlag(uv, use_future_array_shapes=True) if issubclass(uv.__class__, UVData): uvf.weights_array = uv.nsample_array * np.logical_not(uv.flag_array).astype(np.float64) else: @@ -1866,15 +1877,18 @@ def xrfi_run_step(uv_files=None, uv=None, uvf_apriori=None, if dtype=='uvcal': uv = UVCal() # No partial i/o for uvcal yet. - getattr(uv, uvcal_read_method)(uv_files, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uv, uvcal_read_method)(uv_files, use_future_array_shapes=True) if a_priori_flag_yaml is not None: uv = qm_utils.apply_yaml_flags(uv, a_priori_flag_yaml, flag_ants=not(ignore_xants_override), flag_times=not(a_priori_ants_only), flag_freqs=not(a_priori_ants_only)) elif dtype=='uvdata': - uv = UVData() - uv.read(uv_files, read_data=False, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv = UVData.from_file(uv_files, read_data=False, use_future_array_shapes=True) else: raise ValueError("%s is an invalid dtype. Must be 'uvcal' or 'uvdata'."%dtype) no_uvf_apriori = (uvf_apriori is None) @@ -1883,9 +1897,13 @@ def xrfi_run_step(uv_files=None, uv=None, uvf_apriori=None, # if we want, we can reinitialize uv if reinitialize and uv_files is not None: if issubclass(uv.__class__, UVData): - uv.read(uv_files, read_data=False, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv.read(uv_files, read_data=False, use_future_array_shapes=True) else: - getattr(uv, uvcal_read_method)(uv_files, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uv, uvcal_read_method)(uv_files, use_future_array_shapes=True) if a_priori_flag_yaml is not None: uv = qm_utils.apply_yaml_flags(uv, a_priori_flag_yaml, flag_ants=not(ignore_xants_override), @@ -1911,12 +1929,14 @@ def xrfi_run_step(uv_files=None, uv=None, uvf_apriori=None, # iterate over baseline chunks for loadnum in range(nloads): # read in chunk - uv.read( - uv_files, - bls=bls[loadnum * Nwf_per_load:(loadnum + 1) * Nwf_per_load], - axis='blt', - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv.read( + uv_files, + bls=bls[loadnum * Nwf_per_load:(loadnum + 1) * Nwf_per_load], + axis='blt', + use_future_array_shapes=True + ) if a_priori_flag_yaml is not None: uv = qm_utils.apply_yaml_flags(uv, a_priori_flag_yaml, flag_times=not(a_priori_ants_only), @@ -1926,13 +1946,15 @@ def xrfi_run_step(uv_files=None, uv=None, uvf_apriori=None, # and we want to calculate it if calculate_uvf_apriori: # then extract the flags for the chunk of baselines we are on - uvf_apriori_chunk = UVFlag( - uv, - mode='flag', - copy_flags=True, - label='A priori flags.', - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf_apriori_chunk = UVFlag( + uv, + mode='flag', + copy_flags=True, + label='A priori flags.', + use_future_array_shapes=True + ) # waterfall them uvf_apriori_chunk.to_waterfall(method='and', keep_pol=False, run_check=run_check, check_extra=check_extra, @@ -1984,13 +2006,15 @@ def xrfi_run_step(uv_files=None, uv=None, uvf_apriori=None, # do so here. if uvf_apriori is None: if calculate_uvf_apriori: - uvf_apriori = UVFlag( - uv, - mode='flag', - copy_flags=True, - label='A priori flags.', - use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf_apriori = UVFlag( + uv, + mode='flag', + copy_flags=True, + label='A priori flags.', + use_future_array_shapes=True + ) uvf_apriori.to_waterfall(method='and', keep_pol=False, run_check=run_check, check_extra=check_extra, run_check_acceptability=run_check_acceptability) @@ -2446,18 +2470,26 @@ def _run_all_filters(median_round, # Read metadata from first file to get integrations per file. if data_files is not None: uvlist = data_files - uvtemp = UVData.from_file(uvlist[0], read_data=False, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvtemp = UVData.from_file(uvlist[0], read_data=False, use_future_array_shapes=True) elif model_files is not None: uvlist = model_files - uvtemp = UVData.from_file(uvlist[0], read_data=False, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvtemp = UVData.from_file(uvlist[0], read_data=False, use_future_array_shapes=True) elif ocalfits_files is not None: uvlist = ocalfits_files uvtemp = UVCal() - getattr(uvtemp, uvcal_read_method)(uvlist[0], use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvtemp, uvcal_read_method)(uvlist[0], use_future_array_shapes=True) elif acalfits_files is not None: uvlist = acalfits_files uvtemp = UVCal() - getattr(uvtemp, uvcal_read_method)(uvlist[0], use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvtemp, uvcal_read_method)(uvlist[0], use_future_array_shapes=True) nintegrations = len(uvlist) * uvtemp.Ntimes # Determine the actual files to store # We will drop kt_size / (integrations per file) files at the start and @@ -2609,10 +2641,12 @@ def xrfi_h3c_idr2_1_run(ocalfits_files, acalfits_files, model_files, data_files, # Initial run on cal data products # Calculate metric on abscal data uvc_a = UVCal() - getattr(uvc_a, uvcal_read_method)(acalfits_files, use_future_array_shapes=True) - uvf_apriori = UVFlag( - uvc_a, mode='flag', copy_flags=True, label='A priori flags.', use_future_array_shapes=True - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvc_a, uvcal_read_method)(acalfits_files, use_future_array_shapes=True) + uvf_apriori = UVFlag( + uvc_a, mode='flag', copy_flags=True, label='A priori flags.', use_future_array_shapes=True + ) uvf_ag, uvf_agf = xrfi_pipe(uvc_a, alg='detrend_medfilt', Kt=kt_size, Kf=kf_size, xants=xants, cal_mode='gain', sig_init=sig_init, sig_adj=sig_adj, label='Abscal gains, round 1.', **check_kwargs) @@ -2622,7 +2656,9 @@ def xrfi_h3c_idr2_1_run(ocalfits_files, acalfits_files, model_files, data_files, # Calculate metric on omnical data uvc_o = UVCal() - getattr(uvc_o, uvcal_read_method)(ocalfits_files, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvc_o, uvcal_read_method)(ocalfits_files, use_future_array_shapes=True) flag_apply(uvf_apriori, uvc_o, keep_existing=True, run_check=run_check, check_extra=check_extra, run_check_acceptability=run_check_acceptability) @@ -2634,7 +2670,9 @@ def xrfi_h3c_idr2_1_run(ocalfits_files, acalfits_files, model_files, data_files, label='Omnical chisq, round 1.', **check_kwargs) # Calculate metric on model vis - uv_v = UVData.from_file(model_files, axis='blt', use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv_v = UVData.from_file(model_files, axis='blt', use_future_array_shapes=True) uvf_v, uvf_vf = xrfi_pipe(uv_v, alg='detrend_medfilt', xants=[], Kt=kt_size, Kf=kf_size, sig_init=sig_init, sig_adj=sig_adj, label='Omnical visibility solutions, round 1.', @@ -2672,7 +2710,9 @@ def xrfi_h3c_idr2_1_run(ocalfits_files, acalfits_files, model_files, data_files, # Second round -- use init flags to mask and recalculate everything # Read in data file uv_d = UVData() - uv_d = UVData.from_file(data_files, axis='blt', use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uv_d = UVData.from_file(data_files, axis='blt', use_future_array_shapes=True) for uv in [uvc_o, uvc_a, uv_v, uv_d]: flag_apply(uvf_init, uv, keep_existing=True, force_pol=True, **check_kwargs) @@ -2758,7 +2798,9 @@ def xrfi_h3c_idr2_1_run(ocalfits_files, acalfits_files, model_files, data_files, # output files for those, but flag everything. # Read metadata from first file to get integrations per file. - uvtemp = UVData.from_file(data_files[0], read_data=False, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvtemp = UVData.from_file(data_files[0], read_data=False, use_future_array_shapes=True) nintegrations = len(data_files) * uvtemp.Ntimes # Calculate number of files to drop on edges, rounding up. ndrop = int(np.ceil(kt_size / uvtemp.Ntimes)) @@ -2873,19 +2915,25 @@ def day_threshold_run(data_files, history, nsig_f=7., nsig_t=7., if np.all([len(f) > 0 for f in files1_all]) and np.all([len(f) > 0 for f in files2_all]): files1 = [glob.glob(d + '/*' + ext + '1.h5')[0] for d in xrfi_dirs] files2 = [glob.glob(d + '/*' + ext + '2.h5')[0] for d in xrfi_dirs] - uvf1 = UVFlag(files1, use_future_array_shapes=True) - uvf2 = UVFlag(files2, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf1 = UVFlag(files1, use_future_array_shapes=True) + uvf2 = UVFlag(files2, use_future_array_shapes=True) uvf2.metric_array = np.where(np.isinf(uvf2.metric_array), uvf1.metric_array, uvf2.metric_array) filled_metrics.append(uvf2) elif np.all([len(f) > 0 for f in files2_all]): # some flags only exist in round2 (data for example). files = [glob.glob(d + '/*' + ext + '2.h5')[0] for d in xrfi_dirs] - filled_metrics.append(UVFlag(files, use_future_array_shapes=True)) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + filled_metrics.append(UVFlag(files, use_future_array_shapes=True)) elif np.all([len(f) > 0 for f in files1_all]): # some flags only exist in round1 (if we chose median filtering only for example). files = [glob.glob(d + '/*' + ext + '1.h5')[0] for d in xrfi_dirs] - filled_metrics.append(UVFlag(files, use_future_array_shapes=True)) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + filled_metrics.append(UVFlag(files, use_future_array_shapes=True)) else: filled_metrics.append(None) filled_metrics_that_exist = [f for f in filled_metrics if f is not None] @@ -2912,7 +2960,9 @@ def day_threshold_run(data_files, history, nsig_f=7., nsig_t=7., try: ext_here = f'{mext.replace("metrics", "flags")}{rnd}.h5' files = [glob.glob(f'{d}/*.{ext_here}')[0] for d in xrfi_dirs] - uvf_here = UVFlag(files, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvf_here = UVFlag(files, use_future_array_shapes=True) uvf_total |= uvf_here except IndexError: pass @@ -2935,7 +2985,9 @@ def day_threshold_run(data_files, history, nsig_f=7., nsig_t=7., abs_in = '.'.join([basename, incal_ext, 'calfits']) abs_out = '.'.join([basename, outcal_ext, 'calfits']) # abscal flagging only happens if the abscal files exist. - getattr(uvc_a, uvcal_read_method)(abs_in, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvc_a, uvcal_read_method)(abs_in, use_future_array_shapes=True) # select the times from the file we are going to flag uvf_file = uvf_total.select(times=uvc_a.time_array, inplace=False) @@ -3061,7 +3113,9 @@ def xrfi_h1c_run(indata, history, infile_format='miriad', extension='flags.h5', filename = indata elif not isinstance(filename, str): raise ValueError('filename must be string path to file.') - uvd = UVData.from_file(filename, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvd = UVData.from_file(filename, use_future_array_shapes=True) # append to history history = 'Flagging command: "' + history + '", Using ' + __version__ @@ -3098,7 +3152,9 @@ def xrfi_h1c_run(indata, history, infile_format='miriad', extension='flags.h5', # Flag on model visibilities if model_file is not None: - uvm = UVData.from_file(model_file, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvm = UVData.from_file(model_file, use_future_array_shapes=True) if indata is not None and not ( np.allclose(np.unique(uvd.time_array), np.unique(uvm.time_array), atol=1e-5, rtol=0 ) and np.allclose( @@ -3124,7 +3180,9 @@ def xrfi_h1c_run(indata, history, infile_format='miriad', extension='flags.h5', # Flag on gain solutions and chisquared values if calfits_file is not None: uvc = UVCal() - getattr(uvc, uvcal_read_method)(calfits_file, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + getattr(uvc, uvcal_read_method)(calfits_file, use_future_array_shapes=True) if indata is not None and not ( np.allclose(np.unique(uvd.time_array), np.unique(uvc.time_array), atol=1e-5, rtol=0 ) and np.allclose( @@ -3228,7 +3286,9 @@ def xrfi_h1c_apply(filename, history, infile_format='miriad', xrfi_path='', raise AssertionError('xrfi_apply currently only takes a single data file.') if isinstance(filename, (list, np.ndarray, tuple)): filename = filename[0] - uvd = UVData.from_file(filename, use_future_array_shapes=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Future array shapes are now always used") + uvd = UVData.from_file(filename, use_future_array_shapes=True) full_list = [] # Read in flag file