Guest User

Untitled

a guest
Dec 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. from numpy import sin,cos,tan,arcsin,arccos,arctan, pi, modf
  2. from datetime import datetime
  3.  
  4. def Length_of_day(latitude,day_of_year):
  5. """
  6. latitude = latitude in degrees (eg. 39.3292 for Athens Ohio)
  7.  
  8. Example:
  9. import datetime
  10. day_of_year = datetime.datetime.now().timetuple().tm_yday
  11.  
  12. Sunrise/Sunset is when the top of the sun is apparently even with horizon
  13. then p = 0.8333
  14.  
  15. Paper: A Model Comparison for Daylength as a Function of Latitude and Day
  16. of Year (1995)
  17.  
  18. Author: Edward J Rykiel and Randal Stahl
  19. """
  20. J = day_of_year
  21. L = latitude
  22. p = 0.8333 # daylength coefficient
  23. theta = 0.2163108 + 2 * arctan(0.9671396 * tan(.00860 * (J - 186)))
  24. phi = arcsin(0.39795 * cos(theta))
  25.  
  26. D = 24 - (24 / pi) * arccos((sin(p * pi / 180) +\
  27. sin(L * pi / 180) *\
  28. sin(phi)) / (cos(latitude * pi / 180) * cos(phi)))
  29.  
  30. # get hours and minutes
  31. frac, whole = modf(D)
  32. hour = whole
  33. mint = frac * 60
  34.  
  35. s = 'Length of day is: {:.0f} hours {:.0f} minutes'.format(hour,mint)
  36. print(s)
  37. return D
  38.  
  39. latitude = 39.3292 # Athens, OH
  40. day_of_year = datetime.now().timetuple().tm_yday
  41.  
  42. Length_of_day(latitude, day_of_year);
Add Comment
Please, Sign In to add comment