diff --git a/neoexchange/astrometrics/ephem_subs.py b/neoexchange/astrometrics/ephem_subs.py index 66ebef9f5..ed0ad52d2 100644 --- a/neoexchange/astrometrics/ephem_subs.py +++ b/neoexchange/astrometrics/ephem_subs.py @@ -751,10 +751,16 @@ def determine_horizons_id(lines, obj_name, now=None): now = now or datetime.utcnow() timespan = timedelta.max + provisional_comet = False + if obj_name.lstrip().startswith('C/') or obj_name.lstrip().startswith('P/'): + # Provisional comet, need to match on different (combined) columns + provisional_comet = True horizons_id = None for line in lines: chunks = line.split() - if len(chunks) >= 5 and chunks[0].isdigit() is True and chunks[1].isdigit() is True and chunks[3] == obj_name: + if (len(chunks) >= 5 and chunks[0].isdigit() is True and chunks[1].isdigit() is True) and \ + (chunks[3] == obj_name.strip() or \ + (provisional_comet is True and chunks[4] + ' ' + chunks[5] == obj_name.strip())): try: epoch_yr = datetime.strptime(chunks[1], "%Y") if abs(now-epoch_yr) <= timespan: diff --git a/neoexchange/astrometrics/tests/test_ephem_subs.py b/neoexchange/astrometrics/tests/test_ephem_subs.py index 569237aee..144c1b471 100644 --- a/neoexchange/astrometrics/tests/test_ephem_subs.py +++ b/neoexchange/astrometrics/tests/test_ephem_subs.py @@ -3657,6 +3657,54 @@ def test_73P(self): self.assertEqual(expected_id, horizons_id) + def test_C_2025K1(self): + expected_id = 90004909 + lines = ['Ambiguous target name; provide unique id:', + ' Record # Epoch-yr >MATCH DESIG< Primary Desig Name ', + ' -------- -------- ------------- ------------- -------------------------', + ' 90004909 2025 C/2025 K1 C/2025 K1 ATLAS', + ' 90004910 2025 C/2025 K1-B C/2025 K1-B ATLAS', + ' 90004911 2025 C/2025 K1-C C/2025 K1-C ATLAS', + ''] + now = datetime(2025, 5, 11, 17, 20, 42) + obj_name = 'C/2025 K1' + + horizons_id = determine_horizons_id(lines, obj_name, now) + + self.assertEqual(expected_id, horizons_id) + + def test_C_2025K1c(self): + expected_id = 90004911 + lines = ['Ambiguous target name; provide unique id:', + ' Record # Epoch-yr >MATCH DESIG< Primary Desig Name ', + ' -------- -------- ------------- ------------- -------------------------', + ' 90004909 2025 C/2025 K1 C/2025 K1 ATLAS', + ' 90004910 2025 C/2025 K1-B C/2025 K1-B ATLAS', + ' 90004911 2025 C/2025 K1-C C/2025 K1-C ATLAS', + ''] + now = datetime(2025, 5, 11, 17, 20, 42) + obj_name = 'C/2025 K1-C' + + horizons_id = determine_horizons_id(lines, obj_name, now) + + self.assertEqual(expected_id, horizons_id) + + def test_P_2025K1(self): + expected_id = 90004909 + lines = ['Ambiguous target name; provide unique id:', + ' Record # Epoch-yr >MATCH DESIG< Primary Desig Name ', + ' -------- -------- ------------- ------------- -------------------------', + ' 90004909 2025 P/2025 K1 P/2025 K1 ATLAS', + ' 90004910 2025 P/2025 K1-B P/2025 K1-B ATLAS', + ' 90004911 2025 P/2025 K1-C P/2025 K1-C ATLAS', + ''] + now = datetime(2025, 5, 11, 17, 20, 42) + obj_name = ' P/2025 K1' + + horizons_id = determine_horizons_id(lines, obj_name, now) + + self.assertEqual(expected_id, horizons_id) + def test_bad_object(self): expected_id = None lines = ['Unknown target (20000P). Maybe try different id_type?']