AndrewAnnex / SpiceyPy

SpiceyPy: a Pythonic Wrapper for the SPICE Toolkit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spiceypy.ckgp throws NotFoundError even though all kernels are loaded

elastufka opened this issue · comments

Hi, I'm getting a NotFoundError that I can't figure out. From what I understand of the C documentation, if the ck/ files are all loaded for a given date, the attitude data should be able to be found. Yet spiceypy.ckgp is not able to find anything.

Here's the code:

sc='-144'
datestr='2021-08-23T12:00:00'
tolerance=100
system='HGRTN'

et=spiceypy.spiceypy.str2et(datestr)
sclkdp=spiceypy.spiceypy.sce2c(int(sc), et) #Ephemeris time, seconds past J2000.
cmat=spiceypy.spiceypy.ckgp(int(sc), sclkdp, tolerance, system)

I've checked both that the kernel files are present and that they are listed in the file that loads the kernels. Is there something I'm missing?

Anyway, thanks for any advice and for writing this package, 99% of the time it makes my life easier.

@elastufka can you provide links to the kernels you are using please?

Sure, it's here: https://repos.cosmos.esa.int/socci/projects/SPICE_KERNELS/repos/solar-orbiter/browse/kernels/ck

I just git-pulled the main repo today so it is all up to date on my local system.

@elastufka I'll take a look later today, please bear with me.

@elastufka, there were several issues with your piece of code. SpiceyPy was providing the adequate error message:

spiceypy.utils.exceptions.NotFoundError: Spice returns not found for function: ckgp

If you check the CSPICE documentation: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckgp_c.html
you will see the following exception:

  1. If ref is not a supported reference frame, an error is
    signaled by a routine in the call tree of this routine and
    found is set to SPICEFALSE.

And indeed, the frame that you provided is not a frame. I believe you meant the SOLO_SUN_RTN frame. You can see the science "dynamic" frames available here: https://repos.cosmos.esa.int/socci/projects/SPICE_KERNELS/repos/solar-orbiter/browse/kernels/fk/solo_ANC_soc-sci-fk_V07.tf

In addition, the ID that you provided for the inst argument was the ID for SOLO, as you can see in the SOLO FK: https://repos.cosmos.esa.int/socci/projects/SPICE_KERNELS/repos/solar-orbiter/browse/kernels/fk/solo_ANC_soc-sc-fk_V08.tf, you need to provide the S/C frame, that is -144000.

Finally you also needed to package the spiceypy result in a tuple of two elements.

Below the code snippet that will work:

   import spiceypy

   spiceypy.furnsh('solar-orbiter/kernels/mk/solo_ANC_soc-flown-mk_local.tm')

   sc='-144'
   datestr='2021-08-23T12:00:00'
   tolerance=100
   system='SOLO_SUN_RTN'
   sc_frame='-144000'
   et=spiceypy.str2et(datestr)
   sclkdp=spiceypy.sce2c(int(sc), et) #Ephemeris time, seconds past J2000.

   (cmat,clkout)=spiceypy.ckgp(int(sc_frame), sclkdp, tolerance, system)

   print(cmat)

Hope this helps. Please let me know if my suggestions do not work.

@marcsit Thanks, it works! I didn't know the spacecraft frame had a different ID, since I was translating sswidl's get_sunspice_roll and I must have missed the ID change in get_sunspice_cmat somehow.

@elastufka by the way, you should re-consider the value that you use for `tolerance' I suggest that you take a look at the CK Required reading: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/ck.html and/or take a look at the ckgp_c function header.

In addition please note that this routine might not be the best to use for the purpose of obtaining an orientation matrix, instead I would suggest you to use: pxform_c
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pxform_c.html