Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
translunar opened this issue Oct 15, 2024 · 10 comments
Open

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

translunar opened this issue Oct 15, 2024 · 10 comments

Comments

@translunar
Copy link

translunar commented Oct 15, 2024

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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

@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Oct 16, 2024

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
Copy link
Author

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
Copy link
Member

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.

@gregjesl
Copy link

gregjesl commented Dec 3, 2024

I'm encountering a similar issue. Loading from the default almanac works great but when I attempt to load from local copies of the kernels I encounter the following error:

Could not load frame: PlanetaryDataSet { action: "fetching frame by its UID via ephemeris_id", source: DataSetLut { action: "fetching by ID", source: UnknownId { id: 301 } } }

@gregjesl
Copy link

gregjesl commented Dec 3, 2024

let ctx = Almanac::new("./almanac/de440s.bsp").expect("Could not load bsp");
let loaded_ctx = ctx.load("./almanac/moon_pa_de440_200625.bpc").expect("Could not load bpc");
println!("Planetary data length: {}", loaded_ctx.planetary_data.len());

reports

Planetary data length: 0

It looks like Almanac::new and Almanac::load are returning Ok despite not actually loading any data.

For reference, my download script:

mkdir -p almanac
cd almanac
curl http://public-data.nyxspace.com/anise/de440s.bsp -O
curl http://public-data.nyxspace.com/anise/v0.4/pck11.pca -O
curl http://public-data.nyxspace.com/anise/v0.4/moon_fk.epa -O
curl http://public-data.nyxspace.com/anise/moon_pa_de440_200625.bpc -O
curl https://naif.jpl.nasa.gov/pub/naif/generic_kernels/pck/earth_latest_high_prec.bpc -O

@ChristopherRabotin
Copy link
Member

Hi Greg,

The planetary data in the almanac refers only to the data you'd typically find the SPICE PCK files, including gravity parameters and shape of the ellipsoid. The ctx.planetary_data.len() returns the length of that dataset. So you need to also load the pck11.pca file.

let ctx = Almanac::new("./almanac/de440s.bsp").expect("Could not load bsp");
let loaded_ctx = ctx.load("./almanac/moon_pa_de440_200625.bpc").expect("Could not load bpc").load("./almanac/pck11.pca").expect("failure pck");

println!("Planetary data length: {}", loaded_ctx.planetary_data.len());

That will print Planetary data length: 54.

The BPC file only contains the data to rotate from one frame to another. In the case of the Moon PA file, it allows the rotation between the 31008 frame ID and the inertial frame:

Image

(This is a screenshot from the ANISE GUI.)

@gregjesl
Copy link

gregjesl commented Dec 5, 2024

let ctx = Almanac::new("./almanac/de440s.bsp").expect("Could not load bsp");
let loaded_ctx = ctx.load("./almanac/moon_pa_de440_200625.bpc").expect("Could not load bpc").load("./almanac/pck11.pca").expect("failure pck");

That worked for me, thanks! In retrospect, I think I had two issues going on:

  • At first, I was loading all of the files but didn't realize that load returns the loaded instance (I was trying to use ctx instead of loaded_ctx later in the routine)
  • When I attempted to recreate it and stored loaded_ctx, I didn't load all the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants