Skip to content

Commit

Permalink
Fix check_kw handling and changelog errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Feb 27, 2025
1 parent 24c2a87 commit 855988a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

## [Unreleased]

### Changed
- Updated minimum dependency versions: pyuvdata>=3.1.2

### Fixed
- A bug when specifying a frequency buffer for beam frequency selects in telescope
config files.

## [1.4.0] - 2024-10-31

### Changed
- Use new pyuvdata analytic beams and remove the analytic beams defined in this package.
- Major restructuring of the BeamList object to use shared memory and remove the
string/object mode switch.
- BeamLists now contain pyuvdata BeamInterface objects
- Updated minimum dependency versions: pyuvdata>=3.1.2
- Updated minimum dependency versions: pyuvdata>=3.1.0
- Updated minimum optional dependency versions: lunarsky>=0.2.5
- Setting the `select.bls` property in the obsparams file now selects baselines _before_
creating the UVData object, rather than down-selecting afterwards, saving memory and time.

### Fixed
- A bug when specifying a frequency buffer for beam frequency selects in telescope
config files.

## [1.3.1] - 2024-07-18

### Added
Expand Down
41 changes: 16 additions & 25 deletions src/pyuvsim/simsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,10 @@ def initialize_uvdata_from_params(
the setup process. Typical parameters include "order" and "minor_order". Default
values are ``order='time'`` and ``minor_order='baseline'``.
check_kw : dict (optional)
Deprecated and has no effect.
A dictionary of keyword arguments to pass to the :func:`uvdata.UVData.check`
method after object creation. Caution: turning off critical checks can
result in a UVData object that cannot be written to a file.
Returns
-------
Expand All @@ -1925,12 +1928,6 @@ def initialize_uvdata_from_params(
DeprecationWarning,
)

if check_kw is not None:
warnings.warn(
"The check_kw parameter is deprecated and has no effect. This will "
"become an error in version 1.5",
DeprecationWarning,
)
uvparam_dict = {} # Parameters that will go into UVData
if isinstance(obs_params, str):
param_dict = _config_str_to_dict(obs_params) # Container for received settings.
Expand Down Expand Up @@ -2078,6 +2075,7 @@ def initialize_uvdata_from_params(
do_blt_outer=True,
time_axis_faster_than_bls=False,
antpairs=antpairs,
check_kw=check_kw,
**uvparam_dict,
)

Expand All @@ -2104,28 +2102,24 @@ def initialize_uvdata_from_params(
return uv_obj


def _complete_uvdata(uv_in, inplace=False, check_kw=None):
def _complete_uvdata(uv_in, inplace=False):
"""
Fill out all required parameters of a :class:`pyuvdata.UVData` object.
Initialize data-like arrays on a a :class:`pyuvdata.UVData` object.
Ensure that it passes the :func:`pyuvdata.UVData.check()`.
This will overwrite existing data in `uv_in`!
This will overwrite any existing data in `uv_in` unless inplace=True.
Parameters
----------
uv_in : :class:`pyuvdata.UVData` instance
Usually an incomplete object, containing only metadata.
inplace : bool, optional
Whether to perform the filling on the passed object, or a copy.
check_kw : dict, optional
A dict of kwargs to pass to :func:`pyuvdata.UVData.check()`. If not provided,
will be an empty dict (i.e. default checks are run). If set to False, no checks
will be run at all.
Returns
-------
:class:`pyuvdata.UVData` : filled/completed object (if `inplace` is `True`, it is
the modified input). With zeroed data_array, no flags and nsample_array of all ones.
:class:`pyuvdata.UVData` : object with initialized data-like arrays
(if `inplace` is `True`, it is on a copy of the input). With zeroed
data_array, no flags and nsample_array of all ones.
"""
if not inplace:
Expand All @@ -2145,13 +2139,6 @@ def _complete_uvdata(uv_in, inplace=False, check_kw=None):
uv_obj.flag_array = np.zeros(_shape, dtype=bool)
uv_obj.nsample_array = np.ones(_shape, dtype=float)

uv_obj.extra_keywords = {}

if check_kw is not False:
if check_kw is None:
check_kw = {}
uv_obj.check(**check_kw)

return uv_obj


Expand Down Expand Up @@ -2259,6 +2246,10 @@ def initialize_uvdata_from_keywords(
complete : bool (optional)
Whether to fill out the :class:`pyuvdata.UVData` object with its requisite
data arrays, and check if it's all consistent.
check_kw : dict (optional)
A dictionary of keyword arguments to pass to the :func:`uvdata.UVData.check`
method after object creation. Caution: turning off critical checks can
result in a UVData object that cannot be written to a file.
kwargs : dictionary
Any additional valid :class:`pyuvdata.UVData` attribute to assign to object.
Expand Down Expand Up @@ -2407,7 +2398,7 @@ def initialize_uvdata_from_keywords(
)

if complete:
_complete_uvdata(uv_obj, inplace=True, check_kw=False)
_complete_uvdata(uv_obj, inplace=True)

return uv_obj

Expand Down
21 changes: 17 additions & 4 deletions tests/test_simsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,11 @@ def test_param_reader(telparam_in_obsparam, tmpdir):

# Check default configuration
with check_warnings(
[DeprecationWarning, DeprecationWarning],
[DeprecationWarning],
match=[
"The reorder_blt_kw parameter is deprecated in favor of setting "
"obs_param['ordering']['blt_order']. This will become an error in "
"version 1.5",
"The check_kw parameter is deprecated and has no effect. This will "
"become an error in version 1.5",
"version 1.5"
],
):
uv_obj, new_beam_list, new_beam_dict = simsetup.initialize_uvdata_from_params(
Expand Down Expand Up @@ -611,6 +609,21 @@ def test_param_reader(telparam_in_obsparam, tmpdir):
# renumber/rename the phase centers so the equality check will pass.
uv_obj._consolidate_phase_center_catalogs(other=uv_in, ignore_name=True)

# file is missing extra_keywords info
assert uv_obj._extra_keywords != uv_in._extra_keywords
if telparam_in_obsparam:
uv_in.extra_keywords = {
"obsparam": "new_obsparam.yaml",
"telecfg": new_telconfig_file,
"layout": "triangle_bl_layout.csv",
}
else:
uv_in.extra_keywords = {
"obsparam": "param_10time_10chan_0.yaml",
"telecfg": "28m_triangle_10time_10chan.yaml",
"layout": "triangle_bl_layout.csv",
}

assert uv_obj == uv_in


Expand Down
18 changes: 7 additions & 11 deletions tests/test_uvsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import itertools
import os
import warnings

import astropy.constants as const
import numpy as np
Expand Down Expand Up @@ -61,17 +62,12 @@ def multi_beams():

try:
beam5 = beam0.copy()
with check_warnings(
UserWarning,
match="key beam_path in extra_keywords is longer than 8 characters.",
):
beam5.to_healpix(nside=8)
beams.append(beam5)
except AssertionError:
# If we have an assert error, that means that import worked, but the warning
# was not raised due to the change in UVBeam warning behavior. Try again...
# TODO: Simplify this once pyuvdata v3.2 is required
with check_warnings(None):
# filter it this way because the warning only happens in some pyuvdata versions
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="key beam_path in extra_keywords is longer than 8 characters.",
)
beam5.to_healpix(nside=8)
beams.append(beam5)
except ImportError:
Expand Down

0 comments on commit 855988a

Please sign in to comment.