Main Sections

Python Subsections

Astral – Python Sun Calculations.

Astral is a Python module designed to calculate the following times of the day...

Plus solar azimuth and elevation, at a particular time...

for any latitude and longitude.

The following example shows how the module can be used.

from astral import Astral

city-name = 'London'

astral = Astral()
astral.solar-depression = 'civil'

city = astral[city-name]

print('Information for %s/%s\n' % (city-name, city.country))

tz-name = city.tz-name
print('Timezone: %s' % tz-name)

print('Latitude: %.02f; Longitude: %.02f\n' % (city.latitude, city.longitude))

sun = city.sun(local=True)
print('Dawn:    %s' % str(sun['dawn']))
print('Sunrise: %s' % str(sun['sunrise']))
print('Noon:    %s' % str(sun['noon']))
print('Sunset:  %s' % str(sun['sunset']))
print('Dusk:    %s' % str(sun['dusk']))

Which produces the following output:

Information for London/England

Timezone: Europe/London
Latitude: 51.60; Longitude: 0.08

Dawn:     2009-04-22 05:12:56+01:00
Sunrise:  2009-04-22 05:49:36+01:00
Noon:     2009-04-22 12:58:48+01:00
Sunset:   2009-04-22 20:09:07+01:00
Dusk:     2009-04-22 20:45:52+01:00

Dependencies

Astral is dependent on the following Python libraries

Download

Version Description URL
0.7
  • Added capability to retrieve geo data from Google's mapping service
  • Renamed City class to Location
  • Renamed CityDB to AstralGeocoder
  • Added elevations of cities to database and property to obtain elevation from Location class
astral-0.7.zip
0.6.2 astral-0.6.2.zip
0.6.1
  • Corrected inconsistencies in docstrings
astral-0.6.1.zip
0.6
  • Fix for bug 884716 submitted by Martin Heemskerk regarding moon phase calculations
  • Fixes for bug report 944754 submitted by Hajo Werder
    • Changed co-ordinate system so that eastern longitudes are now positive
    • Added solar_depression property to City class
astral-0.6.zip
0.5
  • Changed City to accept unicode name and country.
  • Moved city information into a database class CityDB
  • Added attribute access to database for timezone groups
astral-0.5.zip
0.4
  • Duplicate city names could not be accessed.
  • Sun calculations for some cities failed with times outside valid ranges.
  • Fixes for city data.
  • Added calculation for moon phase.
astral-0.4.zip
0.3
  • Changed to Apache V2.0 license.
  • Fix for bug #555508 submitted by me.
  • US state capitals and other cities added.
astral-0.3.zip
0.2 Fix for bug #554041 (MIT license.) astral-0.2.zip
0.1 Initial version (MIT license.) astral-0.1.zip

Source Code

The source code for the Astral package can be browsed here http://bazaar.launchpad.net/~sffjunkie/astral/trunk/files

You can download the latest version of the source using Bazaar (bzr)

bzr checkout lp:astral

Bug Reports

Please use the Astral project page on Launchpad.net to submit bug reports.