Skip to content

Commit

Permalink
more rounding updates. Fix pytests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Oct 3, 2024
1 parent ecdeb27 commit ac4d491
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ def _makeSceneNxR(self, modulename=None, sceneDict=None, radname=None, addhubhei
''' INITIALIZE VARIABLES '''
text = '!xform '

text += '-rx %s -t %s %s %s ' %(tilt, 0, 0, hubheight)
text += '-rx %s -t %s %s %s ' %(tilt, 0, 0, np.float16(hubheight))

# create nMods-element array along x, nRows along y. 1cm module gap.
text += '-a %s -t %s 0 0 -a %s -t 0 %s 0 ' %(nMods, self.module.scenex, nRows, pitch)
Expand Down Expand Up @@ -3674,7 +3674,7 @@ def _makeSceneNxR(self, modulename=None, sceneDict=None, radname=None, addhubhei
with open(radfile, 'wb') as f:
f.write(text.encode('ascii'))

self.gcr = self.module.sceney / pitch
self.gcr = round(self.module.sceney / pitch, 6)
self.text = text
self.radfiles = radfile
self.sceneDict = sceneDict
Expand Down
38 changes: 18 additions & 20 deletions tests/test_bifacial_radiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_1axis_gencumSky():

trackerdict = demo.makeOct1axis(trackerdict=minitrackerdict, singleindex=-5) # just run this for one timestep: -5 degrees
trackerdict = demo.analysis1axis( modWanted=7, rowWanted=3, sensorsy=2, sceneNum=0)
assert trackerdict[-5.0]['AnalysisObj'][0].x[0] == -10.766
assert trackerdict[-5.0]['AnalysisObj'][0].x[0] == pytest.approx(-10.766, abs=.001)
modscanfront = {}
modscanfront = {'xstart': -5}
trackerdict = demo.analysis1axis( sensorsy=2, modscanfront=modscanfront, sceneNum=0, customname='_test2')
Expand Down Expand Up @@ -298,19 +298,17 @@ def test_SceneObj_makeSceneNxR_lowtilt():
(frontscan,backscan) = analysis.moduleAnalysis(scene)

assert frontscan.pop('orient') == '-0.000 0.174 -0.985'# was 0,0,-11 in v0.2.4
assert frontscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': 0, 'yinc': 0.093556736536159757,
'xstart': 4.627616431348303e-17,'ystart': -0.3778735578756446,
'zinc': 0.016496576878358378, 'zstart': 0.23717753969161476,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
assert frontscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': 0, 'yinc': 0.09357,
'xstart': 0,'ystart': -0.378, 'zinc': 0.0165, 'zstart': 0.2372,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0}, abs=.001)

assert backscan.pop('orient') == '0.000 -0.174 0.985' # was 0,0,1 in v0.2.4
assert backscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': 0, 'yinc': 0.093556736536159757,
'xstart': 4.580831740657635e-17, 'ystart': -0.3740532979669721, 'zinc': 0.016496576878358378,
'zstart': 0.21551176912534617,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
assert backscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': 0, 'yinc': 0.09356,
'xstart': 0, 'ystart': -0.374, 'zinc': 0.0165,'zstart': 0.2155,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0}, abs=.001)
# zstart was 0.01 and zinc was 0 in v0.2.2
#assert scene.text == '!xform -rz -90 -t -0.795 0.475 0 -rx 10 -t 0 0 0.2 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -15.9 -4.5 0 -rz 0 objects\\simple_panel.rad'
assert scene.text[0:117] == '!xform -rx 10 -t 0 0 0.2824828843917919 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 0 -t 0 0 0 "objects' #linux has different directory structure and will error here.
assert scene.text[0:105] == '!xform -rx 10 -t 0 0 0.2825 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 0 -t 0 0 0 "objects' #linux has different directory structure and will error here.

def test_SceneObj_makeSceneNxR_hightilt():
# test _makeSceneNxR(tilt, height, pitch, orientation = None, azimuth = 180, nMods = 20, nRows = 7, radname = None)
Expand Down Expand Up @@ -342,19 +340,19 @@ def test_SceneObj_makeSceneNxR_hightilt():
'''
assert [float(x) for x in temp.split(' ')] == pytest.approx([-0.906, -0.016, -0.423]) #was 0,0,-1 in v0.2.4

assert frontscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': -0.040142620018581696, 'xstart': 0.1796000448657153, 'yinc': -0.0007006920388131139,
'ystart': 0.0031349304442418674, 'zinc': 0.08609923976848174,'zstart': 0.2949742232650364,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
assert frontscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1, 'xinc': -0.04013, 'xstart': 0.1796, 'yinc': -0.0007,
'ystart': 0.00313, 'zinc': 0.0861,'zstart': 0.295,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0}, abs=.001)

temp2 = backscan.pop('orient')
assert [float(x) for x in temp2.split(' ')] == pytest.approx([0.906, 0.016, 0.423]) #was 0,0,1 in v0.2.4
assert backscan == pytest.approx({'Nx': 1, 'Ny': 9, 'Nz': 1,
'xinc': -0.040142620018581696, 'xstart': 0.15966431032235584,
'yinc': -0.0007006920388131139, 'ystart': 0.0027869509033958163,
'zinc': 0.08609923976848174, 'zstart': 0.28567662150674106,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0})
'xinc': -0.0401, 'xstart': 0.1597,
'yinc': -0.0007, 'ystart': 0.002787,
'zinc': 0.0861, 'zstart': 0.2856,
'sx_xinc': 0.0, 'sx_yinc':0.0, 'sx_zinc':0.0}, abs=.001)
#assert scene.text == '!xform -rz -90 -t -0.795 0.475 0 -rx 65 -t 0 0 0.2 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -15.9 -4.5 0 -rz 91 objects\\simple_panel.rad'
assert scene.text[0:118] == '!xform -rx 65 -t 0 0 0.6304961988424087 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 91 -t 0 0 0 "objects'
assert scene.text[0:106] == '!xform -rx 65 -t 0 0 0.6304 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -14.4 -4.5 0 -rz 91 -t 0 0 0 "objects'



Expand Down Expand Up @@ -462,8 +460,8 @@ def test_analyzeRow():
scene = demo.makeScene('test-module',sceneDict) #makeScene creates a .rad file with 20 modules per row, 7 rows.
octfile = demo.makeOct(demo.getfilelist()) # makeOct combines all of the ground, sky and object files into a .oct file.
analysis = bifacial_radiance.AnalysisObj(octfile, demo.name) # return an analysis object including the scan dimensions for back irradiance
rowscan = analysis.analyzeRow(octfile = octfile, scene = scene, name = name,
rowWanted = 1, sensorsy = [5,3])
rowscan = analysis.analyzeRow(octfile=octfile, scene=scene, name=name,
rowWanted=1, sensorsy=[5,3])
assert len(rowscan) == 2
assert rowscan.keys()[2] == 'z'
assert len(rowscan[rowscan.keys()[2]][0]) == 5
Expand Down
8 changes: 4 additions & 4 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def test_moduleFrameandOmegas():
scene = demo.makeScene(module,sceneDict)
analysis = bifacial_radiance.AnalysisObj() # return an analysis object including the scan dimensions for back irradiance
frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=1) # Gives us the dictionaries with coordinates
assert backscan['zstart'] == expectedModuleZ[ii]
assert backscan['zstart'] == pytest.approx(expectedModuleZ[ii], abs=.001)

# read the data back from module.json and check again
module = demo.makeModule(name='test-module')
scene = demo.makeScene('test-module',sceneDict)
analysis = bifacial_radiance.AnalysisObj() # return an analysis object including the scan dimensions for back irradiance
frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=1)
assert backscan['zstart'] == expectedModuleZ[ii]
assert backscan['zstart'] == pytest.approx(expectedModuleZ[ii], abs=.001)
# do it again by passing everying at once
module = bifacial_radiance.ModuleObj(name='test-module',x=2, y=1, zgap = zgap,
frameParams=frameParams, omegaParams=omegaParams,
Expand All @@ -134,7 +134,7 @@ def test_moduleFrameandOmegas():
scene = demo.makeScene(module, sceneDict)
analysis = bifacial_radiance.AnalysisObj() # return an analysis object including the scan dimensions for back irradiance
frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=1) # Gives us the dictionaries with coordinates
assert backscan['zstart'] == expectedModuleZ[0]
assert backscan['zstart'] == pytest.approx(expectedModuleZ[0], abs=.001)

# omega default values
module.addOmega()
Expand All @@ -151,7 +151,7 @@ def test_moduleFrameandOmegas():
scene = demo.makeScene(module, sceneDict)
analysis = bifacial_radiance.AnalysisObj() # return an analysis object including the scan dimensions for back irradiance
frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=10) # Gives us the dictionaries with coordinates
assert backscan['xstart'] == pytest.approx(0.792)
assert backscan['xstart'] == pytest.approx(0.792, abs=.001)

def test_GlassModule():
# test the cell-level module generation
Expand Down

0 comments on commit ac4d491

Please sign in to comment.