5

I have a webcam website and I wanted to display the sunrise time for the actual day. So I used the date_sunrise function in PHP for this purpose. In addition to the coordinates, it takes the suns zenith value as input.

I learned that the correct zenith for sunrise is 90.8333. 90 would be the theoretic angle to the center of the sun (i.e. at the horizon). To account for the diameter of the sun and refraction, 0.8333 is added (16 arcminutes + 34 arcminutes divided by 60).

But I noticed that this input gave different sunrise times that other sites. The most reliable source must be the Astronomical Applications Department of the U.S. Naval Observatory. See their online calculator and read the description of their method. It's stated that they also use a Zenith value of 90.8333 for the purpose of calculating sunrise.

Then I discovered that the php function date_sun_info, which is an array containing various data, gave the correct sunrise time (corresponding to the results from AAD).

To achieve the same sunrise time from the date_sunrise function, I have to enter a zenith value around 90.5.

Why doesn't date_sunrise with zenith=90.8333 give the same result as date_sun_info?

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75
euphoria
  • 55
  • 6
  • PHP's default for the zenith is `90.583333` - have you tried that? Perhaps the basis of calculation is different. – Dave Morrissey Jan 11 '17 at 13:55
  • Please post the code you used for both `date_sunrise` and `date_sun_info`, as well as all inputs, including latitude, longitude, zenith, time, and UTC offset. – bishop Jan 11 '17 at 14:58

3 Answers3

4

According to http://php.net/manual/en/function.date-sunrise.php the default Zenith parameter is taken from a configuration file (See ini_get())

The .ini in question is the php.ini from your PHP install. It has the following lines (they are commented out here, but are used as default unless overwritten in the .ini file).

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

Therefore if you navigate to your php.ini file and remove the semi colon, you can overwrite the default sunrise/set zenith values to whatever you wish. In your case, '90.8333'.

In regards to the difference, 'sun_info' takes the arguements of time, longitude and latitude coordinates. So this could have a more accurate database somewhere rather than using the default value set in the config.

References:

Dan_
  • 1,235
  • 11
  • 20
  • 1
    Thanks, zenith of 90.5833 gave the same result. See this test page: [link](http://trosbyfjorden.holmen.no/test.php?year=2017&month=1&day=10&lon_sign=1&lon_deg=9&lon_min=36&lat_sign=1&lat_deg=58&lat_min=56&tz=1&tz_sign=1) I wonder why PHP zenith=90.5833 gives the same result as other sites with zenith=90.8333. – euphoria Jan 11 '17 at 17:38
  • Mhmm... Certainly an interesting point. Might be worth raising on a forum dedicated to PHP or something. – Dan_ Jan 11 '17 at 19:03
4

Why doesn't date_sunrise with zenith=90.8333 give the same result as date_sun_info?

Good question. Let's go to the source. date_sunrise calculates the altitude as a function of the zenith:

altitude = 90 - zenith;

while date_sun_info calculates altitude as a constant:

-35.0/60

What does altitude mean, and how does changing this value affect the result? Well, cross reference to timelib_astro_rise_set_altitude, which is the library call both date_sunrise and date_sun_info use, we see:

 *       altit = the altitude which the Sun should cross
 *               Set to -35/60 degrees for rise/set, -6 degrees
 *               for civil, -12 degrees for nautical and -18
 *               degrees for astronomical twilight.

Now scan through that code and notice it's just the Generalized Sunrise Equation and the constant -35.0/60 corresponds to the center of the solar disc (−0.83°, or about −50 arcminutes). So the use of the constant here makes sense, as it's part of the generalized equation that USNO AAD uses.

The question now is, why does date_sunrise calculate the altitude as a function of the zenith? Let's notice two things. First, if we supply a zenith of 90.583333, then the calculation 90 - 90.583333 yields exactly the same constant -35/60 == -.583333 that we saw earlier, explaining why using that particular value gives you the same results. Second, that 90 - zenith is the solar elevation angle and also the horizontal parallax. Taking these notes together, I'm guessing the subtraction accounts for the Earth's oblate spheroid shape more precisely than the constant. However, it's not clear to me that the generalized equation tolerates this.

I would therefore recommend using date_sun_info for calculations where you need consistency with other sources.

bishop
  • 37,830
  • 11
  • 104
  • 139
0

However there is also a difference when it comes to the twilights and I fail to see any significant difference in the source code between the two. The twilight is defined as the moment when the geometric center of the sun passes at 6/12/18 degrees under the horizon, so the solar disc should not be taken into account. Both sun_info and sunrise use -6.0 for the altitude, yet the results are slightly different.

mmomtchev
  • 2,497
  • 1
  • 8
  • 23