def test_score_and_match(self): """Test association between a set of sources and an existing DIAObjectCollection. """ assoc_task = AssociationTask() score_struct = assoc_task.score(self.diaObjects, self.diaSourceZeroScatter, 1.0 * geom.arcseconds) self.assertFalse(np.isfinite(score_struct.scores[0])) for src_idx in range(1, len(self.diaSources)): # Our scores should be extremely close to 0 but not exactly so due # to machine noise. self.assertAlmostEqual(score_struct.scores[src_idx], 0.0, places=16) # After matching each DIAObject should now contain 2 DIASources # except the last DIAObject in this collection which should be # newly created during the matching step and contain only one # DIASource. match_result = assoc_task.match(self.diaObjects, self.diaSources, score_struct) self.assertEqual(match_result.nUpdatedDiaObjects, 4) self.assertEqual(match_result.nUnassociatedDiaObjects, 1)
def test_score_and_match(self): """Test association between a set of sources and an existing DIAObjectCollection. This also tests that a DIASource that can't be associated within tolerance is appended to the DIAObjectCollection as a new DIAObject. """ assoc_task = AssociationTask() # Create a set of DIAObjects that contain only one DIASource n_objects = 5 dia_objects = create_test_points_pandas( point_locs_deg=[[0.04 * obj_idx, 0.04 * obj_idx] for obj_idx in range(n_objects)], start_id=0, schema=self.dia_object_schema, scatter_arcsec=-1,) dia_objects.rename(columns={"coord_ra": "ra", "coord_dec": "decl", "id": "diaObjectId"}, inplace=True) n_sources = 5 dia_sources = create_test_points_pandas( point_locs_deg=[ [0.04 * (src_idx + 1), 0.04 * (src_idx + 1)] for src_idx in range(n_sources)], start_id=n_objects, scatter_arcsec=-1) dia_sources.rename(columns={"coord_ra": "ra", "coord_dec": "decl", "id": "diaSourceId"}, inplace=True) score_struct = assoc_task.score(dia_objects, dia_sources, 1.0 * geom.arcseconds) self.assertFalse(np.isfinite(score_struct.scores[-1])) for src_idx in range(4): # Our scores should be extremely close to 0 but not exactly so due # to machine noise. self.assertAlmostEqual(score_struct.scores[src_idx], 0.0, places=16) # After matching each DIAObject should now contain 2 DIASources # except the last DIAObject in this collection which should be # newly created during the matching step and contain only one # DIASource. match_result = assoc_task.match(dia_objects, dia_sources, score_struct) updated_ids = match_result.associated_dia_object_ids self.assertEqual(len(updated_ids), 5) self.assertEqual(match_result.n_updated_dia_objects, 4) self.assertEqual(match_result.n_new_dia_objects, 1) self.assertEqual(match_result.n_unassociated_dia_objects, 1) # Test updating all DiaObjects n_objects = 4 dia_objects = create_test_points_pandas( point_locs_deg=[[0.04 * obj_idx, 0.04 * obj_idx] for obj_idx in range(n_objects)], start_id=0, schema=self.dia_object_schema, scatter_arcsec=-1,) dia_objects.rename(columns={"coord_ra": "ra", "coord_dec": "decl", "id": "diaObjectId"}, inplace=True) n_sources = 4 dia_sources = create_test_points_pandas( point_locs_deg=[ [0.04 * src_idx, 0.04 * src_idx] for src_idx in range(n_sources)], start_id=n_objects, scatter_arcsec=-1) dia_sources.rename(columns={"coord_ra": "ra", "coord_dec": "decl", "id": "diaSourceId"}, inplace=True) score_struct = assoc_task.score(dia_objects[1:], dia_sources[:-1], 1.0 * geom.arcseconds) match_result = assoc_task.match(dia_objects, dia_sources, score_struct) updated_ids = match_result.associated_dia_object_ids self.assertEqual(len(updated_ids), 4)