From fb44d112da89d94bc1d960e3fca022054b8e7442 Mon Sep 17 00:00:00 2001 From: radonnachie Date: Tue, 3 Dec 2024 07:19:05 +0200 Subject: [PATCH 1/7] +^ look_in_catalog avoid unrelated keys for cat_type --- src/pyuvdata/utils/phase_center_catalog.py | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pyuvdata/utils/phase_center_catalog.py b/src/pyuvdata/utils/phase_center_catalog.py index efb3b9249..5b4005e11 100644 --- a/src/pyuvdata/utils/phase_center_catalog.py +++ b/src/pyuvdata/utils/phase_center_catalog.py @@ -161,6 +161,25 @@ def look_in_catalog( "cat_vrad": default_tols, } + typenonfields_dict = { + "sidereal": [ + "cat_times", + ], + "ephem": [ + "cat_pm_ra", + "cat_pm_dec", + ], + "unprojected": [ + "cat_frame", + "cat_pm_ra", + "cat_pm_dec", + "cat_times", + "cat_dist", + "cat_vrad", + ], + } + typenonfields_dict["driftscan"] = typenonfields_dict["unprojected"] + if target_cat_id is not None: if target_cat_id not in phase_center_catalog: raise ValueError(f"No phase center with ID number {target_cat_id}.") @@ -196,7 +215,13 @@ def look_in_catalog( tol_dict[key][1], ) else: - cat_diffs += check_dict[key] is not None + check_type = check_dict.get("cat_type") + check_value = None + # if type is known, avoid unrelated fields + if (check_type is None) or (key not in typenonfields_dict[check_type]): + check_value = check_dict[key] + cat_diffs += check_value is not None + if (cat_diffs == 0) or (cat_name == name): if cat_diffs < match_diffs: # If our current match is an improvement on any previous matches, From 83144cbb0b722c858dfd54589d5699013e534430 Mon Sep 17 00:00:00 2001 From: radonnachie Date: Tue, 3 Dec 2024 20:42:26 +0200 Subject: [PATCH 2/7] *- look_in_catalog minimise fix --- src/pyuvdata/utils/phase_center_catalog.py | 26 +--------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/pyuvdata/utils/phase_center_catalog.py b/src/pyuvdata/utils/phase_center_catalog.py index 5b4005e11..d7f8987a2 100644 --- a/src/pyuvdata/utils/phase_center_catalog.py +++ b/src/pyuvdata/utils/phase_center_catalog.py @@ -161,25 +161,6 @@ def look_in_catalog( "cat_vrad": default_tols, } - typenonfields_dict = { - "sidereal": [ - "cat_times", - ], - "ephem": [ - "cat_pm_ra", - "cat_pm_dec", - ], - "unprojected": [ - "cat_frame", - "cat_pm_ra", - "cat_pm_dec", - "cat_times", - "cat_dist", - "cat_vrad", - ], - } - typenonfields_dict["driftscan"] = typenonfields_dict["unprojected"] - if target_cat_id is not None: if target_cat_id not in phase_center_catalog: raise ValueError(f"No phase center with ID number {target_cat_id}.") @@ -215,12 +196,7 @@ def look_in_catalog( tol_dict[key][1], ) else: - check_type = check_dict.get("cat_type") - check_value = None - # if type is known, avoid unrelated fields - if (check_type is None) or (key not in typenonfields_dict[check_type]): - check_value = check_dict[key] - cat_diffs += check_value is not None + cat_diffs += check_dict.get(key) is not None if (cat_diffs == 0) or (cat_name == name): if cat_diffs < match_diffs: From a124d181c06514290febcae7f3b304ffad1a20ce Mon Sep 17 00:00:00 2001 From: radonnachie Date: Wed, 4 Dec 2024 09:06:54 +0200 Subject: [PATCH 3/7] + tests uvh5 sidereal addition #1506 --- tests/uvdata/test_uvh5.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/uvdata/test_uvh5.py b/tests/uvdata/test_uvh5.py index d408de6f9..d05c7a9a1 100644 --- a/tests/uvdata/test_uvh5.py +++ b/tests/uvdata/test_uvh5.py @@ -414,6 +414,27 @@ def test_uvh5_compression_options(casa_uvfits, tmp_path): return +@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values") +def test_uvh5_addition(casa_uvfits, tmp_path): + testfile = os.path.join(tmp_path, "uv_test_addition.uvh5") + + casa_uvfits.phase( + lon=casa_uvfits.phase_center_catalog[0]["cat_lon"], + lat=casa_uvfits.phase_center_catalog[0]["cat_lat"], + phase_frame="icrs", + cat_type="sidereal", + cat_name=casa_uvfits.phase_center_catalog[0]["cat_name"], + ) + casa_uvfits.write_uvh5(testfile, clobber=True) + uv = UVData() + uv.read(testfile) + uv + uv.copy() + + os.remove(testfile) + + return + + @pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values") def test_uvh5_read_multiple_files(casa_uvfits, tmp_path): """ From cd6f959af8f54d7db6e66d2e33d9a3956ec04bbc Mon Sep 17 00:00:00 2001 From: radonnachie Date: Thu, 5 Dec 2024 06:48:37 +0200 Subject: [PATCH 4/7] ~ tests uvh5 addition --- tests/uvdata/test_uvh5.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/uvdata/test_uvh5.py b/tests/uvdata/test_uvh5.py index d05c7a9a1..d408de6f9 100644 --- a/tests/uvdata/test_uvh5.py +++ b/tests/uvdata/test_uvh5.py @@ -414,27 +414,6 @@ def test_uvh5_compression_options(casa_uvfits, tmp_path): return -@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values") -def test_uvh5_addition(casa_uvfits, tmp_path): - testfile = os.path.join(tmp_path, "uv_test_addition.uvh5") - - casa_uvfits.phase( - lon=casa_uvfits.phase_center_catalog[0]["cat_lon"], - lat=casa_uvfits.phase_center_catalog[0]["cat_lat"], - phase_frame="icrs", - cat_type="sidereal", - cat_name=casa_uvfits.phase_center_catalog[0]["cat_name"], - ) - casa_uvfits.write_uvh5(testfile, clobber=True) - uv = UVData() - uv.read(testfile) - uv + uv.copy() - - os.remove(testfile) - - return - - @pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values") def test_uvh5_read_multiple_files(casa_uvfits, tmp_path): """ From 6789974d305ea0c7a850a9adc5fdde6094764cd8 Mon Sep 17 00:00:00 2001 From: radonnachie Date: Sun, 8 Dec 2024 07:59:28 +0200 Subject: [PATCH 5/7] + tests utils look_in_catalog --- tests/utils/test_phase_center_catalog.py | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/utils/test_phase_center_catalog.py b/tests/utils/test_phase_center_catalog.py index b1d0d7c0f..06a53e7e4 100644 --- a/tests/utils/test_phase_center_catalog.py +++ b/tests/utils/test_phase_center_catalog.py @@ -2,9 +2,17 @@ # Licensed under the 2-clause BSD License """Tests for phase center catalog utility functions.""" +import os + import pytest import pyuvdata.utils.phase_center_catalog as ps_cat_utils +from pyuvdata import UVData +from pyuvdata.data import DATA_PATH + +casa_tutorial_uvfits = os.path.join( + DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits" +) def test_generate_new_phase_center_id_errs(): @@ -13,3 +21,23 @@ def test_generate_new_phase_center_id_errs(): with pytest.raises(ValueError, match="Provided cat_id was found in reserved_ids"): ps_cat_utils.generate_new_phase_center_id(cat_id=1, reserved_ids=[1, 2, 3]) + + +def test_look_in_catalog_missing_entries(): + casa_uvfits = UVData() + casa_uvfits.read(casa_tutorial_uvfits) + phase_cat = casa_uvfits.phase_center_catalog + + # Try that this works normally if we do nothing + assert ps_cat_utils.look_in_catalog( + phase_cat, cat_name=phase_cat[0]["cat_name"] + ) == (0, 5) + + # Now delete some keys + for value in phase_cat.values(): + if "cat_times" in value: + del value["cat_times"] + # Now re-run the above and verify things work as expected + assert ps_cat_utils.look_in_catalog( + phase_cat, cat_name=phase_cat[0]["cat_name"] + ) == (0, 5) From 2ac1880c6e88031c0edb8905e66bc562d665e181 Mon Sep 17 00:00:00 2001 From: radonnachie Date: Mon, 9 Dec 2024 08:58:49 +0200 Subject: [PATCH 6/7] + CHANGELOG look_in_catalog bug fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34df6d881..1eb6d8d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file. ### Fixed - Bug in selecting baselines on a UVData object using `bls` keyword with 3-tuples and more than one polarization (introduced in 3.1.2). +- Bug in the `look_in_catalog` utility function that expected keys which could be +optional for some phase-center catalog-entry types. This was noticed as an issue when +adding two uvh5 objects that were of type "sidereal" which did not have "cat_times" +entries in their phase-center catalogs. ## [3.1.2] - 2024-11-21 From 712fdff9ebee251d339fa2741f19c8ec6c759a49 Mon Sep 17 00:00:00 2001 From: radonnachie Date: Mon, 9 Dec 2024 19:01:31 +0200 Subject: [PATCH 7/7] * CHANGELOG correct order --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eb6d8d3f..8a9df9240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,12 @@ All notable changes to this project will be documented in this file. - ATA has been added to the list of known telescopes. ### Fixed -- Bug in selecting baselines on a UVData object using `bls` keyword with 3-tuples and -more than one polarization (introduced in 3.1.2). - Bug in the `look_in_catalog` utility function that expected keys which could be optional for some phase-center catalog-entry types. This was noticed as an issue when adding two uvh5 objects that were of type "sidereal" which did not have "cat_times" entries in their phase-center catalogs. +- Bug in selecting baselines on a UVData object using `bls` keyword with 3-tuples and +more than one polarization (introduced in 3.1.2). ## [3.1.2] - 2024-11-21