skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.43k stars 213 forks source link

Opposition and Conjunction showing opposite results for `moon` #315

Closed skynoob-new closed 4 years ago

skynoob-new commented 4 years ago

Opposition and Conjunction using the code in the below link for moon giving opposite results [https://rhodesmill.org/skyfield/almanac.html#opposition-and-conjunction] Below is the output for the year 2019 where the opposition are shown as conjunction and vice versa.

['2019-01-06T01:28:11Z', '2019-01-21T05:16:05Z', '2019-02-04T21:03:35Z', '2019-02-19T15:53:35Z', '2019-03-06T16:04:00Z', '2019-03-21T01:42:53Z', '2019-04-05T08:50:30Z', '2019-04-19T11:12:11Z', '2019-05-04T22:45:31Z', '2019-05-18T21:11:22Z', '2019-06-03T10:01:57Z', '2019-06-17T08:30:40Z', '2019-07-02T19:16:13Z', '2019-07-16T21:38:13Z', '2019-08-01T03:11:56Z', '2019-08-15T12:29:16Z', '2019-08-30T10:37:10Z', '2019-09-14T04:32:48Z', '2019-09-28T18:26:23Z', '2019-10-13T21:07:54Z', '2019-10-28T03:38:29Z', '2019-11-12T13:34:25Z', '2019-11-26T15:05:36Z', '2019-12-12T05:12:16Z', '2019-12-26T05:13:08Z'] [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1] ['opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition', 'conjunction', 'opposition'] Wherever it is showing opposition the SUN and MOON were in conjunction on those dates and vice versa. Is this a bug in skyfield

brandon-rhodes commented 4 years ago

This is an interesting case! The Moon travels the sky in the opposite direction from the other planets; while the outer planets travel overall towards the west across the stars, the Moon goes east, so when it enters state 0 or state 1 it is doing it at the other end of the sky from the major planets.

And also the conjunction / opposition distinction will not hold for inner planets Venus and Mercury. For them, both 0 and 1 will be conjunctions, but traveling in different directions.

I'll update the docs to describe all of those cases!

brandon-rhodes commented 4 years ago

Okay, having looked at the various cases, I think this description covers everything, at least for the planets. Could you read over this? If you find it makes sense, I'll add it to the docs!

The result ``t`` will be an array of times, and ``y`` will be an array
of integers indicating which half of the sky the body has just entered:
0 means the half of the sky west of the Sun along the ecliptic, and 1
means the half of the sky east of the Sun.  This means different things
for different bodies:

* For the outer planets Mars, Jupiter, Saturn, Uranus, and all other
  bodies out beyond our orbit, 0 means the moment of conjunction with
  the Sun and 1 means the moment of opposition.

* Because the Moon moves eastward across our sky relative to the Sun,
  not westward, the output is reversed compared to the outer planets: 0
  means the moment of opposition or Full Moon, while 1 means the moment
  of conjunction or New Moon.

* The inner planets Mercury and Venus only ever experience conjunctions
  with the Sun from our point of view, never oppositions, with 0
  indicating an inferior conjunction and 1 a superior conjunction.
skynoob-new commented 4 years ago

Makes sense, but * Because the Moon moves eastward across our sky relative to the Sun, not westward, the output is reversed compared to the outer planets: 0 means the moment of opposition or Full Moon, while 1 means the moment of conjunction or New Moon.

the above point is not correct with respect to the current output? i mean, current output shows 1 for opposition and 0 for conjunction

brandon-rhodes commented 4 years ago

I should have pasted in the code above the new text — it now looks like:

.. testcode::

    t0 = ts.utc(2019, 1, 1)
    t1 = ts.utc(2021, 1, 1)
    f = almanac.oppositions_conjunctions(e, e['mars'])
    t, y = almanac.find_discrete(t0, t1, f)

    print(t.utc_iso())
    print(y)

.. testoutput::

    ['2019-09-02T10:42:14Z', '2020-10-13T23:25:47Z']
    [0 1]

I took out the idea of a dictionary entirely, since no single dictionary can cover all the cases accurately.

skynoob-new commented 4 years ago

sorry, i dont get it. Moon still shows the same thing right?

brandon-rhodes commented 4 years ago

Yes, the Moon will still show the same thing as in your example, because the definition of the function is not changing — it still measures east-or-west-of-the-sun. But the documentation is now being clear what happens if you give it the Moon which, because it's not a planet and doesn't move across the sky like one, enters the east and west halves of the sky in the opposite order from how a planet does.

skynoob-new commented 4 years ago

Thank you. Yes, your explanation looks apt. Thanks for your time