From 31554b660a3cc2e6b93a88f07d3f86d91348df8f Mon Sep 17 00:00:00 2001 From: Bryna Hazelton Date: Mon, 13 Mar 2023 13:54:45 -0700 Subject: [PATCH] Remove deprecated code, update changelog for version 2.3 --- CHANGELOG.md | 7 ++ README.md | 4 +- ci/pyuvdata_min_deps_tests.yml | 2 +- ci/pyuvdata_publish.yml | 2 +- ci/pyuvdata_tests.yml | 2 +- ci/pyuvdata_tests_windows.yml | 2 +- ci/pyuvdata_warning_test.yml | 2 +- environment.yaml | 2 +- pyuvdata/uvcal/calfits.py | 20 ++-- pyuvdata/uvcal/tests/test_fhd_cal.py | 36 +++---- pyuvdata/uvcal/tests/test_uvcal.py | 151 ++++++++++++++++----------- pyuvdata/uvcal/uvcal.py | 30 +----- pyuvdata/uvdata/miriad.py | 2 +- pyuvdata/uvdata/uvdata.py | 5 +- pyuvdata/uvdata/uvfits.py | 2 +- pyuvdata/uvflag/uvflag.py | 2 +- setup.py | 2 +- 17 files changed, 136 insertions(+), 137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e6b0cec3..2b2dbf00ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [2.3.0] - 2023-03-13 + ### Added - A new `interpolation_function` parameter to `UVBeam.interp` and `UVBeam.to_healpix` to allow the function name to be passed into the methods, with sensible defaulting. @@ -19,6 +21,7 @@ they are converted between types using UVData and UVCalobjects. to set several of these new parameters. ### Changed +- Increases the h5py minimum version to 3.1. - Increase the minimum compatible version for lunarsky to 0.2.1 to fix astropy deprecation warnings. @@ -60,6 +63,10 @@ non-wide-band UVCal objects in version 3.0. of the `phase_center_catalog`. The older phase attributes will be removed in version 3.0. - The `lst_from_uv` function in the uvflag module. +### Removed +- Removed deprecated handling for UVCal objects without `telescope_location`, +`antenna_positions` and `lst_array` parameters defined. + ## [2.2.12] - 2022-12-07 ### Changed diff --git a/README.md b/README.md index 30da93e7fb..6317f2cf30 100644 --- a/README.md +++ b/README.md @@ -142,11 +142,11 @@ Note that as of v2.2, `pyuvdata` is only supported on python 3.7+. Required: * astropy >= 5.0.4 -* h5py >= 3.0 +* h5py >= 3.1 * numpy >= 1.19 * pyerfa >= 2.0 * scipy >= 1.3 -* setuptools_scm +* setuptools_scm <7.0|>=7.0.3 Optional: diff --git a/ci/pyuvdata_min_deps_tests.yml b/ci/pyuvdata_min_deps_tests.yml index 2e1789c275..c004acd73d 100644 --- a/ci/pyuvdata_min_deps_tests.yml +++ b/ci/pyuvdata_min_deps_tests.yml @@ -5,7 +5,7 @@ dependencies: - astropy>=5.0.4 - numpy>=1.19.* - scipy>=1.3 - - h5py>=3.0 + - h5py>=3.1 - pyerfa>=2.0 - coverage - pytest>=6.2.0 diff --git a/ci/pyuvdata_publish.yml b/ci/pyuvdata_publish.yml index 876418a908..d498cb3187 100644 --- a/ci/pyuvdata_publish.yml +++ b/ci/pyuvdata_publish.yml @@ -5,7 +5,7 @@ dependencies: - astropy>=5.0.4 - numpy>=1.19.* - scipy>=1.3 - - h5py>=3.0 + - h5py>=3.1 - pyerfa>=2.0 - cython - setuptools_scm<7.0|>=7.0.3 diff --git a/ci/pyuvdata_tests.yml b/ci/pyuvdata_tests.yml index 43304ebad7..180a33f5d5 100644 --- a/ci/pyuvdata_tests.yml +++ b/ci/pyuvdata_tests.yml @@ -5,7 +5,7 @@ dependencies: - astropy>=5.0.4 - astropy-healpix>=0.6 - astroquery>=0.4.4 - - h5py>=3.0 + - h5py>=3.1 - hdf5plugin>=3.1.0 - numpy>=1.19.* - pyerfa>=2.0 diff --git a/ci/pyuvdata_tests_windows.yml b/ci/pyuvdata_tests_windows.yml index 8bf5506379..0f931ce8a8 100644 --- a/ci/pyuvdata_tests_windows.yml +++ b/ci/pyuvdata_tests_windows.yml @@ -5,7 +5,7 @@ dependencies: - astropy>=5.0.4 - astropy-healpix>=0.6 - astroquery>=0.4.4 - - h5py>=3.0 + - h5py>=3.1 - hdf5>=1.12.0 - hdf5plugin>=3.1.0 - numpy>=1.19.* diff --git a/ci/pyuvdata_warning_test.yml b/ci/pyuvdata_warning_test.yml index 4d6486ddb9..98221e47ab 100644 --- a/ci/pyuvdata_warning_test.yml +++ b/ci/pyuvdata_warning_test.yml @@ -5,7 +5,7 @@ dependencies: - astropy>=5.0.4 - astropy-healpix>=0.6 - astroquery>=0.4.4 - - h5py>=3.0 + - h5py>=3.1 - hdf5plugin>=3.1.0 - numpy>=1.19.* - pyerfa>=2.0 diff --git a/environment.yaml b/environment.yaml index 017eb5f807..deb895fdf0 100644 --- a/environment.yaml +++ b/environment.yaml @@ -7,7 +7,7 @@ dependencies: - astroquery>=0.4.4 - coverage - cython>=0.23 - - h5py>=3.0 + - h5py>=3.1 - hdf5plugin>=3.1.0 - numpy>=1.19 - pip diff --git a/pyuvdata/uvcal/calfits.py b/pyuvdata/uvcal/calfits.py index f01d4e6030..b4224e70eb 100644 --- a/pyuvdata/uvcal/calfits.py +++ b/pyuvdata/uvcal/calfits.py @@ -181,13 +181,12 @@ def write_calfits( # Conforming to fits format prihdr["SIMPLE"] = True prihdr["TELESCOP"] = self.telescope_name - if self.telescope_location is not None: - prihdr["ARRAYX"] = self.telescope_location[0] - prihdr["ARRAYY"] = self.telescope_location[1] - prihdr["ARRAYZ"] = self.telescope_location[2] - prihdr["LAT"] = self.telescope_location_lat_lon_alt_degrees[0] - prihdr["LON"] = self.telescope_location_lat_lon_alt_degrees[1] - prihdr["ALT"] = self.telescope_location_lat_lon_alt[2] + prihdr["ARRAYX"] = self.telescope_location[0] + prihdr["ARRAYY"] = self.telescope_location[1] + prihdr["ARRAYZ"] = self.telescope_location[2] + prihdr["LAT"] = self.telescope_location_lat_lon_alt_degrees[0] + prihdr["LON"] = self.telescope_location_lat_lon_alt_degrees[1] + prihdr["ALT"] = self.telescope_location_lat_lon_alt[2] prihdr["GNCONVEN"] = self.gain_convention prihdr["CALTYPE"] = self.cal_type prihdr["CALSTYLE"] = self.cal_style @@ -491,11 +490,8 @@ def write_calfits( self.ant_array, np.zeros(nants_add, dtype=np.int64) - 1 ) col3 = fits.Column(name="ANTARR", format="D", array=ant_array_use) - if self.antenna_positions is not None: - col4 = fits.Column(name="ANTXYZ", format="3D", array=self.antenna_positions) - cols = fits.ColDefs([col1, col2, col3, col4]) - else: - cols = fits.ColDefs([col1, col2, col3]) + col4 = fits.Column(name="ANTXYZ", format="3D", array=self.antenna_positions) + cols = fits.ColDefs([col1, col2, col3, col4]) ant_hdu = fits.BinTableHDU.from_columns(cols) ant_hdu.header["EXTNAME"] = "ANTENNAS" diff --git a/pyuvdata/uvcal/tests/test_fhd_cal.py b/pyuvdata/uvcal/tests/test_fhd_cal.py index 30ab540ba7..07391e4802 100644 --- a/pyuvdata/uvcal/tests/test_fhd_cal.py +++ b/pyuvdata/uvcal/tests/test_fhd_cal.py @@ -292,29 +292,21 @@ def test_break_read_fhdcal(cal_file, obs_file, layout_file, settings_file, nfile expected_history += " Combined data along time axis using pyuvdata." assert fhd_cal.history == expected_history - message_list = ( - ["No layout file, antenna_postions will not be defined."] * nfiles - + ["UVParameter diffuse_model does not match"] * (nfiles - 1) - + [ - "The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3" - ] - * (4 * nfiles - 3) - ) - - warning_list = [UserWarning] * (2 * nfiles - 1) + [DeprecationWarning] * ( - 4 * nfiles - 3 - ) - with uvtest.check_warnings(warning_list, message_list): - fhd_cal.read_fhd_cal( - cal_file, - obs_file, - settings_file=settings_file, - use_future_array_shapes=True, - ) + message_list = [ + "No layout file, antenna_postions will not be defined." + ] * nfiles + ["UVParameter diffuse_model does not match"] * (nfiles - 1) - # Check no antenna_positions - assert fhd_cal.antenna_positions is None + warning_list = [UserWarning] * (2 * nfiles - 1) + with pytest.raises( + ValueError, match="Required UVParameter _antenna_positions has not been set." + ): + with uvtest.check_warnings(warning_list, message_list): + fhd_cal.read_fhd_cal( + cal_file, + obs_file, + settings_file=settings_file, + use_future_array_shapes=True, + ) def test_read_multi(tmp_path): diff --git a/pyuvdata/uvcal/tests/test_uvcal.py b/pyuvdata/uvcal/tests/test_uvcal.py index 011fc85e06..c00b0af136 100644 --- a/pyuvdata/uvcal/tests/test_uvcal.py +++ b/pyuvdata/uvcal/tests/test_uvcal.py @@ -11,6 +11,8 @@ import numpy as np import pytest +from astropy.io import fits +from astropy.table import Table import pyuvdata.tests as uvtest import pyuvdata.utils as uvutils @@ -313,26 +315,6 @@ def test_check(gain_data): assert gain_data.check() -def test_check_warnings(gain_data): - """Test that parameter checks run properly""" - gain_data.telescope_location = None - gain_data.lst_array = None - gain_data.antenna_positions = None - - with uvtest.check_warnings( - DeprecationWarning, - [ - "The telescope_location is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - "The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - "The lst_array is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - ], - ): - assert gain_data.check() - - def test_check_flag_array(gain_data): gain_data.flag_array = np.ones((gain_data.flag_array.shape), dtype=int) @@ -492,30 +474,47 @@ def test_future_array_shape_errors( def test_unknown_telescopes(gain_data, tmp_path): calobj = gain_data - calobj.telescope_name = "foo" - calobj.telescope_location = None - calobj.lst_array = None - calobj.antenna_positions = None - write_file_calfits = str(tmp_path / "test.calfits") - deprecation_messages = [ - "The telescope_location is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - "The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - "The lst_array is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - ] - - with uvtest.check_warnings(DeprecationWarning, match=deprecation_messages): - calobj.write_calfits(write_file_calfits, clobber=True) + write_file = str(tmp_path / "test.calfits") + write_file2 = str(tmp_path / "test2.calfits") + calobj.write_calfits(write_file) + with fits.open(write_file, memmap=True) as hdu_list: + hdunames = uvutils._fits_indexhdus(hdu_list) + primary_hdu = hdu_list[0] + primary_hdr = primary_hdu.header.copy() + del primary_hdr["ARRAYX"] + del primary_hdr["ARRAYY"] + del primary_hdr["ARRAYZ"] + del primary_hdr["LAT"] + del primary_hdr["LON"] + del primary_hdr["ALT"] + primary_hdr["TELESCOP"] = "foo" + primary_hdu.header = primary_hdr + + ant_hdu = hdu_list[hdunames["ANTENNAS"]] + + table = Table(ant_hdu.data) + del table["ANTXYZ"] + ant_hdu = fits.BinTableHDU(table) + ant_hdu.header["EXTNAME"] = "ANTENNAS" + + hdulist = fits.HDUList([primary_hdu, ant_hdu]) + + hdulist.writeto(write_file2) + hdulist.close() calobj2 = UVCal() + with pytest.raises( + ValueError, match="Required UVParameter _antenna_positions has not been set." + ): + with uvtest.check_warnings( + [UserWarning], match=["Telescope foo is not in known_telescopes"] + ): + calobj2.read_calfits(write_file2, use_future_array_shapes=True) with uvtest.check_warnings( - [UserWarning] + [DeprecationWarning] * 3, - match=["Telescope foo is not in known_telescopes"] + deprecation_messages, + [UserWarning], match=["Telescope foo is not in known_telescopes"] ): - calobj2.read_calfits(write_file_calfits, use_future_array_shapes=True) + calobj2.read_calfits(write_file2, use_future_array_shapes=True, run_check=False) def test_nants_data_telescope_larger(gain_data): @@ -3348,21 +3347,29 @@ def test_match_antpos_antname(gain_data, antnamefix, tmp_path): ] # remove the antenna_positions to test matching them on read - gain_data2 = gain_data.copy() - gain_data2.antenna_positions = None + write_file = str(tmp_path / "test.calfits") + write_file2 = str(tmp_path / "test2.calfits") + gain_data.write_calfits(write_file) + with fits.open(write_file, memmap=True) as hdu_list: + hdunames = uvutils._fits_indexhdus(hdu_list) + primary_hdu = hdu_list[0] + ant_hdu = hdu_list[hdunames["ANTENNAS"]] - write_file_calfits = str(tmp_path / "test.calfits") - with uvtest.check_warnings( - DeprecationWarning, - match="The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - ): - gain_data2.write_calfits(write_file_calfits) + table = Table(ant_hdu.data) + del table["ANTXYZ"] + ant_hdu = fits.BinTableHDU(table) + ant_hdu.header["EXTNAME"] = "ANTENNAS" + + hdulist = fits.HDUList([primary_hdu, ant_hdu]) + hdulist.writeto(write_file2) + hdulist.close() + + gain_data2 = UVCal() with uvtest.check_warnings( UserWarning, "antenna_positions is not set. Using known values for HERA." ): - gain_data2.read_calfits(write_file_calfits, use_future_array_shapes=True) + gain_data2.read_calfits(write_file2, use_future_array_shapes=True) assert gain_data2.antenna_positions is not None assert gain_data == gain_data2 @@ -3391,27 +3398,47 @@ def test_set_antpos_from_telescope_errors(gain_data, modtype, tmp_path): gain_data.antenna_numbers[1] = orig_num # remove the antenna_positions to test matching them on read - gain_data2 = gain_data.copy() - gain_data2.antenna_positions = None + write_file = str(tmp_path / "test.calfits") + write_file2 = str(tmp_path / "test2.calfits") + gain_data.write_calfits(write_file) + with fits.open(write_file, memmap=True) as hdu_list: + hdunames = uvutils._fits_indexhdus(hdu_list) + primary_hdu = hdu_list[0] + ant_hdu = hdu_list[hdunames["ANTENNAS"]] - write_file_calfits = str(tmp_path / "test.calfits") - with uvtest.check_warnings( - DeprecationWarning, - match="The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", + table = Table(ant_hdu.data) + del table["ANTXYZ"] + ant_hdu = fits.BinTableHDU(table) + ant_hdu.header["EXTNAME"] = "ANTENNAS" + + hdulist = fits.HDUList([primary_hdu, ant_hdu]) + + hdulist.writeto(write_file2) + hdulist.close() + + gain_data2 = UVCal() + with pytest.raises( + ValueError, match="Required UVParameter _antenna_positions has not been set." ): - gain_data2.write_calfits(write_file_calfits) + with uvtest.check_warnings( + [UserWarning], + match=[ + "Not all antennas have positions in the telescope object. " + "Not setting antenna_positions." + ], + ): + gain_data2.read_calfits(write_file2, use_future_array_shapes=True) with uvtest.check_warnings( - [UserWarning, DeprecationWarning], + UserWarning, match=[ "Not all antennas have positions in the telescope object. " - "Not setting antenna_positions.", - "The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", + "Not setting antenna_positions." ], ): - gain_data2.read_calfits(write_file_calfits, use_future_array_shapes=True) + gain_data2.read_calfits( + write_file2, use_future_array_shapes=True, run_check=False + ) assert gain_data2.antenna_positions is None diff --git a/pyuvdata/uvcal/uvcal.py b/pyuvdata/uvcal/uvcal.py index 46c0e2c43e..21daa06f52 100644 --- a/pyuvdata/uvcal/uvcal.py +++ b/pyuvdata/uvcal/uvcal.py @@ -103,7 +103,7 @@ def __init__(self): description=desc, acceptable_range=(6.35e6, 6.39e6), tols=1e-3, - required=False, + required=True, ) desc = ( @@ -154,7 +154,7 @@ def __init__(self): form=("Nants_telescope", 3), expected_type=float, tols=1e-3, # 1 mm - required=False, + required=True, ) desc = ( @@ -263,7 +263,7 @@ def __init__(self): form=("Ntimes",), expected_type=float, tols=radian_tol, - required=False, + required=True, ) desc = ( @@ -1189,30 +1189,6 @@ def check( elif self.cal_style == "redundant": self._set_redundant() - # If the telescope location is not set issue a deprecation warning - if self.telescope_location is None: - warnings.warn( - "The telescope_location is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - category=DeprecationWarning, - ) - - # If the antenna positions parameter is not set issue a deprecation warning - if self.antenna_positions is None: - warnings.warn( - "The antenna_positions parameter is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - category=DeprecationWarning, - ) - - # If the lst_array parameter is not set issue a deprecation warning - if self.lst_array is None: - warnings.warn( - "The lst_array is not set. It will be a required " - "parameter starting in pyuvdata version 2.3", - category=DeprecationWarning, - ) - # if wide_band is True, Nfreqs must be 1. if self.wide_band: if self.Nfreqs != 1: diff --git a/pyuvdata/uvdata/miriad.py b/pyuvdata/uvdata/miriad.py index 399a72872d..a0b08ac30c 100644 --- a/pyuvdata/uvdata/miriad.py +++ b/pyuvdata/uvdata/miriad.py @@ -851,7 +851,7 @@ def read_miriad( if phase_type is not None: warnings.warn( "The phase_type parameter is deprecated, use the projected parameter " - "instead.", + "instead. This will become an error in version 3.0.", DeprecationWarning, ) if projected is None: diff --git a/pyuvdata/uvdata/uvdata.py b/pyuvdata/uvdata/uvdata.py index 7585de2cf7..eead181f64 100644 --- a/pyuvdata/uvdata/uvdata.py +++ b/pyuvdata/uvdata/uvdata.py @@ -2225,7 +2225,8 @@ def __setattr__(self, __name, __value) -> None: ): warnings.warn( f"phase_center_catalog is already set, so {__name}, which is an " - "old phase attribute, cannot be set.", + "old phase attribute, cannot be set. This will become an error in " + "version 3.0", DeprecationWarning, ) return @@ -12565,7 +12566,7 @@ def read( "The `make_multi_phase` option is deprecated. Since all objects now " "support multiple phase centers, the only effect of setting this to " "True is to prevent rephasing. A better approach is to set " - "`allow_rephase=False`.", + "`allow_rephase=False`. This will become an error in version 3.0.", DeprecationWarning, ) diff --git a/pyuvdata/uvdata/uvfits.py b/pyuvdata/uvdata/uvfits.py index b7fde8f856..273cc7e944 100644 --- a/pyuvdata/uvdata/uvfits.py +++ b/pyuvdata/uvdata/uvfits.py @@ -973,7 +973,7 @@ def write_uvfits( "UVFITS-required metadata are now set automatically to their " 'best known values, and no longer need to be "spoofed". As such, ' "the spoof_nonessential parameter is deprecated, and will be " - "removed in a future release." + "removed in version 2.4." ), DeprecationWarning, ) diff --git a/pyuvdata/uvflag/uvflag.py b/pyuvdata/uvflag/uvflag.py index 62935eb9b6..1393d53a88 100644 --- a/pyuvdata/uvflag/uvflag.py +++ b/pyuvdata/uvflag/uvflag.py @@ -72,7 +72,7 @@ def lst_from_uv(uv): """ warnings.warn( "The lst_from_uv function is deprecated. Use the `set_lsts_from_time_array` " - "method on the input object.", + "method on the input object. This will become an error in version 2.4.", category=DeprecationWarning, ) diff --git a/setup.py b/setup.py index 592c798b2d..9fb79e2798 100644 --- a/setup.py +++ b/setup.py @@ -145,7 +145,7 @@ def is_platform_windows(): "include_package_data": True, "install_requires": [ "astropy>=5.0.4", - "h5py>=3.0", + "h5py>=3.1", "numpy>=1.19", "pyerfa>=2.0", "scipy>=1.3",