def test_wcsgroupcat_recalc_catalog_radec(mock_fits_wcs, rect_imcat): ra, dec = mock_fits_wcs.all_pix2world(rect_imcat.catalog['x'], rect_imcat.catalog['y'], 0) refcat = Table([ra, dec], names=('RA', 'DEC')) ref = RefCatalog(refcat) wim1 = copy.deepcopy(rect_imcat) wim2 = copy.deepcopy(rect_imcat) g = WCSGroupCatalog(wim1) ra = g.catalog['RA'] dec = g.catalog['DEC'] # artificially add another image: g._images.append(wim2) g.recalc_catalog_radec() assert np.allclose(g.catalog['RA'], ra) assert np.allclose(g.catalog['DEC'], dec) g.align_to_ref(ref) mcat = g.get_matched_cat() assert len(mcat) == 5 assert np.allclose(mcat['RA'], ra) assert np.allclose(mcat['DEC'], dec) del g.catalog['RA'] del g.catalog['DEC'] with pytest.raises(RuntimeError): g.calc_tanp_xy(None)
def test_wcsgroupcat_match2ref(mock_fits_wcs, rect_imcat): ra, dec = mock_fits_wcs.all_pix2world(rect_imcat.catalog['x'], rect_imcat.catalog['y'], 0) refcat = Table([ra[:-1], dec[:-1]], names=('RA', 'DEC')) ref = RefCatalog(refcat) # unequal catalog lengths g = WCSGroupCatalog(rect_imcat) with pytest.raises(ValueError): g.match2ref(ref, match=None) refcat = Table([ra, dec], names=('RA', 'DEC')) ref = RefCatalog(refcat) # call calc_tanp_xy before matching with pytest.raises(RuntimeError) as e: g.match2ref(ref, match=TPMatch()) assert (e.value.args[0] == "'calc_tanp_xy()' should have been run " "prior to match2ref()") ref.calc_tanp_xy(rect_imcat.tpwcs) g.calc_tanp_xy(rect_imcat.tpwcs) g.catalog['matched_ref_id'] = np.ones(5, dtype=bool) g.catalog['_raw_matched_ref_idx'] = np.ones(5, dtype=bool) g.match2ref(ref, match=TPMatch())
def test_wcsgroupcat_intersections(mock_fits_wcs, rect_imcat): g = WCSGroupCatalog(rect_imcat) pts1 = list(g.polygon.points)[0] pts2 = list(g.intersection(g.polygon).points)[0] for pt1 in pts1: assert any(np.allclose(pt1, pt2) for pt2 in pts2) pts2 = list(g.intersection(g).points)[0] for pt1 in pts1: assert any(np.allclose(pt1, pt2) for pt2 in pts2) assert np.allclose( g.intersection_area(g), 2.9904967391303217e-12, atol=0.0, rtol=5.0e-4 )
def test_wcsgroupcat_fit2ref(mock_fits_wcs, caplog, rect_imcat): ra, dec = mock_fits_wcs.all_pix2world(rect_imcat.catalog['x'], rect_imcat.catalog['y'], 0) refcat = Table([ra, dec], names=('RA', 'DEC')) ref = RefCatalog(refcat) ref.calc_tanp_xy(rect_imcat.tpwcs) g = WCSGroupCatalog(rect_imcat) g.calc_tanp_xy(rect_imcat.tpwcs) g.match2ref(ref) g.fit2ref(ref, rect_imcat.tpwcs, fitgeom='shift') g.apply_affine_to_wcs(g[0].tpwcs, np.identity(2), np.zeros(2)) g._images = [] g.align_to_ref(ref) assert caplog.record_tuples[-1][-1].endswith("Nothing to align.")
def test_wcsgroupcat_create_group_catalog(mock_fits_wcs, rect_imcat): w1 = copy.deepcopy(rect_imcat) w2 = copy.deepcopy(rect_imcat) g = WCSGroupCatalog([w1, w2]) # catalogs with name set to None: names = [] for im in g: names.append(im.name) im._name = None assert len(g.create_group_catalog()) == 2 * len(rect_imcat.catalog) for im, name in zip(g, names): im.name = name # Mixed catalogs: one has weights and another does not: g[0].catalog.add_column(Column(np.ones(5)), name='weight') with pytest.raises(KeyError) as e: g.create_group_catalog() assert False assert (e.value.args[0] == "Non-empty catalogs in a group must all " "either have or not have 'weight' column.") g[0].catalog.remove_column('weight') # artificially set catalog of one of the images to an empty table: g[0].catalog.remove_rows(slice(None, None)) assert len(g.create_group_catalog()) == len(rect_imcat.catalog) # artificially set all catalogs to empty table: for im in g: im.catalog.remove_rows(slice(None, None)) assert not g.create_group_catalog() # artificially set all catalogs to empty table: for im in g: im._name = None assert not g.create_group_catalog()
def test_wcsgroupcat_init(mock_fits_wcs, rect_imcat): g = WCSGroupCatalog(rect_imcat, 'name1') assert g.name == 'name1' for im in g: assert im.name == 'Unknown' g.name = 'name2' assert g.name == 'name2' assert g[0] is rect_imcat assert len(g) == 1 # input list is empty: with pytest.raises(ValueError) as e: WCSGroupCatalog([]) assert e.value.args[0] == "List of images cannot be empty." # wrong type for the WCSImageCatalog in a list with pytest.raises(TypeError) as e: WCSGroupCatalog([1]) assert (e.value.args[0] == "Each element of the 'images' parameter " "must be an 'WCSImageCatalog' object.") # wrong type for the input catalog: it is not a WCSImageCatalog with pytest.raises(TypeError) as e: WCSGroupCatalog(1) assert (e.value.args[0] == "Parameter 'images' must be either a single " "'WCSImageCatalog' object or a list of 'WCSImageCatalog' objects") # input WCSImageCatalog with a missing catalog: with pytest.raises(ValueError) as e: rect_imcat.catalog = None WCSGroupCatalog(rect_imcat) assert (e.value.args[0] == "Each input WCS image catalog must have a " "valid catalog.") # input WCSImageCatalog with a missing catalog in the input list: with pytest.raises(ValueError) as e: rect_imcat.catalog = None WCSGroupCatalog([rect_imcat]) assert (e.value.args[0] == "Each input WCS image catalog must have a " "valid catalog.")
def test_wcsgroupcat_update_bb_no_images(mock_fits_wcs, rect_imcat): g = WCSGroupCatalog(rect_imcat) g._images = [] g.update_bounding_polygon() assert len(g.polygon) == 0
def test_wcsgroupcat_guarded_intersection_area(mock_fits_wcs, rect_imcat): g = WCSGroupCatalog(rect_imcat) assert np.allclose(g._guarded_intersection_area(g), 2.9904967391303217e-12, atol=0.0, rtol=5.0e-4)