Skip to content

Commit 711b664

Browse files
committed
Fix illogical test
This had tested what would happen if you wanted to use x/y for a catalog but had no x/y in the catalog table and didn't expect that to raise an error.
1 parent ab383e1 commit 711b664

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/astro_image_display_api/api_test.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,10 @@ def test_load_catalog_with_skycoord_no_wcs(self, catalog, data):
543543

544544
# Remove x/y columns from the catalog
545545
del catalog["x", "y"]
546-
self.image.load_catalog(catalog)
547-
# Retrieve the catalog and check that the x and y columns are None
548-
retrieved_catalog = self.image.get_catalog()
549-
assert "x" in retrieved_catalog.colnames
550-
assert "y" in retrieved_catalog.colnames
551-
assert all(rc is None for rc in retrieved_catalog["x"])
552-
assert all(rc is None for rc in retrieved_catalog["y"])
546+
with pytest.raises(
547+
ValueError, match="Cannot use pixel coordinates without pixel columns"
548+
):
549+
self.image.load_catalog(catalog)
553550

554551
def test_load_catalog_with_use_skycoord_no_skycoord_no_wcs(self, catalog, data):
555552
# Check that loading a catalog with use_skycoord=True but no

src/astro_image_display_api/image_viewer_logic.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,16 @@ def load_catalog(
492492
x, y = self._wcs.world_to_pixel(coords)
493493
to_add[x_colname] = x
494494
to_add[y_colname] = y
495+
xy = (x, y)
495496
else:
496497
to_add[x_colname] = to_add[y_colname] = None
497498

499+
if not use_skycoord and xy is None:
500+
raise ValueError(
501+
"Cannot use pixel coordinates without pixel columns or both "
502+
"coordinates and a WCS."
503+
)
504+
498505
if coords is None:
499506
if use_skycoord and self._wcs is None:
500507
raise ValueError(
@@ -703,13 +710,15 @@ def get_viewport(
703710
"sky coordinates."
704711
)
705712
else:
706-
center = viewport.wcs.pixel_to_world(
707-
viewport.center[0], viewport.center[1]
708-
)
709-
pixel_scale = proj_plane_pixel_scales(viewport.wcs)[
710-
viewport.largest_dimension
711-
]
712-
fov = pixel_scale * viewport.fov * u.degree
713+
if center is None:
714+
center = viewport.wcs.pixel_to_world(
715+
viewport.center[0], viewport.center[1]
716+
)
717+
if fov is None:
718+
pixel_scale = proj_plane_pixel_scales(viewport.wcs)[
719+
viewport.largest_dimension
720+
]
721+
fov = pixel_scale * viewport.fov * u.degree
713722
else:
714723
# Pixel coordinates
715724
if isinstance(viewport.center, SkyCoord):

0 commit comments

Comments
 (0)