Skip to content

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

@Pavanyogi121

Description

@Pavanyogi121

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$

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions