solar_azimuth problem

Asked by Wim Nijntjes on 2018-03-30

Hello, I want to know the azimuth of the sunrise point.

I don't know what to use as the first parameter and format for the "solar-azimuth(datetime, latitude, longitude)

The way I use it now gives this error:

sunRiseAzimuth = a.solar_azimuth(a.datetime, city.latitude, city.longitude)

AttributeError: 'Astral' object has no attribute 'datetime'

Please can someone give me a good advise?

Regards, Wim

Question information

Language:
English Edit question
Status:
Solved
For:
astral Edit question
Assignee:
No assignee Edit question
Solved by:
Wim Nijntjes
Solved:
2018-04-03
Last query:
2018-04-03
Last reply:
Wim Nijntjes (paysan) said : #1

import datetime
from astral import Astral
city_name = 'Amsterdam'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]

print ('Info for %s/%s\n' % (city_name, city.region))
timezone = city.timezone
print ('Timezone: %s' % timezone)

sun = city.sun(date=datetime.date.today(), local=True)
print('Latitude: %.02f; Longitude: %.02f\n' % (city.latitude, city.longitude))
print ('SunRise : %s' % str(sun['sunrise']))
print ('SunSet : %s' % str(sun['sunset']))

sunRiseAzimuth = a.solar_azimuth(a.datetime, city.latitude, city.longitude)
print sunRiseazimuth

Wim Nijntjes (paysan) said : #2

Why does nobody reply? Is something wrong with my question?
Wim

Simon Kennedy (sffjunkie) said : #3

The first parameter is a Python datetime instance.

To get one of these you need to"from datetime import datetime" (slightly confusingly the module name is the same as the class name) then you can create an instance using "dt = datetime.now()" which will return an instance with the time right now. You can then pass dt as the first parameter to solar_azimuth.

   sunRiseAzimuth = a.solar_azimuth(dt, city.latitude, city.longitude)

For a specific time use datetime(2018,3,31,9,0,0) for march 31 2018 at 9 am.

Wim Nijntjes (paysan) said : #4

Thanks a lot Simon. It looks like it works now.
Maybe some problems with the TZ but I think I can solve this my own.

Gegards, Wim