diff --git a/bifacial_radiance/main.py b/bifacial_radiance/main.py index aceae78b..21825600 100644 --- a/bifacial_radiance/main.py +++ b/bifacial_radiance/main.py @@ -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 @@ -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 @@ -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: @@ -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: @@ -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 @@ -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* \ diff --git a/docs/sphinx/source/conf.py b/docs/sphinx/source/conf.py index 62a26e72..b56c5f29 100644 --- a/docs/sphinx/source/conf.py +++ b/docs/sphinx/source/conf.py @@ -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() diff --git a/docs/sphinx/source/whatsnew/v0.4.4.rst b/docs/sphinx/source/whatsnew/v0.4.4.rst new file mode 100644 index 00000000..5cbce1df --- /dev/null +++ b/docs/sphinx/source/whatsnew/v0.4.4.rst @@ -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`) + diff --git a/docs/sphinx/source/whatsnew/pending.rst b/docs/sphinx/source/whatsnew/v0.5.0.rst similarity index 85% rename from docs/sphinx/source/whatsnew/pending.rst rename to docs/sphinx/source/whatsnew/v0.5.0.rst index b1c705fd..945a49c8 100644 --- a/docs/sphinx/source/whatsnew/pending.rst +++ b/docs/sphinx/source/whatsnew/v0.5.0.rst @@ -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) diff --git a/requirements.txt b/requirements.txt index 7708d612..270c707e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index b04e96c6..dc0bdacb 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/test_bifacial_radiance.py b/tests/test_bifacial_radiance.py index 0fb0420d..f6783d87 100644 --- a/tests/test_bifacial_radiance.py +++ b/tests/test_bifacial_radiance.py @@ -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') - \ No newline at end of file + 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 \ No newline at end of file