Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the prayer times calculations #2

Open
mohamed opened this issue May 14, 2014 · 37 comments
Open

Update the prayer times calculations #2

mohamed opened this issue May 14, 2014 · 37 comments

Comments

@mohamed
Copy link
Contributor

mohamed commented May 14, 2014

The methods used in prayertime are a bit old and do not reflect the prayer times reported by most modern prayer times tools. I am working on a "clean-room" implementation of prayertime which is based on the theory given in http://praytimes.org/calculation/

@z3bi
Copy link
Contributor

z3bi commented May 14, 2014

I think the only calculation that differs from that document is Asr, and I have fixed that in my pull request #3 all of the others seem to be fine.

@mohamed
Copy link
Contributor Author

mohamed commented May 14, 2014

I live in the Netherlands and I see that the times reported by ITL differ from the calendar used by the local mosques for all prayers by 2+ minutes. I think that the source of error is the method used to compute the Sun coordinates. The current astro.h/.c use the method from Jean Meeus book in 1998. That method uses huge tables. The US Naval Observatory (USNO) released an approximate algorithm for calculating the Sun coordinates (see http://aa.usno.navy.mil/faq/docs/SunApprox.php). I would propose that we replace astro.c/.h with simple and easy-to-maintain method to determine the Sun coordinates.

@arabeyes
Copy link
Contributor

Go ahead and try it Mohamed. If the USNO algorithm implementation gives more accurate timings than the old method, then we'll use it in lieu of the old one.

@mohamed
Copy link
Contributor Author

mohamed commented May 19, 2014

Hi arabeyes,
Do you know which references almanac is used for the Sun coordinates? I am thinking of using NASA almanac program (Windows only) as a reference point.

@arabeyes
Copy link
Contributor

No idea. I am not the original project owner and this isn't really my field of expertise. Is this program developed by NASA itself, or someone else did it based on NASA's almanac? If it is the latter, we should perhaps double-check it to make sure it contains no mistakes.

@ghost
Copy link

ghost commented May 19, 2014

Salam,
" I see that the times reported by ITL differ from the calendar used by the local mosques for all prayers by 2+ minutes"
I think local mosques aren't a good bentch mark :)
Here in the UK, when I asked some mosques on how they produce their timetables, all they do is adapt what's on islamicfinder.net.
Not sure who are the people behind that website, and what lib/implementations they use.

@ghost ghost mentioned this issue May 19, 2014
@mohamed
Copy link
Contributor Author

mohamed commented May 19, 2014

Wa alikom alsalam haqman,

I agree that local mosques are not a proper reference point. However, we can use the official calendars used in Islamic countries as the reference point.

@abougouffa
Copy link

Hi Mr. @mohamed,
Check my library and my small program written in Python for the calculation of prayer times using the same (I think) method you mentioned, if this program works, I will re-write it in C
https://github.com/a-bougouffa/islamic-lib

@mohamed
Copy link
Contributor Author

mohamed commented May 27, 2014

Salam abdelhak,
Thanks for the information. I have already finished the new implementation and I plan to push it soon to a new branch.

@abougouffa
Copy link

Hi, @mohamed After I saw the code of the current pray times implementation of ITL, I think that in your case it require more inputs to perform the exact results, because as you can see at the "Location" structure, it had three extras fields "temperature", "pressure" and "seaLevel", try to change the default values, if you get wrong results for your location, the new implementation will be the best one 👍

@acamarata
Copy link

Was this implementation finished or is any work needed to help test?

@acamarata
Copy link

If the sun coordinates could be calculated would there be a need at all for the different calculation methods (ISNA, MWL, etc.) since those only differ in the sun angle for Fajr and Isha? If the angle could be dynamically calculated based on lat/lng to some accuracy than wouldn't that be better than these methods and provide the ability to make a "one formula" that would be "most accurate"?

If this can be implemented it is an exciting proposition and I would like to port to JavaScript to stop using praytimes.org inshaa' Allah

@abougouffa
Copy link

Assalam 3alaykom my brother @alisalaah, of course, the sun coordinates (sun declination) can be calculated, but for the lat/long depended zenith angle I don't know!
I've a fully implemented prayer times library; I will port it from Python to C and itegrate it in ITL becouse @mohamed haven't do it!
If you are interested to port the library from Python to JavaScript, you can find it here https://github.com/a-bougouffa/pyIslam

@acamarata
Copy link

I already have a Javascript library that works but with the 6 methods "trying" to get the times.. I would port this library if it had a sun angle algorithm that offered a one calculation for all locations and better accuracy. Otherwise I'll hold off inshaa' Allah

@abougouffa
Copy link

Yes of course, in my pyIslam library, all calculations depend on:
longitude, latitude, timezone, fajr & ishaa method, asr madhab
it calculate all needed algorithms depending on this variables and the date of course!
To know how the library calculate prayer times you can see the sources at the prayertimes.py file and the "gregorianToJulianDay" function on baselib.py and for Omm al-Qura implementation, you need also to calculate the hijri date (the hijri.py file).

@z3bi
Copy link
Contributor

z3bi commented Jul 11, 2014

I'm not sure we have determined if calculating things like the declination of the sun is better than the current table of values. I don't think we should make this change unless we can say for certain that calculating these values is more accurate. Honestly, I feel like the table is less error prone as the calculation will lose precision due to floating point math.

@acamarata
Copy link

Is there an endorsed global table/map of when to use which calculation for
the most accurate times? The end result is just which angles to use for
Fajr/Isha and so on but it seems to have direct relation to how far one is
from the equator as we see UK/US and others using different values than say
the middle east and so on. I am simply interested in trying to have the
best, most accurate and consistent approach when doing prayer times
anywhere - globally - inshaa' Allah. What do you see as the best solution
to being able to get this with only inputting a users coords and having the
software calc/formula handle the rest?

On Fri, Jul 11, 2014 at 11:30 PM, Ameir Al-Zoubi notifications@github.com
wrote:

I'm not sure we have determined if calculating things like the declination
of the sun is better than the current table of values. I don't think we
should make this change unless we can say for certain that calculating
these values is more accurate. Honestly, I feel like the table is less
error prone as the calculation will lose precision due to floating point
math.


Reply to this email directly or view it on GitHub
#2 (comment).

@z3bi
Copy link
Contributor

z3bi commented Jul 15, 2014

@alisalaah I don't think there is any official table of which method to use for a particular country. As with any Fiqh issue there will always be multiple opinions. My suggestion is to start an open source listing of the most common method for different countries. This could potentially be a component of this project or perhaps a separate repo. We could then compile this list and verify each addition with a valid source, eventually we would be able to have a comprehensive list inshAllah.

@acamarata
Copy link

Is the only difference per each method the Fajr and Isha angles? Could we
not collect a table of best angles per area and make a table of the known
best angles at given coords and then grab closest data from that to do this
automatically.

I haven't studied the different methods in detail but could we do something
like best angles per area to make it location based?
On Jul 15, 2014 9:46 PM, "Ameir Al-Zoubi" notifications@github.com wrote:

@alisalaah https://github.com/alisalaah I don't think there is any
official table of which method to use for a particular country. As with any
Fiqh issue there will always be multiple opinions. My suggestion is to
start an open source listing of the most common method for different
countries. This could potentially be a component of this project or perhaps
a separate repo. We could then compile this list and verify each addition
with a valid source, eventually we would be able to have a comprehensive
list inshAllah.


Reply to this email directly or view it on GitHub
#2 (comment).

@acamarata
Copy link

http://moonsighting.com/how-we.html

On Tue, Jul 15, 2014 at 9:53 PM, Ali Camarata alisalaah@gmail.com wrote:

Is the only difference per each method the Fajr and Isha angles? Could we
not collect a table of best angles per area and make a table of the known
best angles at given coords and then grab closest data from that to do this
automatically.

I haven't studied the different methods in detail but could we do
something like best angles per area to make it location based?
On Jul 15, 2014 9:46 PM, "Ameir Al-Zoubi" notifications@github.com
wrote:

@alisalaah https://github.com/alisalaah I don't think there is any
official table of which method to use for a particular country. As with any
Fiqh issue there will always be multiple opinions. My suggestion is to
start an open source listing of the most common method for different
countries. This could potentially be a component of this project or perhaps
a separate repo. We could then compile this list and verify each addition
with a valid source, eventually we would be able to have a comprehensive
list inshAllah.


Reply to this email directly or view it on GitHub
#2 (comment).

@mohamed
Copy link
Contributor Author

mohamed commented Nov 23, 2014

Alsalam alikom all,
I uploaded a new commit that implements a simpler calculation method which uses the approximate Sun coordinates method from the US Naval Observatory as discussed above (see: http://aa.usno.navy.mil/faq/docs/SunApprox.php). Please note that this work is still far from being complete and it is still WIP. Any efforts to improve/test the new method are highly welcome.

@z3bi
Copy link
Contributor

z3bi commented Nov 23, 2014

Thank you for the work on this. I will try to help in creating some test cases so we can verify the new calculations against the existing ones.

@z3bi
Copy link
Contributor

z3bi commented Nov 23, 2014

@mohamed I left a few comments on your pull request based on a quick glance, I will try to do a more thorough review soon inshAllah.

@mohamed
Copy link
Contributor Author

mohamed commented Nov 23, 2014

Thanks a lot Ameir! I will look into them and update the code accordingly.

@z3bi
Copy link
Contributor

z3bi commented Nov 30, 2014

@mohamed I've been using the new_method code with actual prayer time applications and I have a few comments/suggestions. The idea of "config" files are good for testing, but for practically using this as a library, it also needs a good programmatic interface. This will most likely be how most people interact with this code. Specifically, the way you set a date is not ideal. The previous code had a struct with year, month, day which was very easy to use. I recommend doing something similar.

It also doesn't make sense to use round DOWN or round UP. Turning 5:29:01 into 5:30 or 5:29:59 into 5:29 is a big difference. It would be safer to use normal rounding, that way at most the difference is 29 seconds.

For the dhuhr safety margin you are currently adding, it is based on the third definition of this page http://praytimes.org/wiki/A_note_on_Dhuhr but if you look at the first two fiqh definitions, a safety margin is not needed. Perhaps the dhuhr safety margin can be something set, a boolean to decide whether or not to include it. Based on my earlier comment about the programmatic interface I would suggest making the location struct contain location information only (latitude, longitude, altitude, timezone) and then having another struct with all the configuration info (method, madhab, extreme, etc) and then similar to the current library there should be a method to populate the config struct with the default values.

My last comment right now is that it does not build on Mac OS X as it errors out on the redefining of the "round" function.

@mohamed
Copy link
Contributor Author

mohamed commented Nov 30, 2014

@ameiralzoubi I am glad that someone is taking a careful look to the code! 👍
I agree with your comments. So if you have time, please feel free to submit a patch to change the code. Otherwise, I will try to address them. However, I am quite busy during the week and I work on this only/mainly during the weekends.

@z3bi
Copy link
Contributor

z3bi commented Nov 30, 2014

I will work on that inshAllah and add in the ability for custom angles.

@acamarata
Copy link

I implemented the USNO for a globally accurate single dynamic formula at http://praycalc.com which is also on my github (written in JavaScript for Meteor, based on the SunCalc (USNO formula) which does most the work).

@mohamed
Copy link
Contributor Author

mohamed commented Apr 25, 2015

Alsalam alikom Ali, Thanks a lot for the link. Did you implement the extreme latitude methods? That's the only missing thing now from my USNO implementation. I didn't have time to go and study the equations and methods used in the extreme latitude calculations so an existing clean implementation is highly valuable.

@acamarata
Copy link

No, I haven't done that yet due to time but it should be easy. The current methods return times due to the inaccuracy of static angles and the USNO would return null because the twilights never actual happen, which we know.

According to fiqh you should go by the time of the nearest place that has these times in reality. All that needs to be done is, if Fajr is null, then loop calculating Fajr again but subtract .1 from the latitude until you get a result. Then display the result (maybe with a * to show it's derived this way). Same for Isha or Maghrib.

@z3bi
Copy link
Contributor

z3bi commented Apr 8, 2016

If anyone on this thread is interested, I created a new prayer time library https://github.com/batoulapps/Adhan

All astronomical equations have been implemented from scratch directly from the book "Astronomical Algorithms", it has an official implementation in Swift and JavaScript with Python and Java in progress. It also features an extensive set of unit tests as well as worldwide location testing.x

@ghost
Copy link

ghost commented Apr 11, 2016

How does it compare with libITL?

I need to remove C++ dependency from munadi.org and have one app for both web and native!

On 8 Apr 2016, at 04:01, زعبي notifications@github.com wrote:

If anyone on this thread is interested, I created a new prayer time library https://github.com/batoulapps/Adhan

All astronomical equations have been implemented from scratch directly from the book "Astronomical Algorithms", it has an official implementation in Swift and JavaScript with Python and Java in progress. It also features an extensive set of unit tests as well as worldwide location testing.x


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@z3bi
Copy link
Contributor

z3bi commented Apr 11, 2016

@haqman the main differences is that in Adhan we re-implemented all the astronomical equations from scratch using a widely recognized book on astronomical calculations. Every equation is cited back to the book and has unit tests using values from the book. In addition we will be adding suggested methods for a location very soon. Right now we are collecting data to use for automated testing and to help determine the best method for a particular location.

@acamarata
Copy link

If using the NOAA, etc. algorithms there should be no need for "calculation
methods" as they will return the correct values for every latitude and
longitude with a single formula. For summer and winter at extreme north
and such you will obviously get a "null" for Isha times and such and this
should be dealt with by doing a loop and moving .1 (or whatever amount)
closer to the equator until you get a non-null value, then return that with
some identifier that this is derived not real (so people can indicate such
on their sites).

On Mon, Apr 11, 2016 at 8:12 PM, زعبي notifications@github.com wrote:

@haqman https://github.com/haqman the main differences is that in Adhan
we re-implemented all the astronomical equations from scratch using a
widely recognized book on astronomical calculations. Every equation is
cited back to the book and has unit tests using values from the book. In
addition we will be adding suggested methods for a location very soon.
Right now we are collecting data to use for automated testing and to help
determine the best method for a particular location.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#2 (comment)

@z3bi
Copy link
Contributor

z3bi commented Apr 11, 2016

@alisalaah the astronomical equations can give you precise values for sunrise, sunset, transit and whatever hour angle you ask it for. However, the challenge is still finding the visual appearance and disappearance of twilight (the basis for fajr and isha) which have a lot of variation based on light refraction. In addition, safeguards are put in place not just for null values, but to account for "hardship". An isha time of 11:45 PM and a fajr time of 1:30 AM are not reasonable, in these situations a comprise is used (such as using the more favorable time of 1/7 of the night).

@mohamed
Copy link
Contributor Author

mohamed commented Apr 11, 2016

@z3bi Are you planning to have an implementation in C?

@z3bi
Copy link
Contributor

z3bi commented Apr 11, 2016

@mohamed right now we don't have a plan to write a version in C but we would gladly accept a pull request if someone was interested in doing it. The large number of unit tests should make it easier to stay consistent when porting to a new language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants