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

Use the astral python package for more accurate calcuations of sunrise, noon, sunset, and dusk times for a given latitude and longitude  #872

Open
Pavanyogi121 opened this issue Oct 11, 2022 · 1 comment

Comments

@Pavanyogi121
Copy link

Is your feature request related to a problem? Please describe.
We can use astral python package for more accurate calculations of sunrise, noon, sunset, and dusk times for a given latitude and longitude 

Describe the solution you'd like
We can use astral python package for more accurate calculations of sunrise, noon, sunset, and dusk times for a given latitude and longitude 

Describe alternatives you've considered
We can use astral python package for more accurate calculations of sunrise, noon, sunset, and dusk times for a given latitude and longitude. With precise sunset, sunrise time calculations, the user experience will also increase significantly.

Additional context
Here is the example code.

from astral import LocationInfo
import datetime
from astral.sun import sun

# classastral.LocationInfo(name: str = 'Greenwich', region: str = 'England', timezone: str = 'Europe/London', latitude: float = 51.4733, longitude: float = -0.0008333)
# https://astral.readthedocs.io/en/latest/package.html#astral.LocationInfo 
city = LocationInfo("London", "England", "Europe/London", 51.5, -0.116)
#city = LocationInfo("Atewa", "India", "Asia/Kolkata", 26.386771, 76.933267)

s = sun(city.observer, date=datetime.date.today(), tzinfo=city.timezone)

print((
    f"Information for {city.name}/{city.region}\n"
    f"Timezone: {city.timezone}\n"
    f"Latitude: {city.latitude:.02f}; Longitude: {city.longitude:.02f}\n"
))

print((
    f'Dawn:    {format(s["dawn"].strftime("%Y-%m-%d %H:%M:%S"))}\n'
    f'Sunrise: {format(s["sunrise"].strftime("%Y-%m-%d %H:%M:%S"))}\n'
    f'Noon:    {format(s["noon"].strftime("%Y-%m-%d %H:%M:%S"))}\n'
    f'Sunset:  {format(s["sunset"].strftime("%Y-%m-%d %H:%M:%S"))}\n'
    f'Dusk:    {format(s["dusk"].strftime("%Y-%m-%d %H:%M:%S"))}\n'
))

output

u-20:~/.../sunrise sunset time calculation$ python sunrise-sunset-for-a-given-day.py
Information for London/England
Timezone: Europe/London
Latitude: 51.50; Longitude: -0.12

Dawn:    2022-10-11 06:43:37
Sunrise: 2022-10-11 07:17:46
Noon:    2022-10-11 12:47:19
Sunset:  2022-10-11 18:15:45
Dusk:    2022-10-11 18:49:49

u-20:~/.../sunrise sunset time calculation$
@Pavanyogi121
Copy link
Author

I checked the file https://github.com/jonls/redshift/blob/master/src/solar.c . It looks like the equivalent similar code is already in place.

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

1 participant