mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.07k stars 412 forks source link

Investigate more precise sun calculations #57

Open mourner opened 8 years ago

mourner commented 8 years ago

Formulas in https://github.com/maoserr/redshiftgui/blob/master/src/solar.c#L94 are more precise. We should look whether it's worth making suncalc calculations slightly more precise in expense of worse performance.

glittle commented 8 years ago

While my instance of the library is now isolated, I like the speed! I often have to calculate sunsets for an entire year 'instantly'.

I don't feel more accurate times are needed for sunset/sunrise, unless you can include the person's current elevation and what hills/valleys are between them and the sun. For example, in a valley, the sun sets much earlier than the calculations, and the sun rise is much later!

mourner commented 8 years ago

Yeah, I agree. The question is how expensive this will be, and whether we can fine a compromise. E.g. if I find out that we can improve precision with only several percents of performance overhead, that's perfectly fine.

KrishnaPG commented 8 years ago

One middle way would be to have a accuracy-controller option (configuable dynamically at run-time) that picks which version to run (accuracy vs speed). Just similar to how those zlib compression algorithms do (with compression profiles fast vs best compression).

mourner commented 7 years ago

I've started working on a rewrite of SunCalc based on Meeus Astronomical Algorithms (2nd ed). It's in very early stage as I figure out all the underlying concepts, but it's a start. https://github.com/mourner/suncalc/tree/meeus cc @Fabiz

Fabiz commented 7 years ago

Hey Vladimir

Have you already seen my implementation of the meeus algorithms: https://github.com/Fabiz/MeeusJs? https://github.com/Fabiz/MeeusJs? Maybe you can use some of the code (or the whole package of course).

Best regards Fabio

Am 05.01.2017 um 13:43 schrieb Vladimir Agafonkin notifications@github.com:

I've started working on a rewrite of SunCalc based on Meeus Astronomical Algorithms (2nd ed). It's in very early stage as I figure out all the underlying concepts, but it's a start. https://github.com/mourner/suncalc/tree/meeus https://github.com/mourner/suncalc/tree/meeus cc @Fabiz https://github.com/Fabiz — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mourner/suncalc/issues/57#issuecomment-270635736, or mute the thread https://github.com/notifications/unsubscribe-auth/ABKYhoeAZ220ZotselJ-uSqcIDnRExEDks5rPOVVgaJpZM4GgW03.

glittle commented 7 years ago

Things I'd look for in the new version...

Other ideas

Thanks for continuing to work on this very functional and useful library!

Fabiz commented 7 years ago

Hi Glen

You may also check out the following lib: https://github.com/Fabiz/MeeusJs https://github.com/Fabiz/MeeusJs Sun and moon calcs are separated into different files. But it’s bigger than suncalc because it uses some lookup tables for more exact calculations.

I used this lib for the peakfinder website. There you can also get the real times according to the topology. Here is an example from a famous place in Switzerland that doesn’t get a lot of sun in the winter time: https://www.peakfinder.org/?lat=46.6287&lng=8.0407&azi=193&zoom=4&ele=1137&cfg=sm&date=2017-01-05T19:13Z https://www.peakfinder.org/?lat=46.6287&lng=8.0407&azi=193&zoom=4&ele=1137&cfg=sm&date=2017-01-05T19:13Z

Best Fabio

Am 05.01.2017 um 16:27 schrieb Glen Little notifications@github.com:

Things I'd look for in the new version...

Fast calc for sunset and sunrise per day for lat/long. That's all I'm interested in, so I typically gut the file and remove all the moon related calculations and the non-sunset/rise times. It would nice if the code was clean, well-separated, and easy to determine what to remove! Other ideas

When the lat/long is learned on mobile phones, we sometimes also get altitude returned. Being able to feed that in, along with lat/long would be nice. However, I suspect the difference in times would be negligible. If so, this is likely not worth it. I feel that the experienced sunset/rise times vary per person according to the topology between them and the sun... nearby mountains, valleys, etc. That introduces a large 'margin of error', so trying to calculate the times to the sub-second is mostly pointless. Being accurate to the nearest minute is more than enough! Thanks for continuing to work on this very functional and useful library!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mourner/suncalc/issues/57#issuecomment-270670708, or mute the thread https://github.com/notifications/unsubscribe-auth/ABKYhvQBg9XC-KklmUoFVgGayssYaYeLks5rPQvLgaJpZM4GgW03.

glittle commented 7 years ago

Thanks, @Fabiz.

That is an amazing site!

For my simple purposes, I'm quite happy with suncalc!

ghost commented 7 years ago

I did some analysis on this topic myself... would like to know why the times are not more closely together...

Sunrise/Sunset Utilities with Varying Results ?!? http://robertjliguori.blogspot.com/2017/01/sunrisesunset-utilities-with-varying.html

Wikinaut commented 6 years ago

Added here as reference:

this (German) page uses the Meeus calculation in Javascript: http://www.computus.de/mondphase/mondphase.htm .

tdulcet commented 5 years ago

I created a webpage here to compare the sun rise/set times returned from the SunCalc, MeeusJs and Sun and moon rise/set project libraries for any location. It also shows the sun rise/set times returned from the OpenWeatherMap and Yahoo Weather APIs. Note that you must click on the "More" near the bottom of the page to show MeeusJs. Click on "Developers" at the top of the page to test a location other than your current.

Suggestions for improvement are welcome.

mourner commented 5 years ago

@tdulcet nice tool — thanks for sharing!

I already wrote the minimal, heavily optimized code with Meeus-based formulas for Sun position/times that are more precise ready to replace the one in suncalc. The only problem is that I didn't do an equivalent for moon, which will need a lot more code. So the options are:

  1. Release a new version with new sun calculations + old moon calculations.
  2. Release a new fast and lean version without moon calculation as a major version now, and hope to add moon calculations again in future.
  3. Wait until there are new moon calculations and release at once, but it's unclear when that will happen.
derWebdesigner commented 7 months ago

@mourner Thank you so much for all your efforts, I highly appreciate it. I just ran into the same issue that the calculations are sometimes around 5-10 minutes different than others I found on the web and so I was searching for solutions or if it's simply my mistake. Now reading that there is a more precise version already sounds awesome and I quickly wanted to ask about the status.

From my side 1. sounds best since it would at least immediately improve the sun calculations or is there any downside where this would interfere with the moon calculations?

Or maybe allow an optional parameter to use the old version until moon calculations are also available?

Thank you very much for a feedback and in general for providing this super nice library.