nyx-space / anise

ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of the NAIF SPICE toolkit.
Mozilla Public License 2.0
71 stars 14 forks source link

MetaAlmanac not loading planetary data for 301 (Earth's Moon) #339

Open translunar opened 1 month ago

translunar commented 1 month ago

Bug report

Describe the bug

I cannot access lunar planetary constants or frame data through anise.

To Reproduce

Steps to reproduce the behavior:

import pathlib
import anise

def load_kernels() -> anise.MetaAlmanac:
    my_constants_filename = (
        'my_constants.tpc')
    earth_assoc_itrf93_fk_filename = (
        'earth_assoc_itrf93.tf')
    earth_assoc_itrf93_epa_filename = (
        'earth_assoc_itrf93.epa')

    if not pathlib.Path(my_constants_filename).is_file():
        # Make sure the constants file exists (create if not)
        anise.utils.convert_tpc(
                'pck00010.tpc',
                'gm_de440.tpc',
                my_constants_filename)

    if not pathlib.Path(earth_assoc_itrf93_epa_filename).is_file():
        anise.utils.convert_fk(
            earth_assoc_itrf93_fk_filename,
            earth_assoc_itrf93_epa_filename)

    earth_latest_high_prec = anise.MetaFile(
        'earth_latest_high_prec.bpc',
    )
    jpl_moon_rotation = anise.MetaFile(
        'moon_pa_de440_200625.bpc',
    )
    de440 = anise.MetaFile(
        'de440.bsp'
    )
    moon_frames = anise.MetaFile(
        'moon_fk.epa'
    )
    itrf93 = anise.MetaFile(earth_assoc_itrf93_epa_filename)
    my_constants = anise.MetaFile(
        'my_constants.tpc'
    )
    new_meta = anise.MetaAlmanac()
    new_meta.files = [
        earth_latest_high_prec,
        jpl_moon_rotation,
        de440,
        itrf93,
        moon_frames,
        my_constants
    ]
    return almanac

and then almanac.describe(spk=True, bpc=True, planetary=True) does not list 301. I believe this should be in de440.bsp, but maybe I'm missing something. I spent a bunch of time staring at the documentation for MetaAlmanac and Almanac and couldn't figure this out.

Expected behavior

I would expect loading the planetary constants and BPC files should yield planetary data for 301. I should also be able to get the MOON_J2000 frame, but I get the following error with almanac.frame_info(Frames.MOON_J2000):

Exception: when fetching frame by its UID via ephemeris_id, when fetching by ID, ID 301 not in look up table

Platform

Linux, Anise 0.4.4

Additional context

This comes from the tutorial, which suggests the following should work:

    moon_j2000 = Frames.MOON_J2000
    loaded_moon_j2000 = almanac.frame_info(moon_j2000)

The tutorial may need to be updated, or else this code simply doesn't work.

translunar commented 1 month ago

I found a workaround, which is to load a pck11.pca, but this was hard to do because the tutorial link is still to the v0.3 version of that file, and so I had to do a little URL hacking to figure out what I needed to wget.

ChristopherRabotin commented 1 month ago

Hi Juno,

Thanks for the bug report. The tutorials need some updating to the paths, and I suspect the readme might still point to version 3 of the files: I'll fix this in #341.

Would it be possible for you to share the files used for creating this planetary constants input file? I'd like to reproduce the issue: from your code, it seems like everything should have worked.

Thanks

translunar commented 1 month ago

They are as listed: pck00010.tpc and gm_de440.tpc. These should be available from NAIF. Are you asking for some other file?

ChristopherRabotin commented 1 month ago

Yes: would you have a copy of the my_constants.tpc created by the call to convert_tpc so I can open it in the GUI? Both pck08.pca and pck11.pca are built using that same call in the tests, and they both include body 301.

PCK08: Image

PCK11: Image

The GUI is prebuilt for Linux and Windows on Github: https://github.com/nyx-space/anise/actions/runs/11367543965

translunar commented 1 month ago

Yeah. Oddly SPICE isn't loading 301 or 399 from pck 10 either, though I see the variables in the file. Here is the output file: constants.tpc.txt

And here is the input: pck00010.tpc.txt

ChristopherRabotin commented 1 month ago

Hey Juno,

Has the pck 11 or 08 versions been working for you? I can investigate this issue further at a later date. I'm also a bit surprised that the data present neither in SPICE nor ANISE since it sure looks present in the original tpc file.