Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion neoexchange/astrometrics/ephem_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions neoexchange/astrometrics/tests/test_ephem_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?']
Expand Down