22import nested_pandas as npd
33import numpy as np
44from lsdb .core .crossmatch .kdtree_match import KdTreeCrossmatch
5+
56from lsdb_crossmatch .mag_difference_crossmatch import MyCrossmatchAlgorithm
67
8+
79def test_mag_difference_crossmatch (m67_delve_dir , m67_ps1_dir ):
810 left_data = lsdb .open_catalog (m67_ps1_dir )
911 right_data = lsdb .open_catalog (m67_delve_dir )
@@ -20,58 +22,32 @@ def test_mag_difference_crossmatch(m67_delve_dir, m67_ps1_dir):
2022 suffixes = ["_left" , "_right" ],
2123 algorithm = KdTreeCrossmatch ,
2224 radius_arcsec = 0.01 * 3600 ,
23- n_neighbors = 5 ,
25+ n_neighbors = 5 ,
2426 ).compute ()
25- """
26- print("\n KDTREE RESULTS")
27- print("\n id col left")
28- print(kdtree_result[id_col_left])
29- print("\n id col right")
30- print(kdtree_result[id_col_right])
31- print("------------")
32- """
33- """
34- target_left_id = 10493100048242
35- count_in_left_catalog = left_data["objID"].value_counts().compute().get(target_left_id, 0)
36- print(f"\n Number of times {target_left_id} appears in the original left catalog: {count_in_left_catalog}")
37-
38- target_right_id = 10493100048242
39- count_in_right_catalog = right_data["QUICK_OBJECT_ID"].value_counts().compute().get(target_right_id, 0)
40-
41- print(f"\n Number of times {target_right_id} appears in the original right catalog: {count_in_right_catalog}")
42- """
27+
4328 result = lsdb .crossmatch (
4429 left_data ,
4530 right_data ,
4631 suffixes = ["_left" , "_right" ],
4732 algorithm = MyCrossmatchAlgorithm ,
4833 radius_arcsec = 0.01 * 3600 ,
49- left_mag_col = left_mag_col ,
50- right_mag_col = right_mag_col ,
51- n_neighbors = 5
34+ left_mag_col = left_mag_col ,
35+ right_mag_col = right_mag_col ,
36+ n_neighbors = 5 ,
5237 ).compute ()
53- """
54- print("\n MAG CROSSMATCH RESULTS")
55- print("\n id col left")
56- print(result[id_col_left])
57- print("\n id col right")
58- print(result[id_col_right])
59- print("------------")
60- """
6138
6239 assert isinstance (result , npd .NestedFrame )
63-
40+
6441 if not result .empty :
6542 assert len (result ) == len (result [id_col_left ].unique ())
6643 assert result [id_col_left ].value_counts ().max () == 1
67-
68-
44+
6945 if not kdtree_result .empty :
7046 kdtree_result ["magnitude_difference" ] = np .abs (
7147 kdtree_result [right_mag_col + "_right" ] - kdtree_result [left_mag_col + "_left" ]
7248 )
73-
74- target_left_id = 122650089529714672
49+
50+ target_left_id = 122650089529714672
7551
7652 if not kdtree_result .empty and target_left_id in kdtree_result [id_col_left ].values :
7753 potential_matches_for_target = kdtree_result [kdtree_result [id_col_left ] == target_left_id ]
@@ -82,47 +58,14 @@ def test_mag_difference_crossmatch(m67_delve_dir, m67_ps1_dir):
8258 ).reset_index (drop = True )
8359
8460 expected_best_right_id = potential_matches_for_target .iloc [0 ][id_col_right ]
85-
61+
8662 actual_match_from_my_algo = result [result [id_col_left ] == target_left_id ]
8763
8864 if not actual_match_from_my_algo .empty :
89- actual_matched_right_id = actual_match_from_my_algo .iloc [0 ][id_col_right ]
65+ actual_matched_right_id = actual_match_from_my_algo .iloc [0 ][id_col_right ]
9066
91- assert actual_matched_right_id == expected_best_right_id
67+ assert actual_matched_right_id == expected_best_right_id
9268 else :
9369 print (f"No potential matches found in kdtree_result for { target_left_id } ." )
94- else :
70+ else :
9571 print (f"Target left ID { target_left_id } not found in kdtree_result." )
96-
97- """
98- for target_left_id in result[id_col_left].values:
99- if not kdtree_result.empty and target_left_id in kdtree_result[id_col_left].values:
100- potential_matches_for_target = kdtree_result[kdtree_result[id_col_left] == target_left_id].copy()
101-
102- if not potential_matches_for_target.empty:
103- potential_matches_for_target = potential_matches_for_target.sort_values(
104- by="magnitude_difference"
105- ).reset_index(drop=True)
106-
107- #print(f"\n All potential matches for {target_left_id}:")
108- #print(potential_matches_for_target[[id_col_left, id_col_right, "magnitude_difference"]])
109-
110- expected_best_right_id = potential_matches_for_target.iloc[0][id_col_right]
111-
112- #print(f"\n Expected best match for {target_left_id}:")
113- #print(f" Right ID: {expected_best_right_id}")
114-
115- actual_match_from_my_algo = result[result[id_col_left] == target_left_id]
116-
117- if not actual_match_from_my_algo.empty:
118- actual_matched_right_id = actual_match_from_my_algo.iloc[0][id_col_right]
119-
120- #print(f"\n Actual match from MyCrossmatchAlgorithm for {target_left_id}:")
121- #print(f" Right ID: {actual_matched_right_id}")
122-
123- assert actual_matched_right_id == expected_best_right_id
124- else:
125- print(f"No potential matches found in kdtree_result for {target_left_id}.")
126- else:
127- print(f"Target left ID {target_left_id} not found in kdtree_result.")
128- """
0 commit comments