@@ -622,6 +622,7 @@ def match_spectra_to_base_and_merge_duplicates(specs, base, debug=None, matching
622622 possible_match ["ba" ] if "ba" in possible_match .colnames else None ,
623623 possible_match ["phi" ] if "phi" in possible_match .colnames else None ,
624624 )
625+ possible_match ["SPEC_Z" ] = specs ["SPEC_Z" ][spec_idx_this ]
625626
626627 # using following criteria one by one to find matching photo obj, stop when found
627628 for q , sorter in matching_order :
@@ -820,10 +821,11 @@ def remove_shreds_near_spec_obj(base, nsa=None, shreds_recover=None):
820821 has_nsa = Query ("OBJ_NSAID > -1" )
821822 has_sga = QueryMaker .equal ("REF_CAT" , "L3" )
822823 has_spec_z = Query (
823- "SPEC_Z > 0 " ,
824+ "SPEC_Z >= 0.002 " ,
824825 "ZQUALITY >= 3" ,
825826 "is_galaxy" ,
826827 "radius > abs(radius_err) * 2.0" ,
828+ "radius > 0" ,
827829 )
828830
829831 if "REF_CAT" in base .colnames :
@@ -887,7 +889,7 @@ def remove_shreds_near_spec_obj(base, nsa=None, shreds_recover=None):
887889
888890 elif obj_this ["REMOVE" ] == 0 : # any other good, non-NSA objects
889891
890- radius = obj_this ["radius" ]
892+ radius = obj_this ["radius" ] * 0.9
891893
892894 # HOT FIX for NGC7162A (330.148221, -43.140536) in pgc67817 (base v2)
893895 if obj_this ["OBJID" ] == 219806824 :
@@ -919,33 +921,31 @@ def remove_shreds_near_spec_obj(base, nsa=None, shreds_recover=None):
919921 nearby_obj ["_idx" ] = np .flatnonzero (nearby_obj_mask )
920922 del nearby_obj_mask
921923
922- remove_basic_conditions = Query ("is_galaxy" , "r_mag > 14" )
924+ is_brighter = Query ("r_mag < {}" .format (obj_this ["r_mag" ]))
925+ is_fainter = ~ is_brighter
926+ remove_basic_conditions = Query ("is_galaxy" , is_fainter , "r_mag > 14" )
927+
923928 if "REF_CAT" in base .colnames :
924- remove_basic_conditions &= ~ has_sga
925929 remove_basic_conditions |= has_nsa
930+ remove_basic_conditions &= QueryMaker .equal ("REF_CAT" , "" )
926931 elif "OBJ_NSAID" in base .colnames :
927932 remove_basic_conditions &= ~ has_nsa
928933
929- close_spec_z = Query (
930- remove_basic_conditions ,
931- "ZQUALITY >= 0" ,
932- (
933- lambda z : np .fabs (z - obj_this ["SPEC_Z" ]) < 200.0 / SPEED_OF_LIGHT ,
934- "SPEC_Z" ,
935- ),
936- )
934+ if shreds_recover is not None :
935+ remove_basic_conditions &= QueryMaker .in1d ("OBJID" , shreds_recover , invert = True )
936+
937+ z_limit = v2z ([300 , 250 , 200 , 150 ][np .searchsorted ([14 , 16 , 20 ], obj_this ["r_mag" ])])
938+ close_spec_z = Query ("ZQUALITY > -1" , (lambda z : np .abs (z - obj_this ["SPEC_Z" ]) < z_limit , "SPEC_Z" ))
937939 good_close_spec_z = Query (close_spec_z , "ZQUALITY >= 3" )
938- is_fainter = Query ((lambda r : (r >= obj_this ["r_mag" ]) | (~ np .isfinite (r )), "r_mag" ))
939- to_remove = close_spec_z | Query (remove_basic_conditions , is_fainter , "ZQUALITY < 2" )
940+ no_spec_z = Query ("ZQUALITY < 2" )
940941
941- if shreds_recover is not None :
942- to_remove = to_remove & QueryMaker .in1d ("OBJID" , shreds_recover , invert = True )
942+ to_remove = Query (remove_basic_conditions , close_spec_z | no_spec_z )
943943
944944 if not to_remove .mask (nearby_obj ).any (): # Nothing to remove, carry on
945945 continue
946946
947947 new_remove_count = Query (to_remove , "REMOVE == 0" ).count (nearby_obj )
948- if new_remove_count > 25 and remove_flag == 29 :
948+ if new_remove_count > 25 and "NSA" not in obj_this [ "SPEC_REPEAT" ] and "SGA" not in obj_this [ "SPEC_REPEAT" ] :
949949 logging .warning (
950950 '{} photo obj newly removed within ~{:.3f}" of {} spec obj {} ({}, {})' .format (
951951 new_remove_count ,
@@ -957,7 +957,10 @@ def remove_shreds_near_spec_obj(base, nsa=None, shreds_recover=None):
957957 )
958958 )
959959
960- base ["REMOVE" ][to_remove .filter (nearby_obj , "_idx" )] += 1 << remove_flag
960+ base ["REMOVE" ][to_remove .filter (nearby_obj , "_idx" )] |= 1 << remove_flag
961+
962+ close_spec_z = close_spec_z & remove_basic_conditions
963+ good_close_spec_z = good_close_spec_z & remove_basic_conditions
961964
962965 if not close_spec_z .mask (nearby_obj ).any ():
963966 continue
0 commit comments