vacendak

Daylight Calculation

Mar 8th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. """
  2. Created on Sun Mar  8 19:51:26 2020
  3.  
  4. @author: James Densmore & Sergio Sanz
  5. https://www.dataliftoff.com/author/dataliftoff_tuq2s3/
  6.  
  7. """
  8.  
  9. import math
  10. import datetime
  11.  
  12.  
  13. def day_length(day_of_year, latitude):
  14.    
  15.     P = math.asin(0.39795 * math.cos(0.2163108 + 2 * math.atan(0.9671396
  16.         * math.tan(.00860 * (day_of_year - 186)))))
  17.  
  18.     pi = math.pi
  19.     day_light_hours = 24 - (24 / pi) * math.acos((math.sin(0.8333 * pi / 180)
  20.         + math.sin(latitude * pi / 180) * math.sin(P))
  21.         / (math.cos(latitude * pi / 180) * math.cos(P)))
  22.  
  23.     print(str(int(day_light_hours)) + ' hours, '
  24.           + str(int((day_light_hours - int(day_light_hours)) * 60)) + ' min.')
  25.    
  26. time_now = datetime.datetime.now()
  27. day_of_year = int(time_now.strftime('%j'))
  28.  
  29. latitude = float(input('Introduce your latitude: '))
  30.  
  31. day_length(day_of_year, latitude)
Advertisement
Add Comment
Please, Sign In to add comment