Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/NREL/bifacial_radiance
Browse files Browse the repository at this point in the history
… into development
  • Loading branch information
shirubana committed Sep 4, 2024
2 parents 7e01972 + 562ddd2 commit 7750ba7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 12 deletions.
37 changes: 30 additions & 7 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def _modDict(originaldict, moddict, relative=False):

return newdict

def _heightCasesSwitcher(sceneDict, preferred='hub_height', nonpreferred='clearance_height'):
def _heightCasesSwitcher(sceneDict, preferred='hub_height', nonpreferred='clearance_height',
suppress_warning=False):
"""
Parameters
Expand All @@ -183,7 +184,9 @@ def _heightCasesSwitcher(sceneDict, preferred='hub_height', nonpreferred='cleara
nonpreferred : TYPE, optional
When sceneDict has hub_height and clearance_height,
it wil ldelete this nonpreferred option. The default is 'clearance_height'.
suppress_warning : Bool, default False
If both heights passed in SceneDict, suppress the warning
Returns
-------
sceneDict : TYPE
Expand Down Expand Up @@ -238,9 +241,10 @@ def _heightCasesSwitcher(sceneDict, preferred='hub_height', nonpreferred='cleara
del sceneDict[nonpreferred]

elif heightCases == '_clearance_height__hub_height__':
print("sceneDict Warning: 'hub_height' and 'clearance_height'"+
" are being passed. Using "+preferred+
" and removing "+ nonpreferred)
if not suppress_warning:
print("sceneDict Warning: 'hub_height' and 'clearance_height'"+
" are being passed. Using "+preferred+
" and removing "+ nonpreferred)
del sceneDict[nonpreferred]

else:
Expand Down Expand Up @@ -301,7 +305,24 @@ def _subhourlydatatoGencumskyformat(gencumskydata, label='right'):
if (gencumskydata.index.year[-1] == gencumskydata.index.year[-2]+1) and len(gencumskydata)>8760:
gencumskydata = gencumskydata[:-1]
return gencumskydata
# end _subhourlydatatoGencumskyformat
# end _subhourlydatatoGencumskyformat

def _checkRaypath():
# Ensure that os.environ['RAYPATH'] exists and contains current directory '.'
if os.name == 'nt':
splitter = ';'
else:
splitter = ':'
try:
raypath = os.getenv('RAYPATH', default=None)
if not raypath:
raise KeyError()
raysplit = raypath.split(splitter)
if not '.' in raysplit:
os.environ['RAYPATH'] = splitter.join(filter(None, raysplit + ['.'+splitter]))
except (KeyError, AttributeError, TypeError):
raise Exception('No RAYPATH set for RADIANCE. Please check your RADIANCE installation.')



class RadianceObj:
Expand Down Expand Up @@ -362,6 +383,7 @@ def __init__(self, name=None, path=None, hpc=False):

now = datetime.datetime.now()
self.nowstr = str(now.date())+'_'+str(now.hour)+str(now.minute)+str(now.second)
_checkRaypath() # make sure we have RADIANCE path set up correctly

# DEFAULTS

Expand Down Expand Up @@ -4879,7 +4901,8 @@ def _checkSensors(sensors):

sceneDict, use_clearanceheight = _heightCasesSwitcher(sceneDict,
preferred = 'hub_height',
nonpreferred = 'clearance_height')
nonpreferred = 'clearance_height',
suppress_warning=True)

if use_clearanceheight :
height = sceneDict['clearance_height'] + 0.5* \
Expand Down
4 changes: 2 additions & 2 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __getattr__(cls, name):
MOCK_MODULES = []
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
"""
# import distutils before calling pd.show_versions()
# import distutils before calling pd.show_versions(). not needed for pd >= 1.4.x
# https://github.com/pypa/setuptools/issues/3044
import distutils # noqa: F401
#import distutils # noqa: F401

import pandas as pd
pd.show_versions()
Expand Down
29 changes: 29 additions & 0 deletions docs/sphinx/source/whatsnew/v0.4.4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _whatsnew_0440:

v0.4.4 (XX / XX / 2024)
------------------------
Bugfix Release ...


API Changes
~~~~~~~~~~~~
*

Enhancements
~~~~~~~~~~~~
* Conduct an automated check for proper radiance RAYPATH setting (:issue:`525`)(:pull:`537`)


Bug fixes
~~~~~~~~~
* versioning with setuptools_scm- set fallback_version to bifirad v0.4.3 to prevent crashes if git is not present (:issue:`535`)(:pull:`539`)

Documentation
~~~~~~~~~~~~~~
* No longer provide a warning message when both `hub_height` and `clearance_height` are passed to :py:class:`~bifacial_radiance.AnalysisObj.moduleAnalysis` (:pull:`540`)

Contributors
~~~~~~~~~~~~
* Silvana Ayala (:ghuser:`shirubana`)
* Chris Deline (:ghuser:`cdeline`)

Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
.. _whatsnew_0440:

v0.4.4 (XX / XX / 2024)
------------------------
Bugfix Release ...


API Changes
~~~~~~~~~~~~
*

Enhancements
~~~~~~~~~~~~
* Conduct an automated check for proper radiance RAYPATH setting (:issue:`525`)(:pull:`537`)


Bug fixes
~~~~~~~~~
* versioning with setuptools_scm- set fallback_version to bifirad v0.4.3 to prevent crashes if git is not present (:issue:`535`)(:pull:`539`)

Documentation
~~~~~~~~~~~~~~
* No longer provide a warning message when both `hub_height` and `clearance_height` are passed to :py:class:`~bifacial_radiance.AnalysisObj.moduleAnalysis` (:pull:`540`)

Contributors
~~~~~~~~~~~~
* Silvana Ayala (:ghuser:`shirubana`)
* Chris Deline (:ghuser:`cdeline`)
.. _whatsnew_050:

v0.5.0 (4 / XX / 2024)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ ipython==8.13.0
kiwisolver==1.4.4
matplotlib==3.5.1
more-itertools==9.1.0
numba==0.58.1
numpy==1.24.2
pandas==1.3.5
pandas==1.4.4
pluggy==1.0.0
pvlib==0.9.4
pvmismatch==4.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
#version='0.4.4',
use_scm_version=True,
use_scm_version={"fallback_version":"0.4.3"},
description='Tools to interface with Radiance for the PV researcher',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
16 changes: 15 additions & 1 deletion tests/test_bifacial_radiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,4 +679,18 @@ def test_customObj():
f.readline()
line = f.readline()
assert(line == '!xform -rx 0 -t 2 1 0 objects/Marker.rad') or (line == '!xform -rx 0 -t 2 1 0 objects\Marker.rad')

assert trackerdict[-20]['count'] == 37

def test_raypath():
# test errors and raypath updates
import re
raypath0 = os.getenv('RAYPATH', default=None)

os.environ['RAYPATH'] = ''
with pytest.raises(Exception):
bifacial_radiance.main._checkRaypath()
os.environ['RAYPATH'] = 'test'
bifacial_radiance.main._checkRaypath()
assert '.' in re.split(':|;', os.environ['RAYPATH'])

os.environ['RAYPATH'] = raypath0

0 comments on commit 7750ba7

Please sign in to comment.