Merge pull request #348 from jobermayr/master

ArchSite can now also use Python3 Pysolar.
This commit is contained in:
wwmayer 2016-11-23 13:53:38 +01:00 committed by GitHub
commit b8f8d61020

View File

@ -72,13 +72,20 @@ def makeSolarDiagram(longitude,latitude,scale=1,complete=False):
returns a solar diagram as a pivy node. If complete is returns a solar diagram as a pivy node. If complete is
True, the 12 months are drawn""" True, the 12 months are drawn"""
try: from subprocess import call
import Pysolar py3_failed = call(["python3", "-c", "import Pysolar"])
except:
print("Pysolar is not installed. Unable to generate solar diagrams") if py3_failed:
return None try:
import Pysolar
except:
print("Pysolar is not installed. Unable to generate solar diagrams")
return None
else:
from subprocess import check_output
from pivy import coin from pivy import coin
if not scale: if not scale:
return None return None
@ -129,9 +136,16 @@ def makeSolarDiagram(longitude,latitude,scale=1,complete=False):
for i,d in enumerate(m): for i,d in enumerate(m):
pts = [] pts = []
for h in range(24): for h in range(24):
dt = datetime.datetime(year,d[0],d[1],h) if not py3_failed:
alt = math.radians(Pysolar.solar.GetAltitudeFast(latitude,longitude,dt)) dt = "datetime.datetime(%s, %s, %s, %s)" % (year, d[0], d[1], h)
az = Pysolar.solar.GetAzimuth(latitude,longitude,dt) alt_call = "python3 -c 'import datetime,Pysolar; print (Pysolar.solar.get_altitude_fast(%s, %s, %s))'" % (latitude, longitude, dt)
alt = math.radians(float(check_output(alt_call, shell=True).strip()))
az_call = "python3 -c 'import datetime,Pysolar; print (Pysolar.solar.get_azimuth(%s, %s, %s))'" % (latitude, longitude, dt)
az = float(re.search('.+$', check_output(az_call, shell=True)).group(0))
else:
dt = datetime.datetime(year,d[0],d[1],h)
alt = math.radians(Pysolar.solar.GetAltitudeFast(latitude,longitude,dt))
az = Pysolar.solar.GetAzimuth(latitude,longitude,dt)
az = -90 + az # pysolar's zero is south az = -90 + az # pysolar's zero is south
if az < 0: if az < 0:
az = 360 + az az = 360 + az