Skip to content

Commit

Permalink
Add test for unknown catalog name in FHD file
Browse files Browse the repository at this point in the history
Improve error message, update changelog
  • Loading branch information
bhazelton committed Feb 9, 2024
1 parent dbdc363 commit f2cc19d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- A memo describing the SkyH5 format in docs/references.

### Changed
- Added support for more types of FHD catalog files and better error messages.
- Added support (and testing) for python 3.12, dropped support for python 3.8
- Moved the optional data-sized arrays (stokes_error and beam_amp) from the Header
datagroup to the Data datagroup in SkyH5 files.
Expand Down
Binary file added src/pyradiosky/data/fhd_catalog_bad.sav
Binary file not shown.
5 changes: 4 additions & 1 deletion src/pyradiosky/skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4357,7 +4357,10 @@ def read_fhd_catalog(
elif "source_array" in catalog.keys():
catalog = catalog["source_array"]
else:
raise KeyError(f"File {filename_sav} does not contain a known catalog name")
raise KeyError(
f"File {filename_sav} does not contain a known catalog name. "
f"File variables include {list(catalog.keys())}"
)
ids = catalog["id"].astype(str)
ra = catalog["ra"]
dec = catalog["dec"]
Expand Down
37 changes: 25 additions & 12 deletions tests/test_skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2941,21 +2941,21 @@ def test_read_votable_errors():
)


def test_fhd_catalog_reader():
for fname in ["catalog", "source_array"]:
catfile = os.path.join(SKY_DATA_PATH, f"fhd_{fname}.sav")
@pytest.mark.parametrize("fname", ["catalog", "source_array"])
def test_fhd_catalog_reader(fname):
catfile = os.path.join(SKY_DATA_PATH, f"fhd_{fname}.sav")

if fname == "catalog":
with uvtest.check_warnings(
UserWarning, match="Source IDs are not unique. Defining unique IDs."
):
skyobj = SkyModel.from_fhd_catalog(catfile, expand_extended=False)
else:
if fname == "catalog":
with uvtest.check_warnings(
UserWarning, match="Source IDs are not unique. Defining unique IDs."
):
skyobj = SkyModel.from_fhd_catalog(catfile, expand_extended=False)
else:
skyobj = SkyModel.from_fhd_catalog(catfile, expand_extended=False)

assert skyobj.filename == [f"fhd_{fname}.sav"]
catalog = scipy.io.readsav(catfile)[fname]
assert skyobj.Ncomponents == len(catalog)
assert skyobj.filename == [f"fhd_{fname}.sav"]
catalog = scipy.io.readsav(catfile)[fname]
assert skyobj.Ncomponents == len(catalog)

assert np.all(skyobj.reference_frequency > 50 * units.MHz)

Expand Down Expand Up @@ -3042,6 +3042,19 @@ def test_fhd_catalog_reader_labeling_extended_sources():
assert skyobj.name[comp] == expected_name[comp]


def test_fhd_catalog_reader_errors():
catfile = os.path.join(SKY_DATA_PATH, "fhd_catalog_bad.sav")

with pytest.raises(
KeyError,
match=re.escape(
f"File {catfile} does not contain a known catalog name. "
"File variables include ['src_arr']"
),
):
SkyModel.from_fhd_catalog(catfile)


def test_point_catalog_reader():
catfile = os.path.join(SKY_DATA_PATH, "pointsource_catalog.txt")
skyobj = SkyModel.from_file(catfile)
Expand Down

0 comments on commit f2cc19d

Please sign in to comment.