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
496 stars 63 forks source link

Calculating the parallactic angle of the moon #292

Closed sihil closed 1 year ago

sihil commented 1 year ago

Hi there,

I've been enjoying using astronomy engine so far (JS version in my case) so thanks for your work on this project.

I'd like to find out what the parallactic angle of the moon is from a given date and observation point on earth. I've done a fairly good hunt through the docs but haven't found anything that looks right. I suspect that I might be able to calculate it from other bits of data but would need to research that and only want to do so if you can confirm that it is in fact not in the library.

Thanks

cosinekitty commented 1 year ago

Hi @sihil and welcome to the project!

Usually people don't need to worry about parallax of the Moon because it is corrected by the Equator function.

I'm not sure what you are trying to do, but if you want to calculate the parallax angle directly, it is possible. My approach would be

I hope this helps. I'm not sure what your goal is, so please let me know if you could use some more information.

sihil commented 1 year ago

Thanks for the swift reply @cosinekitty!

I suspect that my terminology might be causing confusion here - the internet led me to believe that I should describe it as the parallactic angle (unrelated to parallax) but this might be wrong so let me describe it too.

I'm trying to draw an image of the moon with respect to the horizon. The moon's appearance to an observer varies depending on latitude and where the bodies are in their orbits. For example, phases appear to be opposite in the southern hemisphere and quarters don't appear to be "upright" but tend to be at an angle (see the image at https://www.space.com/18880-moon-phases.html). Without knowing much in this domain I imagine that this will change between moonrise and moonset (although I'm only looking for culminations) and also depending on the tilt of the earth (I reason that at a solstice, the culmination of a first or third quarter moon will appear to be at an angle of 23º or so?)

Does that make sense?

cosinekitty commented 1 year ago

OK, I had not heard the term parallactic angle before, so I misunderstood. I just looked it up and now I learned something new!

I'm trying to draw an image of the moon with respect to the horizon.

I have a Node.js demo program called camera.js that should be very close to what you are looking for. It calculates the angle of the sunlit side of the Moon relative to the observer's horizon.

Here is an example of running camera.js:

$ node camera 29 -81 2021-03-22T02:45:00Z
Moon horizontal position: azimuth = 274.486, altitude = 52.101
Moon check: x = 1.000000, y = 0.000000, z = 0.000000
Sun vector: x = -0.088530, y = -0.319392, z = -0.939663
Tilt angle of sunlit side of the Moon = -108.773 degrees counterclockwise from up.
Moon magnitude = -10.27, phase angle = 84.22 degrees.
Angle between Moon and Sun as seen from Earth = 95.64 degrees.
sihil commented 1 year ago

This is exactly what I'm trying to do!

I think I largely understand the conceptual idea here of following the sun to find out which side is illuminated - I will dig in and figure out the concepts.

Thanks very much for your pointers.

sihil commented 1 year ago

I've now got this working for drawing the illuminated shape of the moon as viewed from a position on earth. Thanks for your help here.

What I want to do next however is draw some of the surface features on each picture. The answer you gave above related to the direction the sun is from the moon rather than the parallactic angle of the moon itself so is perfect for the illuminated shape but not for the surface features. Much of the time they will be similar, although near full and new moons the illumination angle is often very different due to the bodies being almost aligned.

I suspect that the same principles apply here, possibly starting with getting the vector for the moon's axis and then going from there. Do you know if I can find that in Astronomy Engine somehow? A look through of the functions highlights Libration which gives an idea of which lats and longs I'd be able to see but not what angle they'd be effectively visible at.

cosinekitty commented 1 year ago

Congratulations on getting the illuminated shape working. That is cool!

Yes, the libration functions will help you figure out the amount of wobble in the near-facing side of the moon, in terms of latitude and longitude displacements. But first I recommend looking at the RotationAxis function, which gives you a vector from the body's center pointing toward its north pole.

The formulas for the Moon's rotation axis come from the bottom of page 8 in this IAU working group document that was published in 2009.

My recommendation would be to start with ignoring libration and focus on getting the orientation of the Moon's axis working. Then you can go back and use the longitude correction from the libration function. You won't need the latitude correction because it will already be implicit in the Moon's axis vector.

habibr commented 1 year ago

moon-wairarapa-new-zealand-

Hi, I am currently testing your module to draw the moon orientation in the sky. But, I haven't understood the "tilt angle" completely. So, I bring to you a recent photograph of the crescent moon from Wairarapa, New Zealand taken around sunset local time. I want to relate the tilt angle and the crescent photograph. So, I run node command with the following results:

node js/camera.js -41.17 175.5 2023-03-24T04:07:31.000Z Moon horizontal position: azimuth = 330.697, altitude = 29.627 Moon check: x = 1.000000, y = 0.000000, z = 0.000000 Sun vector: x = 0.844418, y = 0.529518, z = -0.011875 Tilt angle of sunlit side of the Moon = -1.285 degrees counterclockwise from up. Moon magnitude = -7.02, phase angle = 147.80 degrees. Angle between Moon and Sun as seen from Earth = 32.13 degrees.

Could you give me some explanation...

cosinekitty commented 1 year ago

Yes, something is wrong here. Based on your photograph, the tilt angle looks like about +120 degrees. Can you double-check that the date and time are correct for UTC? The reason I ask is that I checked sunset time for your location on the same date and I find:

$ node riseset -41.17 175.5 2023-03-24T00:00:00.000Z
search   : 2023-03-24T00:00:00.000Z
sunrise  : 2023-03-24T18:25:11.137Z
sunset   : 2023-03-24T06:24:09.646Z
moonrise : 2023-03-24T22:04:53.634Z
moonset  : 2023-03-24T07:39:35.556Z

It looks like your photograph was taken after sunset, but the time 04:07 is before sunset (06:24), not after.

Even still, when I provide a time after sunset, the values I calculate for the angle don't match up with your photograph, so I will have to study this some more.

sihil commented 1 year ago

I don't know if it's a useful data point but my experimental notes on the tilt in my code were:

// I think tilt is the direction the sunlight is coming from and is "clockwise from left"
// i.e. -11 is slightly down to the left
//      -156 is down to the right
//      170 is up to the right
//      30 is up to the left

On that basis I'd expect -25 or so. 🤔

It has somewhat wild values very close to new or full moons, which I've assumed is due to the sun being almost in a line with the moon and earth so the alignment becomes significant.

habibr commented 1 year ago

Thank you for replying my comment so promptly.

You're right about the sunset time, it was just my quick and rough guess.

I was a bit confused with the tilt angle that the program gives and the description in your camera.js. You said that the angle is counter-clockwise from up. So, if the angle is negative, then it goes clockwise, right?

Btw. I stumbled upon suncalc repo: https://github.com/mourner/suncalc and there they said about this moon tilt angle as: "By subtracting the parallacticAngle from the angle one can get the zenith angle of the moons bright limb (anticlockwise). The zenith angle can be used do draw the moon shape from the observers perspective (e.g. moon lying on its back)."

I did try to find the corresponding angles (i.e. parallactic angle and bright limb angle) in your Astronomy module, but has not found them.

cosinekitty commented 1 year ago

Here is a picture that shows how I intended the angles.

image

So the photograph by @habibr shows the Moon a little more counterclockwise than +90° but less than +180°.

I did try to find the corresponding angles (i.e. parallactic angle and bright limb angle) in your Astronomy module, but has not found them.

Astronomy Engine doesn't provide calculation of parallactic angles or bright limb angles. The camera.js demo is supposed to directly calculate the zenith angle as depicted in the above diagram, but clearly something is going wrong, and I'm not yet sure what it is. I will investigate over the next few days and reply back here when I figure it out.

habibr commented 1 year ago

Here is another crescent moon photo that may help you clarifying this issue. This time from northern hemisphere: Calgary, Alberta, Canada on the evening of 23-03-2023 local time.

The camera.js command gave the following data: node js/camera.js 51.05 -114.07 2023-03-24T02:07:31.000Z Moon horizontal position: azimuth = 260.269, altitude = 23.466 Moon check: x = 1.000000, y = 0.000000, z = 0.000000 Sun vector: x = 0.860507, y = -0.263445, z = -0.428589 Tilt angle of sunlit side of the Moon = -121.578 degrees counterclockwise from up. Moon magnitude = -6.94, phase angle = 148.85 degrees. Angle between Moon and Sun as seen from Earth = 31.08 degrees. moon-20230323-Calgary-Alberta-Canada

cosinekitty commented 1 year ago

Good news: I was able to find and fix the bug in the camera demos (C, C#, Node, and Python). I have pushed the changes to the repo. The problem was simple: I had the arguments for atan2 backwards, so I was actually calculating the angle clockwise from the horizontal ray pointing to the right, not counterclockwise from the vertical like I intended.

Your data and photographs were helpful. Combined with my own first-hand observation tonight from Florida, I now have 3 different tests in my automated test suite. So now I get the following:

$ node camera -41.17 175.5 2023-03-24T06:30:00Z
Moon horizontal position: azimuth = 300.698, altitude = 10.854
Moon check: x = 1.000000, y = 0.000000, z = 0.000000
Sun vector: x = 0.835771, y = 0.507283, z = -0.194463
Tilt angle of sunlit side of the Moon = 110.974 degrees counterclockwise from up.
Moon magnitude = -7.12, phase angle = 146.54 degrees.
Angle between Moon and Sun as seen from Earth = 33.38 degrees.

$ node camera 51.05 -114.07 2023-03-24T02:07:31.000Z
Moon horizontal position: azimuth = 260.269, altitude = 23.466
Moon check: x = 1.000000, y = 0.000000, z = 0.000000
Sun vector: x = 0.860507, y = -0.263445, z = -0.428589
Tilt angle of sunlit side of the Moon = -148.422 degrees counterclockwise from up.
Moon magnitude = -6.94, phase angle = 148.85 degrees.
Angle between Moon and Sun as seen from Earth = 31.08 degrees.

I think you will agree that these numbers match up with the photographs.

My mistake here is somehow I didn't verify my tests for the camera demo were correct. Now that I have 3 tests that I verified with real world evidence, I think they are correct. I also reviewed all the algorithms to make sure they still make sense, and the only thing I saw were the backwards arguments for atan2.

Thank you so much for taking the time to report this issue and to provide good numbers and photographs. The moon photographs are also beautiful, by the way!

habibr commented 1 year ago

That's great.

I think you got it. I have tested with "waning crescent moon" too.

cosinekitty commented 1 year ago

That's great news. Thanks again for bringing the issue to my attention. I updated the documentation on the demo pages to explain the camera program and to include the above diagram explaining the tilt angle orientation.