{"id":41167,"date":"2018-10-10T03:01:48","date_gmt":"2018-10-09T17:01:48","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=41167"},"modified":"2018-10-09T20:54:06","modified_gmt":"2018-10-09T10:54:06","slug":"phpjavascripthtml-and-python-pyephem-moon-angle-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-and-python-pyephem-moon-angle-tutorial\/","title":{"rendered":"PHP\/Javascript\/HTML and Python PyEphem Moon Angle Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP\/Javascript\/HTML and Python PyEphem Moon Angle Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/MoonAnglePython.jpg\" title=\"PHP\/Javascript\/HTML and Python PyEphem Moon Angle Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript\/HTML and Python PyEphem Moon Angle Tutorial<\/p><\/div>\n<p>A long time ago now we presented <a title='PHP\/Javascript\/HTML Moon Angle Tutorial' href='#phpjhtmlmat'>PHP\/Javascript\/HTML Moon Angle Tutorial<\/a> but now we feel is a good time for it to get a makeover.  Why is that?  Well, we have the relatively new discovery of the very useful Python <a target=_blank title='PyEphem ... thanks' href='\/\/rhodesmill.org\/pyephem\/'>PyEphem<\/a> module to thank for that.<\/p>\n<p>As far as the new version goes we now offer a Moon Angle &#8220;time of transit (and relative to now)&#8221; calculation, which we think will be of more use to users.<\/p>\n<p>The Moon Angle at Transit calculations again involve the <a target=_blank title='Sublunary Point' href='http:\/\/translate.google.com.au\/translate?hl=en&#038;sl=de&#038;u=http:\/\/de.wikipedia.org\/wiki\/Sublunarer_Punkt&#038;prev=\/search%3Fq%3D%2522Sublunarer%2522%2Bwikipedia%26client%3Dfirefox-a%26hs%3D3co%26rls%3Dorg.mozilla:en-US:official%26biw%3D1213%26bih%3D619'>Sublunary Point<\/a> as the position on Earth directly above which is Moon is located.  Add in the Python PyEphem work and some more terminology that may interest you could involve &#8230;<\/p>\n<ul>\n<li><a target=_blank title='Sidereal time information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Sidereal_time'>sidereal time<\/a><\/li>\n<li><a target=_blank title='UTC information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Coordinated_Universal_Time'>Coordinated Universal Time &#8230; or UTC<\/a><\/li>\n<li><a target=_blank title='Transit information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Transit_(astronomy)'>transit<\/a><\/li>\n<\/ul>\n<p> &#8230; within the Python of interest, a snapshot of which is shown below, but which changes each time somebody recreates this <a target=_blank title='sublunarx.py' href='http:\/\/www.rjmprogramming.com.au\/Python\/sublunarx.py'>sublunarx.py<\/a> &#8230;<\/p>\n<p><code><br \/>\nimport ephem<br \/>\nimport math<br \/>\nimport time<br \/>\nfrom datetime import datetime, timedelta<br \/>\ngreenwich = ephem.Observer()<br \/>\ngreenwich.lat = \"0\"<br \/>\ngreenwich.lon = \"0\"<br \/>\ngreenwich.date = datetime.utcnow()<br \/>\nmoon = ephem.Moon(greenwich)<br \/>\nmoon.compute(greenwich.date)<br \/>\nmoon_lon = math.degrees(moon.ra - greenwich.sidereal_time() )<br \/>\nif moon_lon &lt; -180.0 :<br \/>\n  moon_lon = 360.0 + moon_lon<br \/>\nelif moon_lon &gt; 180.0 :<br \/>\n  moon_lon = moon_lon - 360.0<br \/>\nmoon_lat = math.degrees(moon.dec)<br \/>\nd1 = ephem.next_full_moon(greenwich.date)<br \/>\nd2 = ephem.next_new_moon(greenwich.date)<br \/>\ngreenwich.lat = \"151:10.586502000000001\"<br \/>\ngreenwich.lon = \"-33:54.445878\"<br \/>\ngreenwich.date = datetime.utcnow()<br \/>\nmoon = ephem.Moon(greenwich)<br \/>\nmoon.compute(greenwich.date)<br \/>\nbetw = (greenwich.next_transit(moon) - greenwich.date) * 86400.0 \/ 60.0 \/ 60.0<br \/>\ngnt = greenwich.next_transit(moon)<br \/>\ngreenwich.date = gnt<br \/>\nmoon = ephem.Moon(greenwich)<br \/>\nmoon.compute(gnt)<br \/>\nmoon_lon_x = math.degrees(moon.ra - greenwich.sidereal_time() )<br \/>\nif moon_lon_x &lt; -180.0 :<br \/>\n  moon_lon_x = 360.0 + moon_lon_x<br \/>\nelif moon_lon_x &gt; 180.0 :<br \/>\n  moon_lon_x = moon_lon_x - 360.0<br \/>\nmoon_lat_y = math.degrees(moon.dec)<br \/>\nprint('%s %s %s %s %s %s %s %f' % (moon_lon, moon_lat, d1, d2, gnt, moon_lon_x, moon_lat_y, betw))<br \/>\nquit()<br \/>\n<\/code><\/p>\n<p>The Moon Angle web application <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php\" title=\"Click picture\">live run<\/a>, which we welcome you to try, has the underlying PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php------GETME\" itle=\"moon_angle_now_at.php\">moon_angle_now_at.php<\/a> that supervises the Python exemplied above, and which featured <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php------GETME\" itle=\"moon_angle_now_at.php\">these changes<\/a> to make this happen.<\/p>\n<hr>\n<p id='phpjhtmlmat'>Previous relevant <a target=_blank title='PHP\/Javascript\/HTML Moon Angle Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php\/javascript\/html-moon-angle-tutorial\/'>PHP\/Javascript\/HTML Moon Angle Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP\/Javascript\/HTML Moon Angle Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/MoonAngle.jpg\" title=\"PHP\/Javascript\/HTML Moon Angle Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript\/HTML Moon Angle Tutorial<\/p><\/div>\n<p>Here is a tutorial that calculates Noon Moon Angles from Earth via the entry of Latitude and Longitude.  The calculation of noon moon angles uses the concept of Sublunary Point, which is explained in the quote from Wikipedia below.<\/p>\n<blockquote><p>The sublunary point (Latin sub-lunar, under the moon &#8216;, from Latin) is the one place on earth where the moon in exactly the zenith is. He is the point where the line connecting the centers of the Earth and Moon intersects the Earth&#8217;s surface. The point is a common auxiliary point to observe the Moon in the celestial mechanics and astronomical phenomenology , and in particular the theory of the tides , as well as the theory of eclipses .<\/p>\n<p>The calculation of the point corresponding to the determination of the geocentric coordinates of the Moon, it has the same longitude and latitude , as the moon astronomical length and width has &#8211; both are denoted by \u03c6 and \u03b2. <\/p><\/blockquote>\n<p>The Javascript embellishments in this tutorial mainly revolve around:<\/p>\n<ul>\n<li><a target=_blank title='window.open' href='http:\/\/www.w3schools.com\/jsref\/met_win_open.asp'>window.open<\/a><\/li>\n<\/ul>\n<p>The use of window.open can sometimes be blocked by web browsers depending on their settings and you can read a bit more about such issues <a target=_blank title='pop-up windows' href='http:\/\/en.wikipedia.org\/wiki\/Pop-up_ad'>here<\/a>.<\/p>\n<p>Useful tutorials that helped, and we give thanks to, were:<\/p>\n<ul>\n<li><a target=_blank title='Sublunary Point' href='http:\/\/translate.google.com.au\/translate?hl=en&#038;sl=de&#038;u=http:\/\/de.wikipedia.org\/wiki\/Sublunarer_Punkt&#038;prev=\/search%3Fq%3D%2522Sublunarer%2522%2Bwikipedia%26client%3Dfirefox-a%26hs%3D3co%26rls%3Dorg.mozilla:en-US:official%26biw%3D1213%26bih%3D619'>Sublunary Point<\/a> (information from Wikipedia, from where quote above comes)<\/li>\n<li><a target=_blank title='Sublunary Point calculator helper' href='http:\/\/www.timeanddate.com\/worldclock\/sunearth.html'>Sublunary Point calculator helper<\/a> via <a target=_blank title='cURL in PHP and command line' href='http:\/\/php.net\/manual\/en\/book.curl.php'>cURL<\/a><\/li>\n<li><a target=_blank title='Moon Phase calculator helper' href='http:\/\/www.zodiacarts.com\/Calendar.shtml'>Moon Phase calculator helper<\/a> via <a target=_blank title='cURL in PHP and command line' href='http:\/\/php.net\/manual\/en\/book.curl.php'>cURL<\/a><\/li>\n<li><a target=_blank title='Sun Angle formulae applied to the case of the Moon Sublunary Point' href='http:\/\/www.google.com.au\/url?sa=t&#038;rct=j&#038;q=&#038;esrc=s&#038;source=web&#038;cd=1&#038;ved=0CC8QFjAA&#038;url=http%3A%2F%2Fgeoalliance.asu.edu%2Fazga_site%2Fsites%2Fdefault%2Ffiles%2FLessonFiles%2FDorn%2FPulse%2FDornPulse.ppt&#038;ei=QTGRUuiXEcGtiAfwlIGICw&#038;usg=AFQjCNEYL6f1yBLg5hdC5qgYnnfWS00nOg&#038;sig2=2kQ25M8OoDltE6baNCRlnQ&#038;bvm=bv.56988011,d.aGc'>Sun Angle formulae applied to the case of the Moon Sublunary Point<\/a><\/li>\n<li><a target=_blank title='Sydney positioning' href='http:\/\/stutzfamily.com\/mrstutz\/LatLong\/latlonglist.htm#AUSTRALIA'>Sydney positioning<\/a><\/li>\n<li><a target=_blank title='CSS 2D Transformation Rotations' href='http:\/\/www.w3schools.com\/css\/css3_2dtransforms.asp'>CSS 2D Transformation Rotations<\/a><\/li>\n<\/ul>\n<p>Here is a link to a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php\" title='Live run'>live run<\/a>.  (The way it changed on 1\/12\/2013 to have a dropdown of placenames as extra functionality will be explained in a tutorial called PHP\/Javascript\/HTML Geographical Placename Integration Tutorial on 3\/12\/2013.)<\/p>\n<p>Here is a link to some downloadable PHP programming source code which you may want to rename to <a target=_blank title='sun_angle_now_at.php' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/MoonAngle\/moon_angle_now_at.php_GETME\">moon_angle_now_at.php<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5383' onclick='var dv=document.getElementById(\"d5383\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=59\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5383' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d41167' onclick='var dv=document.getElementById(\"d41167\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/pyephem\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d41167' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A long time ago now we presented PHP\/Javascript\/HTML Moon Angle Tutorial but now we feel is a good time for it to get a makeover. Why is that? Well, we have the relatively new discovery of the very useful Python &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-and-python-pyephem-moon-angle-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[109,2708,2695,932,997,2691,1012,2705,2709,2706,1319,2707],"class_list":["post-41167","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-astronomy","tag-gmt","tag-moon","tag-php","tag-programming","tag-pyephem","tag-python","tag-sidereal-time","tag-sublunar-point","tag-transit","tag-tutorial","tag-utc"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41167"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=41167"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41167\/revisions"}],"predecessor-version":[{"id":41170,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/41167\/revisions\/41170"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=41167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=41167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=41167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}