diff --git a/CHANGELOG.md b/CHANGELOG.md index 486e786d..8ea29028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] + +## [0.2.0] - 2023-01-01 + ### Added - Add support for all astropy coordinate frames with the new `skycoord` attribute (which contains an astropy SkyCoord object) on point objects and the new `hpx_frame` attribute @@ -40,6 +43,22 @@ favor of the `lon_column` and `lat_column` as a part of supporting more frames i votable files. - The `to_recarray` and `from_recarray` methods. +### Removed +- Removed support for the older input parameter order to `SkyModel.__init__`. +- Removed support for passing `freq_array`, `reference_freq` or `stokes` to +`SkyModel.__init__` as anything other than appropriate Quantities. +- `set_spectral_type_params` and `read_idl_catalog` methods have been +removed from `SkyModel` +- Removed the `read_healpix_hdf5`, `healpix_to_sky`, `write_healpix_hdf5`, +`skymodel_to_array`, `array_to_skymodel`, `source_cuts`, `read_votable_catalog`, +`read_gleam_catalog`, `read_text_catalog`, `read_idl_catalog`, `write_catalog_to_file` +functions (many similar methods on `SkyModel` remain). +- Removed support for passing telescope_location directly to the +`SkyModel.coherency_calc` method. +- Removed support for votable_files with tables with no name or ID. +- Removed `frequency` column and alias like `flux_density_I` for flux columns in output +of `SkyModel.to_recarray`, + ## [0.1.3] - 2022-02-22 ### Added diff --git a/pyradiosky/__init__.py b/pyradiosky/__init__.py index 19c50208..48f3e1ca 100644 --- a/pyradiosky/__init__.py +++ b/pyradiosky/__init__.py @@ -20,17 +20,4 @@ # package is not installed pass -from .skymodel import ( - SkyModel, - array_to_skymodel, - healpix_to_sky, - read_gleam_catalog, - read_healpix_hdf5, - read_idl_catalog, - read_text_catalog, - read_votable_catalog, - skymodel_to_array, - source_cuts, - write_catalog_to_file, - write_healpix_hdf5, -) +from .skymodel import SkyModel diff --git a/pyradiosky/skymodel.py b/pyradiosky/skymodel.py index d670ccca..5c57fd65 100644 --- a/pyradiosky/skymodel.py +++ b/pyradiosky/skymodel.py @@ -37,21 +37,7 @@ from . import spherical_coords_transforms as sct from . import utils as skyutils -__all__ = [ - "hasmoon", - "SkyModel", - "read_healpix_hdf5", - "healpix_to_sky", - "skymodel_to_array", - "array_to_skymodel", - "source_cuts", - "read_gleam_catalog", - "read_votable_catalog", - "read_text_catalog", - "read_idl_catalog", - "write_catalog_to_file", - "write_healpix_hdf5", -] +__all__ = ["hasmoon", "SkyModel"] try: from lunarsky import LunarTopo, MoonLocation @@ -414,6 +400,7 @@ def _set_component_type_params(self, component_type): self._hpx_order.required = False self._hpx_frame.required = False + @units.quantity_input(freq_array=units.Hz, reference_frequency=units.Hz) def __init__( self, name=None, @@ -441,8 +428,7 @@ def __init__( filename=None, ): # standard angle tolerance: 1 mas in radians. - self.angle_tol = Angle(1, units.arcsec) - self.future_angle_tol = Angle(1e-3, units.arcsec) + self.angle_tol = Angle(1e-3, units.arcsec) # Frequency tolerance: 1 Hz self.freq_tol = 1 * units.Hz @@ -691,24 +677,6 @@ def __init__( " Read/written with pyradiosky version: " + __version__ + "." ) - # handle old parameter order - # (use to be: name, ra, dec, stokes, freq_array, spectral_type) - if isinstance(spectral_type, (np.ndarray, list, float, Quantity)): - warnings.warn( - "The input parameters to SkyModel.__init__ have changed. Please " - "update the call. This will become an error in version 0.2.0.", - category=DeprecationWarning, - ) - freqs_use = spectral_type - spectral_type = freq_array - - if spectral_type == "flat" and np.asarray(freqs_use).size == 1: - reference_frequency = np.zeros(self.Ncomponents) + freqs_use[0] - freq_array = None - else: - freq_array = freqs_use - reference_frequency = None - if component_type is not None: if component_type not in self._component_type.acceptable_vals: raise ValueError( @@ -921,62 +889,12 @@ def __init__( self._set_spectral_type_params(spectral_type) if freq_array is not None: - if isinstance(freq_array, (list)): - # try just converting the list to a Quantity. This will work if all - # the elements are Quantities with compatible units or if all the - # elements are just numeric (in which case the units will be ""). - warnings.warn( - "freq_array is a list. Attempting to convert to a Quantity." - ) - try: - freq_array = Quantity(freq_array) - except TypeError as err: - raise ValueError( - "If freq_array is supplied as a list, all the elements must be " - "Quantity objects with compatible units." - ) from err - if not isinstance(freq_array, (Quantity,)) or freq_array.unit == "": - # This catches arrays or lists that have all numeric types - warnings.warn( - "In version 0.2.0, the freq_array will be required to be an " - "astropy Quantity with units that are convertable to Hz. " - "Currently, floats are assumed to be in Hz.", - category=DeprecationWarning, - ) - freq_array = freq_array * units.Hz self.freq_array = np.atleast_1d(freq_array) self.Nfreqs = self.freq_array.size else: self.Nfreqs = 1 if reference_frequency is not None: - if isinstance(reference_frequency, (list)): - # try just converting the list to a Quantity. This will work if all - # the elements are Quantities with compatible units or if all the - # elements are just numeric (in which case the units will be ""). - warnings.warn( - "reference_frequency is a list. Attempting to convert to a " - "Quantity." - ) - try: - reference_frequency = Quantity(reference_frequency) - except TypeError as err: - raise ValueError( - "If reference_frequency is supplied as a list, all the " - "elements must be Quantity objects with compatible units." - ) from err - if ( - not isinstance(reference_frequency, (Quantity,)) - or reference_frequency.unit == "" - ): - # This catches arrays or lists that have all numeric types - warnings.warn( - "In version 0.2.0, the reference_frequency will be required to " - "be an astropy Quantity with units that are convertable to Hz. " - "Currently, floats are assumed to be in Hz.", - category=DeprecationWarning, - ) - reference_frequency = reference_frequency * units.Hz self.reference_frequency = np.atleast_1d(reference_frequency) if spectral_index is not None: @@ -984,29 +902,10 @@ def __init__( if isinstance(stokes, Quantity): self.stokes = stokes - elif isinstance(stokes, list): - raise ValueError( - "Stokes should be passed as an astropy Quantity array not a list" - ) - elif isinstance(stokes, np.ndarray): - # this catches stokes supplied as a numpy array - if self.component_type == "point": - allowed_units = ["Jy", "K sr"] - default_unit = "Jy" - else: - allowed_units = ["Jy/sr", "K"] - default_unit = "K" - - warnings.warn( - "In version 0.2.0, stokes will be required to be an astropy " - f"Quantity with units that are convertable to one of {allowed_units}. " - f"Currently, floats are assumed to be in {default_unit}.", - category=DeprecationWarning, - ) - self.stokes = Quantity(stokes, default_unit) else: raise ValueError( - "Stokes should be passed as an astropy Quantity array." + "Stokes should be passed as an astropy Quantity array (not a list " + "or numpy array)." ) if self.Ncomponents == 1: @@ -1152,20 +1051,6 @@ def _set_spectral_type_params(self, spectral_type): self._reference_frequency.required = False self._Nfreqs.acceptable_vals = [1] - def set_spectral_type_params(self, spectral_type): - """ - Set parameters depending on spectral_type. - - Deprecated, use _set_spectral_type_params - """ - warnings.warn( - "This function is deprecated, use `_set_spectral_type_params` instead. " - "This funtion will be removed in 0.2.0.", - category=DeprecationWarning, - ) - - self._set_spectral_type_params(spectral_type) - @property def ncomponent_length_params(self): """Iterate over ncomponent length paramters.""" @@ -1276,36 +1161,6 @@ def __eq__( other, check_extra=check_extra, allowed_failures=allowed_failures ) - if equal and not self.component_type == "healpix": - # Issue deprecation warning if skycoords aren't close to future_angle_tol levels - sky_separation = self.skycoord.separation(other.skycoord).rad - if np.any(sky_separation > self.future_angle_tol.rad): - warnings.warn( - "The skycoord parameters are not within the future tolerance. " - f"The sky separation between them is {sky_separation}, " - "This will become an error in version 0.2.0", - category=DeprecationWarning, - ) - - if not equal: - equal = super(SkyModel, self).__eq__(other, check_extra=False) - - if equal: - # required params are equal, extras are not but check_extra is turned on. - # Issue future warning! - unequal_name_list = [] - for param in self.extra(): - this_param = getattr(self, param) - other_param = getattr(other, param) - if this_param != other_param: - unequal_name_list.append(this_param.name) - - warnings.warn( - f"Future equality does not pass, because parameters {unequal_name_list} " - "are not equal. This will become an error in version 0.2.0", - category=DeprecationWarning, - ) - return equal def transform_to(self, frame): @@ -2629,7 +2484,7 @@ def _calc_coherency_rotation(self, inds=None): return coherency_rot_matrix - def coherency_calc(self, deprecated_location=None, store_frame_coherency=True): + def coherency_calc(self, store_frame_coherency=True): """ Calculate the local coherency in alt/az basis. @@ -2641,9 +2496,6 @@ def coherency_calc(self, deprecated_location=None, store_frame_coherency=True): Parameters ---------- - deprecated_location : :class:`astropy.coordinates.EarthLocation` - This keyword is deprecated. It is preserved to maintain backwards - compatibility and sets the EarthLocation on this SkyModel object. store_frame_coherency : bool Option to store the frame_coherency to the object. This saves time for repeated calls but adds memory. @@ -2652,6 +2504,7 @@ def coherency_calc(self, deprecated_location=None, store_frame_coherency=True): ------- array of float local coherency in alt/az basis, shape (2, 2, Nfreqs, Ncomponents) + """ if self.above_horizon is None: warnings.warn( @@ -2662,15 +2515,6 @@ def coherency_calc(self, deprecated_location=None, store_frame_coherency=True): else: above_horizon = self.above_horizon - if deprecated_location is not None: - warnings.warn( - "Passing telescope_location to SkyModel.coherency_calc is " - "deprecated. Set the telescope_location via SkyModel.update_positions. " - "This will become an error in version 0.2.0", - category=DeprecationWarning, - ) - self.update_positions(self.time, deprecated_location) - if not isinstance( self.telescope_location, self._telescope_location.expected_type ): @@ -3466,14 +3310,11 @@ def _text_write_preprocess(self): # This will add e.g. ra_J2000 and dec_J2000 for FK5 component_fieldnames.append(comp_name + "_" + frame_desc_str) fieldnames = ["source_id"] + component_fieldnames - # Alias "flux_density_" for "I", etc. - stokes_names = [(f"flux_density_{k}", k) for k in ["I", "Q", "U", "V"]] + stokes_names = ["I", "Q", "U", "V"] fieldshapes = [()] * 3 if self.stokes_error is not None: - stokes_error_names = [ - (f"flux_density_error_{k}", f"{k}_error") for k in ["I", "Q", "U", "V"] - ] + stokes_error_names = [(f"{k}_error") for k in ["I", "Q", "U", "V"]] n_stokes = 0 stokes_keep = [] @@ -3499,17 +3340,9 @@ def _text_write_preprocess(self): fieldtypes.append("f8") fieldshapes.extend([(self.Nfreqs,)]) elif self.reference_frequency is not None: - # add frequency field (a copy of reference_frequency) for backwards - # compatibility. - warnings.warn( - "The reference_frequency is aliased as `frequency` in the recarray " - "for backwards compatibility. In version 0.2.0, " - "only `reference_frequency` will be an accepted column key.", - category=DeprecationWarning, - ) - fieldnames.extend([("frequency", "reference_frequency")]) - fieldtypes.extend(["f8"] * 2) - fieldshapes.extend([()] * n_stokes + [()] * 2) + fieldnames.extend([("reference_frequency")]) + fieldtypes.extend(["f8"]) + fieldshapes.extend([()] * n_stokes + [()]) if self.spectral_index is not None: fieldnames.append("spectral_index") fieldtypes.append("f8") @@ -3535,11 +3368,9 @@ def _text_write_preprocess(self): for ii in range(4): if stokes_keep[ii]: - arr[stokes_names[ii][0]] = self.stokes[ii].T.to("Jy").value + arr[stokes_names[ii]] = self.stokes[ii].T.to("Jy").value if self.stokes_error is not None: - arr[stokes_error_names[ii][0]] = ( - self.stokes_error[ii].T.to("Jy").value - ) + arr[stokes_error_names[ii]] = self.stokes_error[ii].T.to("Jy").value if self.freq_array is not None: if self.spectral_type == "subband": @@ -3547,7 +3378,7 @@ def _text_write_preprocess(self): else: arr["frequency"] = self.freq_array.to("Hz").value elif self.reference_frequency is not None: - arr["frequency"] = self.reference_frequency.to("Hz").value + arr["reference_frequency"] = self.reference_frequency.to("Hz").value if self.spectral_index is not None: arr["spectral_index"] = self.spectral_index @@ -3556,12 +3387,6 @@ def _text_write_preprocess(self): if hasattr(self, "_set_lst"): arr["set_lst"] = self._set_lst - warnings.warn( - "recarray flux columns will no longer be labeled" - " `flux_density_I` etc. in version 0.2.0. Use `I` instead.", - DeprecationWarning, - ) - if original_comp_type == "healpix": self._point_to_healpix() if original_units_k: @@ -4217,35 +4042,15 @@ def read_votable_catalog( table_ids = [table._ID for table in tables] table_names = [table.name for table in tables] - if None not in table_ids: - try: - table_name_use = _get_matching_fields(table_name, table_ids) - table_match = [ - table for table in tables if table._ID == table_name_use - ][0] - except ValueError: - table_name_use = _get_matching_fields(table_name, table_names) - table_match = [ - table for table in tables if table.name == table_name_use - ][0] - else: - warnings.warn( - f"File {votable_file} contains tables with no name or ID, Support for " - "such files is deprecated and will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - # Find correct table using the field names - tables_match = [] - for table in tables: - id_col_use = _get_matching_fields( - id_column, table.to_table().colnames, brittle=False - ) - if id_col_use is not None: - tables_match.append(table) - if len(tables_match) > 1: - raise ValueError("More than one matching table.") - else: - table_match = tables_match[0] + if None in table_ids: + raise ValueError(f"File {votable_file} contains tables with no name or ID.") + + try: + table_name_use = _get_matching_fields(table_name, table_ids) + table_match = [table for table in tables if table._ID == table_name_use][0] + except ValueError: + table_name_use = _get_matching_fields(table_name, table_names) + table_match = [table for table in tables if table.name == table_name_use][0] # Convert to astropy Table astropy_table = table_match.to_table() @@ -4995,68 +4800,6 @@ def from_fhd_catalog(cls, filename_sav, **kwargs): self.read_fhd_catalog(filename_sav, **kwargs) return self - def read_idl_catalog( - self, - filename_sav, - expand_extended=True, - source_select_kwds=None, - run_check=True, - check_extra=True, - run_check_acceptability=True, - ): - """ - Read in an FHD style catalog file. - - Deprecated. Use `read_fhd_catalog` instead. - - Parameters - ---------- - filename_sav: str - Path to IDL .sav file. - - expand_extended: bool - If True, include extended source components. - source_select_kwds : dict, optional - This parameter is Deprecated, please use the `select` and/or the - :meth:`cut_nonrising` methods as appropriate. - - Dictionary of keywords for source selection. Valid options: - - * `latitude_deg`: Latitude of telescope in degrees. Used for declination coarse - * horizon cut. - * `horizon_buffer`: Angle (float, in radians) of buffer for coarse horizon cut. - Default is about 10 minutes of sky rotation. (See caveats in - :func:`array_to_skymodel` docstring) - * `min_flux`: Minimum stokes I flux to select [Jy] - * `max_flux`: Maximum stokes I flux to select [Jy] - run_check : bool - Option to check for the existence and proper shapes of parameters - after downselecting data on this object (the default is True, - meaning the check will be run). - check_extra : bool - Option to check optional parameters as well as required ones (the - default is True, meaning the optional parameters will be checked). - run_check_acceptability : bool - Option to check acceptable range of the values of parameters after - downselecting data on this object (the default is True, meaning the - acceptable range check will be done). - - - """ - warnings.warn( - "This method is deprecated, use `read_fhd_catalog` instead. " - "This method will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - self.read_fhd_catalog( - filename_sav, - expand_extended=expand_extended, - source_select_kwds=source_select_kwds, - run_check=run_check, - check_extra=check_extra, - run_check_acceptability=run_check_acceptability, - ) - def read( self, filename, @@ -5710,584 +5453,3 @@ def write_text_catalog(self, filename): ) else: fo.write(format_str.format(srcid, lon, lat, *fluxes_write)) - - -def read_healpix_hdf5(hdf5_filename): - """ - Read hdf5 healpix files using h5py and get a healpix map, indices and frequencies. - - Deprecated. Use `read_skyh5` or `read_healpix_hdf5` instead. - - Parameters - ---------- - hdf5_filename : str - Path and name of the hdf5 file to read. - - Returns - ------- - hpmap : array_like of float - Stokes-I surface brightness in K, for a set of pixels - Shape (Ncomponents, Nfreqs) - indices : array_like, int - Corresponding HEALPix indices for hpmap. - freqs : array_like, float - Frequencies in Hz. Shape (Nfreqs) - """ - warnings.warn( - "This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - with h5py.File(hdf5_filename, "r") as fileobj: - hpmap = fileobj["data"][0, ...] # Remove Nskies axis. - indices = fileobj["indices"][()] - freqs = fileobj["freqs"][()] - - return hpmap, indices, freqs - - -def write_healpix_hdf5(filename, hpmap, indices, freqs, nside=None, history=None): - """ - Write a set of HEALPix maps to an HDF5 file. - - Deprecated. Use `SkyModel.write_skyh5` instead. - - Parameters - ---------- - filename : str - Name of file to write to. - hpmap : array_like of float - Pixel values in Kelvin. Shape (Nfreqs, Npix) - indices : array_like of int - HEALPix pixel indices corresponding with axis 1 of hpmap. - freqs : array_like of floats - Frequencies in Hz corresponding with axis 0 of hpmap. - nside : int - nside parameter of the map. Optional if the hpmap covers - the full sphere (i.e., has no missing pixels), since the nside - can be inferred from the map size. - history : str - Optional history string to include in the file. - - """ - try: - import astropy_healpix - except ImportError as e: - raise ImportError( - "The astropy-healpix module must be installed to use HEALPix methods" - ) from e - - warnings.warn( - "This function is deprecated, use `SkyModel.write_skyh5` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - Nfreqs = freqs.size - Npix = len(indices) - if nside is None: - try: - nside = astropy_healpix.npix_to_nside(Npix) - except ValueError: - raise ValueError( # noqa: B904 - "Need to provide nside if giving a subset of the map." - ) - - try: - assert hpmap.shape == (Nfreqs, Npix) - except AssertionError: - raise ValueError("Invalid map shape {}".format(str(hpmap.shape))) # noqa: B904 - - if history is None: - history = "" - - valid_params = { - "Npix": Npix, - "nside": nside, - "Nskies": 1, - "Nfreqs": Nfreqs, - "data": hpmap[None, ...], - "indices": indices, - "freqs": freqs, - "units": "K", - "history": history, - } - dsets = { - "data": np.float64, - "indices": np.int32, - "freqs": np.float64, - "history": h5py.special_dtype(vlen=str), - } - - with h5py.File(filename, "w") as fileobj: - for k in valid_params: - d = valid_params[k] - if k in dsets: - if np.isscalar(d): - fileobj.create_dataset(k, data=d, dtype=dsets[k]) - else: - fileobj.create_dataset( - k, - data=d, - dtype=dsets[k], - compression="gzip", - compression_opts=9, - ) - else: - fileobj.attrs[k] = d - - -def healpix_to_sky(hpmap, indices, freqs, hpx_order="ring"): - """ - Convert a healpix map in K to a set of point source components in Jy. - - Deprecated. Use `read_skyh5` or `read_healpix_hdf5` instead. - - Parameters - ---------- - hpmap : array_like of float - Stokes-I surface brightness in K, for a set of pixels - Shape (Nfreqs, Ncomponents) - indices : array_like, int - Corresponding HEALPix indices for hpmap. - freqs : array_like, float - Frequencies in Hz. Shape (Nfreqs) - hpx_order : str - HEALPix map ordering parameter: ring or nested. - Defaults to ring. - - Returns - ------- - sky : :class:`SkyModel` - The sky model created from the healpix map. - - Notes - ----- - Currently, this function only converts a HEALPix map with a frequency axis. - """ - try: - import astropy_healpix - except ImportError as e: - raise ImportError( - "The astropy-healpix module must be installed to use HEALPix methods" - ) from e - - warnings.warn( - "This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - hpx_order = str(hpx_order).casefold() - if hpx_order not in ["ring", "nested"]: - raise ValueError("order must be 'nested' or 'ring'") - - nside = int(astropy_healpix.npix_to_nside(hpmap.shape[-1])) - - freq = Quantity(freqs, "hertz") - - stokes = Quantity(np.zeros((4, len(freq), len(indices))), "K") - stokes[0] = hpmap * units.K - - sky = SkyModel( - stokes=stokes, - spectral_type="full", - freq_array=freq, - nside=nside, - hpx_inds=indices, - hpx_order=hpx_order, - ) - return sky - - -def skymodel_to_array(sky): - """ - Make a recarray of source components from a SkyModel object. - - Deprecated, will be removed in v0.2.0. - - Parameters - ---------- - sky : :class:`pyradiosky.SkyModel` - SkyModel object to convert to a recarray. - - Returns - ------- - catalog_table : recarray - recarray equivalent to SkyModel data. - - Notes - ----- - This stores all SkyModel data in a contiguous array - that can be more easily handled with numpy. - This is used by pyuvsim for sharing catalog data via MPI. - """ - warnings.warn( - "This function is deprecated, and will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return sky.to_recarray() - - -def array_to_skymodel(catalog_table): - """ - Make a SkyModel object from a recarray. - - Deprecated, will be removed in v0.2.0. - - Parameters - ---------- - catalog_table : recarray - recarray to turn into a SkyModel object. - - Returns - ------- - :class:`pyradiosky.SkyModel` - - """ - warnings.warn( - "This function is deprecated, and will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return SkyModel.from_recarray(catalog_table) - - -def source_cuts( - catalog_table, - latitude_deg=None, - horizon_buffer=0.04364, - min_flux=None, - max_flux=None, - freq_range=None, -): - """ - Perform flux and horizon selections on recarray of source components. - - Deprecated. Use the `SkyModel.select` and/or `SkyModel.cut_nonrising` methods - instead. - - Parameters - ---------- - catalog_table : recarray - recarray of source catalog information. Must have the columns: - 'source_id', 'ra_j2000', 'dec_j2000', 'flux_density' - may also have the colums: - 'frequency' or 'reference_frequency' - latitude_deg : float - Latitude of telescope in degrees. Used to estimate rise/set lst. - horizon_buffer : float - Angle buffer for coarse horizon cut in radians. - Default is about 10 minutes of sky rotation. `SkyModel` - components whose calculated altitude is less than `horizon_buffer` are excluded. - Caution! The altitude calculation does not account for precession/nutation of the Earth. - The buffer angle is needed to ensure that the horizon cut doesn't exclude sources near - but above the horizon. Since the cutoff is done using lst, and the lsts are calculated - with astropy, the required buffer should _not_ drift with time since the J2000 epoch. - The default buffer has been tested around julian date 2457458.0. - min_flux : float - Minimum stokes I flux to select [Jy] - max_flux : float - Maximum stokes I flux to select [Jy] - freq_range : :class:`astropy.units.Quantity` - Frequency range over which the min and max flux tests should be performed. - Must be length 2. If None, use the range over which the object is defined. - - Returns - ------- - recarray - A new recarray of source components, with additional columns for rise and set lst. - - """ - warnings.warn( - "This function is deprecated, use the `SkyModel.select` and/or" - "`SkyModel.cut_nonrising` methods instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - skyobj = SkyModel.from_recarray(catalog_table) - - if min_flux is not None and max_flux is not None: - if min_flux is not None: - min_flux = min_flux * units.Jy - if max_flux is not None: - max_flux = max_flux * units.Jy - - skyobj.select( - min_brightness=min_flux, - max_brightness=max_flux, - brightness_freq_range=freq_range, - ) - - if latitude_deg is not None: - lat_use = Latitude(latitude_deg, units.deg) - skyobj.cut_nonrising(lat_use) - skyobj.calculate_rise_set_lsts(lat_use, horizon_buffer=horizon_buffer) - - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return skyobj.to_recarray() - - -def read_votable_catalog( - votable_file, - table_name="GLEAM", - id_column="GLEAM", - ra_column="RAJ2000", - dec_column="DEJ2000", - flux_columns="Fintwide", - reference_frequency=200e6 * units.Hz, - freq_array=None, - spectral_index_column=None, - source_select_kwds=None, - return_table=False, -): - """ - Create a SkyModel object from a VOTable catalog. - - Deprecated. Use `SkyModel.read_votable_catalog` instead. - - Parameters - ---------- - votable_file : str - Path to votable catalog file. - table_name : str - Part of expected table name. Should match only one table name in votable_file. - id_column : str - Part of expected ID column. Should match only one column in the table. - ra_column : str - Part of expected RA column. Should match only one column in the table. - dec_column : str - Part of expected Dec column. Should match only one column in the table. - flux_columns : str or list of str - Part of expected Flux column(s). Each one should match only one column in the table. - reference_frequency : :class:`astropy.units.Quantity` - Reference frequency for flux values, assumed to be the same value for all rows. - freq_array : :class:`astropy.units.Quantity` - Frequencies corresponding to flux_columns (should be same length). - Required for multiple flux columns. - return_table : bool, optional - Whether to return the astropy table instead of a list of Source objects. - source_select_kwds : dict, optional - Dictionary of keywords for source selection Valid options: - - * `latitude_deg`: Latitude of telescope in degrees. Used for declination coarse - horizon cut. - * `horizon_buffer`: Angle (float, in radians) of buffer for coarse horizon cut. - Default is about 10 minutes of sky rotation. (See caveats in - :func:`array_to_skymodel` docstring) - * `min_flux`: Minimum stokes I flux to select [Jy] - * `max_flux`: Maximum stokes I flux to select [Jy] - - Returns - ------- - recarray or :class:`pyradiosky.SkyModel` - if return_table, recarray of source parameters, otherwise - :class:`pyradiosky.SkyModel` instance - - """ - warnings.warn( - "This function is deprecated, use `SkyModel.read_votable_catalog` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - skyobj = SkyModel() - skyobj.read_votable_catalog( - votable_file, - table_name, - id_column, - ra_column, - dec_column, - flux_columns, - frame="icrs", - reference_frequency=reference_frequency, - freq_array=freq_array, - spectral_index_column=spectral_index_column, - source_select_kwds=source_select_kwds, - ) - - if return_table: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return skyobj.to_recarray() - - return skyobj - - -def read_gleam_catalog( - gleam_file, spectral_type="subband", source_select_kwds=None, return_table=False -): - """ - Create a SkyModel object from the GLEAM votable catalog. - - Deprecated. Use `SkyModel.read_gleam_catalog` instead. - - Tested on: GLEAM EGC catalog, version 2 - - Parameters - ---------- - gleam_file : str - Path to GLEAM votable catalog file. - spectral_type : str - One of 'flat', 'subband' or 'spectral_index'. If set to 'flat', the - wide band integrated flux will be used, if set to 'spectral_index' the - fitted flux at 200 MHz will be used for the flux column. - return_table : bool, optional - Whether to return the astropy table instead of a SkyModel object. - source_select_kwds : dict, optional - Dictionary of keywords for source selection Valid options: - - * `latitude_deg`: Latitude of telescope in degrees. Used for declination coarse - horizon cut. - * `horizon_buffer`: Angle (float, in radians) of buffer for coarse horizon cut. - Default is about 10 minutes of sky rotation. (See caveats in - :func:`array_to_skymodel` docstring) - * `min_flux`: Minimum stokes I flux to select [Jy] - * `max_flux`: Maximum stokes I flux to select [Jy] - - Returns - ------- - recarray or :class:`pyradiosky.SkyModel` - if return_table, recarray of source parameters, - otherwise :class:`pyradiosky.SkyModel` instance - """ - warnings.warn( - "This function is deprecated, use `SkyModel.read_gleam_catalog` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - skyobj = SkyModel() - skyobj.read_gleam_catalog( - gleam_file, spectral_type=spectral_type, source_select_kwds=source_select_kwds - ) - - if return_table: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return skyobj.to_recarray() - - return skyobj - - -def read_text_catalog(catalog_csv, source_select_kwds=None, return_table=False): - """ - Read in a text file of sources. - - Deprecated. Use `SkyModel.read_text_catalog` instead. - - Parameters - ---------- - catalog_csv: str - Path to tab separated value file with the following required columns: - * `Source_ID`: source name as a string of maximum 10 characters - * `ra_j2000`: right ascension at J2000 epoch, in decimal degrees - * `dec_j2000`: declination at J2000 epoch, in decimal degrees - * `Flux [Jy]`: Stokes I flux density in Janskys - - If flux is specified at multiple frequencies (must be the same set for all - components), the frequencies must be included in each column name, - e.g. `Flux at 150 MHz [Jy]`. Recognized units are ('Hz', 'kHz', 'MHz' or 'GHz'): - - If flux is only specified at one reference frequency (can be different per - component), a frequency column should be added (note: assumed to be in Hz): - * `Frequency`: reference frequency [Hz] - - Optionally a spectral index can be specified per component with: - * `Spectral_Index`: spectral index - - source_select_kwds : dict, optional - Dictionary of keywords for source selection. Valid options: - - * `latitude_deg`: Latitude of telescope in degrees. Used for declination coarse - * horizon cut. - * `horizon_buffer`: Angle (float, in radians) of buffer for coarse horizon cut. - Default is about 10 minutes of sky rotation. (See caveats in - :func:`array_to_skymodel` docstring) - * `min_flux`: Minimum stokes I flux to select [Jy] - * `max_flux`: Maximum stokes I flux to select [Jy] - - Returns - ------- - sky_model : :class:`SkyModel` - A sky model created from the text catalog. - """ - warnings.warn( - "This function is deprecated, use `SkyModel.read_text_catalog` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - skyobj = SkyModel() - skyobj.read_text_catalog(catalog_csv, source_select_kwds=source_select_kwds) - - if return_table: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return skyobj.to_recarray() - - return skyobj - - -def read_idl_catalog(filename_sav, expand_extended=True): - """ - Read in an FHD-readable IDL .sav file catalog. - - Deprecated. Use `SkyModel.read_fhd_catalog` instead. - - Parameters - ---------- - filename_sav: str - Path to IDL .sav file. - - expand_extended: bool - If True, return extended source components. - Default: True - - Returns - ------- - :class:`pyradiosky.SkyModel` - """ - warnings.warn( - "This function is deprecated, use `SkyModel.read_fhd_catalog` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - skyobj = SkyModel() - skyobj.read_fhd_catalog(filename_sav, expand_extended=expand_extended) - - return skyobj - - -def write_catalog_to_file(filename, skymodel): - """ - Write out a catalog to a text file. - - Readable with :meth:`read_text_catalog()`. - - Parameters - ---------- - filename : str - Path to output file (string) - skymodel : :class:`SkyModel` - The sky model to write to file. - """ - warnings.warn( - "This function is deprecated, use `SkyModel.write_text_catalog` instead. " - "This function will be removed in version 0.2.0.", - category=DeprecationWarning, - ) - - skymodel.write_text_catalog(filename) diff --git a/pyradiosky/tests/test_skymodel.py b/pyradiosky/tests/test_skymodel.py index 9c2cc81b..18a14d30 100644 --- a/pyradiosky/tests/test_skymodel.py +++ b/pyradiosky/tests/test_skymodel.py @@ -295,15 +295,6 @@ def healpix_gsm_icrs(): del sky -def test_set_spectral_params(zenith_skymodel): - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `_set_spectral_type_params` instead.", - ): - zenith_skymodel.set_spectral_type_params(zenith_skymodel.spectral_type) - - def test_init_error(zenith_skycoord): with pytest.raises(ValueError, match="If initializing with values, all of"): @@ -355,16 +346,34 @@ def test_init_error_freqparams(zenith_skycoord, spec_type): def test_check_errors(): skyobj = SkyModel.from_gleam_catalog(GLEAM_vot, with_error=True) + skyobj2 = skyobj.copy() # Change units on stokes_error - skyobj.stokes_error = skyobj.stokes_error / units.sr + skyobj2.stokes_error = skyobj.stokes_error / units.sr with pytest.raises( ValueError, match="stokes_error parameter must have units that are equivalent to the " "units of the stokes parameter.", ): - skyobj.check() + skyobj2.check() + + # incompatible units for freq_array or reference_freq + skyobj2 = skyobj.copy() + skyobj2.freq_array = skyobj2.freq_array / units.sr + with pytest.raises( + ValueError, match="freq_array must have a unit that can be converted to Hz." + ): + skyobj2.check() + + skyobj = SkyModel.from_gleam_catalog(GLEAM_vot, spectral_type="spectral_index") + skyobj2 = skyobj.copy() + skyobj2.reference_frequency = skyobj2.reference_frequency / units.sr + with pytest.raises( + ValueError, + match="reference_frequency must have a unit that can be converted to Hz.", + ): + skyobj2.check() def test_source_zenith_from_icrs(time_location): @@ -408,15 +417,7 @@ def test_source_zenith(time_location, zenith_skymodel): assert np.allclose(zenith_source_lmn, np.array([0, 0, 1])) -@pytest.mark.parametrize( - "spec_type, param", - [ - ("flat", "ra"), - ("flat", "dec"), - ("spectral_index", "reference_frequency"), - ("subband", "freq_array"), - ], -) +@pytest.mark.parametrize("spec_type, param", [("flat", "ra"), ("flat", "dec")]) def test_init_lists(spec_type, param, zenith_skycoord): icrs_coord = zenith_skycoord @@ -455,103 +456,78 @@ def test_init_lists(spec_type, param, zenith_skycoord): spectral_type=spec_type, ) - list_warning = None if param == "ra": ras = list(ras) elif param == "dec": decs = list(decs) - elif param == "reference_frequency": - ref_freqs = list(ref_freqs) - list_warning = ( - "reference_frequency is a list. Attempting to convert to a Quantity." - ) - warn_type = UserWarning - elif param == "freq_array": - freq_array = list(freq_array) - list_warning = "freq_array is a list. Attempting to convert to a Quantity." - warn_type = UserWarning - if list_warning is not None: - with uvtest.check_warnings(warn_type, match=list_warning): - list_model = SkyModel( - name=names, - ra=ras, - dec=decs, - frame="icrs", - stokes=stokes, - reference_frequency=ref_freqs, - spectral_index=spec_index, - freq_array=freq_array, - spectral_type=spec_type, - ) - else: - list_model = SkyModel( - name=names, - ra=ras, - dec=decs, - frame="icrs", - stokes=stokes, - reference_frequency=ref_freqs, - spectral_index=spec_index, - freq_array=freq_array, - spectral_type=spec_type, - ) + list_model = SkyModel( + name=names, + ra=ras, + dec=decs, + frame="icrs", + stokes=stokes, + reference_frequency=ref_freqs, + spectral_index=spec_index, + freq_array=freq_array, + spectral_type=spec_type, + ) assert ref_model == list_model @pytest.mark.parametrize( - "spec_type, param, msg", + ["spec_type", "param", "err_type", "msg"], [ - ("flat", "ra", "ra must be one or more Longitude objects"), - ("flat", "ra_lat", "ra must be one or more Longitude objects"), - ("flat", "dec", "dec must be one or more Latitude objects"), - ("flat", "dec_lon", "dec must be one or more Latitude objects"), + ("flat", "ra", ValueError, "ra must be one or more Longitude objects"), + ("flat", "ra_lat", ValueError, "ra must be one or more Longitude objects"), + ("flat", "dec", ValueError, "dec must be one or more Latitude objects"), + ("flat", "dec_lon", ValueError, "dec must be one or more Latitude objects"), ( "flat", "stokes", - "Stokes should be passed as an astropy Quantity array not a list", + ValueError, + "Stokes should be passed as an astropy Quantity array (not a list or numpy " + "array).", ), - ("flat", "stokes_obj", "Stokes should be passed as an astropy Quantity array."), ( - "spectral_index", - "reference_frequency", - "If reference_frequency is supplied as a list, all the elements must be " - "Quantity objects with compatible units.", + "flat", + "stokes_obj", + ValueError, + "Stokes should be passed as an astropy Quantity array (not a list or numpy " + "array).", ), ( "spectral_index", - "reference_frequency_jy", - re.escape( - "'Jy' (spectral flux density) and 'Hz' (frequency) are not convertible" - ), + "reference_frequency", + TypeError, + "Argument 'reference_frequency' to function '__init__' has no 'unit' " + "attribute. You should pass in an astropy Quantity instead.", ), ( "spectral_index", - "reference_frequency_obj", - "If reference_frequency is supplied as a list, all the elements must be " - "Quantity objects with compatible units.", + "reference_frequency_jy", + units.core.UnitsError, + "Argument 'reference_frequency' to function '__init__' must be in units " + "convertible to 'Hz'.", ), ( "subband", "freq_array", - "If freq_array is supplied as a list, all the elements must be Quantity " - "objects with compatible units.", + TypeError, + "Argument 'freq_array' to function '__init__' has no 'unit' attribute. " + "You should pass in an astropy Quantity instead.", ), ( "subband", "freq_array_ang", - re.escape("'deg' (angle) and 'Hz' (frequency) are not convertible"), - ), - ( - "subband", - "freq_array_obj", - "If freq_array is supplied as a list, all the elements must be Quantity " - "objects with compatible units.", + units.core.UnitsError, + "Argument 'freq_array' to function '__init__' must be in units " + "convertible to 'Hz'.", ), ], ) -def test_init_lists_errors(spec_type, param, msg, zenith_skycoord): +def test_init_lists_errors(spec_type, param, err_type, msg, zenith_skycoord): icrs_coord = zenith_skycoord ras = Longitude( @@ -578,16 +554,6 @@ def test_init_lists_errors(spec_type, param, msg, zenith_skycoord): ref_freqs = None spec_index = None - list_warning = None - if "freq_array" in param: - list_warning = "freq_array is a list. Attempting to convert to a Quantity." - warn_type = UserWarning - elif "reference_frequency" in param: - list_warning = ( - "reference_frequency is a list. Attempting to convert to a Quantity." - ) - warn_type = UserWarning - if param == "ra": ras = list(ras) ras[1] = ras[1].value @@ -602,22 +568,12 @@ def test_init_lists_errors(spec_type, param, msg, zenith_skycoord): decs[1] = ras[1] elif param == "reference_frequency": ref_freqs = list(ref_freqs) - ref_freqs[1] = ref_freqs[1].value elif param == "reference_frequency_jy": - ref_freqs = list(ref_freqs) - ref_freqs[1] = ref_freqs[1].value * units.Jy - elif param == "reference_frequency_obj": - ref_freqs = list(ref_freqs) - ref_freqs[1] = icrs_coord + ref_freqs = ref_freqs.value * units.Jy elif param == "freq_array": freq_array = list(freq_array) - freq_array[1] = freq_array[1].value elif param == "freq_array_ang": - freq_array = list(freq_array) - freq_array[1] = ras[1] - elif param == "freq_array_obj": - freq_array = list(freq_array) - freq_array[1] = icrs_coord + freq_array = ras elif param == "stokes": stokes = list(stokes) stokes[1] = stokes[1].value.tolist() @@ -626,32 +582,18 @@ def test_init_lists_errors(spec_type, param, msg, zenith_skycoord): elif param == "stokes_obj": stokes = icrs_coord - with pytest.raises(ValueError, match=msg): - if list_warning is not None: - with uvtest.check_warnings(warn_type, match=list_warning): - SkyModel( - name=names, - ra=ras, - dec=decs, - frame=frame, - stokes=stokes, - reference_frequency=ref_freqs, - spectral_index=spec_index, - freq_array=freq_array, - spectral_type=spec_type, - ) - else: - SkyModel( - name=names, - ra=ras, - dec=decs, - frame=frame, - stokes=stokes, - reference_frequency=ref_freqs, - spectral_index=spec_index, - freq_array=freq_array, - spectral_type=spec_type, - ) + with pytest.raises(err_type, match=re.escape(msg)): + SkyModel( + name=names, + ra=ras, + dec=decs, + frame=frame, + stokes=stokes, + reference_frequency=ref_freqs, + spectral_index=spec_index, + freq_array=freq_array, + spectral_type=spec_type, + ) def test_skymodel_init_errors(zenith_skycoord): @@ -696,17 +638,6 @@ def test_skymodel_init_errors(zenith_skycoord): freq_array=[1e8] * units.Hz, ) - with pytest.raises( - ValueError, match=("freq_array must have a unit that can be converted to Hz.") - ): - SkyModel( - name="icrs_zen", - skycoord=icrs_coord, - stokes=[1.0, 0, 0, 0] * units.Jy, - spectral_type="flat", - freq_array=[1e8] * units.m, - ) - with pytest.raises(ValueError, match=("For point component types, the stokes")): SkyModel( name="icrs_zen", @@ -741,222 +672,6 @@ def test_skymodel_init_errors(zenith_skycoord): sky.frame_coherency = sky.frame_coherency.value * units.m sky.check() - with pytest.raises( - ValueError, - match=("reference_frequency must have a unit that can be converted to Hz."), - ): - SkyModel( - name="icrs_zen", - skycoord=icrs_coord, - stokes=[1.0, 0, 0, 0] * units.Jy, - spectral_type="flat", - reference_frequency=[1e8] * units.m, - ) - - -def test_skymodel_deprecated(time_location): - """Test that old init works with deprecation.""" - source_new = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=np.array([1e8]) * units.Hz, - ) - - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "The input parameters to SkyModel.__init__ have changed", - "No frame was specified for RA and Dec.", - ], - ): - source_old = SkyModel( - "Test", - Longitude(12.0 * units.hr), - Latitude(-30.0 * units.deg), - [1.0, 0.0, 0.0, 0.0] * units.Jy, - np.array([1e8]) * units.Hz, - "flat", - ) - assert source_new == source_old - - # test numpy array for reference_frequency - with uvtest.check_warnings( - DeprecationWarning, - match="In version 0.2.0, the reference_frequency will be required to be an " - "astropy Quantity", - ): - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=np.array([1e8]), - ) - assert source_new == source_old - - # test list of floats for reference_frequency - with uvtest.check_warnings( - [UserWarning, DeprecationWarning], - match=[ - "reference_frequency is a list. Attempting to convert to a Quantity.", - "In version 0.2.0, the reference_frequency will be required to be an " - "astropy Quantity", - ], - ): - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=[1e8], - ) - assert source_new == source_old - - with uvtest.check_warnings( - DeprecationWarning, - match="In version 0.2.0, stokes will be required to be an astropy " - "Quantity with units that are convertable to one of", - ): - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=np.asarray([1.0, 0.0, 0.0, 0.0]), - spectral_type="flat", - reference_frequency=np.array([1e8]) * units.Hz, - ) - assert source_new == source_old - - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=np.array([1.5e8]) * units.Hz, - ) - with uvtest.check_warnings( - DeprecationWarning, - match=( - re.escape( - "Future equality does not pass, because parameters ['reference_frequency']" - ) - ), - ): - assert source_new == source_old - - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg + 2e-3 * units.arcsec), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=np.array([1e8]) * units.Hz, - ) - with uvtest.check_warnings( - DeprecationWarning, - match=("The skycoord parameters are not within the future tolerance"), - ): - assert source_new == source_old - - source_old = SkyModel( - name="Test", - ra=Longitude(Longitude(12.0 * units.hr) + Longitude(2e-3 * units.arcsec)), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=[1.0, 0.0, 0.0, 0.0] * units.Jy, - spectral_type="flat", - reference_frequency=np.array([1e8]) * units.Hz, - ) - with uvtest.check_warnings( - DeprecationWarning, - match=("The skycoord parameters are not within the future tolerance"), - ): - assert source_new == source_old - - stokes = np.zeros((4, 2, 1)) * units.Jy - stokes[0, :, :] = 1.0 * units.Jy - source_new = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=stokes, - spectral_type="subband", - freq_array=np.array([1e8, 1.5e8]) * units.Hz, - ) - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "The input parameters to SkyModel.__init__ have changed", - "No frame was specified for RA and Dec.", - ], - ): - source_old = SkyModel( - "Test", - Longitude(12.0 * units.hr), - Latitude(-30.0 * units.deg), - stokes, - np.array([1e8, 1.5e8]) * units.Hz, - "subband", - ) - assert source_new == source_old - - # test numpy array for freq_array - with uvtest.check_warnings( - DeprecationWarning, - match="In version 0.2.0, the freq_array will be required to be an astropy Quantity", - ): - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=stokes, - spectral_type="subband", - freq_array=np.array([1e8, 1.5e8]), - ) - assert source_new == source_old - - # test list of floats for freq_array - with uvtest.check_warnings( - [UserWarning, DeprecationWarning], - match=[ - "freq_array is a list. Attempting to convert to a Quantity.", - "In version 0.2.0, the freq_array will be required to be an astropy Quantity", - ], - ): - source_old = SkyModel( - name="Test", - ra=Longitude(12.0 * units.hr), - dec=Latitude(-30.0 * units.deg), - frame="icrs", - stokes=stokes, - spectral_type="subband", - freq_array=[1e8, 1.5e8], - ) - assert source_new == source_old - - time, telescope_location = time_location - - with uvtest.check_warnings( - DeprecationWarning, - match="Passing telescope_location to SkyModel.coherency_calc is deprecated", - ): - source_new.update_positions(time, telescope_location) - source_new.coherency_calc(telescope_location) - @pytest.mark.parametrize("spec_type", ["flat", "subband", "spectral_index"]) def test_jansky_to_kelvin_loop(spec_type): @@ -2002,61 +1717,6 @@ def test_concat_compatibility_errors(healpix_disk_new, time_location): assert skyobj1 == skyobj_hpx_disk -@pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") -def test_read_healpix_hdf5_old(healpix_data): - m = np.arange(healpix_data["npix"]) - m[healpix_data["ipix_disc"]] = healpix_data["npix"] - 1 - - indices = np.arange(healpix_data["npix"]) - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead.", - ): - hpmap, inds, freqs = skymodel.read_healpix_hdf5( - os.path.join(SKY_DATA_PATH, "healpix_disk.hdf5") - ) - - assert np.allclose(hpmap[0, :], m) - assert np.allclose(inds, indices) - assert np.allclose(freqs, healpix_data["frequencies"]) - - -@pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") -def test_healpix_to_sky(healpix_data, healpix_disk_old): - - healpix_filename = os.path.join(SKY_DATA_PATH, "healpix_disk.hdf5") - with h5py.File(healpix_filename, "r") as fileobj: - hpmap = fileobj["data"][0, ...] # Remove Nskies axis. - indices = fileobj["indices"][()] - freqs = fileobj["freqs"][()] - history = np.string_(fileobj["history"][()]).tobytes().decode("utf8") - - hmap_orig = np.arange(healpix_data["npix"]) - hmap_orig[healpix_data["ipix_disc"]] = healpix_data["npix"] - 1 - - hmap_orig = np.repeat(hmap_orig[None, :], 10, axis=0) - hmap_orig = hmap_orig * units.K - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead.", - "In version 0.3.0, the frame keyword will be required for HEALPix maps. " - "Defaulting to ICRS", - ], - ): - sky = skymodel.healpix_to_sky(hpmap, indices, freqs) - assert isinstance(sky.stokes, Quantity) - - sky.history = history + sky.pyradiosky_version_str - - assert healpix_disk_old.filename == ["healpix_disk.hdf5"] - assert healpix_disk_old == sky - assert units.quantity.allclose(healpix_disk_old.stokes[0], hmap_orig) - - @pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") def test_units_healpix_to_sky(healpix_data, healpix_disk_old): @@ -2077,46 +1737,12 @@ def test_units_healpix_to_sky(healpix_data, healpix_disk_old): assert units.quantity.allclose(sky.stokes[0, 0], stokes[0]) -@pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") -@pytest.mark.parametrize("hpx_order", ["none", "ring", "nested"]) -def test_order_healpix_to_sky(healpix_data, hpx_order): - - inds = np.arange(healpix_data["npix"]) - hmap_orig = np.zeros_like(inds) - hmap_orig[healpix_data["ipix_disc"]] = healpix_data["npix"] - 1 - hmap_orig = np.repeat(hmap_orig[None, :], 10, axis=0) - - warn_msg = [ - "This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead.", - "In version 0.3.0, the frame keyword will be required for HEALPix maps.", - ] - # the none option doesn't issue the frame warning so drop it - if hpx_order == "none": - del warn_msg[-1] - - with uvtest.check_warnings(DeprecationWarning, match=warn_msg): - if hpx_order == "none": - with pytest.raises(ValueError, match="order must be 'nested' or 'ring'"): - sky = skymodel.healpix_to_sky( - hmap_orig, inds, healpix_data["frequencies"], hpx_order=hpx_order - ) - else: - sky = skymodel.healpix_to_sky( - hmap_orig, inds, healpix_data["frequencies"], hpx_order=hpx_order - ) - assert sky.hpx_order == hpx_order - - def test_healpix_recarray_loop(healpix_disk_new): skyobj = healpix_disk_new with uvtest.check_warnings( DeprecationWarning, - match=[ - "The to_recarray method is deprecated and will be removed in 0.3.0.", - "recarray flux columns will no longer be labeled", - ], + match="The to_recarray method is deprecated and will be removed in 0.3.0.", ): skyarr = skyobj.to_recarray() @@ -2131,61 +1757,6 @@ def test_healpix_recarray_loop(healpix_disk_new): assert skyobj == skyobj2 -@pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") -@pytest.mark.filterwarnings("ignore:This method writes an old 'healvis' style healpix") -def test_read_write_healpix_oldfunction(tmp_path, healpix_data): - - healpix_filename = os.path.join(SKY_DATA_PATH, "healpix_disk.hdf5") - with h5py.File(healpix_filename, "r") as fileobj: - hpmap = fileobj["data"][0, ...] # Remove Nskies axis. - indices = fileobj["indices"][()] - freqs = fileobj["freqs"][()] - - freqs = freqs * units.Hz - filename = os.path.join(tmp_path, "tempfile.hdf5") - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `SkyModel.write_skyh5` instead.", - ): - with pytest.raises( - ValueError, match="Need to provide nside if giving a subset of the map." - ): - skymodel.write_healpix_hdf5( - filename, hpmap, indices[:10], freqs.to("Hz").value - ) - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `SkyModel.write_skyh5` instead.", - ): - with pytest.raises(ValueError, match="Invalid map shape"): - skymodel.write_healpix_hdf5( - filename, - hpmap, - indices[:10], - freqs.to("Hz").value, - nside=healpix_data["nside"], - ) - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `SkyModel.write_skyh5` instead.", - ): - skymodel.write_healpix_hdf5(filename, hpmap, indices, freqs.to("Hz").value) - - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, use `SkyModel.read_skyh5` or " - "`SkyModel.read_healpix_hdf5` instead.", - ): - hpmap_new, inds_new, freqs_new = skymodel.read_healpix_hdf5(filename) - - assert np.allclose(hpmap_new, hpmap) - assert np.allclose(inds_new, indices) - assert np.allclose(freqs_new, freqs.to("Hz").value) - - @pytest.mark.filterwarnings("ignore:This method reads an old 'healvis' style healpix") @pytest.mark.filterwarnings("ignore:This method writes an old 'healvis' style healpix") @pytest.mark.parametrize("change_history", [True, False, "error"]) @@ -2375,19 +1946,14 @@ def test_healpix_positions(tmp_path, time_location): skyobj.frame_coherency = skyobj.frame_coherency.value * units.m skyobj.check() - with uvtest.check_warnings( - DeprecationWarning, - match="In version 0.2.0, stokes will be required to be an astropy " - "Quantity with units that are convertable to one of", - ): - skyobj = SkyModel( - nside=nside, - hpx_inds=range(Npix), - stokes=stokes, - freq_array=freqs * units.Hz, - spectral_type="full", - frame="icrs", - ) + skyobj = SkyModel( + nside=nside, + hpx_inds=range(Npix), + stokes=stokes * units.K, + freq_array=freqs * units.Hz, + spectral_type="full", + frame="icrs", + ) filename = os.path.join(tmp_path, "healpix_single.hdf5") with uvtest.check_warnings( @@ -2439,7 +2005,9 @@ def test_healpix_positions(tmp_path, time_location): @pytest.mark.filterwarnings("ignore:recarray flux columns will no longer be labeled") @pytest.mark.parametrize("spec_type", ["flat", "subband", "spectral_index", "full"]) @pytest.mark.parametrize("with_error", [False, True]) -def test_array_to_skymodel_loop(spec_type, with_error): +@pytest.mark.parametrize("rise_set_lsts", [False, True]) +def test_array_to_skymodel_loop(spec_type, with_error, rise_set_lsts, time_location): + _, array_location = time_location spectral_type = "subband" if spec_type == "full" else spec_type sky = SkyModel.from_file( @@ -2448,14 +2016,13 @@ def test_array_to_skymodel_loop(spec_type, with_error): if spec_type == "full": sky.spectral_type = "full" - messages = [ - "The to_recarray method is deprecated and will be removed in 0.3.0.", - "recarray flux columns will no longer be labeled", - ] - if spec_type in ["flat", "spectral_index"]: - messages += ["The reference_frequency is aliased as"] + if rise_set_lsts: + sky.calculate_rise_set_lsts(array_location.lat) - with uvtest.check_warnings(DeprecationWarning, match=messages): + with uvtest.check_warnings( + DeprecationWarning, + match="The to_recarray method is deprecated and will be removed in 0.3.0.", + ): arr = sky.to_recarray() with uvtest.check_warnings( @@ -2928,10 +2495,9 @@ def test_select_field_error(): @pytest.mark.filterwarnings("ignore:The to_recarray method is deprecated") @pytest.mark.filterwarnings("ignore:recarray flux columns will no longer be labeled") -@pytest.mark.parametrize("function", ["source_cuts", "cut_nonrising"]) -def test_circumpolar_nonrising(time_location, function): - # Check that the source_cut function correctly identifies sources that are circumpolar or - # won't rise. +def test_circumpolar_nonrising(time_location): + # Check that the cut_nonrising method correctly identifies sources that are + # circumpolar or won't rise. # Working with an observatory at the HERA latitude. time, location = time_location @@ -2958,30 +2524,12 @@ def test_circumpolar_nonrising(time_location, function): name=names, ra=ra, dec=dec, frame="icrs", stokes=stokes, spectral_type="flat" ) - if function == "cut_nonrising": - sky2 = sky.cut_nonrising(location.lat, inplace=False) - - # Boolean array identifying nonrising sources that were removed by source_cuts - nonrising = np.array([sky.name[ind] not in sky2.name for ind in range(Nsrcs)]) - sky2.calculate_rise_set_lsts(location.lat) + sky2 = sky.cut_nonrising(location.lat, inplace=False) - else: - src_arr = sky.to_recarray() - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "This function is deprecated, use the `SkyModel.select` and/or" - "`SkyModel.cut_nonrising` methods instead." - ], - ): - src_arr = skymodel.source_cuts( - src_arr, latitude_deg=location.lat.deg, min_flux=0.5, max_flux=2.0 - ) + # Boolean array identifying nonrising sources that were removed + nonrising = np.array([sky.name[ind] not in sky2.name for ind in range(Nsrcs)]) + sky2.calculate_rise_set_lsts(location.lat) - # Boolean array identifying nonrising sources that were removed by source_cuts - nonrising = np.array( - [sky.name[ind] not in src_arr["source_id"] for ind in range(Nsrcs)] - ) is_below_horizon = np.zeros(Nsrcs).astype(bool) is_below_horizon[nonrising] = True @@ -2994,12 +2542,9 @@ def test_circumpolar_nonrising(time_location, function): # Check that sources below the horizon by coarse cut are # indeed below the horizon. lst = times[ti].sidereal_time("mean").rad - if function == "cut_nonrising": - dt0 = lst - sky2._rise_lst - dt1 = sky2._set_lst - sky2._rise_lst - else: - dt0 = lst - src_arr["rise_lst"] - dt1 = src_arr["set_lst"] - src_arr["rise_lst"] + dt0 = lst - sky2._rise_lst + dt1 = sky2._set_lst - sky2._rise_lst + with warnings.catch_warnings(): warnings.filterwarnings( "ignore", message="invalid value encountered", category=RuntimeWarning @@ -3027,33 +2572,6 @@ def test_circumpolar_nonrising(time_location, function): # Confirm that the source cuts excluded the non-rising sources. assert np.all(np.where(nonrising)[0] == nonrising_test) - if function != "cut_nonrising": - # check that rise_lst and set_lst get added to object when converted - with uvtest.check_warnings( - DeprecationWarning, - match="This function is deprecated, and will be removed in version 0.2.0.", - ): - new_sky = skymodel.array_to_skymodel(src_arr) - assert hasattr(new_sky, "_rise_lst") - assert hasattr(new_sky, "_set_lst") - - # and that it's round tripped - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "This function is deprecated, and will be removed in version 0.2.0." - ], - ): - src_arr2 = skymodel.skymodel_to_array(new_sky) - assert src_arr.dtype == src_arr2.dtype - assert len(src_arr) == len(src_arr2) - - for name in src_arr.dtype.names: - if isinstance(src_arr[name][0], (str,)): - assert np.array_equal(src_arr[name], src_arr2[name]) - else: - assert np.allclose(src_arr[name], src_arr2[name], equal_nan=True) - def test_cut_nonrising_error(time_location): _, location = time_location @@ -3113,6 +2631,12 @@ def test_cut_nonrising_error(time_location): {"brittle": False}, None, ), + ( + "j2000", + ["_RAJ2000", "_DEJ2000", "RAJ2000", "DEJ2000", "GLEAM"], + {"brittle": False}, + ["_RAJ2000", "_DEJ2000", "RAJ2000", "DEJ2000"], + ), ], ) def test_get_matching_fields(name_to_match, name_list, kwargs, result): @@ -3151,31 +2675,16 @@ def test_read_gleam(spec_type): source_select_kwds = {"min_flux": 0.5} msg_expected = [ - "This function is deprecated, use `SkyModel.read_gleam_catalog` instead.", "The source_select_kwds parameter is deprecated", "The `source_cuts` method is deprecated and will be removed", ] with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - cut_catalog = skymodel.read_gleam_catalog( - GLEAM_vot, - spectral_type=spec_type, - source_select_kwds=source_select_kwds, - return_table=True, - ) - - assert len(cut_catalog) < skyobj.Ncomponents - - msg_expected = [ - "This function is deprecated, use `SkyModel.read_gleam_catalog` instead.", - "The source_select_kwds parameter is deprecated", - "The `source_cuts` method is deprecated and will be removed", - ] - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - cut_obj = skymodel.read_gleam_catalog( + cut_sky = SkyModel() + cut_sky.read_gleam_catalog( GLEAM_vot, spectral_type=spec_type, source_select_kwds=source_select_kwds ) - assert len(cut_catalog) == cut_obj.Ncomponents + assert cut_sky.Ncomponents < skyobj.Ncomponents def test_read_errors(tmpdir): @@ -3212,6 +2721,17 @@ def test_read_votable(): ) assert skyobj.Ncomponents == 2 + skyobj2 = SkyModel.from_votable_catalog( + votable_file, + "VIII/1000/single", + "source_id", + "RAJ2000", + "DEJ2000", + "Si", + frame="fk5", + ) + assert skyobj2 == skyobj + with uvtest.check_warnings( DeprecationWarning, match=[ @@ -3219,7 +2739,7 @@ def test_read_votable(): "The `dec_column` keyword is deprecated and will be removed", ], ): - skyobj2 = SkyModel.from_file( + skyobj3 = SkyModel.from_file( votable_file, table_name="VIII_1000_single", id_column="source_id", @@ -3228,70 +2748,37 @@ def test_read_votable(): flux_columns="Si", frame="fk5", ) - assert skyobj == skyobj2 - - msg_expected = [ - "This function is deprecated, use `SkyModel.read_votable_catalog` instead." - ] - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - skyobj2 = skymodel.read_votable_catalog( - votable_file, - table_name="VIII/1000/single", - id_column="source_id", - ra_column="RAJ2000", - dec_column="DEJ2000", - flux_columns="Si", - reference_frequency=None, - ) - - assert skyobj != skyobj2 - skyobj2.skycoord = SkyCoord(skyobj2.skycoord.ra, skyobj2.skycoord.dec, frame="fk5") - assert skyobj == skyobj2 + assert skyobj == skyobj3 - msg_expected = [ - "This function is deprecated, use `SkyModel.read_votable_catalog` instead." - ] - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - skyarr = skymodel.read_votable_catalog( - votable_file, - table_name="VIII/1000/single", - id_column="source_id", - ra_column="RAJ2000", - dec_column="DEJ2000", - flux_columns="Si", - reference_frequency=None, - return_table=True, + with uvtest.check_warnings( + DeprecationWarning, + match="frame parameter was not set. Defaulting to 'icrs'. This will become " + "an error in version 0.3", + ): + skyobj4 = SkyModel.from_votable_catalog( + votable_file, "VIII_1000_single", "source_id", "RAJ2000", "DEJ2000", "Si" ) + assert skyobj != skyobj4 - skyobj2.from_recarray(skyarr) - assert skyobj == skyobj2 + new_skycoord = SkyCoord( + ra=skyobj4.skycoord.ra, dec=skyobj4.skycoord.dec, frame="fk5" + ) + skyobj4.skycoord = new_skycoord + assert skyobj == skyobj4 def test_read_deprecated_votable(): votable_file = os.path.join(SKY_DATA_PATH, "single_source_old.vot") skyobj = SkyModel() - msg_expected = [ - "contains tables with no name or ID, Support for such files is deprecated.", - "frame parameter was not set. Defaulting to 'icrs'. This will become an error " - "in version 0.3", - ] - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): + with pytest.raises( + ValueError, + match=re.escape(f"File {votable_file} contains tables with no name or ID."), + ): skyobj.read_votable_catalog( votable_file, "GLEAM", "GLEAM", "RAJ2000", "DEJ2000", "Fintwide" ) - assert skyobj.Ncomponents == 1 - - msg_expected = [ - "contains tables with no name or ID, Support for such files is deprecated." - ] - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - with pytest.raises(ValueError, match=("More than one matching table.")): - skyobj.read_votable_catalog( - votable_file, "GLEAM", "de", "RAJ2000", "DEJ2000", "Fintwide" - ) - def test_read_votable_errors(): @@ -3386,29 +2873,6 @@ def test_fhd_catalog_reader(): catalog = scipy.io.readsav(catfile)["catalog"] assert skyobj.Ncomponents == len(catalog) - with uvtest.check_warnings( - [DeprecationWarning, UserWarning], - match=[ - "This function is deprecated, use `SkyModel.read_fhd_catalog` instead.", - "Source IDs are not unique. Defining unique IDs.", - ], - ): - skyobj2 = skymodel.read_idl_catalog(catfile, expand_extended=False) - - assert skyobj == skyobj2 - - with uvtest.check_warnings( - [DeprecationWarning, UserWarning], - match=[ - "This method is deprecated, use `read_fhd_catalog` instead.", - "Source IDs are not unique. Defining unique IDs.", - ], - ): - skyobj3 = SkyModel() - skyobj3.read_idl_catalog(catfile, expand_extended=False) - - assert skyobj == skyobj3 - def test_fhd_catalog_reader_source_cuts(): catfile = os.path.join(SKY_DATA_PATH, "fhd_catalog.sav") @@ -3543,30 +3007,16 @@ def test_point_catalog_reader(): # Check cuts source_select_kwds = {"min_flux": 1.0} - with uvtest.check_warnings( - DeprecationWarning, - match=[ - "This function is deprecated, use `SkyModel.read_text_catalog` instead.", - "The source_select_kwds parameter is deprecated", - "The `source_cuts` method is deprecated and will be removed", - ], - ): - skyarr = skymodel.read_text_catalog( - catfile, source_select_kwds=source_select_kwds, return_table=True - ) - assert len(skyarr) == 2 with uvtest.check_warnings( DeprecationWarning, match=[ - "This function is deprecated, use `SkyModel.read_text_catalog` instead.", "The source_select_kwds parameter is deprecated", "The `source_cuts` method is deprecated and will be removed", ], ): - skyobj2 = skymodel.read_text_catalog( - catfile, source_select_kwds=source_select_kwds - ) + skyobj2 = SkyModel() + skyobj2.read_text_catalog(catfile, source_select_kwds=source_select_kwds) assert skyobj2.Ncomponents == 2 @@ -3618,7 +3068,11 @@ def test_catalog_file_writer(tmp_path, time_location, frame): @pytest.mark.filterwarnings("ignore:The reference_frequency is aliased as `frequency`") @pytest.mark.parametrize("spec_type", ["flat", "subband", "spectral_index", "full"]) @pytest.mark.parametrize("with_error", [False, True]) -def test_text_catalog_loop(tmp_path, spec_type, with_error): +@pytest.mark.parametrize("rise_set_lsts", [False, True]) +def test_text_catalog_loop( + tmp_path, spec_type, with_error, rise_set_lsts, time_location +): + _, array_location = time_location spectral_type = "subband" if spec_type == "full" else spec_type skyobj = SkyModel.from_file( @@ -3627,14 +3081,12 @@ def test_text_catalog_loop(tmp_path, spec_type, with_error): if spec_type == "full": skyobj.spectral_type = "full" - fname = os.path.join(tmp_path, "temp_cat.txt") + if rise_set_lsts: + skyobj.calculate_rise_set_lsts(array_location.lat) - msg_expected = [ - "This function is deprecated, use `SkyModel.write_text_catalog` instead." - ] + fname = os.path.join(tmp_path, "temp_cat.txt") - with uvtest.check_warnings(DeprecationWarning, match=msg_expected): - skymodel.write_catalog_to_file(fname, skyobj) + skyobj.write_text_catalog(fname) skyobj2 = SkyModel.from_file(fname) assert skyobj == skyobj2 diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index a2da636b..5a3cb68c 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -33,21 +33,17 @@ def test_stokes_tofrom_coherency(): 0.5 * np.array([[4.2, 1.2 + 0.15j], [1.2 - 0.15j, 4.8]]) * units.Jy ) - with pytest.warns( - DeprecationWarning, - match="In version 0.2.0, stokes_arr will be required to be an astropy " - "Quantity. Currently, floats are assumed to be in Jy.", - ): - coherency = skyutils.stokes_to_coherency(stokes) + with pytest.raises(ValueError, match="stokes_arr must be an astropy Quantity."): + skyutils.stokes_to_coherency(stokes) - assert np.allclose(expected_coherency, coherency) + coherency = skyutils.stokes_to_coherency(stokes * units.Jy) - with pytest.warns( - DeprecationWarning, - match="In version 0.2.0, coherency_matrix will be required to be an astropy " - "Quantity. Currently, floats are assumed to be in Jy.", + with pytest.raises( + ValueError, match="coherency_matrix must be an astropy Quantity." ): - back_to_stokes = skyutils.coherency_to_stokes(coherency.value) + skyutils.coherency_to_stokes(coherency.value) + + back_to_stokes = skyutils.coherency_to_stokes(coherency) assert np.allclose(stokes * units.Jy, back_to_stokes) diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index 63ccf55c..1935912b 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -3,7 +3,6 @@ # Licensed under the 3-clause BSD License """Utility methods.""" import os -import warnings import astropy.units as units import erfa @@ -90,12 +89,7 @@ def stokes_to_coherency(stokes_arr): Array of coherencies, shape (2, 2) or (2, 2, Nfreqs, Ncomponents) """ if not isinstance(stokes_arr, Quantity): - warnings.warn( - "In version 0.2.0, stokes_arr will be required to be an astropy " - "Quantity. Currently, floats are assumed to be in Jy.", - category=DeprecationWarning, - ) - stokes_arr = stokes_arr * units.Jy + raise ValueError("stokes_arr must be an astropy Quantity.") initial_shape = stokes_arr.shape if initial_shape[0] != 4: @@ -141,12 +135,7 @@ def coherency_to_stokes(coherency_matrix): Array of stokes parameters, shape(4,) or (4, Ncomponents) """ if not isinstance(coherency_matrix, Quantity): - warnings.warn( - "In version 0.2.0, coherency_matrix will be required to be an astropy " - "Quantity. Currently, floats are assumed to be in Jy.", - category=DeprecationWarning, - ) - coherency_matrix = coherency_matrix * units.Jy + raise ValueError("coherency_matrix must be an astropy Quantity.") initial_shape = coherency_matrix.shape if len(initial_shape) < 2 or initial_shape[0] != 2 or initial_shape[1] != 2: