<p>The issue appears to be in your understanding of the <code>separation</code> function. You state that</p>

<blockquote>
  <p>it calculates the separation (angle) between those 2 planets with respect to their "x" projection in a plane.</p>
</blockquote>

<p>however, <a href="https://rhodesmill.org/pyephem/tutorial.html" rel="nofollow noreferrer">the documentation states</a></p>

<blockquote>
  <p>The <code>separation()</code> function computes the angle in degrees between two bodies, <strong>as measured by their right ascension and declination.</strong> <br/><br/>In general <code>separation()</code> <strong>can measure the angle between any pair of spherical coordinates</strong>, so long as the elements of each coordinate are spherical longitude (angle around the sphere) followed by spherical latitude (angle above or below its equator). Each pair should be provided as a two-item sequence like a tuple or list. Appropriate coordinate pairs include right ascension and declination; heliocentric longitude and latitude; azimuth and altitude; and even the geographic longitude and latitude of two locations on earth.</p>
</blockquote>

<p>This means that this function is calculating the angular separation between the two objects, not just the separation in a particular plane. If you want to perform the same calculation (as the documentation says they're performing), it looks like you actually want the general <a href="https://en.wikipedia.org/wiki/Angular_distance#Equation" rel="nofollow noreferrer">angular distance formula</a>.</p>

<p><span class="math-container">$$\theta = \cos^{-1}\left[\sin(\delta_1)sin(\delta_2)+\cos(\delta_1)\cos(\delta_2)\cos(\alpha_1-\alpha_2)\right]$$</span></p>

<p>where <span class="math-container">$\delta\in[-\pi/2,\pi/2]$</span> is the declination, and <span class="math-container">$\alpha\in[0,2\pi]$</span> is the Right Ascension.</p>

CC BY-SA 4.0
2018-10-29T23:13:24.270Z
thank you, this is a great clarification. Indeed, my knowledge was not right
Luis Miguel
CC BY-SA 4.0
2018-10-29T20:35:36.363Z
2018-10-29T20:35:36.363Z
zephyr
<p>I am experimenting with the Python library PyEphem for astronomy, and I am trying to recreate/understand some of the basic calculations there.</p>

<p>There is a function called separation that, given two planets and a date/time, it calculates the separation (angle) between those 2 planets with respect to their "x" projection in a plane.</p>

<p>So for 2018/1/1 for planets Mercury and Mars, we have:</p>

<pre><code>import ephem
import math

mercury = ephem.Mercury('2018/1/1')
mars = ephem.Mars('2018/1/1')

s1 = ephem.separation(mercury, mars)
print(math.degrees(s1))
</code></pre>

<p>Which returns</p>

<pre><code>33.792384499568264
</code></pre>

<p>But if I wanted to calculate this without the separation function, then I think that the calculation would be as simple as the "right ascension" of 1 minus the "right ascension" of the other:</p>

<pre><code>math.degrees(mercury.ra) - math.degrees(mars.ra)
</code></pre>

<p>Which returns</p>

<pre><code>35.114532008671574
</code></pre>

<p>Why are the angles different? Since I am not including a latitude and longitude of the observer, all the calculations are supposed to be geo-centric, according to PyEphem.</p>

<p>Is anybody familiar with the calculations going on behind PyEphem, or another library with built-in ephemeris that can produce consistent results for separation?</p>

<python><ephemeris><right-ascension>
Calculating right ascension for two planets and their separation using python
Luis Miguel
# Calculating right ascension for two planets and their separation using python

(Asked by: username_0 on 2018-10-29)

I am experimenting with the Python library PyEphem for astronomy, and I am trying to recreate/understand some of the basic calculations there.
There is a function called separation that, given two planets and a date/time, it calculates the separation (angle) between those 2 planets with respect to their "x" projection in a plane.
So for 2018/1/1 for planets Mercury and Mars, we have:
import ephem
import math

mercury = ephem.Mercury('2018/1/1')
mars = ephem.Mars('2018/1/1')

s1 = ephem.separation(mercury, mars)
print(math.degrees(s1))

Which returns
33.792384499568264

But if I wanted to calculate this without the separation function, then I think that the calculation would be as simple as the "right ascension" of 1 minus the "right ascension" of the other:
math.degrees(mercury.ra) - math.degrees(mars.ra)

Which returns
35.114532008671574

Why are the angles different? Since I am not including a latitude and longitude of the observer, all the calculations are supposed to be geo-centric, according to PyEphem.
Is anybody familiar with the calculations going on behind PyEphem, or another library with built-in ephemeris that can produce consistent results for separation?

**Tags:** python, ephemeris, right-ascension


---

## 1 answers

### Answer by username_1 on 2018-10-29. Score: 2 | Accepted answer

The issue appears to be in your understanding of the `separation` function. You state that

> it calculates the separation (angle) between those 2 planets with respect to their "x" projection in a plane.

however, [the documentation states](https://rhodesmill.org/pyephem/tutorial.html)

> The `separation()` function computes the angle in degrees between two bodies, **as measured by their right ascension and declination.**   
>   
> In general `separation()` **can measure the angle between any pair of spherical coordinates**, so long as the elements of each coordinate are spherical longitude (angle around the sphere) followed by spherical latitude (angle above or below its equator). Each pair should be provided as a two-item sequence like a tuple or list. Appropriate coordinate pairs include right ascension and declination; heliocentric longitude and latitude; azimuth and altitude; and even the geographic longitude and latitude of two locations on earth.

This means that this function is calculating the angular separation between the two objects, not just the separation in a particular plane. If you want to perform the same calculation (as the documentation says they're performing), it looks like you actually want the general [angular distance formula](https://en.wikipedia.org/wiki/Angular_distance#Equation).

$$\theta = \cos^{-1}\left[\sin(\delta\_1)sin(\delta\_2)+\cos(\delta\_1)\cos(\delta\_2)\cos(\alpha\_1-\alpha\_2)\right]$$

where $\delta\in[-\pi/2,\pi/2]$ is the declination, and $\alpha\in[0,2\pi]$ is the Right Ascension.

> **Comments:**
> **username_0**: thank you, this is a great clarification. Indeed, my knowledge was not right  

---

