Skip to content

Commit 4d3b6da

Browse files
committed
corrected broken imports in radiation.py for solar.GetDayOfYear() by relocating it to julian.py. Corrected all imports in the modules that use this function
1 parent 02cbc0d commit 4d3b6da

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

Pysolar/elevation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"""Various elevation-related calculations
2121
2222
"""
23-
import math
2423

2524
def GetPressureWithElevation(h, Ps=101325.00, Ts=288.15, Tl=-0.0065, Hb=0.0, R=8.31432, g=9.80665, M=0.0289644):
2625
#This function returns an estimate of the pressure in pascals as a function of elevation above sea level

Pysolar/julian.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
2323
"""
2424
import math
25+
import datetime
26+
27+
def GetDayOfYear(utc_datetime):
28+
year_start = datetime.datetime(utc_datetime.year, 1, 1, tzinfo=utc_datetime.tzinfo)
29+
delta = (utc_datetime - year_start)
30+
return delta.days
2531

2632
def GetJulianCentury(julian_day):
2733
return (julian_day - 2451545.0) / 36525.0

Pysolar/radiation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"""Calculate different kinds of radiation components via default values
2121
2222
"""
23-
#from . import solar
2423
import math
24+
import julian
2525

2626
def GetAirMassRatio(altitude_deg):
2727
# from Masters, p. 412
@@ -40,7 +40,7 @@ def GetRadiationDirect(utc_datetime, altitude_deg):
4040
# from Masters, p. 412
4141

4242
if(altitude_deg > 0):
43-
day = solar.GetDayOfYear(utc_datetime)
43+
day = julian.GetDayOfYear(utc_datetime)
4444
flux = GetApparentExtraterrestrialFlux(day)
4545
optical_depth = GetOpticalDepth(day)
4646
air_mass_ratio = GetAirMassRatio(altitude_deg)

Pysolar/solar.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def GetAltitudeFast(latitude_deg, longitude_deg, utc_datetime):
8686

8787
# expect 19 degrees for solar.GetAltitude(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 13, 1, 130320))
8888

89-
day = GetDayOfYear(utc_datetime)
89+
day = julian.GetDayOfYear(utc_datetime)
9090
declination_rad = math.radians(GetDeclination(day))
9191
latitude_rad = math.radians(latitude_deg)
9292
hour_angle = GetHourAngle(utc_datetime, longitude_deg)
@@ -133,7 +133,7 @@ def GetAzimuth(latitude_deg, longitude_deg, utc_datetime, elevation = 0):
133133

134134
def GetAzimuthFast(latitude_deg, longitude_deg, utc_datetime):
135135
# expect -50 degrees for solar.GetAzimuth(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 18, 0, 0))
136-
day = GetDayOfYear(utc_datetime)
136+
day = julian.GetDayOfYear(utc_datetime)
137137
declination_rad = math.radians(GetDeclination(day))
138138
latitude_rad = math.radians(latitude_deg)
139139
hour_angle_rad = math.radians(GetHourAngle(utc_datetime, longitude_deg))
@@ -149,11 +149,6 @@ def GetAzimuthFast(latitude_deg, longitude_deg, utc_datetime):
149149
def GetCoefficient(jme, constant_array):
150150
return sum([constant_array[i-1][0] * math.cos(constant_array[i-1][1] + (constant_array[i-1][2] * jme)) for i in range(len(constant_array))])
151151

152-
def GetDayOfYear(utc_datetime):
153-
year_start = datetime.datetime(utc_datetime.year, 1, 1, tzinfo=utc_datetime.tzinfo)
154-
delta = (utc_datetime - year_start)
155-
return delta.days
156-
157152
def GetDeclination(day):
158153
'''The declination of the sun is the angle between
159154
Earth's equatorial plane and a line between the Earth and the sun.
@@ -297,7 +292,7 @@ def GetRefractionCorrection(pressure_millibars, temperature_celsius, topocentric
297292
return a / b
298293

299294
def GetSolarTime(longitude_deg, utc_datetime):
300-
day = GetDayOfYear(utc_datetime)
295+
day = julian.GetDayOfYear(utc_datetime)
301296
return (((utc_datetime.hour * 60) + utc_datetime.minute + (4 * longitude_deg) + EquationOfTime(day))/60)
302297

303298
# Topocentric functions calculate angles relative to a location on the surface of the earth.

Pysolar/util.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from datetime import datetime as dt
3434
from datetime import timedelta
3535
import math
36+
import julian
3637
import pytz
3738
from pytz import all_timezones
3839
from . import solar
@@ -90,7 +91,7 @@ def GetSunriseSunset(latitude_deg, longitude_deg, utc_datetime, timezone):
9091
"""
9192

9293
# Day of the year
93-
day = solar.GetDayOfYear(utc_datetime)
94+
day = julian.GetDayOfYear(utc_datetime)
9495

9596
# Solar hour angle
9697
SHA = ((timezone)* 15.0 - longitude_deg)
@@ -153,7 +154,7 @@ def mean_earth_sun_distance(utc_datetime):
153154
radiation models, p.113
154155
"""
155156

156-
return (1 - (0.0335 * math.sin(360 * ((solar.GetDayOfYear(utc_datetime)) - 94)) / (365)))
157+
return (1 - (0.0335 * math.sin(360 * ((julian.GetDayOfYear(utc_datetime)) - 94)) / (365)))
157158

158159
def extraterrestrial_irrad(utc_datetime, latitude_deg, longitude_deg,SC=SC_default):
159160
"""Equation calculates Extratrestrial radiation. Solar radiation incident outside the earth's
@@ -188,11 +189,12 @@ def extraterrestrial_irrad(utc_datetime, latitude_deg, longitude_deg,SC=SC_defau
188189
.. [2] Dr. J. Schumacher and et al,"INSEL LE(Integrated Simulation Environment Language)Block reference",p.68
189190
190191
"""
191-
day = solar.GetDayOfYear(utc_datetime)
192-
ab = math.cos(2 * math.pi * (solar.GetDayOfYear(utc_datetime) - 1.0)/(365.0))
193-
bc = math.sin(2 * math.pi * (solar.GetDayOfYear(utc_datetime) - 1.0)/(365.0))
194-
cd = math.cos(2 * (2 * math.pi * (solar.GetDayOfYear(utc_datetime) - 1.0)/(365.0)))
195-
df = math.sin(2 * (2 * math.pi * (solar.GetDayOfYear(utc_datetime) - 1.0)/(365.0)))
192+
day = julian.GetDayOfYear(utc_datetime)
193+
day_ratio = (julian.GetDayOfYear(utc_datetime) - 1.0)/(365.0)
194+
ab = math.cos(2 * math.pi * day_ratio)
195+
bc = math.sin(2 * math.pi * day_ratio)
196+
cd = math.cos(2 * (2 * math.pi * day_ratio))
197+
df = math.sin(2 * (2 * math.pi * day_ratio))
196198
decl = solar.GetDeclination(day)
197199
ha = solar.GetHourAngle(utc_datetime, longitude_deg)
198200
ZA = math.sin(latitude_deg) * math.sin(decl) + math.cos(latitude_deg) * math.cos(decl) * math.cos(ha)
@@ -222,7 +224,7 @@ def declination_degree(utc_datetime, TY = TY_default ):
222224
.. [1] http://pysolar.org/
223225
224226
"""
225-
return 23.45 * math.sin((2 * math.pi / (TY)) * ((solar.GetDayOfYear(utc_datetime)) - 81))
227+
return 23.45 * math.sin((2 * math.pi / (TY)) * ((julian.GetDayOfYear(utc_datetime)) - 81))
226228

227229

228230
def solarelevation_function_clear(latitude_deg, longitude_deg, utc_datetime,temperature_celsius = 25,

0 commit comments

Comments
 (0)