Skip to content

Commit

Permalink
corrected get_refraction_correction
Browse files Browse the repository at this point in the history
Corrected approximation according to NREL's C code (http://www.nrel.gov/midc/spa/)
Now the function is only applied if the sun is not close to horizon
  • Loading branch information
solarjoe committed Jan 9, 2015
1 parent 61476a2 commit cb89528
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 cb89528

Please sign in to comment.