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 can also calculate moon phase for a specific date.
The module provides 2 main classes Astral and City.
Has 2 main responsibilities
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.05
>>> 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.
city = astral['London']
You can supply an optional country name by adding a comma followed by the country name. Where multiple cities have the same name you may need to supply the country name otherwise the first result will be returned which may not be the one you’re looking for.
city = astral['Abu Dhabi,United Arab Emirates']
Handles city names with spaces and mixed case.
Return type: | Dictionary of cities indexed by city name. |
---|
Calculate dawn time in the UTC timezone.
Parameters: |
|
---|---|
Return type: | date/time in UTC timezone |
Calculate dusk time in the UTC timezone.
Parameters: |
|
---|---|
Return type: | date/time in UTC timezone |
Calculates the phase of the moon on the specified date.
Parameters: | date (datetime.date) – The date to calculate the phase for. |
---|---|
Return type: | Integer designating phase
|
Calculate ruhakaalam times in the UTC timezone.
Parameters: |
|
---|---|
Return type: | Dictionary with keys start and end |
Calculate the azimuth of the sun in the UTC timezone.
Parameters: |
|
---|---|
Return type: | Azimuth in degrees |
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 the elevation of the sun.
Parameters: |
|
---|---|
Return type: | Elevation in degrees |
Calculate solar noon time in the UTC timezone.
Parameters: |
|
---|---|
Return type: | date/time in UTC timezone |
Calculate all the info for the sun at once.
Parameters: |
|
---|---|
Return type: | Dictionary with keys dawn, sunrise, noon, sunset and dusk |
Calculate sunrise time in the UTC timezone.
Parameters: |
|
---|---|
Return type: | date/time in UTC timezone |
Calculate sunset time in the UTC timezone.
Parameters: |
|
---|---|
Return type: | date/time in UTC timezone |
Provides access to information for single city.
Initializes the object with a tuple of information.
Parameters: | info – A tuple of information to fill in the city info. The tuple should contain items in the following order
See timezone property for a method of obtaining time zone names |
---|
The country in which the city is located.
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: |
|
---|---|
Return type: | datetime.datetime of dawn |
Calculates the dusk time (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: |
|
---|---|
Return type: | datetime.datetime of dusk |
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.
The city name.
Calculates the period of rahukaalam.
Parameters: |
|
---|---|
Return type: | datetime.datetime of dusk |
Calculates the solar azimuth angle for a specific date/time.
Parameters: | dateandtime (datetime.datetime) – The date and time for which to calculate the angle. |
---|---|
Return type: | The angle in degrees clockwise from North as a float. |
Calculates the solar elevation angle for a specific time.
Parameters: | dateandtime (datetime.datetime) – The date and time for which to calculate the angle. |
---|---|
Return type: | The angle in degrees from the horizon as a float. |
Calculates the solar noon (the time when the sun is at its highest point.)
Parameters: |
|
---|---|
Return type: | datetime.datetime of noon |
Returns dawn, sunrise, noon, sunset and dusk as a dictionary.
Parameters: |
|
---|---|
Return type: | datetime.datetime of dusk |
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: |
|
---|---|
Return type: | datetime.datetime of sunrise |
Calculates sunset time (the time in the evening when the sun is a 0.833 degrees below the horizon. This is to account for refraction.)
Parameters: |
|
---|---|
Return type: | datetime.datetime of sunset |
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
The timezone.