Пример #1
0
def test_albedo_tmy3():
    # test 1xN albedo array
    demo = bifacial_radiance.RadianceObj(name = 'test')
    demo.readWeatherFile(MET_FILENAME2)
    demo.setGround(demo.metdata.albedo)
    assert demo.ground.Rrefl.__len__() == 8760
    assert demo.ground.ReflAvg.__len__() == 8760
def test_SingleModule_end_to_end():
    # 1 module for STC conditions. DNI:900, DHI:100, sun angle: 33 elevation 0 azimuth
    name = "_test_SingleModule_end_to_end"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    demo.setGround('litesoil')
    metdata = demo.readEPW(epwfile=MET_FILENAME)
    demo.gendaylit(metdata, 4020)  # Noon, June 17th
    # create a scene using panels in landscape at 10 deg tilt, 1.5m pitch. 0.2 m ground clearance
    sceneDict = {
        'tilt': 0,
        'pitch': 1.5,
        'clearance_height': 1,
        'nMods': 1,
        'nRows': 1
    }
    demo.makeModule(name='test', y=0.95, x=1.59, xgap=0)
    scene = demo.makeScene('test', sceneDict)

    #objname='Marker'
    #text='! genbox white_EPDM mymarker 0.02 0.02 2.5 | xform -t -.01 -.01 0'
    #customObject = demo.makeCustomObject(objname,text)
    #demo.appendtoScene(scene.radfiles, customObject, '!xform -rz 0')
    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
    (frontscan, backscan) = analysis.moduleAnalysis(scene, sensorsy=1)
    analysis.analysis(octfile, demo.name, frontscan,
                      backscan)  # compare the back vs front irradiance
    assert analysis.mattype[0][:12] == 'a0.0.a0.test'
    assert analysis.rearMat[0][:12] == 'a0.0.a0.test'
    assert analysis.x == [0]
    assert analysis.y == [0]
Пример #3
0
def test_TorqueTubes_Module():
    name = "_test_TorqueTubes"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    module = demo.makeModule(name='square',
                             y=0.95,
                             x=1.59,
                             tubeParams={
                                 'tubetype': 'square',
                                 'axisofrotation': False
                             },
                             hpc=True)  #suppress saving .json
    assert module.x == 1.59
    assert module.text == '! genbox black square 1.59 0.95 0.02 | xform -t -0.795 -0.475 0 -a 1 -t 0 0.95 0\r\n! genbox Metal_Grey tube1 1.6 0.1 0.1 | xform -t -0.8 -0.05 -0.2'
    module = demo.makeModule(name='round',
                             y=0.95,
                             x=1.59,
                             tubeParams={
                                 'tubetype': 'round',
                                 'axisofrotation': False
                             },
                             hpc=True)
    assert module.text[0:30] == '! genbox black round 1.59 0.95'
    module = demo.makeModule(name='hex',
                             y=0.95,
                             x=1.59,
                             tubeParams={
                                 'tubetype': 'hex',
                                 'axisofrotation': False
                             },
                             hpc=True)
    assert module.text[0:30] == '! genbox black hex 1.59 0.95 0'
    module = demo.makeModule(name='oct', y=0.95, x=1.59, hpc=True)
    module.addTorquetube(tubetype='oct', axisofrotation=False, recompile=False)
    module.compileText(rewriteModulefile=False, json=False)
    assert module.text[0:30] == '! genbox black oct 1.59 0.95 0'
def test_RadianceObj_1axis_gendaylit_end_to_end():
    # 1-axis tracking end-to-end test with torque tube and gap generation.  
    # Takes 20 seconds for 2-sensor scan
    module_height = 1.95 * 2 + 0.1  # module portrait dimension in meters
    gcr = 0.35   # ground cover ratio,  = module_height / pitch
    albedo = 0.3     # ground albedo
    hub_height = 2   # tracker height at 0 tilt in meters (hub height)
    
    demo = bifacial_radiance.RadianceObj()  # Create a RadianceObj 'object'
    demo.setGround(albedo) # input albedo number or material name like 'concrete'.  To see options, run this without any input.
    metdata = demo.readEPW(MET_FILENAME) # read in the EPW weather data from above
    #metdata = demo.readTMY(MET_FILENAME2) # select a TMY file using graphical picker
    # create metdata files for each condition. keys are timestamps for gendaylit workflow
    trackerdict = demo.set1axis(cumulativesky = False)
    # create the skyfiles needed for 1-axis tracking
    demo.gendaylit1axis(metdata = metdata, enddate = '01/01')
    # test modules with gap and rear tube
    demo.makeModule(name='Longi_torquetube',x=0.984,y=1.95,torquetube = True, numpanels = 2, panelgap = 0.1)
    #demo.makeModule(name='Longi_torquetube',x=0.984,y=1.95)
    # set module type to be used and passed into makeScene1axis
    module_type = 'Longi_torquetube'
        
    # Create the scene for the 1-axis tracking
    sceneDict = {'pitch': module_height / gcr,'height':hub_height,'orientation':'portrait'}  
    key = '01_01_11'
    demo.makeScene1axis({key:trackerdict[key]}, module_type,sceneDict, cumulativesky = False, nMods = 10, nRows = 3, modwanted = 3, rowwanted = 3, sensorsy = 2) #makeScene creates a .rad file with 20 modules per row, 7 rows.
    
    demo.makeOct1axis(trackerdict,key) # just run this for one timestep: Jan 1 11am
    demo.analysis1axis(trackerdict,key) # just run this for one timestep: Jan 1 11am

    assert(np.mean(demo.Wm2Front) == pytest.approx(205.0, 0.01) ) # was 214 in v0.2.3
    assert(np.mean(demo.Wm2Back) == pytest.approx(40.0, 0.1) )
Пример #5
0
def test_albedo_tmy3():
    # test 1xN albedo array
    demo = bifacial_radiance.RadianceObj(name='test')
    demo.readWeatherFile(MET_FILENAME2, coerce_year=2001)
    demo.setGround(demo.metdata.albedo)
    assert demo.ground.Rrefl.mean() == pytest.approx(0.2051, abs=.0001)
    assert demo.ground.ReflAvg[0] == 0.33
Пример #6
0
def test_SceneObj_makeSceneNxR_hightilt():
    # test _makeSceneNxR(tilt, height, pitch, orientation = None, azimuth = 180, nMods = 20, nRows = 7, radname = None)
    # default scene with simple_panel, 50 degree tilt, 0.2 height, 1.5 row spacing, landscape
    name = "_test__makeSceneNxR_hightilt"
    demo = bifacial_radiance.RadianceObj(name)
    demo.makeModule(name='test', y=0.95, x=1.59)
    #scene = bifacial_radiance.SceneObj(moduletype = name)
    #scene._makeSceneNxR(tilt=65,height=0.2,pitch=1.5,azimuth=89)
    sceneDict = {'tilt': 65, 'height': 0.2, 'pitch': 1.5, 'azimuth': 89}
    scene = demo.makeScene(moduletype='test', sceneDict=sceneDict)
    analysis = bifacial_radiance.AnalysisObj()
    (frontscan, backscan) = analysis.moduleAnalysis(scene)

    temp = frontscan.pop('orient')
    '''
    assert [float(x) for x in temp.split(' ')] == pytest.approx([-0.999847695156, -0.0174524064373, 0])

    assert frontscan == pytest.approx({'Nx': 1, 'Ny': 1, 'Nz': 9, 'xinc': 0, 'xstart': 0, 'yinc': 0,
                                'ystart': 0, 'zinc': 0.086099239768481745,'zstart': 0.28609923976848173})
                               
    temp2 = backscan.pop('orient')
    assert [float(x) for x in temp2.split(' ')] == pytest.approx([0.999847695156, 0.0174524064373, 0])
    assert backscan == pytest.approx({'Nx': 1, 'Ny': 1, 'Nz': 9, 'xinc': 0, 'xstart': -0.94985531039857163, 
                            'yinc': 0, 'ystart': -0.016579786115419416, 'zinc': 0.086099239768481745, 'zstart': 0.28609923976848173})
    #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:93] == '!xform -rx 65 -t 0 0 0.2 -a 20 -t 1.6 0 0 -a 7 -t 0 1.5 0 -i 1 -t -16.0 -4.5 0 -rz 91 objects'
    '''
    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
    })

    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
    })
    #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:
        117] == '!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'
Пример #7
0
def test_gh127_abspath():
    """RadianceObj path must be absolute"""
    testpath = os.path.abspath(os.path.dirname(__file__))
    projpath = os.path.dirname(testpath)
    temp_path = os.path.join(projpath, 'bifacial_radiance', 'TEMP')
    demo = bifacial_radiance.RadianceObj(name='test', path=temp_path)
    os.path.isabs(demo.path)
def test_RadianceObj_set1axis():  
    # test set1axis.  requires metdata for boulder. 
    demo = bifacial_radiance.RadianceObj()
    demo.readEPW(epwfile = MET_FILENAME)
    trackerdict = demo.set1axis()
    assert trackerdict[0]['count'] == 108
    assert trackerdict[45]['count'] == 823
def test_1axis_gencumSky():
    name = "test_1axis_gencumSky"
    # Takes 20 seconds for 2-sensor scan
    gcr = 0.35   # ground cover ratio,  = module_height / pitch
    albedo = 0.3     # ground albedo
    hub_height = 2   # tracker height at 0 tilt in meters (hub height)
    
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    demo.setGround(albedo) # input albedo number or material name like 'concrete'.  To see options, run this without any input.
    demo.readEPW(MET_FILENAME, starttime='01_01_01', endtime = '01_01_23') # read in the EPW weather data from above
    moduleDict=demo.makeModule(name='test',x=0.984,y=1.95, numpanels = 2, ygap = 0.1)
    pitch= np.round(moduleDict['sceney'] / gcr,3)
    trackerdict = demo.set1axis(cumulativesky = True, gcr=gcr)
    demo.genCumSky1axis()
    assert trackerdict[-45.0]['skyfile'][0:5] == 'skies' #  # Having trouble with the \ or //    'skies\\1axis_-45.0.rad'
    sceneDict = {'gcr': gcr,'hub_height':hub_height, 'clearance_height':hub_height, 'nMods':10, 'nRows':3}  
    trackerdict = demo.makeScene1axis(sceneDict=sceneDict, moduletype = 'test')
    # Removing all of this other tests for hub_height and height since it's ben identified that
    # a new module to handle hub_height and height in sceneDict needs to be implemented
    # instead of checking inside of makeScene, makeSceneNxR, and makeScene1axis
    assert trackerdict[-5.0]['radfile'][0:7] == 'objects' # 'objects\\1axis-5.0_1.825_11.42_5.0_10x3_origin0,0.rad'
    sceneDict = {'pitch': pitch,'clearance_height':hub_height, 'nMods':10, 'nRows':3}  # testing height filter too
    trackerdict = demo.makeScene1axis(sceneDict=sceneDict, moduletype = 'test')
#    assert trackerdict[-5.0]['radfile'] == 'objects\\1axis-5.0_1.825_11.42_5.0_10x3_origin0,0.rad'
    sceneDict = {'pitch': pitch,'height':hub_height, 'nMods':10, 'nRows':3}  # testing height filter too
    trackerdict = demo.makeScene1axis(sceneDict=sceneDict, moduletype = 'test')
#    assert trackerdict[-5.0]['radfile'] == 'objects\\1axis-5.0_1.825_11.42_5.0_10x3_origin0,0.rad'
    sceneDict = {'pitch': pitch,'height':hub_height, 'clearance_height':hub_height, 'nMods':10, 'nRows':3}  # testing height filter too
    trackerdict = demo.makeScene1axis(sceneDict=sceneDict, moduletype = 'test')
#    assert trackerdict[-5.0]['radfile'] == 'objects\\1axis-5.0_1.825_11.42_5.0_10x3_origin0,0.rad'
    sceneDict = {'pitch': pitch,'height':hub_height, 'hub_height':hub_height, 'nMods':10, 'nRows':3}  # testing height filter too
    trackerdict = demo.makeScene1axis(sceneDict=sceneDict, moduletype = 'test')
    demo.exportTrackerDict(trackerdict, savefile = 'results\exportedTrackerDict')
    assert trackerdict[-5.0]['radfile'][0:7] == 'objects' 
def test_tiltandazimuthModuleTest():
    # test full routine for Vertical Modules.
    name = "_test_tiltandazimuth"
    demo = bifacial_radiance.RadianceObj(name)
    demo.setGround(0.2)
    metdata = demo.readWeatherFile(weatherFile=MET_FILENAME)
    demo.gendaylit(4020)
    demo.makeModule(name='test-module', y=2, x=1)
    sceneDict = {
        'gcr': 0.35,
        'hub_height': 2.3,
        'tilt': 45,
        'azimuth': 135,
        'nMods': 1,
        'nRows': 1
    }
    scene = demo.makeScene('test-module', sceneDict)
    octfile = demo.makeOct(demo.getfilelist())
    analysis = bifacial_radiance.AnalysisObj(octfile, demo.basename)
    frontscan, backscan = analysis.moduleAnalysis(scene, sensorsy=[4, 4])
    results = analysis.analysis(octfile, demo.basename, frontscan, backscan)
    assert analysis.mattype[0] == 'a0.0.a0.test-module.6457'
    assert analysis.mattype[1] == 'a0.0.a0.test-module.6457'
    assert analysis.mattype[2] == 'a0.0.a0.test-module.6457'
    assert analysis.mattype[3] == 'a0.0.a0.test-module.6457'
    assert analysis.rearMat[0] == 'a0.0.a0.test-module.2310'
    assert analysis.rearMat[1] == 'a0.0.a0.test-module.2310'
    assert analysis.rearMat[2] == 'a0.0.a0.test-module.2310'
    assert analysis.rearMat[3] == 'a0.0.a0.test-module.2310'
Пример #11
0
def test_TorqueTubes_Module():
    name = "_test_TorqueTubes"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    moduleDict = demo.makeModule(name='square',
                                 y=0.95,
                                 x=1.59,
                                 rewriteModulefile=True,
                                 torquetube=True,
                                 tubetype='square')
    assert moduleDict['x'] == 1.59
    assert moduleDict[
        'text'] == '! genbox black square 1.59 0.95 0.02 | xform -t -0.795 -0.475 0 -a 1 -t 0 0.95 0\r\n! genbox Metal_Grey tube1 1.6 0.1 0.1 | xform -t -0.8 -0.05 -0.2'
    moduleDict = demo.makeModule(name='round',
                                 y=0.95,
                                 x=1.59,
                                 rewriteModulefile=True,
                                 torquetube=True,
                                 tubetype='round')
    assert moduleDict['text'][0:30] == '! genbox black round 1.59 0.95'
    moduleDict = demo.makeModule(name='hex',
                                 y=0.95,
                                 x=1.59,
                                 rewriteModulefile=True,
                                 torquetube=True,
                                 tubetype='hex')
    assert moduleDict['text'][0:30] == '! genbox black hex 1.59 0.95 0'
    moduleDict = demo.makeModule(name='oct',
                                 y=0.95,
                                 x=1.59,
                                 rewriteModulefile=True,
                                 torquetube=True,
                                 tubetype='oct')
    assert moduleDict['text'][0:30] == '! genbox black oct 1.59 0.95 0'
def test_left_label_metdata():
    # left labeled MetObj read in with -1 hour timedelta should be identical to
    # right labeled MetObj
    import pvlib
    import pandas as pd
    (tmydata, metadata) = pvlib.iotools.epw.read_epw(MET_FILENAME,
                                                     coerce_year=2001)
    # rename different field parameters to match output from
    # pvlib.tmy.readtmy: DNI, DHI, DryBulb, Wspd
    tmydata.rename(columns={
        'dni': 'DNI',
        'dhi': 'DHI',
        'temp_air': 'DryBulb',
        'wind_speed': 'Wspd',
        'ghi': 'GHI',
        'albedo': 'Alb'
    },
                   inplace=True)
    metdata1 = bifacial_radiance.MetObj(tmydata, metadata, label='left')
    demo = bifacial_radiance.RadianceObj('test')
    metdata2 = demo.readWeatherFile(weatherFile=MET_FILENAME,
                                    label='right',
                                    coerce_year=2001)
    pd.testing.assert_frame_equal(metdata1.solpos[:-1], metdata2.solpos[:-1])
    assert metdata2.solpos.index[0] == pd.to_datetime('2001-01-01 07:42:00 -7')
def test_addMaterialGroundRad():
    # test addMaterialGroundRad.  requires metdata for boulder.
    name = "_test_addMaterial"
    demo = bifacial_radiance.RadianceObj(name)
    demo.setGround(0.2)
    material = 'demoMat'
    com = "a demonstration material"
    Rrefl = 0.9
    Grefl = 0.2
    Brefl = 0.9
    demo.addMaterial(material=material,
                     Rrefl=Rrefl,
                     Grefl=Grefl,
                     Brefl=Brefl,
                     comment=com)
    demo.setGround('demoMat')
    assert list(demo.ground.Rrefl) == [0.9]
    Rrefl = 0.45
    demo.addMaterial(material=material,
                     Rrefl=Rrefl,
                     Grefl=Grefl,
                     Brefl=Brefl,
                     comment=com,
                     rewrite=False)
    demo.setGround('demoMat')
    assert list(demo.ground.Rrefl) == [0.9]
    demo.addMaterial(material=material,
                     Rrefl=Rrefl,
                     Grefl=Grefl,
                     Brefl=Brefl,
                     comment=com,
                     rewrite=True)
    demo.setGround('demoMat')
    assert list(demo.ground.Rrefl) == [0.45]
def test_SingleModule_end_to_end():
    # 1 module for STC conditions. DNI:900, DHI:100, sun angle: 33 elevation 0 azimuth
    name = "_test_SingleModule_end_to_end"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    demo.setGround('litesoil') 
    metdata = demo.readEPW(epwfile= MET_FILENAME)
    demo.gendaylit(metdata,4020,debug=True)  # 1pm, June 17th
    # create a scene using panels in landscape at 10 deg tilt, 1.5m pitch. 0.2 m ground clearance
    tilt=demo.getSingleTimestampTrackerAngle(metdata=metdata, timeindex=4020, gcr=0.33)
    assert tilt == pytest.approx(-6.7, abs = 0.4)
    sceneDict = {'tilt':0,'pitch':1.5,'clearance_height':1, 'nMods':1, 'nRows':1}  
    demo.makeModule()
    demo.makeModule(name='test',y=0.95,x=1.59, xgap=0)
    scene = demo.makeScene('test',sceneDict) 
   
    #objname='Marker'
    #text='! genbox white_EPDM mymarker 0.02 0.02 2.5 | xform -t -.01 -.01 0'   
    #customObject = demo.makeCustomObject(objname,text)
    #demo.appendtoScene(scene.radfiles, customObject, '!xform -rz 0')
    octfile = demo.makeOct(demo.getfilelist(), hpc=True)  # 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
    (frontscan,backscan) = analysis.moduleAnalysis(scene, sensorsy=1)
    analysis.analysis(octfile, demo.name, frontscan, backscan)  # compare the back vs front irradiance  
    assert analysis.mattype[0][:12] == 'a0.0.a0.test'
    assert analysis.rearMat[0][:12] == 'a0.0.a0.test'
    assert analysis.x == [0]
    assert analysis.y == [0]
    assert np.mean(analysis.Wm2Front) == pytest.approx(1025, abs = 2)
    analysis.makeImage('side.vp', hpc=True)
    analysis.makeFalseColor('side.vp') #TODO: this works on silvanas computer, 
    # side.vp must exist inside of views folder in test folder... make sure this works 
    # in other computers
    assert np.mean(analysis.Wm2Back) == pytest.approx(166, abs = 6)
    
def test_RadianceObj_fixed_tilt_end_to_end():
    # just run the demo example.  Rear irradiance fraction roughly 11.8% for 0.95m landscape panel
    # takes 12 seconds
    name = "_test_fixed_tilt_end_to_end"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    demo.setGround(0.62) # input albedo number or material name like 'concrete'.  To see options, run this without any input.
  
    metdata = demo.readEPW(epwfile= MET_FILENAME) # read in the EPW weather data from above
    #metdata = demo.readTMY() # select a TMY file using graphical picker
    # Now we either choose a single time point, or use cumulativesky for the entire year. 
    fullYear = False
    if fullYear:
        demo.genCumSky(demo.epwfile) # entire year.
    else:
        demo.gendaylit(metdata,4020)  # Noon, June 17th
    # create a scene using panels in landscape at 10 deg tilt, 1.5m pitch. 0.2 m ground clearance
    sceneDict = {'tilt':10,'pitch':1.5,'height':0.2, 'nMods':10, 'nRows':3}  
    demo.makeModule(name='test',y=0.95,x=1.59, xgap=0)
    scene = demo.makeScene('test',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
    (frontscan,backscan) = analysis.moduleAnalysis(scene)
    analysis.analysis(octfile, demo.name, frontscan, backscan)  # compare the back vs front irradiance  
    #assert np.round(np.mean(analysis.backRatio),decimals=2) == 0.12  # NOTE: this value is 0.11 when your module size is 1m, 0.12 when module size is 0.95m
    assert np.mean(analysis.backRatio) == pytest.approx(0.12, abs = 0.01)
Пример #16
0
def test_load_trackerdict():
    # example of saving and loading files in /results/ for 1-axis hourly workflow.
    # this requires some pre-saved files in
    demo = bifacial_radiance.RadianceObj(name='test')
    demo.readEPW(MET_FILENAME)
    trackerdict = demo.set1axis(cumulativesky=False)
    demo.loadtrackerdict(trackerdict, fileprefix='test_')
    assert demo.Wm2Front[0] == pytest.approx(166.3, abs=0.01)
def test_RadianceObj_set1axis():
    # test set1axis.  requires metdata for boulder.
    name = "_test_set1axis"
    demo = bifacial_radiance.RadianceObj(name)
    metdata = demo.readEPW(epwfile=MET_FILENAME)
    trackerdict = demo.set1axis()
    assert trackerdict[0]['count'] == 80  #this was 108 < v0.2.4 and 75 < 0.3.2
    assert trackerdict[45]['count'] == 822  #this was 823 < 0.3.2
def simulate_single(tilt=None, results_folder_fmt=None, weather_file=None):

    # Verify test_folder exists
    test_folder = results_folder_fmt.format(f'{tilt:02}')
    if not os.path.exists(test_folder):
        os.makedirs(test_folder)

    # Variables that stay the same
    #Main Variables needed throughout
    albedo = 0.6
    sim_general_name = 'bifacial_example'
    lat = 37.5
    lon = -77.6
    moduletype = 'Prism Solar Bi60 landscape'
    pitch = 3
    clearance_height = 0.2
    azimuth = 180
    nMods = 20
    nRows = 7
    hpc = True

    pitch = 3
    clearance_height = 0.2
    azimuth = 90
    nMods = 20
    nRows = 7
    hpc = True

    sim_name = sim_general_name + '_' + str(tilt)
    demo = bifacial_radiance.RadianceObj(sim_name, str(test_folder))
    demo.setGround(albedo)
    metdata = demo.readWeatherFile(weather_file)
    demo.genCumSky(savefile=sim_name)
    sceneDict = {
        'tilt': tilt,
        'pitch': pitch,
        'clearance_height': clearance_height,
        'azimuth': azimuth,
        'nMods': nMods,
        'nRows': nRows
    }
    scene = demo.makeScene(moduletype=moduletype,
                           sceneDict=sceneDict,
                           hpc=hpc,
                           radname=sim_name)
    octfile = demo.makeOct(filelist=demo.getfilelist(),
                           octname=demo.basename,
                           hpc=hpc)
    analysis = bifacial_radiance.AnalysisObj(octfile=octfile, name=sim_name)
    frontscan, backscan = analysis.moduleAnalysis(scene=scene)
    frontdict, backdict = analysis.analysis(octfile,
                                            name=sim_name,
                                            frontscan=frontscan,
                                            backscan=backscan)

    results = 1

    return results
Пример #19
0
def test_gendaylit2manual():
    name = "_test_gendaylit2manual"
    demo = bifacial_radiance.RadianceObj(name)
    demo.setGround('litesoil')
    skyname = demo.gendaylit2manual(dni=700, dhi=100, sunalt=67,
                                    sunaz=180)  # Invented values.
    assert skyname[
        0:
        5] == 'skies'  # Having trouble with the \ or // with 'skies\sky2__test_gendaylit2manual.rad'
def simulate_single(daydate=None, results_folder_fmt=None, weather_file=None):

    # Verify test_folder exists
    test_folder = results_folder_fmt.format(f'{daydate}')
    if not os.path.exists(test_folder):
        os.makedirs(test_folder)

    # Variables that stay the same
    #Main Variables needed throughout
    albedo = 0.6
    sim_general_name = 'bifacial_example'
    lat = 37.5
    lon = -77.6
    moduletype = 'Prism Solar Bi60 landscape'
    gcr = 0.35
    hub_height = 0.2

    nMods = 20
    nRows = 7
    hpc = True
    cumulativesky = False

    limit_angle = 60
    backtrack = True

    sim_name = sim_general_name + '_' + str(daydate)
    demo = bifacial_radiance.RadianceObj(sim_name, str(test_folder))
    demo.setGround(albedo)
    metdata = demo.readWeatherFile(weather_file, coerce_year=2021)
    sceneDict = {
        'gcr': gcr,
        'hub_height': hub_height,
        'nMods': nMods,
        'nRows': nRows
    }
    trackerdict = demo.set1axis(limit_angle=limit_angle,
                                backtrack=backtrack,
                                gcr=gcr,
                                cumulativesky=cumulativesky)

    # Restrict trackerdict here
    #foodict = {k: v for k, v in trackerdict.items() if k.startswith('21'+'_'+day_date)}
    #trackerdict = demo.gendaylit1axis(trackerdict = foodict)
    trackerdict = demo.gendaylit1axis(startdate=daydate, enddate=daydate)
    trackerdict = demo.makeScene1axis(
        moduletype=moduletype,
        sceneDict=sceneDict,
        cumulativesky=cumulativesky,
        hpc=hpc
    )  #makeScene creates a .rad file with 20 modules per row, 7 rows.
    trackerdict = demo.makeOct1axis(customname=sim_name, hpc=hpc)
    demo.analysis1axis(customname=sim_name, hpc=hpc)

    results = 1

    return results
def test_customTrackerAngles():
    # TODO: I think with the end test on this function the
    #         test_RadianceObj_set1axis is no longer needed
    name = "_test_customTrackerAngles"
    demo = bifacial_radiance.RadianceObj(name)
    metdata = demo.readWeatherFile(weatherFile=MET_FILENAME5)
    assert metdata.meastracker_angle is not None
    trackerdict = demo.set1axis(azimuth=90, useMeasuredTrackerAngle=True)
    assert trackerdict[-20]['count'] == 3440
    trackerdict = demo.set1axis(azimuth=90, useMeasuredTrackerAngle=False)
    assert trackerdict[-20]['count'] == 37
def test_RadianceObj_set1axis():  
    # test set1axis.  requires metdata for boulder. 
    name = "_test_set1axis"
    demo = bifacial_radiance.RadianceObj(name)
    try:
        epwfile = demo.getEPW(lat=40.01667, lon=-105.25)  # From EPW: {N 40°  1'} {W 105° 15'}
    except: # adding an except in case the internet connection in the lab forbids the epw donwload.
        epwfile = MET_FILENAME
    metdata = demo.readEPW(epwfile = epwfile)
    trackerdict = demo.set1axis()
    assert trackerdict[0]['count'] == 80 #this was 108 < v0.2.4 and 75 < 0.3.2
    assert trackerdict[45]['count'] == 822 #this was 823 < 0.3.2
def test_SceneObj_makeSceneNxR_lowtilt():
    # test _makeSceneNxR(tilt, height, pitch, azimuth = 180, nMods = 20, nRows = 7, radname = None)
    # default scene with simple_panel, 10 degree tilt, 0.2 height, 1.5 row spacing, landscape
    name = "_test_makeSceneNxR_lowtilt"
    demo = bifacial_radiance.RadianceObj(name)
    demo.makeModule(name='test-module', y=0.95, x=1.59)
    #scene = bifacial_radiance.SceneObj(moduletype = name)
    #scene._makeSceneNxR(tilt=10,height=0.2,pitch=1.5)
    sceneDict = {'tilt': 10, 'clearance_height': 0.2, 'pitch': 1.5}
    scene = demo.makeScene(module='test-module', sceneDict=sceneDict)
    analysis = bifacial_radiance.AnalysisObj()
    (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 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
    })
    # 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:
        116] == '!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.
Пример #24
0
def test_SingleModule_gencumsky():
    import datetime

    # 1 module for STC conditions. DNI:900, DHI:100, sun angle: 33 elevation 0 azimuth
    name = "_test_fixedtilt_end_to_end"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    demo.setGround(0.62)
    metdata = demo.readWeatherFile(MET_FILENAME,
                                   starttime='06_17_13',
                                   endtime='06_17_13')
    demo.genCumSky()  # 1p, June 17th
    # create a scene using panels in landscape at 10 deg tilt, 1.5m pitch. 0.2 m ground clearance
    sceneDict = {
        'tilt': 10,
        'pitch': 1.5,
        'clearance_height': 0.2,
        'nMods': 10,
        'nRows': 3
    }
    demo.makeModule(name='test', y=0.95, x=1.59, xgap=0)
    scene = demo.makeScene('test', sceneDict)
    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
    (frontscan, backscan) = analysis.moduleAnalysis(scene)
    analysis.analysis(octfile, demo.name, frontscan,
                      backscan)  # compare the back vs front irradiance
    assert analysis.mattype[0][:12] == 'a4.1.a0.test'
    assert analysis.rearMat[0][:12] == 'a4.1.a0.test'
    assert np.mean(analysis.x) == pytest.approx(0)
    assert np.mean(analysis.y) == pytest.approx(0)

    if DEBUG:
        print(np.mean(analysis.Wm2Front))
        print(np.mean(analysis.Wm2Back))
        print(np.mean(analysis.backRatio))
    # Note: gencumsky has 30-50 Wm-2 variability from run to run...  unsure why.
    assert np.mean(analysis.Wm2Front) == pytest.approx(
        1030, abs=60)  #1023,1037,1050, 1035, 1027, 1044, 1015, 1003, 1056
    assert np.mean(analysis.Wm2Back) == pytest.approx(
        133, abs=15)  # 127, 131, 131, 135, 130, 139, 120, 145

    # run 1-axis gencumsky option
    trackerdict = demo.set1axis(metdata,
                                limit_angle=45,
                                backtrack=True,
                                gcr=0.33)
    demo.genCumSky1axis(trackerdict)
def test_CellLevelModule():
    # test the cell-level module generation 
    name = "_test_CellLevelModule"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'
    cellParams = {'xcell':0.156, 'ycell':0.156, 'numcellsx':6, 'numcellsy':10,  
                   'xcellgap':0.02, 'ycellgap':0.02}
    #moduleDict = demo.makeModule(name=name, cellLevelModule=True, xcell=0.156, rewriteModulefile=True, ycell=0.156,  
    #                             numcellsx=6, numcellsy=10, xcellgap=0.02, ycellgap=0.02)
    moduleDict = demo.makeModule(name='test', rewriteModulefile=True, cellLevelModuleParams = cellParams)
    assert moduleDict['x'] == 1.036
    assert moduleDict['y'] == 1.74
    assert moduleDict['scenex'] == 1.046
    assert moduleDict['sceney'] == 1.74
    assert moduleDict['text'] == '! genbox black cellPVmodule 0.156 0.156 0.02 | xform -t -0.44 -0.87 0 -a 6 -t 0.176 0 0 -a 10 -t 0 0.176 0 -a 1 -t 0 1.74 0'
def test_RadianceObj_set1axis():
    # test set1axis.  requires metdata for boulder.
    name = "_test_set1axis"
    demo = bifacial_radiance.RadianceObj(name)
    assert str(
        demo
    )[-16:
      -2] == name  #this depends on the insertion order of the dictionary repr of demo - may not be consistent
    #try:
    #    epwfile = demo.getEPW(lat=40.01667, lon=-105.25)  # From EPW: {N 40°  1'} {W 105° 15'}
    #except: # adding an except in case the internet connection in the lab forbids the epw donwload.
    epwfile = MET_FILENAME
    metdata = demo.readWeatherFile(weatherFile=epwfile, coerce_year=2001)
    trackerdict = demo.set1axis()
    assert trackerdict[0]['count'] == 78  #80
    assert trackerdict[45]['count'] == 822  #
def test_readWeatherFile_subhourly():
    # need to test out is_leap_and_29Feb and _subhourlydatatoGencumskyformat
    # and len(tmydata) != 8760 and _readSOLARGIS
    name = "_test_readWeatherFile_subhourly_gencumsky"
    demo = bifacial_radiance.RadianceObj(name)
    metdata = demo.readWeatherFile(weatherFile=MET_FILENAME4,
                                   source='solargis',
                                   tz_convert_val=2)
    assert len(demo.gencumsky_metfile) == 2
    gencumsky_file2 = pd.read_csv(demo.gencumsky_metfile[1],
                                  delimiter=' ',
                                  header=None)
    assert gencumsky_file2.__len__() == 8760
    assert gencumsky_file2.iloc[11, 0] == pytest.approx(284.0, abs=0.1)
    assert metdata.elevation == 497
    assert metdata.timezone == 2
Пример #28
0
def test_CellLevelModule():
    # test the cell-level module generation
    name = "_test_CellLevelModule"
    demo = bifacial_radiance.RadianceObj(name)  # Create a RadianceObj 'object'

    module = demo.makeModule(name='test-module',
                             rewriteModulefile=True,
                             cellModule=cellParams)
    assert module.x == 1.036
    assert module.y == 1.74
    assert module.scenex == 1.046
    assert module.sceney == 1.74
    assert module.text == '! genbox black cellPVmodule 0.156 0.156 0.02 | xform -t -0.44 -0.87 0 -a 6 -t 0.176 0 0 -a 10 -t 0 0.176 0 -a 1 -t 0 1.74 0'

    module.addCellModule(
        **cellParams,
        centerJB=0.01)  #centerJB simulations still under development.
Пример #29
0
def test_generate_spectra():
    # test set1axis.  requires metdata for boulder.
    name = "_test_generate_spectra"
    rad_obj = br.RadianceObj(name, TESTDIR)
    metdata = rad_obj.readWeatherFile(MET_FILENAME,
                                      starttime='2001-06-16',
                                      endtime='2001-06-18',
                                      coerce_year=2001)
    idx = metdata.datetime.index(pd.to_datetime('2001-06-17 12:0:0 -7'))

    (spectral_alb, spectral_dni,
     spectral_dhi) = br.generate_spectra(idx,
                                         rad_obj.metdata,
                                         material='Grass',
                                         spectra_folder=SPECTRA_FOLDER)
    assert spectral_alb.data.__len__() == 1962
    assert spectral_dhi.data.index[1961] == 4000.0
    assert spectral_dni.data.iloc[0, 0] == 0.003805
def test_analyzeRow():
    # test analyzeRow. Requires metdata for boulder.

    name = "_test_analyzeRow"
    demo = bifacial_radiance.RadianceObj(name)
    demo.setGround(0.2)
    metdata = demo.readWeatherFile(weatherFile=MET_FILENAME)
    nMods = 2
    nRows = 2
    sceneDict = {
        'tilt': 0,
        'pitch': 30,
        'clearance_height': 3,
        'azimuth': 90,
        'nMods': nMods,
        'nRows': nRows
    }
    demo.setGround(0.2)
    demo.gendaylit(4020)
    demo.makeModule(name='test-module', y=1, x=2, xgap=0.0)
    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=[3, 3])
    assert len(rowscan) == 2
    assert rowscan.keys()[2] == 'z'
    assert len(rowscan[rowscan.keys()[2]][0]) == 3
    # Assert z is the same for two different modules
    assert rowscan[rowscan.keys()[2]][0][0] == rowscan[rowscan.keys()[2]][1][0]
    # Assert Y is different for two different modules
    assert rowscan[rowscan.keys()[1]][0][0] + 2 == rowscan[rowscan.keys()
                                                           [1]][1][0]