# Sunlight based on GPS coordinates and UTC+date

I'm trying to create a sunlight map. I found the following question: Sunlight layer into CartoDB

However, my interest is in trying to calculate the amount of sunlight manually. Can you please point me to the formulas/documentation on how I could compute the amount of sunlight (sunrise/sunset) based on GPS coordinates and UTC/date?

• Could you please clarify "amount" of sunlight? Do you only need to know the duration of daylight (sunrise to sunset) or also its intensity? Jun 20, 2016 at 0:14
• esrl.noaa.gov/gmd/grad/solcalc Jun 20, 2016 at 0:18
• @StephenLead: just the duration is fine... basically theoretically, without knowing clouds/weather, which hours of the day would be 'sunny'.
– econ
Jun 20, 2016 at 2:16
• I'm not sure that this is strictly a GIS question..... I just googled "sunrise calculation" and got some promising hits, including How to calculate sunrise and set and sunrise equation Jun 20, 2016 at 4:51

The pyephem Python module can help here. From the docs:

>>> import ephem
>>> atlanta = ephem.Observer()
>>> atlanta.pressure = 0
>>> atlanta.horizon = '-0:34'
>>> atlanta.lat, atlanta.lon = '33.8', '-84.4'
>>> atlanta.date = '2009/09/06 17:00' # noon EST
>>> print(atlanta.previous_rising(ephem.Sun()))
2009/9/6 11:14:57
>>> print(atlanta.next_setting(ephem.Sun()))
2009/9/6 23:56:10

Note that the above times are UTC.

• Thank you for this. I know I will need to read the docs carefully, but could you say whether the pressure and horizon settings are very important? I'm trying to calculate a sunlight map and I don't have pressure/horizon for all points on the map... Should I just set them both to zero?
– econ
Jun 20, 2016 at 15:26
• @econ Dunno on the pressure and horizon settings, I'm not an astronomer by any stretch, just have used pyephem before. I'd read the docs and do some further research on how those parameters relate to sunrise and sunset. Jun 20, 2016 at 15:43