Instrument IDs < -1_000_000 give an error
Instrument IDs <= -1_000_000 give an error when using, e.g., <trajectory>.intersect():
Testcase
from moon_coverage import TourConfig
from moon_coverage import GanymedeROIs
tour = TourConfig(mk='5.0',
spacecraft='JUICE',
target='GANYMEDE',
download_kernels=(True))
tour['2035-06-30':'2035-09-01':'1 day']
sc_traj = tour['2035-07-01':'2035-07-02':'30 s']
# One specific pixel of PEP JNA
# PEP_JNA_SECTOR_06 has a seven digit ID
inst_traj = sc_traj['PEP_JNA_SECTOR_06']
mask_traj = inst_traj.where(inst_traj.intersect(GanymedeROIs[2], True))
this fails with (only end of stacktrace shown):
File "/home/tinu/anaconda3/envs/pep39/lib/python3.9/site-packages/moon_coverage/spice/references.py", line 357, in spacecraft
return SpiceSpacecraft(-(-int(self) // 1_000))
File "/home/tinu/anaconda3/envs/pep39/lib/python3.9/site-packages/moon_coverage/spice/references.py", line 201, in __init__
super().__init__(ref)
File "/home/tinu/anaconda3/envs/pep39/lib/python3.9/site-packages/moon_coverage/spice/references.py", line 58, in __init__
self.name, self.id = spice_name_code(ref)
File "/home/tinu/anaconda3/envs/pep39/lib/python3.9/site-packages/moon_coverage/spice/references.py", line 37, in spice_name_code
raise ValueError(f'Unknown reference: `{ref}`')
ValueError: Unknown reference: `-285`
Cause
In moon_coverage/spice/references.py, line 357, in spacecraft where the spacecraft ID is calculated based on the instrument ID using:
def spacecraft(self):
"""Parent spacecraft."""
return SpiceSpacecraft(-(-int(self) // 1_000))
This will fail if the instrument ID is outside of NAIFs original spec with ID > -1000000 (see also docstring for def is_valid(self), line 316)
Possible fix
def spacecraft(self):
"""Parent spacecraft."""
return SpiceSpacecraft(int(str(int(self))[:3])) # use the first 3 *characters* as spacecraft ID (-2851000 -> -28 )