The astral module provides the means to calculate dawn, sunrise, solar noon, sunset, dusk and rahukaalam times, plus solar azimuth and elevation, for specific cities or at a specific latitude/longitude.
It provides 2 main classes Astral and City.
Has 2 main capabilities
For example
>>> from astral import *
>>> a = Astral()
>>> city = a['London']
>>> print('Information for %s' % city.name)
Information for London
>>> timezone = city.timezone
>>> print('Timezone: %s' % timezone)
Timezone: Europe/London
>>> print('Latitude: %.02f; Longitude: %.02f' % (city.latitude, city.longitude))
Latitude: 51.60; Longitude: 0.08
>>> sun = city.sun(local=True)
>>> print('Dawn: %s' % str(sun['dawn']))
Dawn: 2009-04-22 05:12:56+01:00
Returns a City object for the specified city.
Handles city names with spaces and mixed case.
Calculate dawn time for a specific date at a particular position.
Returns date/time in UTC
Calculate dusk time for a specific date at a particular position.
Returns date/time in UTC
The number of degrees the sun must be below the horizon for the dawn/dusk calc.
Can either be set as a number of degrees below the horizon or as one of the following strings
String | Degrees |
---|---|
civil | 6.0 |
nautical | 12.0 |
astronomical | 18.0 |
Calculate solar noon time for a specific date at a particular position.
Returns date/time in UTC
Calculate sunrise time for a specific date at a particular position.
Returns date/time in UTC
Calculate sunset time for a specific date at a particular position.
Returns date/time in UTC
Provides access to information for single city.
Initializes the object with a tuple of information.
The tuple should contain items in the following order
Field | Default |
---|---|
name | Greenwich |
country | England |
latitude | 51.168 |
longitude | 0 |
time zone name | Europe/London |
See timezone property for a method of obtaining time zone names
Return dawn time.
Calculates the time in the morning when the sun is a certain number of degrees below the horizon. By default this is 6 degrees but can be changed by setting the Astral.solar_depression property.
Parameters:
date - The date for which to calculate the sunrise time.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
Return dusk time.
Calculates the time in the evening when the sun is a certain number of degrees below the horizon. By default this is 6 degrees but can be changed by setting the Astral.solar_depression property.
Parameters:
date - The date for which to calculate the dusk time.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
The city’s latitude
latitude can be set either as a string or as a number
For strings they must be of the form:
degrees°minutes'[N|S] e.g. 51°31'N
For numbers, negative numbers signify latitudes to the South.
The city’s longitude.
longitude can be set either as a string or as a number
For strings they must be of the form:
degrees°minutes'[E|W] e.g. 51°31'W
For numbers, negative numbers signify longitudes to the East. This is opposite to the normal convention of +ve being to the West but is required for the calculations.
Calculates the period of rahukaalam.
Parameters:
date - The date for which to calculate rahukaalam period.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
Calculates the solar azimuth angle for a specific time.
The angle returned is in degrees clockwise from North.
Parameters:
dateandtime - The date and time for which to calculate the angle.
Calculates the solar elevation angle for a specific time.
The angle returned is in degrees from the horizon
Parameters:
dateandtime - The date and time for which to calculate the angle.
Return the solar noon time.
Calculates the time when the sun is at its highest point.
Parameters:
date - The date for which to calculate the noon time.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
Returns dawn, sunrise, noon, sunset and dusk as a dictionary.
Parameters:
date - The date for which to calculate the times.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
Return sunrise time.
Calculates the time in the morning when the sun is a 0.833 degrees below the horizon. This is to account for refraction.
Parameters:
date - The date for which to calculate the sunrise time.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
Return sunset time.
Calculates the time in the evening when the sun is a 0.833 degrees below the horizon. This is to account for refraction.
Parameters:
date - The date for which to calculate the sunset time.
A value of None uses the current date.
local - True = Time to be returned in cities time zone (Default);
False = Time to be returned in UTC.
The time zone name in which the city is located.
A list of time zone names can be obtained from pytz. For example.
>>> from pytz import all_timezones
>>> for tz in all_timezones:
... print tz