Skip to content

Commit

Permalink
Fix load.cleanResult to work with files created with different sensor…
Browse files Browse the repository at this point in the history
…sy. Fixes #419
  • Loading branch information
cdeline committed Oct 7, 2024
1 parent 32cdf6d commit 8ae8877
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
20 changes: 13 additions & 7 deletions bifacial_radiance/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,19 @@ def cleanResult(resultsDF, matchers=None):

if matchers is None:
matchers = ['sky','pole','tube','bar','ground', '3267', '1540']
NaNindex = [i for i,s in enumerate(resultsDF['mattype']) if any(xs in s for xs in matchers)]
NaNindex2 = [i for i,s in enumerate(resultsDF['rearMat']) if any(xs in s for xs in matchers)]
#NaNindex += [i for i,s in enumerate(frontDict['mattype']) if any(xs in s for xs in matchers)]
for i in NaNindex:
resultsDF.loc[i,'Wm2Front'] = np.nan
for i in NaNindex2:
resultsDF.loc[i,'Wm2Back'] = np.nan
try:
NaNindex = [i for i,s in enumerate(resultsDF['mattype']) if any(xs in s for xs in matchers)]
for i in NaNindex:
resultsDF.loc[i,'Wm2Front'] = np.nan
except KeyError:
pass

try:
NaNindex2 = [i for i,s in enumerate(resultsDF['rearMat']) if any(xs in s for xs in matchers)]
for i in NaNindex2:
resultsDF.loc[i,'Wm2Back'] = np.nan
except KeyError:
pass

return resultsDF

Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ What's New

These are new features and improvements of note in each release.

.. include:: whatsnew/v0.4.4.rst
.. include:: whatsnew/v0.4.3.rst
.. include:: whatsnew/v0.4.2.rst
.. include:: whatsnew/v0.4.1.rst
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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`)
* :py:func:`bifacial_radiance.load.readconfigurationinputfile` now properly handles loading moduleObj parameters from .ini files: `glass`, `glassEdge`, `frameParamsDict`, `omegaParamsDict` (:pull:`551`)
* Fixed a leap year bug in :py:func:`~bifacial_radiance.RadianceObj.readWeatherFile` that crashed if epwfiles are loaded that include leap year data (like Feb. 28 2020). (:issue:`552`)
* Bug fix in :py:func:`bifacial_radiance.load.cleanResult` that wouldn't work with files created when front and rear scan are different lengths. (:issue:`419`)

Documentation
~~~~~~~~~~~~~~
Expand Down
10 changes: 10 additions & 0 deletions tests/results/test_irr_1axis_2021-06-17_1300_Back.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x,y,z,rearMat,Wm2Back
0.187,0.324,0.215,a4.1.a0.test-module.2310,122.371
0.140,0.243,0.232,a4.1.a0.test-module.2310,85.541
0.093,0.162,0.248,a4.1.a0.test-module.2310,69.828
0.047,0.081,0.265,a4.1.a0.test-module.2310,55.036
-0.000,-0.000,0.281,a4.1.tube1.16,0.881
-0.047,-0.081,0.298,a4.1.a0.test-module.2310,58.626
-0.094,-0.162,0.314,a4.1.a0.test-module.2310,235.992
-0.140,-0.243,0.331,a4.1.a0.test-module.2310,328.776
-0.187,-0.324,0.347,a4.1.a0.test-module.2310,397.733
9 changes: 9 additions & 0 deletions tests/results/test_irr_1axis_2021-06-17_1300_Front.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
x,y,z,mattype,Wm2Front
0.184,0.318,0.239,a4.1.a0.test-module.6457,893.281
0.132,0.228,0.257,a4.1.a0.test-module.6457,893.723
0.080,0.138,0.275,a4.1.a0.test-module.6457,894.165
0.028,0.048,0.294,a4.1.a0.test-module.6457,897.640
-0.024,-0.042,0.312,a4.1.a0.test-module.6457,897.709
-0.076,-0.132,0.330,a4.1.a0.test-module.6457,897.779
-0.128,-0.222,0.349,a4.1.a0.test-module.6457,897.849
-0.180,-0.312,0.367,a4.1.a0.test-module.6457,899.870
16 changes: 13 additions & 3 deletions tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import bifacial_radiance
import os, pytest
import numpy as np

# try navigating to tests directory so tests run from here.
try:
Expand All @@ -22,7 +23,8 @@
TESTDIR = os.path.dirname(__file__) # this folder
MET_FILENAME = 'USA_CO_Boulder.724699_TMY2.epw'
TEST_FILE = os.path.join('results','test_2001-01-01_1000.csv')

TEST_FILE2_FRONT = os.path.join('results', 'test_irr_1axis_2021-06-17_1300_Front.csv')
TEST_FILE2_BACK = os.path.join('results', 'test_irr_1axis_2021-06-17_1300_Back.csv')


# test load function on a dummy csv file in the /tests/ directory
Expand All @@ -47,7 +49,7 @@ def test_load_trackerdict():
def test_cleanResult():
# example of setting NaN's when the scan intersects undesired material
# test_01_01_10.csv has some ground and sky references
import numpy as np

resultsDF = bifacial_radiance.load.read1Result(TEST_FILE)
cleanedDF = bifacial_radiance.load.cleanResult(resultsDF)
assert np.isnan(cleanedDF.Wm2Front.loc[4])
Expand Down Expand Up @@ -117,4 +119,12 @@ def test_celllevel_module():
'xcell': 0.15,
'ycell': 0.15,
'xcellgap': 0.01,
'ycellgap': 0.01}
'ycellgap': 0.01}

def test_GH419_front_and_back_sensors():
resultsDF_front = bifacial_radiance.load.read1Result(TEST_FILE2_FRONT)
cleanedDF_front = bifacial_radiance.load.cleanResult(resultsDF_front)

resultsDF_back = bifacial_radiance.load.read1Result(TEST_FILE2_BACK)
cleanedDF_back = bifacial_radiance.load.cleanResult(resultsDF_back)
assert np.isnan(cleanedDF_back.Wm2Back.loc[4])

0 comments on commit 8ae8877

Please sign in to comment.