Skip to content

Commit f989429

Browse files
authored
Merge pull request #2 from cdeline/533_pyrad_falsecolor
Switch makeFalseColor() over to the falsecolor.py script which is added to the bifacial_radiance/scripts directory. This should no longer have RADIANCE dependence.
2 parents a395cd1 + 165672a commit f989429

5 files changed

Lines changed: 919 additions & 21 deletions

File tree

bifacial_radiance/main.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
5252
"""
5353
import os
54+
import sys
5455
import datetime
5556
from subprocess import Popen, PIPE # replacement for os.system()
5657
import pandas as pd
@@ -5052,28 +5053,14 @@ def makeFalseColor(self, viewfile, octfile=None, name=None):
50525053
WM2max = max(map(float, extrm_out.split()))
50535054

50545055
print('Saving scene in false color')
5055-
# Use pyradiance.falsecolor if available, otherwise fall back to subprocess
5056-
if PYRADIANCE_AVAILABLE:
5057-
try:
5058-
#auto scale false color map
5059-
if WM2max < 1100:
5060-
false_color_data = pyradiance.falsecolor(WM2_out, label="W/m2", multiplier=1, scale="1100", ndivs=11)
5061-
else:
5062-
false_color_data = pyradiance.falsecolor(WM2_out, label="W/m2", multiplier=1, scale=str(WM2max))
5063-
5064-
with open(os.path.join("images","%s%s_FC.hdr"%(name,viewfile[:-3]) ),"wb") as f:
5065-
f.write(false_color_data)
5066-
err = None
5067-
except Exception as e:
5068-
err = f"Error: {str(e)}"
5056+
# use falsecolor.py script modified slightly from github.com/gmischler/PyRad
5057+
_falsecolor_script = os.path.join(os.path.dirname(__file__), 'scripts', 'falsecolor.py')
5058+
if WM2max < 1100:
5059+
cmd = [sys.executable, _falsecolor_script, '-l', 'W/m2', '-m', '1', '-s', '1100', '-n', '11']
50695060
else:
5070-
#auto scale false color map
5071-
if WM2max < 1100:
5072-
cmd = "falsecolor -l W/m2 -m 1 -s 1100 -n 11"
5073-
else:
5074-
cmd = "falsecolor -l W/m2 -m 1 -s %s"%(WM2max,)
5075-
with open(os.path.join("images","%s%s_FC.hdr"%(name,viewfile[:-3]) ),"w") as f:
5076-
data,err = _popen(cmd,WM2_out.encode('latin1'),f)
5061+
cmd = [sys.executable, _falsecolor_script, '-l', 'W/m2', '-m', '1', '-s', str(WM2max)]
5062+
with open(os.path.join("images", "%s%s_FC.hdr" % (name, viewfile[:-3])), "wb") as f:
5063+
data, err = _popen(cmd, WM2_out.encode('latin1') if isinstance(WM2_out, str) else WM2_out, f)
50775064

50785065
if err is not None:
50795066
print(err)

0 commit comments

Comments
 (0)