4

I'm trying to get the Earth distance and the right ascension (relative to my observer point in Earth) of a satellite not orbiting the Earth, but pyEphem isn't returning the same properties as other solar bodies.

With Ganymede (the largest moon of Jupiter), for instance:

import math, ephem

Observer = ephem.city('London')
Observer.date = '2013-04-23'
Observer.pressure, Observer.elevation = 0, 100

moonGanymede = ephem.Ganymede(Observer)

print math.cos(moonGanymede.ra) # right ascension
print moonGanymede.earth_distance * ephem.meters_per_au # distance

I get this error:

AttributeError: 'Ganymede' object has no attribute 'earth_distance'

The ra attribute exists, but is it relative to my Observer or to Jupiter?

Seems to be relative to the Observer, since if I change the location, the value changes too.

I've read the documentation and I know that these properties are not defined for moons, but I have no idea how to compute those relative to the Earth given the additional defined properties of moon bodies:

On planetary moons, also sets:

Position of moon relative to planet (measured in planet radii)

x — offset +east or –west
y — offset +south or –north
z — offset +front or –behind

Doing:

print moonGanymede.x, moonGanymede.y, moonGanymede.z

Outputs:

-14.8928060532 1.52614057064 -0.37974858284

Since Jupiter has an average radius of 69173 kilometers, those values translate to:

moonGanymede.x = 1030200 kilometers (west)
moonGanymede.y = 105570 kilometers (south)
moonGanymede.z = 26268 kilometers (behind)

Given that I know the distance and right ascension of Jupiter relative to the Observer, how can I calculate the distance and right ascension of moonGanymede (also relative to the Observer)?

I'm using pyEphem 3.7.5.1 (with Python 2.7).

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
  • 1
    From what I've seen, there is no easy way to get Cartesian coordinates from pyephem. Have you considered using NOVAS - http://aa.usno.navy.mil/software/novas/novas_py/novaspy_intro.php? – mattc May 18 '13 at 14:57
  • @mattc: I haven't, no. To be honest it took me a while to get used to pyEphem and I'd rather stay with it than messing around with yet another package (I'm sure NOVAS has its quirks too). I've just realized that WolframAlpha can help me corroborate my results (see http://www.wolframalpha.com/input/?i=Ganymede+position+from+London+on+2013-04-23 and http://www.wolframalpha.com/input/?i=Ganymede+distance+from+London) so I guess I'll try to figure out the math by myself tonight or something - but thanks for the suggestion, always good to know. =) – Alix Axel May 18 '13 at 15:25

3 Answers3

1

Just some thoughts; You probably need to do it two steps.

  1. Get location of satellite relative to parent planet
  2. Get location of planet relative to observer
  3. Trigonometry calculation; get the location of satellite relative to observer.

You already did 1, and can easily do 2. Convert all values to x,y,z and add then back to angular. Or I'm sure you / ephym can do this for you directly.

HTH

Ayman
  • 11,265
  • 16
  • 66
  • 92
  • Thanks, that was the general path I was aiming for. Like I said, I already did #2, but I only have right ascension and declination of Jupiter. My problem is exactly with #3, I'm not sure how to work the math around it (and even if I do come up with something, I won't be sure if the results are the correct ones). AFAIK, pyEphem also doesn't seem to provide any methods to convert between the cartesian and the equatorial coordinate systems (see http://rhodesmill.org/pyephem/coordinates). – Alix Axel May 15 '13 at 15:12
0

Looks like right ascension, declination, azimuth, etc are computed correctly:

In [31]: g = ephem.Ganymede(Observer)

In [32]: j = ephem.Jupiter(Observer)

In [33]: g.ra, g.az, g.dec
Out[33]: (1.3024204969406128, 5.586287021636963, 0.38997682929039)

In [34]: j.ra, j.az, j.dec
Out[34]: (1.303646765055829, 5.5853118896484375, 0.39010250333236757)

Values for Ganimede and Jupiter are close enough, it looks like you get correct results for everything except distance to object.

mac13k
  • 2,423
  • 23
  • 34
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
  • Indeed, but I really need the distance as well. I started reading about it yesterday, perhaps I'll be able to come up with a solution today. – Alix Axel May 19 '13 at 12:14
  • Yep, looks like range is only computed for man-made bodies... I guess this asks for improvement, implement and submit a patch :) – Dima Tisnek May 19 '13 at 12:47
0

I'm still trying to figure it out (if anyone spots something, please do tell), but it seems that if I do:

sqrt((-14.8928060532)^2 + (1.52614057064)^2 + (-0.37974858284)^2) = 14.9756130481

I'll always get a value that always falls within the min/max distance from orbit center (14.95 - 14.99).

Since that's specified in orbit center radii, I'll need to multiply it by 69173 * 1000 to get the SI unit:

14.9756130481 * 69173 * 1000 = 1.0359080813762213 * 10^9 meters

Since pyEphem deals in distances with AU:

print (1.0359080813762213 * 10**9) / ephem.meters_per_au # 0.00692461785302

At the same time, the Earth-Jupiter distance was 5.79160547256 AU.

Now, to get the distance, I should either add or subtract depending on the sign of the z coordinate:

5.79160547256 - 0.00692461785302 = 5.78468085470698 AU

Running the same code for today (now) returns 6.03799937821 which seems to very close to the value of 6.031 that WolframAlpha is returning at the present time, it doesn't match 100% but perhaps that could be accounted for by some different underlying ephemeris library or data source. Not sure...

Alix Axel
  • 151,645
  • 95
  • 393
  • 500