Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyuvdata3 #464

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ omit =
*/tests/*
*/data/*
*/scripts/*

[report]
omit =
*/tests/*
*/data/*
*/scripts/*
*/scripts/*
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', "3.11", "3.12"]
steven-murray marked this conversation as resolved.
Show resolved Hide resolved
python-version: ['3.10', "3.11", "3.12"]
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ hera_qm/data/test_output/ant_metrics_output.json
hera_qm/_version.py

artifacts/*
result.md
result.md
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exclude: '(^docs/conf.py|^hera_qm/data/|.codecov.yml)'

ci:
autoupdate_schedule: monthly

Expand Down
5 changes: 1 addition & 4 deletions hera_qm/firstcal_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ def __init__(self, calfits_files, use_gp=True):
# Instantiate UVCal and read calfits
self.UVC = UVCal()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Future array shapes are now always used"
)
self.UVC.read_calfits(calfits_files, use_future_array_shapes=True)
self.UVC.read_calfits(calfits_files)

if hasattr(self.UVC, "telescope"):
x_orientation = self.UVC.telescope.x_orientation
Expand Down
24 changes: 15 additions & 9 deletions hera_qm/metrics_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ def _recursively_save_dict_to_group(h5file, path, in_dict):
"""
allowed_types = (np.ndarray, np.float32, float, int,
bytes, str, list, bool, np.bool_)


compressable_types = (np.ndarray, list)
for key in in_dict:
# Catch case with numpy 2 where keys of type (np.int32(ant), 'polstr')) are
# converted to string with the full np.int32 identifier in them.
if isinstance(key, tuple):
key = tuple(int(k) if isinstance(k, (int, np.int32, np.int64)) else k for k in key)

key_str = str(key)
if key == 'reds':
in_dict[key] = _reds_list_to_dict(in_dict[key])
Expand Down Expand Up @@ -346,17 +353,16 @@ def _recursively_load_dict_to_group(h5file, path, group_is_ordered=False):

item = h5file[path][key]

if isinstance(item, h5py.Dataset):
if item.attrs['key_is_string']:
out_dict[str(key)] = item[()]
else:
out_key = _parse_key(key)
if isinstance(item, (h5py.Dataset, h5py.Group)):
out_key = str(key) if item.attrs['key_is_string'] else _parse_key(key)
#print(key, out_key, item.attrs['key_is_string'])
if isinstance(item, h5py.Dataset):
out_dict[out_key] = item[()]

elif isinstance(item, h5py.Group):
out_key = str(key) if item.attrs['key_is_string'] else _parse_key(key)
out_dict[out_key] = _recursively_load_dict_to_group(h5file, (path + key + '/'),
group_is_ordered=item.attrs["group_is_ordered"])
elif isinstance(item, h5py.Group):
out_dict[out_key] = _recursively_load_dict_to_group(
h5file, (path + key + '/'), group_is_ordered=item.attrs["group_is_ordered"]
)
else:
raise TypeError("The HDF5 path: {} is not associated with either "
"a dataset or group object. "
Expand Down
13 changes: 2 additions & 11 deletions hera_qm/omnical_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import json
import copy
import os
import warnings


def get_omnical_metrics_dict():
Expand Down Expand Up @@ -174,11 +173,7 @@ def load_firstcal_gains(fc_file):
The polarization of the .calfits file.
"""
uvc = UVCal()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Future array shapes are now always used"
)
uvc.read_calfits(fc_file, use_future_array_shapes=True)
uvc.read_calfits(fc_file)
fc_gains = np.moveaxis(uvc.gain_array, 1, 2)[:, :, :, 0]
d_nu = np.mean(uvc.freq_array[1:] - uvc.freq_array[:-1])
d_phi = np.abs(np.mean(np.angle(fc_gains)[:, :, 1:] - np.angle(fc_gains)[:, :, :-1], axis=2))
Expand Down Expand Up @@ -453,11 +448,7 @@ def __init__(self, omni_calfits, history=''):

# Instantiate Data Object
self.uv = UVCal()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Future array shapes are now always used"
)
self.uv.read_calfits(omni_calfits, use_future_array_shapes=True)
self.uv.read_calfits(omni_calfits)

# Get relevant metadata
self.Nants = self.uv.Nants_data
Expand Down
6 changes: 5 additions & 1 deletion hera_qm/tests/test_ant_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ def test_ant_metrics_run_and_load_antenna_metrics():
# test a priori flagging via YAML
four_pol_uvh5 = DATA_PATH + '/zen.2457698.40355.full_pol_test.uvh5'
apf_yaml = os.path.join(DATA_PATH, 'a_priori_flags_sample.yaml')
am = ant_metrics.ant_metrics_run(four_pol_uvh5, diff_files=four_pol_uvh5, overwrite=True, a_priori_xants_yaml=apf_yaml, verbose=True)

# SGM: not sure if the following warning *should* be raised.
with pytest.warns(RuntimeWarning, match='All-NaN slice encountered'):
am = ant_metrics.ant_metrics_run(four_pol_uvh5, diff_files=four_pol_uvh5, overwrite=True, a_priori_xants_yaml=apf_yaml, verbose=True)

am_hdf5 = ant_metrics.load_antenna_metrics(four_pol_uvh5.replace('.uvh5', '.ant_metrics.hdf5'))
for ant in [(0, 'Jee'), (0, 'Jnn'), (10, 'Jee'), (10, 'Jnn'), (1, 'Jee'), (3, 'Jnn')]:
assert ant in am_hdf5['xants']
Expand Down
3 changes: 3 additions & 0 deletions hera_qm/tests/test_auto_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def test_auto_metrics_run():
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="All-NaN slice encountered")
warnings.filterwarnings("ignore", message="K1 value 8 is larger than the data of dimension 4; using the size of the data for the kernel size")
warnings.filterwarnings("ignore", message="Mean of empty slice")
warnings.filterwarnings("ignore", message="Degrees of freedom <= 0 for slice")

ex_ants, modzs, spectra, flags = auto_metrics.auto_metrics_run(metrics_outfile, auto_files,
median_round_modz_cut=75., mean_round_modz_cut=5.,
edge_cut=100, Kt=8, Kf=8, sig_init=5.0, sig_adj=2.0,
Expand Down
7 changes: 3 additions & 4 deletions hera_qm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_apply_yaml_flags_uvdata(tmpdir, filein, flag_freqs, flag_times, flag_an
integration_flags = [0, 1] # integrations from yaml file that should be flagged.
ant_flags = [0, 10, [1, 'Jee'], [3, 'Jnn']]
uvd = UVData()
uvd.read(test_d_file, use_future_array_shapes=True)
uvd.read(test_d_file)
uvd = utils.apply_yaml_flags(uvd, test_flag, flag_freqs=flag_freqs, flag_times=flag_times,
flag_ants=flag_ants, unflag_first=True)
if 'no_integrations' not in test_flag:
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_apply_yaml_flags_uvcal(filein):
test_flag = os.path.join(DATA_PATH, filein)
test_c_file = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA.omni.calfits')
uvc = UVCal()
uvc.read_calfits(test_c_file, use_future_array_shapes=True)
uvc.read_calfits(test_c_file)

uvc = utils.apply_yaml_flags(uvc, test_flag, unflag_first=True)
freq_regions = [(0, 110e6), (150e6, 155e6), (190e6, 200e6)] # frequencies from yaml file.
Expand Down Expand Up @@ -420,13 +420,12 @@ def test_apply_yaml_flags_uvcal(filein):
throw_away_flagged_ants=True, ant_indices_only=False)


@pytest.mark.filterwarnings("ignore:Future array shapes are now always used")
def test_apply_yaml_flags_errors():
test_flag_jds = os.path.join(DATA_PATH, 'a_priori_flags_jds.yaml')
test_c_file = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA.omni.calfits')
# check NotImplementedErrors
uvc = UVCal()
uvc.read_calfits(test_c_file, use_future_array_shapes=True)
uvc.read_calfits(test_c_file)
# check that setting uv to an object that is not a subclass of UVCal or UVData throws a NotImplementedError
pytest.raises(NotImplementedError, utils.apply_yaml_flags, 'uvdata', test_flag_jds)

Expand Down
20 changes: 10 additions & 10 deletions hera_qm/tests/test_vis_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import copy
import pytest
import warnings
from erfa.core import ErfaWarning

pytestmark = pytest.mark.filterwarnings(
"ignore:The uvw_array does not match the expected values given the antenna positions.",
Expand All @@ -19,18 +20,18 @@
def vismetrics_data():
data = UVData()
filename = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA')
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Future array shapes are now always used")
data.read_miriad(filename, use_future_array_shapes=True, check_autos=False)
data.read_miriad(filename, check_autos=False)

# massage the object to make it work with check_noise_variance
data.select(antenna_nums=data.get_ants()[0:10])
data.select(freq_chans=range(100))
# Data file only has three times... need more.
while data.Ntimes < 90:
d2 = copy.deepcopy(data)
d2.time_array += d2.time_array.max() + d2.integration_time / (24 * 3600)
data += d2
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=ErfaWarning)
while data.Ntimes < 90:
d2 = copy.deepcopy(data)
d2.time_array += d2.time_array.max() + d2.integration_time / (24 * 3600)
data += d2
ntimes = data.Ntimes
nchan = data.Nfreqs
data1 = qmtest.noise(size=(ntimes, nchan))
Expand Down Expand Up @@ -79,10 +80,9 @@ def test_check_noise_variance_inttime_error(vismetrics_data):
def uvd():
uvd = UVData()
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Future array shapes are now always used")
uvd.read_miriad(
os.path.join(DATA_PATH, 'zen.2458002.47754.xx.HH.uvA'),
projected=False, use_future_array_shapes=True,
projected=False,
check_autos=False
)
return uvd
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_plot_bl_bl_scatter(uvd):
@pytest.mark.filterwarnings("ignore:Future array shapes are now always used")
def test_sequential_diff():
uvd = UVData()
uvd.read_miriad(os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA'), use_future_array_shapes=True)
uvd.read_miriad(os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA'))

# diff across time
uvd_diff = vis_metrics.sequential_diff(uvd, axis=0, pad=False)
Expand Down
Loading
Loading