cosinekitty / astronomy

Astronomy Engine: multi-language calculation of Sun, Moon, and planet positions. Predicts lunar phases, eclipses, transits, oppositions, conjunctions, equinoxes, solstices, rise/set times, and other events. Provides vector and angular coordinate transforms among equatorial, ecliptic, horizontal, and galactic orientations.
MIT License
492 stars 63 forks source link

demo/c/riseset: are moon{rise,set} really in UTC? #60

Closed larryhynes closed 4 years ago

larryhynes commented 4 years ago

Hi

Thanks for all the work on this. :)

I have a minor issue - following is the output of riseset (from ../demo/c/) for (roughly) my location:

<master> ~/astronomy/demo/c $ ./riseset 53.26 -8.79
search   : 2020-04-13 15:01:04 UTC
sunrise  : 2020-04-14 05:37:20 UTC
sunset   : 2020-04-13 19:32:44 UTC
moonrise : 2020-04-14 02:33:48 UTC
moonset  : 2020-04-14 09:59:51 UTC

Values for sunrise and sunset are in UTC. But other tools that I'm testing (mooncalc.org online and solunar's cli) are giving 02:33 as the value for moonrise in my local TZ (Irish Summer Time i.e. UTC +1 due to Daylight Saving Time). So something seems off somewhere, I just don't know where! (The value for moonset is "off" by approximately an hour also.)

tool moonrise moonset
riseset (UTC +1) 02:33 09:59
mooncalc (UTC +1) 02:34 10:04
solunar (UTC) 02:33 10:05

mooncalc and solunar are both adjusting for DST - solunar has a "use UTC" flag, and returns 01:33 with that on.

So I'm wondering how riseset's values for sunrise and sunset would be in UTC, but moonrise and moonset appear to be in UTC +1! (I'm digging around in it here, but thought I would pen this note anyway.)

cosinekitty commented 4 years ago

Hi Larry! Thanks for reaching out. I'm excited there is somebody trying out Astronomy Engine.

I think I see what's happening. I decided to consult yet another tool. Take a look at this, using the same coordinates you gave me:

https://www.timeanddate.com/moon/@53.26,-8.79

For today's calendar date, April 13, it lists moonrise at 02:34 and moonset at 10:04, both expressed in your current local time, UTC+01. I believe the other tools start their search at 00:00 (midnight). However, by default riseset starts its search at the computer's current date and time. Both moonrise and moonset for April 13 are already in the past, so it's finding both for April 14. Both moonrise and moonset happen about 1 hour later on the subsequent day.

You can provide an optional date and time value to riseset to start its search, to get compatible results. For example:

don@spearmint:~/github/astronomy/demo/c $ ./riseset 53.26 -8.79 2020-04-13T00:00:00Z
search   : 2020-04-13 00:00:00 UTC
sunrise  : 2020-04-13 05:39:37 UTC
sunset   : 2020-04-13 19:32:44 UTC
moonrise : 2020-04-13 01:34:37 UTC
moonset  : 2020-04-13 09:04:10 UTC
larryhynes commented 4 years ago

Ah! Of course - it's right there in front of me! duh :)

Thanks a million.

cosinekitty commented 4 years ago

Glad I could help. Don't feel bad. You had me worried for about 15 minutes before I spotted it. What really threw me off was how close the change of moonrise time over 1 day was to 60 minutes in this case. That's not typical. On average it is 50 minutes per day. The moon's orbit is an insane beast: it's by far the most complicated thing Astronomy Engine has to calculate.

larryhynes commented 4 years ago

Yes, I think the 60 minutes is what set me on such a "it must be out, it simple must!" path. :) I'm currently replacing gnu's gcal with a much smaller lighter calendar programme, but I missed gcal's astro functions and started looking at how I might replace them; at one stage yesterday I had 4 tools, each giving different results and it was driving me nuts, but it also gave me a small insight into just how difficult this stuff is to pin down. (And a large insight into my own utter lack of meaningful precision of any kind, lol.) Thanks for sorting it out... using Astronomy Engine I was finally able to get a benchmark value that I was happy with.

cosinekitty commented 4 years ago

I would be interested to see what you come up with. If you think Astronomy Engine would be a good fit, it would be helpful to know if there is any useful functionality it lacks. I would love for people to start using this in real projects.

A note about rise/set times: this is one area where different tools calculate different times, sometimes more than a minute away from each other. The reason is atmospheric refraction depends on a lot of variables that can't be predicted: temperature, pressure, and humidity among them. And not just at the observer's altitude, but at every layer of the atmosphere that the light rays have to pass through, all the way from the upper stratosphere to the ground. So there is no single "correct" answer for a rise/set time that can be predicted in advance. Different calculators out there use different models for atmospheric refraction. Mine uses the same formula as the JPL Horizons online calculator.

larryhynes commented 2 years ago

So - just a note to say that I eventually did hack something together, in C, which meets my needs. In short:

~ $ astron
System time: Sun 17 Apr 2022 13:50:19 IST
Sunrise: 2022-04-18 05:29 UTC
Sunset: 2022-04-17 19:39 UTC
Moon phase angle: 190 degrees
Last quarter: 2022-04-23 11:56 UTC
New moon: 2022-04-30 20:28 UTC
First quarter: 2022-05-09 00:22 UTC
Full moon: 2022-05-16 04:14 UTC

~ $ astron -s
System time: Sun 17 Apr 2022 13:50:23 IST
Sunrise: 2022-04-18 05:29 UTC
Sunset: 2022-04-17 19:39 UTC
Moon phase angle: 190 degrees
Last quarter: 2022-04-23 11:56 UTC
New moon: 2022-04-30 20:28 UTC
First quarter: 2022-05-09 00:22 UTC
Full moon: 2022-05-16 04:14 UTC
Vernal equinox: 2022-03-20 15:33 UTC
Summer solstice: 2022-06-21 09:13 UTC
Autumnal equinox: 2022-09-23 01:04 UTC
Winter solstice: 2022-12-21 21:47 UTC

The code is appalling. If I ever clean it up and put it somewhere, I'll let you know but do not hold your breath - it's doing the job and that's what matters right now.

Thanks again for your work on this.