helgee / JPLEphemeris.jl

JPL ephemerides for Julia
https://juliaastrodynamics.github.io/
Other
40 stars 12 forks source link

Function to get right ascension, decline, and distance? #20

Closed jakewilliami closed 4 years ago

jakewilliami commented 4 years ago

Is there functionality (possibly using AstroLib) to get the right ascension, decline, and distance of a planet with respect to earth?

helgee commented 4 years ago

There is no one-stop solution AFAIK but you should be able to piece something together with the tools provided by the ecosystem.

What coordinate frame do you want to use? Topocentric, i.e. RA and declination of the planets for some place on Earth? Or w.r.t. to the ecliptic or equatorial plane?

jakewilliami commented 4 years ago

The former I believe (Topocentric). To be honest, my knowledge of this is limited. I am trying to recreate a Python script I made a while back:

from skyfield.api import load
import datetime

planets = load('de421.bsp')
earth, mercury = planets['earth'], planets['mercury']
ts = load.timescale()

ra, dec, distance = earth.at(ts.now()).observe(mercury)astrometric1.radec()

return ra

I'm just not exactly sure how to go about this using Julia.

bgodard commented 4 years ago

What you are showing here is not topocentric: topocentric means azimuth, elevation (above local horizon) for an observer. If you want RA, DEC from the center of the Earth, you just get the vector:

position(spk, myplanet, jd) - position(spk, "earth", jd)

and convert it to spherical coordinates: r [ cos(ra) cos(dec) , sin(ra) * cos(dec), sin(dec) ]

But depending on your application you may also want to correct for light time, stellar aberration.

jakewilliami commented 4 years ago

Ah, I didn't know this. Thank you @bgodard. I have tried using position with this code

julia> using AstroLib, JPLEphemeris, Dates

julia> spk = SPK("de430.bsp")
SPK(DE-0430LE-0430)

julia> t1 = Dates.datetime2julian.(Dates.now())
2.4590243628225345e6

but I get the error

julia> position(spk, "earth", t1)
ERROR: MethodError: no method matching position(::SPK, ::String, ::Float64)
Closest candidates are:
  position(::AstroBase.Ephemerides.AbstractEphemeris, ::AstroTime.Epochs.Epoch, ::CelestialBody; kwargs...) at /Users/jakeireland/.julia/packages/AstroBase/LxXo1/src/Ephemerides/abstract.jl:84
  position(::AstroBase.Ephemerides.AbstractEphemeris, ::AstroTime.Epochs.Epoch, ::CelestialBody, ::CelestialBody; kwargs...) at /Users/jakeireland/.julia/packages/AstroBase/LxXo1/src/Ephemerides/abstract.jl:76
Stacktrace:
 [1] top-level scope at REPL[7]:1
helgee commented 4 years ago

The package is in bad shape right now. You might want to try CALCEPH.jl instead.

jakewilliami commented 4 years ago

Thanks for the suggestion @helgee! So it looks like I can just use (going off @bgodard's help)

compute(eph, jd1, jd2, naifId.id[:mercury], naifId.id[:earth])

to get the same result...right?

bgodard commented 4 years ago
compute(eph, jd1, jd2, naifId.id[:mercury], naifId.id[:earth], useNaifId+unitKM+unitSec,0)

You need to specify useNaifId and units. The 0 at the end is to get position only.

Note that ephemerides are generally given in ICRF reference axes which is the usual celestial reference for RA, DEC, but it may depend slightly on the application and depending on what your accuracy is you may care or not. If you tell us what is your application for, we can let you know if you need to apply other corrections.

jakewilliami commented 4 years ago

@bgodard I thought the last two parameters were optional? Either way, I don't think mercury is supported here:

CALCEPH ERROR : Target object 199 is not supported.
ERROR: LoadError: CALCEPHException("Unable to compute ephemeris")
bgodard commented 4 years ago

Last two parameters are optional but without them:

The bodies which are supported depends on the ephemerides file you load. I do not know which ephemerides file you are using but most planetary ephemerides usually contain only Earth, Moon, Sun and the barycenter of the planet-moons systems: For most purpose the barycenter of the planet-moons is close enough to the planet. Because Mercury has no Moons its barycenter is identical.

So you might want to use identifier 1 or naifId.id[:mercury_barycenter].

jakewilliami commented 4 years ago

Oh, I see. Do you know if CALCEPH supports reading de430.bsp (as JPLEphemeris does)? The ephemerides file which I am loading is inpop13c_TDB_m100_p100_tt.dat, which is the one on their README.

helgee commented 4 years ago

Do you know if CALCEPH supports reading de430.bsp (as JPLEphemeris does)?

It does 👍

bgodard commented 4 years ago

de430.bsp should work fine but I expect it has the same bodies as INPOP13C.

jakewilliami commented 4 years ago

Okay, thank you both very much. I am sorry for my ignorance regarding all of this. The current state of the conversation is far from the original "issue", so I suspect this should be closed. However...I am still having issues. Is one of you available for email communication while I get this working correctly? Or perhaps there is a different, more appropriate place to ask these questions?

helgee commented 4 years ago

There is an astronomy channel on the Julia Slack where you can ask quick questions or you could start a thread on the Julia Discourse for more in-depth questions (https://discourse.julialang.org/c/domain/astro/32).

jakewilliami commented 4 years ago

Excellent, thank you both so much!