jonls / redshift

Redshift adjusts the color temperature of your screen according to your surroundings. This may help your eyes hurt less if you are working in front of the screen at night.
http://jonls.dk/redshift
GNU General Public License v3.0
5.87k stars 424 forks source link

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 1 year ago

Pavanyogi121 commented 1 year ago

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 commented 1 year ago

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.