python - Solar_noon function - having date/time calc issues -


non-programmer type here attempting construct python solar noon calculation. believe code there having difficulty obtaining solar_noon time. using formula http://www.esrl.noaa.gov/gmd/grad/solcalc/solareqns.pdf

i have used online calculator, http://www.esrl.noaa.gov/gmd/grad/solcalc/ verify eqtime pretty close. calculation error? believe related time conversions.

#!/usr/local/bin/python  import sys datetime import datetime, time, timedelta math import pi, cos, sin  def solar_time(dt, longitude):     return ha  def main():     if len(sys.argv) != 4:         print 'usage: hour_angle.py [yyyy/mm/dd] [hh:mm:ss] [longitude]'         sys.exit()     else:         #dt = datetime.strptime(sys.argv[1] + ' ' + sys.argv[2], '%y/%m/%d %h:%m:%s')         #longitude = float(sys.argv[3])         """             set date/time, longitude ease coding troubleshooting         """         longitude = -71.96 # montauk, ny         dt = datetime.strp('2013-05-21 11:00:00', "%y-%m-%d %h:%m:%s")       gamma = 2 * pi / 365 * (dt.timetuple().tm_yday - 1 + float(dt.hour - 12) / 24)     eqtime = 229.18 * (0.000075 + 0.001868 * cos(gamma) - 0.032077 * sin(gamma) \              - 0.014615 * cos(2 * gamma) - 0.040849 * sin(2 * gamma))     decl = 0.006918 - 0.399912 * cos(gamma) + 0.070257 * sin(gamma) \            - 0.006758 * cos(2 * gamma) + 0.000907 * sin(2 * gamma) \            - 0.002697 * cos(3 * gamma) + 0.00148 * sin(3 * gamma)     time_offset = eqtime + 4 * longitude +60 * -4    #eastern daylight savings time     tst = dt.hour * 60 + dt.minute + dt.second / 60 + time_offset     solar_time = datetime.combine(dt.date(), time(0)) + timedelta(minutes=tst)     print eqtime     print solar_time     snoon = 720 * 4 * longitude -eqtime     solar_noon = datetime.combine(dt.date(), time(0)) + timedelta(minutes=snoon)     print solar_noon  if __name__ == '__main__':     main() 


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -