Skip to content

Commit

Permalink
Merge pull request pingswept#23 from solarjoe/master
Browse files Browse the repository at this point in the history
Made get_refraction_correction conditional on not being too far below the horizon.
  • Loading branch information
pingswept committed Jan 15, 2015
2 parents 61476a2 + 825fa3f commit 2d754d5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pysolar/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,24 @@ def get_sun_earth_distance(jme):
return get_coeff(jme, constants.sun_earth_distance_coeffs) / 1e8

def get_refraction_correction(pressure, temperature, topocentric_elevation_angle):

#function and default values according to original NREL SPA C code
#http://www.nrel.gov/midc/spa/

sun_radius = 0.26667
atmos_refract = 0.5667

del_e = 0.0
tea = topocentric_elevation_angle
a = pressure * 2.830 * 1.02
b = 1010.0 * temperature * 60.0 * math.tan(math.radians(tea + (10.3/(tea + 5.11))))
return a / b

#approximation only valid if sun is not close to horizon
if (tea >= -1.0*(sun_radius + atmos_refract)):

a = pressure * 2.830 * 1.02
b = 1010.0 * temperature * 60.0 * math.tan(math.radians(tea + (10.3/(tea + 5.11))))
del_e = a / b

return del_e

def get_solar_time(longitude_deg, when):
"returns solar time in hours for the specified longitude and time," \
Expand Down

0 comments on commit 2d754d5

Please sign in to comment.