Lunar Phase API

The crucial calculation is determining the Moon Zenith Angle, which involves subtracting the Moon Parallactic Angle from the Moon Phase Angle (also known as the Position Angle of the Moon’s Bright Limb in Jean Meeus’s book). To determine the orientation of the Moon at my location, I searched for a pre-existing formula for some time.


Question:

In my search for a free API that offers lunar phase predictions along with moonrise and moonset data, I have come across an issue. The tide tables application I use, which is based on PHP, relies on NOAA for weather and tide data. Unfortunately, it seems that NOAA does not provide any lunar data. I’m wondering if there is any Google API that includes this information that I’m not aware of.

In case there is no knowledge of a free API, particularly the one provided by the government, is there a straightforward method to compute this? I came across a post that suggests ways to calculate it with great accuracy, but a small deviation is acceptable.


Solution 1:

It is a simple task to compute it on your own.

  • This website provides a PHP class that can compute the phase of the Moon.
  • Check out this website, Jivebay, where you can calculate the value of MSDT A1.

According to a post on wxforums.net by user ‘Cristian’…

rad
     function todeg($x)  { return ($x * (180.0 / M_PI)); }               # rad->deg
     function jtime($t)
         {
         $julian = ($t / 86400) + 2440587.5;     # (seconds /(seconds per day)) + julian date of epoch       2440587.5 / 86400 = 28,24753472222 Days
         return ($julian);
         }
     function kepler($m, $ecc)
         {
         $EPSILON = 1e-6;
         $m = Moon::torad($m);
         $e = $m;
         while (abs($delta) > $EPSILON)
             {
             $delta = $e - $ecc * sin($e) - $m;
             $e -= $delta / (1 - $ecc * cos($e));
             }
         return ($e);
         }
     }
 //Exemple d'utilisation :
//Pour le 11 Avril 2009 à 00h00
list($MoonPhase, $MoonAge, $MoonDist, $MoonAng, $SunDist, $SunAng, $mpfrac) = Moon::phase(2009, 04, 11, 00, 00, 01);
echo "La Lune est éclairée à ".number_format($MoonPhase*100, 2, ',', '')."%"."
"; echo "Son age est de ".number_format($MoonAge, 0, ',', '')." jours"."
"; echo "Et elle se situe à une distance de ".number_format($MoonDist, 0, ',', '')." km par rapport à la Terre."."
"; ?>


Solution 2:


You can access NOAA’s API by specifying the year and month in the URL at https://tidesandcurrents.noaa.gov/moon_phases.shtml?year=2020&data_type=monApr.

The data provided comprises information for both lunar and solar events, however, it regrettably lacks details on moonrise and moonset.

The page with filtering options by month or phase can be accessed at https://tidesandcurrents.noaa.gov/astronomical.html, which serves as the base page.

Frequently Asked Questions

Posted in Php