@@ -268,6 +268,50 @@ def test_load_catalog(self):
268268 tab = self .image .get_catalog (catalog_label = 'test1' )
269269 self ._assert_empty_catalog_table (tab )
270270
271+ def test_load_catalog_with_skycoord_no_wcs (self , catalog , data ):
272+ # Check that loading a catalog with skycoord but no x/y and
273+ # no WCS returns a catlog with None for x and y.
274+ self .image .load_array (data )
275+
276+ # Remove x/y columns from the catalog
277+ del catalog ['x' , 'y' ]
278+ self .image .load_catalog (catalog )
279+ # Retrieve the catalog and check that the x and y columns are None
280+ retrieved_catalog = self .image .get_catalog ()
281+ assert 'x' in retrieved_catalog .colnames
282+ assert 'y' in retrieved_catalog .colnames
283+ assert all (rc is None for rc in retrieved_catalog ['x' ])
284+ assert all (rc is None for rc in retrieved_catalog ['y' ])
285+
286+ def test_load_catalog_with_use_skycoord_no_skycoord_no_wcs (self , catalog , data ):
287+ # Check that loading a catalog with use_skycoord=True but no
288+ # skycoord column and no WCS raises an error.
289+ self .image .load_array (data )
290+ del catalog ['coord' ] # Remove the skycoord column
291+ with pytest .raises (ValueError , match = 'Cannot use sky coordinates without' ):
292+ self .image .load_catalog (catalog , use_skycoord = True )
293+
294+ def test_load_catalog_with_xy_and_wcs (self , catalog , data , wcs ):
295+ # Check that loading a catalog that wants to use sky coordinates,
296+ # has no coordinate column but has x/y and a WCS works.
297+ self .image .load_nddata (NDData (data = data , wcs = wcs ))
298+
299+ # Remove the skycoord column from the catalog
300+ del catalog ['coord' ]
301+
302+ # Add the catalog with x/y and WCS
303+ self .image .load_catalog (catalog , use_skycoord = True )
304+
305+ # Retrieve the catalog and check that the x and y columns are there
306+ retrieved_catalog = self .image .get_catalog ()
307+ assert 'x' in retrieved_catalog .colnames
308+ assert 'y' in retrieved_catalog .colnames
309+ assert 'coord' in retrieved_catalog .colnames
310+
311+ # Check that the coordinates are correct
312+ coords = wcs .pixel_to_world (catalog ['x' ], catalog ['y' ])
313+ assert all (coords .separation (retrieved_catalog ['coord' ]) < 1e-9 * u .deg )
314+
271315 def test_catalog_info_preserved_after_load (self , catalog ):
272316 # Make sure that any catalog columns in addition to the position data
273317 # is preserved after loading a catalog.
0 commit comments