https://github.com/taco-c/suntime
Calculate times for sunrise, sunset, and noon.
https://github.com/taco-c/suntime
astronomy library
Last synced: 7 months ago
JSON representation
Calculate times for sunrise, sunset, and noon.
- Host: GitHub
- URL: https://github.com/taco-c/suntime
- Owner: taco-c
- License: gpl-3.0
- Created: 2019-01-15T22:46:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-23T08:36:33.000Z (almost 5 years ago)
- Last Synced: 2025-02-14T19:46:40.631Z (9 months ago)
- Topics: astronomy, library
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Suntime
Calculate sunrises and sunsets. In an arguably messy way. Also doesn't support midnight sun (days without sunset) or polar night (days without sunrise).
Adapted from NOAA's solar calculations spreadsheets, found here:
* https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html
## Use
Use it as a module. Suntime.py consists of three classes, where `Sun` is the main one.
```python3
# date is a datetime object
# location is a Location object
# timezone is a TimeZone object, defaults to UTC
Sun (date, location, timezone)
# N, E are latitude and longitude, positive towards north and east
Location (name, N, E)
# hours, minutes, seconds ahead of UTC
# minutes, seconds defaults to 0
Timezone (name, hours, minutes, seconds)
```
The `Sun` object will have the properties `sunrise`, `sunset`, and `noon`, which all will be `datetime` objects.
## Example
```python3
import datetime
import suntime
# Datetime of today
today = datetime.datetime.now()
# Location
rome = suntime.Location("Rome", 41.89, 12.48)
# Time zone
CET = suntime.TimeZone("CET", 1)
sun = suntime.Sun(today, rome, CET)
print(sun.sunrise)
print(sun.noon)
print(sun.sunset)
print("Day lenght:", sun.sunset - sun.sunrise)
```