Leaflet.Terminator icon indicating copy to clipboard operation
Leaflet.Terminator copied to clipboard

please add refraction correction to the terminator

Open chaimkeh opened this issue 7 years ago • 4 comments

Please update your wonderful javascript using the calculation of the terminator that includes an averaged atmoshpheric refraction addition: that I (chaim) explained how to calculated in the following post: http://physics.stackexchange.com/questions/28563/hours-of-light-per-day-based-on-latitude-longitude-formula/320092#320092 The calculation manner is as following. After calculating the percentage of dayligh for any latitude, calculate the longitude of noon for any time, and the day night terminator at that latitude will be a half of the percentage of daylight in angle on either direction of the noon position. Thank you!

chaimkeh avatar Mar 20 '17 09:03 chaimkeh

Thanks for your suggestion. It's unfortunately not quite straightforward to implement this. Leaflet.Terminator internally computes the hour angle of the Sun for each longitude and not the hour angle of the sunset, i.e., you need to solve the equation

cos \theta_s = sin \phi sin \delta + cos \phi cos \delta cos h

for \phi. This is trivial if \theta_s = 90°, which is currently what the code does. The general case requires some spherical trigonometry, which I currently don't have the time for. I'd be happy to take somebody else's solution (or even better a PR). Otherwise it'll be a while before I get to this.

joergdietrich avatar Mar 21 '17 08:03 joergdietrich

Dear Jorg:The hour angle of sunset from noon is actually the opposite of the hour angle from noon to sunrise.  I looked into your code and you already calculate all the terms necessary to calculate the total hours of daylight which can be easily used to calculate the terminator with any zenith angle.  (For standard refraction, the zenith angle is 90.8333.)  I will send you a more detailed explanation this evening on how to modify your calculations to calculate it.  The rest requires your expertise on setting up the polygons, which is different from the way it is done now especially close to the equinox since the terminator is no longer a square wave but flares out in the Arctic region (since the day is longer there due to the refraction.)  Could you please look first at my (chaim) solution at the following link: http://physics.stackexchange.com/questions/28563/hours-of-light-per-day-based-on-latitude-longitude-formula/320092#320092

Thank you!Chaim

  From: Jörg Dietrich <[email protected]>

To: joergdietrich/Leaflet.Terminator [email protected] Cc: chaimkeh [email protected]; Author [email protected] Sent: Tuesday, March 21, 2017 10:48 AM Subject: Re: [joergdietrich/Leaflet.Terminator] please add refraction correction to the terminator (#7)

Thanks for your suggestion. It's unfortunately not quite straightforward to implement this. Leaflet.Terminator internally computes the hour angle of the Sun for each longitude and not the hour angle of the sunset, i.e., you need to solve the equationcos \theta_s = sin \phi sin \delta + cos \phi cos \delta cos h for \phi. This is trivial if \theta_s = 90°, which is currently what the code does. The general case requires some spherical trigonometry, which I currently don't have the time for. I'd be happy to take somebody else's solution (or even better a PR). Otherwise it'll be a while before I get to this.— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chaimkeh avatar Mar 21 '17 11:03 chaimkeh

Here's more details.  I will use the terminology of your javascript, l.terminator.js.Within your_hourAngle function, you calculate the gst.  That is basically all you need to calculate the longitude of noon at any UTC. That is, the sun is due south at longitude_noon ( i.e., noon on the earth at a certain UTC time), where  longitude_noon = lst15 - sunPos.alpha + UTC15 degrees,  where lng = 0  (i.e., set lng = 0 since we want the local meridian of Greenwich, i.e., time in UTC), where,  UTC = computer time - time zone of computer. The day terminator will be at an hour angle, ha, of sunrise to the West of longitude_sun and a hour angle, ha of sunset to the East of longitude_sun.  The hour angle of sunrise and sunset at any latitude, lat, is equal in magnitude to: ha = arccos (cos(90.833) /(cos(lng)*cos(sunPos.delta)) - tan(lng)*tan(sunPos.delta))  (convert to degrees)

As you see, you already calculate everything you need to know to determine a more realistic terminator.  You just need to modify _hourAngle to calculate longitude_noon, and then create a function to calculate ha, and then the terminator at any latitude = lat will be symmetric about longitude_noon at the following longitudes. longitudes = longitude_sun +/- ha degrees. If the expression in the arccos above is greater than 1, then it is either perpetual day or night depending on the value of the declination (which you calculate as sunPos.delta) as follows: For latitude, lat > 0 (Northern Hemisphere)If sunPos.delta > 0 then it is perpetual daylightIf sunPos.delta < 0 then it is perpetual night For latitude, lat <0 (Sourthern Hemisphere)If sunPos.delta > 0 then it is perpetual nightIf sunPos.delta < 0 then it is perpetual day You can use the above method to plot any sort of setting and twilight by just changing the Zenith Angle.  For sunrise/sunset it is customary to use 90.833 degrees as I used above.  For twilight, refraction can be ignored.  Therefore, for civil twilight, the zenith angle is 96 degrees, nautical twilight it is 102 degrees, for astronomical twilight it is 108 degrees. It would be really useful to allow the user to change that in the javascript.   In my opinion, if your application was changed to calculate a terminator with refraction it should have a very big impact on all sorts of sites that need to display the terminator, e.g., flight tracking apps.  Almost everybody today uses the non physical approximation of no refraction.  That is a shame since the more physical calculation is not difficult at all. Yours,Chaim

  From: Jörg Dietrich <[email protected]>

To: joergdietrich/Leaflet.Terminator [email protected] Cc: chaimkeh [email protected]; Author [email protected] Sent: Tuesday, March 21, 2017 10:48 AM Subject: Re: [joergdietrich/Leaflet.Terminator] please add refraction correction to the terminator (#7)

Thanks for your suggestion. It's unfortunately not quite straightforward to implement this. Leaflet.Terminator internally computes the hour angle of the Sun for each longitude and not the hour angle of the sunset, i.e., you need to solve the equationcos \theta_s = sin \phi sin \delta + cos \phi cos \delta cos h for \phi. This is trivial if \theta_s = 90°, which is currently what the code does. The general case requires some spherical trigonometry, which I currently don't have the time for. I'd be happy to take somebody else's solution (or even better a PR). Otherwise it'll be a while before I get to this.— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chaimkeh avatar Mar 21 '17 23:03 chaimkeh

Dear Chaim,

Many thanks for your detailed explanation. I agree having the zenith angle as a configure option would be very nice to have, e.g., to plot twilight in addition to a sharp terminator. As I said the logic right now is that I assumed there would be a unique solution for latitude at every longitude. With a zenith angle different from 90° this is not correct anymore.

It'll be a few weeks before I can implement this, but it's definitely on my to do list.

joergdietrich avatar Mar 23 '17 16:03 joergdietrich