def test_RadianceObj_set1axis():
    # test set1axis.  requires metdata for boulder.
    demo = RadianceObj()
    demo.readEPW(epwfile=MET_FILENAME)
    trackerdict = demo.set1axis()
    assert trackerdict[0]['count'] == 108
    assert trackerdict[45]['count'] == 823
Esempio n. 2
0
albedo = 0.2  # ground albedo
hub_height = 2  # tracker height at 0 tilt in meters (hub height)
limit_angle = 45  # tracker rotation limit angle
# Import modules

import numpy as np
import datetime
try:
    from bifacial_radiance import RadianceObj
except ImportError:
    raise RuntimeError('bifacial_radiance is required. download distribution')

print('starting simulation: {}'.format(datetime.datetime.now()))
# Example 1-axis tracking system using Radiance.  This takes 5-10 minutes to complete, depending on computer.

demo = RadianceObj(
    path=testfolder)  # Create a RadianceObj 'object' named 'demo'

demo.setGround(
    albedo
)  # input albedo number or material name like 'concrete'.  To see options, run this without any input.

epwfile = demo.getEPW(
    37.5, -77.6
)  #Pull TMY weather data for any global lat/lon.  In this case, Richmond, VA

metdata = demo.readEPW(epwfile)  # read in the weather data

# create separate metdata files for each 1-axis tracker angle (5 degree resolution).
trackerdict = demo.set1axis(metdata,
                            limit_angle=limit_angle,
                            backtrack=True,
print("Your simulation will be stored in %s" % testfolder)

from bifacial_radiance import RadianceObj, AnalysisObj

# <a id='step1a'></a>

# ### A. Generating the firt scene object
#
# This is a standard fixed-tilt setup for one hour. Gencumsky could be used too for the whole year.
#
# The key here is that we are setting in sceneDict the variable **appendRadfile** to true.

# In[4]:

demo = RadianceObj("MultipleObj",
                   path=testfolder)  # Create a RadianceObj 'object'
demo.setGround(0.62)
epwfile = demo.getEPW(lat=37.5, lon=-77.6)
metdata = demo.readWeatherFile('EPWs\\USA_VA_Richmond.Intl.AP.724010_TMY.epw')
fullYear = True
demo.gendaylit(metdata,
               4020)  # Noon, June 17th  . # Gencumsky could be used too.
module_type = 'Prism Solar Bi60 landscape'
demo.makeModule(name=module_type, y=1, x=1.7)
sceneDict = {
    'tilt': 10,
    'pitch': 1.5,
    'clearance_height': 0.2,
    'azimuth': 180,
    'nMods': 5,
    'nRows': 2,
Esempio n. 4
0
def simulate_single(idx=None,
                    wavelength=None,
                    test_folder_fmt=None,
                    best_data_file=None,
                    data_folder=None):

    # Verify test_folder exists before creating radiance obj
    test_folder = test_folder_fmt.format(f'{idx:04}', f'{wavelength:04}')
    if not os.path.exists(test_folder):
        os.makedirs(test_folder)

    ### NEW FOR SPECTRA

    # Create radiance obj
    radiance_name = 'BEST'
    rad_obj = RadianceObj(radiance_name, str(test_folder))

    # Set ground
    rad_obj.readWeatherFile(best_data_file, label='center')

    # Check to see if file exists
    foo = rad_obj.metdata.datetime[idx]

    # If a wavelength was specified, assume this is a spectral simulation and
    # try to load spectra files.
    # Determine file suffix
    suffix = f'_{idx}.txt'

    # Generate/Load albedo
    alb_file = os.path.join(data_folder, "alb" + suffix)
    spectral_alb = spectral_property.load_file(alb_file)

    # Generate/Load dni and dhi
    dni_file = os.path.join(data_folder, "dni" + suffix)
    dhi_file = os.path.join(data_folder, "dhi" + suffix)
    ghi_file = os.path.join(data_folder, "ghi" + suffix)
    spectral_dni = spectral_property.load_file(dni_file)
    spectral_dhi = spectral_property.load_file(dhi_file)
    spectral_ghi = spectral_property.load_file(ghi_file)

    weighted_albedo = False
    if wavelength:
        alb = spectral_alb[wavelength]
        dni = spectral_dni[wavelength]
        dhi = spectral_dhi[wavelength]
    elif weighted_albedo:
        _alb = np.array(spectral_alb[range(300, 2501, 10)])
        _dni = np.array(spectral_dni[range(300, 2501, 10)])
        _dhi = np.array(spectral_dhi[range(300, 2501, 10)])
        _ghi = np.array(spectral_ghi[range(300, 2501, 10)])

        alb_scale = np.sum(_alb * (_ghi)) / np.sum(alb * (_ghi))
        alb *= alb_scale
        print(f'For IDX {idx}, albedo scaled by {alb_scale}')

    res_name = "irr_Hydra_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute) + '.csv'

    rad_obj.setGround(alb)
    # Set sky
    solpos = rad_obj.metdata.solpos.iloc[idx]
    zen = float(solpos.zenith)
    azm = float(solpos.azimuth) - 180
    rad_obj.gendaylit2manual(dni, dhi, 90 - zen, azm)

    lat = 39.742  # NREL SSRL location
    lon = -105.179  # NREL SSRL location
    elev = 1829
    timezone = -7
    axis_tilt = 0
    axis_azimuth = 180
    limit_angle = 60
    backtrack = True  # Set to false since it's only 1 row, no shading.
    gcr = 0.35
    angledelta = 0  # rounding to ints
    numpanels = 1
    torquetube = False  # We are going to add it separately
    diameter = 0.130175  # 5 1/8 in
    torqueTubeMaterial = 'Metal_Grey'
    tubetype = 'Round'
    axisofrotationTorqueTube = True
    azimuth = 90
    material = 'Metal_Grey'
    hub_height = 1.5  #0.927
    postdiamy = 0.1016  # N-S measurement, 4 "
    postdiamx = 0.1524  # E-W measurement, 6 "
    ttedgeoffset = -1.07  # south edge 42 in. negative because that's how I coded the trnaslation.
    ttedgeoffsetNorth = 0.10795  # North edge $ 4 1/4 inches
    length = 21.64 - ttedgeoffset + ttedgeoffsetNorth  # map goes from beginning of south post, but there is a bit more post to hold the sensor
    decimate = True
    zgap = 0.05 + diameter / 2  # 1 inch of arm, + 1 3/16 of panel width on average ~ 0.055 m
    decimateinterval = '15Min'
    pitch = 5.7  # distance between rows
    ypostlist = [0, 4.199, 10.414, 16.63, 21.64]
    ymods = [
        0.589, 1.596, 2.603, 3.610, 4.788, 5.795, 6.803, 7.810, 8.818, 9.825,
        11.003, 12.011, 13.018, 14.026, 15.034, 16.041, 17.220, 18.230, 19.240,
        20.250
    ]

    numcellsx = 6
    numcellsy = 12
    xcell = 0.142
    ycell = 0.142
    xcellgap = 0.02
    ycellgap = 0.02
    module_type = 'Bi60'

    xgap = 0.046
    ygap = 0
    glass = False

    # Set tracker information
    try:
        tilt = round(
            rad_obj.getSingleTimestampTrackerAngle(rad_obj.metdata,
                                                   idx,
                                                   gcr,
                                                   limit_angle=65), 1)
    except:
        print("Night time !!!!!!!!!")
        print("")
        print("")
        return None

    if math.isnan(tilt):
        return None

    sazm = 90

    cellLevelModuleParams = {
        'numcellsx': numcellsx,
        'numcellsy': numcellsy,
        'xcell': xcell,
        'ycell': ycell,
        'xcellgap': xcellgap,
        'ycellgap': ycellgap
    }

    # Running make module on HPC can cause issues if too many works try to
    # write to the module file at the same time. If something goes wrong,
    # assume the module has already been created.
    '''
    try:
    
        mymodule = rad_obj.makeModule(name=module_type, torquetube=torquetube, diameter=diameter, tubetype=tubetype, material=material, 
                                          xgap=xgap, ygap=ygap, zgap=zgap, numpanels=numpanels,# x=0.952, y=1.924,
                                          cellLevelModuleParams=cellLevelModuleParams, 
                                          axisofrotationTorqueTube=axisofrotationTorqueTube, glass=glass, z=0.0002)
        rad_obj.makeModule(name='sensor', x=0.15, y=0.15, z=0.04)

    except:
        print('Failed to make module.')
    '''
    radname = "Bi60_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute) + "_"

    sceneDict1 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 0,
        'originy': ymods[0]
    }
    sceneObj1 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict1,
                                  radname=radname)

    sceneDict2 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 1,
        'originy': ymods[0]
    }
    sceneObj2 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict2,
                                  radname=radname)

    sceneDict3 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 2,
        'originy': ymods[0]
    }
    sceneObj3 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict3,
                                  radname=radname)

    sceneDict4 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 3,
        'originy': ymods[0]
    }
    sceneObj4 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict4,
                                  radname=radname)

    sceneDict5 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 4,
        'originy': ymods[0]
    }
    sceneObj5 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict5,
                                  radname=radname)

    sceneDict6 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 5,
        'originy': ymods[0]
    }
    sceneObj6 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict6,
                                  radname=radname)

    sceneDict7 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 6,
        'originy': ymods[0]
    }
    sceneObj7 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict7,
                                  radname=radname)

    sceneDict8 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 7,
        'originy': ymods[0]
    }
    sceneObj8 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict8,
                                  radname=radname)

    sceneDict9 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 8,
        'originy': ymods[0]
    }
    sceneObj9 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict9,
                                  radname=radname)

    sceneDict10 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 9,
        'originy': ymods[0]
    }
    sceneObj10 = rad_obj.makeScene(moduletype=module_type,
                                   sceneDict=sceneDict10,
                                   radname=radname)

    #sceneObjects[tilt] = {'Obj1': sceneObj1, 'Obj2': sceneObj2, 'Obj3': sceneObj3, 'Obj4': sceneObj4, 'Obj5': sceneObj5, 'Obj6': sceneObj6, 'Obj7': sceneObj7, 'Obj8': sceneObj8, 'Obj9': sceneObj9, 'Obj10': sceneObj10}

    modulesArray = []
    fieldArray = []

    modulesArray.append(sceneObj1)
    modulesArray.append(sceneObj2)
    modulesArray.append(sceneObj3)
    modulesArray.append(sceneObj4)
    modulesArray.append(sceneObj5)
    modulesArray.append(sceneObj6)
    modulesArray.append(sceneObj7)
    modulesArray.append(sceneObj8)
    modulesArray.append(sceneObj9)
    modulesArray.append(sceneObj10)
    fieldArray.append(modulesArray)

    textrow1 = ''
    textrow2 = sceneObj2.text + '\r\n'
    textrow3 = sceneObj3.text + '\r\n'
    textrow4 = sceneObj4.text + '\r\n'
    textrow5 = sceneObj5.text + '\r\n'
    textrow6 = sceneObj6.text + '\r\n'
    textrow7 = sceneObj7.text + '\r\n'
    textrow8 = sceneObj8.text + '\r\n'
    textrow9 = sceneObj9.text + '\r\n'
    textrow10 = sceneObj10.text + '\r\n'

    # Row 1
    for i in range(1, 20):
        modulesArray = []

        sceneDict1 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 0,
            'originy': ymods[i]
        }
        sceneObj1 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict1,
                                      radname=radname)

        sceneDict2 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 1,
            'originy': ymods[i]
        }
        sceneObj2 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict2,
                                      radname=radname)

        sceneDict3 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 2,
            'originy': ymods[i]
        }
        sceneObj3 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict3,
                                      radname=radname)

        sceneDict4 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 3,
            'originy': ymods[i]
        }
        sceneObj4 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict4,
                                      radname=radname)

        sceneDict5 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 4,
            'originy': ymods[i]
        }
        sceneObj5 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict5,
                                      radname=radname)

        sceneDict6 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 5,
            'originy': ymods[i]
        }
        sceneObj6 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict6,
                                      radname=radname)

        sceneDict7 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 6,
            'originy': ymods[i]
        }
        sceneObj7 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict7,
                                      radname=radname)

        sceneDict8 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 7,
            'originy': ymods[i]
        }
        sceneObj8 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict8,
                                      radname=radname)

        sceneDict9 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 8,
            'originy': ymods[i]
        }
        sceneObj9 = rad_obj.makeScene(moduletype=module_type,
                                      sceneDict=sceneDict9,
                                      radname=radname)

        sceneDict10 = {
            'tilt': tilt,
            'pitch': pitch,
            'hub_height': hub_height,
            'azimuth': azimuth,
            'nMods': 1,
            'nRows': 1,
            'originx': pitch * 9,
            'originy': ymods[i]
        }
        sceneObj10 = rad_obj.makeScene(moduletype=module_type,
                                       sceneDict=sceneDict10,
                                       radname=radname)

        textrow1 += sceneObj1.text + '\r\n'
        textrow2 += sceneObj2.text + '\r\n'
        textrow3 += sceneObj3.text + '\r\n'
        textrow4 += sceneObj4.text + '\r\n'
        textrow5 += sceneObj5.text + '\r\n'
        textrow6 += sceneObj6.text + '\r\n'
        textrow7 += sceneObj7.text + '\r\n'
        textrow8 += sceneObj8.text + '\r\n'
        textrow9 += sceneObj9.text + '\r\n'
        textrow10 += sceneObj10.text + '\r\n'

        modulesArray.append(sceneObj1)
        modulesArray.append(sceneObj2)
        modulesArray.append(sceneObj3)
        modulesArray.append(sceneObj4)
        modulesArray.append(sceneObj5)
        modulesArray.append(sceneObj6)
        modulesArray.append(sceneObj7)
        modulesArray.append(sceneObj8)
        modulesArray.append(sceneObj9)
        modulesArray.append(sceneObj10)

        fieldArray.append(modulesArray)

    # Redoing the first module to append everything to it.
    sceneDict1 = {
        'tilt': tilt,
        'pitch': pitch,
        'hub_height': hub_height,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': pitch * 0,
        'originy': ymods[0]
    }
    sceneObj1 = rad_obj.makeScene(moduletype=module_type,
                                  sceneDict=sceneDict1,
                                  radname=radname)

    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow1)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow2)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow3)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow4)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow5)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow6)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow7)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow8)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow9)
    rad_obj.appendtoScene(sceneObj1.radfiles, '', textrow10)

    # Custom BSA Geometry
    # Bottom posttubes and torquetube:
    for i in range(0, 10):
        xpost = i * pitch

        # adding torquetube
        torquetube = '\n\r! genrev Metal_Grey torquetube{} t*{} {} 32 | xform -rx -90 -t {} {} {}'.format(
            i, length, diameter / 2.0, xpost, ttedgeoffset, hub_height - zgap)
        rad_obj.appendtoScene(sceneObj1.radfiles, '', torquetube)

        for j in range(0, 5):
            ypost = ypostlist[j]

            post1 = '! genbox Metal_Grey pile{} {} {} {} | xform -t {} {} 0 '.format(
                (str(i) + "," + str(j)), postdiamx, postdiamy, hub_height,
                -postdiamx / 2.0 + xpost, -postdiamy + ypost)
            rad_obj.appendtoScene(sceneObj1.radfiles, '', post1)

    ###########################
    # Create sensor objects   #
    ###########################

    # West Sensors
    shhw = 1.5 + (1 - 0.226 / 2) * sin(
        radians(tilt)) + (0.130175 / 2 + 0.05 - 0.02) * cos(radians(tilt))
    sxw = pitch * 2 - (1 - 0.226 / 2) * cos(
        radians(tilt)) + (0.130175 / 2 + 0.05 - 0.02) * sin(radians(tilt))
    syw = ymods[9] + 0.5 + 0.226 / 2
    sensorw_scene = {
        'tilt': tilt,
        'pitch': 1,
        'hub_height': shhw,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': sxw,
        'originy': syw,
        'appendRadfile': True
    }
    res_name = "SensorW_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    sensorw_sceneObj = rad_obj.makeScene(moduletype='sensor',
                                         sceneDict=sensorw_scene,
                                         radname=res_name)

    syw = ymods[15] + 0.5 + 0.226 / 2
    sensorIMTw_scene = {
        'tilt': tilt,
        'pitch': 1,
        'hub_height': shhw,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': sxw,
        'originy': syw,
        'appendRadfile': True
    }
    res_name = "SensorIMTW_" + str(foo.year) + "_" + str(
        foo.month) + "_" + str(foo.day) + "_" + str(foo.hour) + "_" + str(
            foo.minute)
    sensorIMTw_sceneObj = rad_obj.makeScene(moduletype='sensor',
                                            sceneDict=sensorIMTw_scene,
                                            radname=res_name)

    # East Sensors
    shhe = 1.5 - (1 - 0.226 / 2) * sin(
        radians(tilt)) + (0.130175 / 2 + 0.05 - 0.02) * cos(radians(tilt))
    sxe = pitch * 2 + (1 - 0.226 / 2) * cos(
        radians(tilt)) + (0.130175 / 2 + 0.05 - 0.02) * sin(radians(tilt))
    sye = ymods[9] + 0.5 + 0.226 / 2
    sensore_scene = {
        'tilt': tilt,
        'pitch': 1,
        'hub_height': shhe,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': sxe,
        'originy': sye,
        'appendRadfile': True
    }
    res_name = "SensorE_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    sensore_sceneObj = rad_obj.makeScene(moduletype='sensor',
                                         sceneDict=sensore_scene,
                                         radname=res_name)

    sye = ymods[15] + 0.5 + 0.226 / 2
    sensorIMTe_scene = {
        'tilt': tilt,
        'pitch': 1,
        'hub_height': shhe,
        'azimuth': azimuth,
        'nMods': 1,
        'nRows': 1,
        'originx': sxe,
        'originy': sye,
        'appendRadfile': True
    }
    res_name = "SensorIMTE_" + str(foo.year) + "_" + str(
        foo.month) + "_" + str(foo.day) + "_" + str(foo.hour) + "_" + str(
            foo.minute)
    sensorIMTe_sceneObj = rad_obj.makeScene(moduletype='sensor',
                                            sceneDict=sensorIMTe_scene,
                                            radname=res_name)

    # Build oct file
    sim_name = "BEST_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    octfile = rad_obj.makeOct(rad_obj.getfilelist(), octname=sim_name)

    #################
    # Run analysis  #
    #################

    #Row 3 Module 10 sensors
    analysis = AnalysisObj(octfile, rad_obj.basename)

    frontscan, backscan = analysis.moduleAnalysis(
        sensorw_sceneObj,
        sensorsy=1)  #, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)
    res_name = "SensorW_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan,
                                            backscan)

    frontscan, backscan = analysis.moduleAnalysis(
        sensore_sceneObj,
        sensorsy=1)  #, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)
    res_name = "SensorE_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan,
                                            backscan)

    #IMT Sensors Row 3 Module 5
    '''
    frontscan, backscan = analysis.moduleAnalysis(sensorIMTw_sceneObj, sensorsy=1)#, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)
    res_name = "SensorIMTW_"+str(foo.year)+"_"+str(foo.month)+"_"+str(foo.day)+"_"+str(foo.hour)+"_"+str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan, backscan)

    frontscan, backscan = analysis.moduleAnalysis(sensorIMTe_sceneObj, sensorsy=1)#, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)
    res_name = "SensorIMTE_"+str(foo.year)+"_"+str(foo.month)+"_"+str(foo.day)+"_"+str(foo.hour)+"_"+str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan, backscan)
    
    #fieldARray[module][row]

    #HYDRA
    modmod = 16
    rowrow = 1
    frontscan, backscan = analysis.moduleAnalysis(fieldArray[modmod][rowrow], sensorsy=12)#, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)        
    res_name = "Hydra_"+str(foo.year)+"_"+str(foo.month)+"_"+str(foo.day)+"_"+str(foo.hour)+"_"+str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan, backscan)

    '''

    #LOCATION_APOGEES
    modmod = 9
    rowrow = 2
    frontscan, backscan = analysis.moduleAnalysis(
        fieldArray[modmod][rowrow],
        sensorsy=4)  #, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)
    frontscan['ystart'] = frontscan['ystart'] + 0.45
    backscan['ystart'] = backscan['ystart'] + 0.45
    res_name = "Apogee_" + str(foo.year) + "_" + str(foo.month) + "_" + str(
        foo.day) + "_" + str(foo.hour) + "_" + str(foo.minute)
    frontdict, backdict = analysis.analysis(octfile, res_name, frontscan,
                                            backscan)
    '''
    # SCAN FULL ROWS
    for rowrow in range(5, 7):
        for modmod in range(0, 20):
            frontscan, backscan = analysis.moduleAnalysis(fieldArray[modmod][rowrow], sensorsy=12)#, frontsurfaceoffset=0.021)#, backsurfaceoffset = 0.02)        
            res_name = "Row_"+str(rowrow)+"_Mod_"+str(modmod)+"_"+str(foo.year)+"_"+str(foo.month)+"_"+str(foo.day)+"_"+str(foo.hour)+"_"+str(foo.minute)
            frontdict, backdict = analysis.analysis(octfile, res_name, frontscan, backscan)
    '''
    # Read in results
    #results_file = os.path.join('results', f'irr_sensor_{sim_name}.csv')
    #results = load.read1Result(results_file)
    results = 1

    # Format output
    #tracker_theta = tilt
    #front = ','.join([ str(f) for f in results['Wm2Front'] ])
    #back = ','.join([ str(r) for r in results['Wm2Back'] ])
    print("***** Finished simulation for " + str(foo))
    #time_str = metdata.datetime[idx]
    #    print(f"sim_results,{idx},{time_str},{wavelength},{dni},{dhi},{alb}," \
    #          f"{tracker_theta},{front},{back}")
    return results
def test_RadianceObj_high_azimuth_angle_end_to_end():
    # modify example for high azimuth angle to test different parts of makesceneNxR.  Rear irradiance fraction roughly 17.3% for 0.95m landscape panel
    # takes 14 seconds for sensorsy = 9, 11 seconds for sensorsy = 2
    demo = RadianceObj()  # Create a RadianceObj 'object'
    demo.setGround(
        'white_EPDM'
    )  # input albedo number or material name like 'concrete'.  To see options, run this without any input.

    #metdata = demo.readEPW() # read in the EPW weather data from above
    metdata = demo.readTMY(
        MET_FILENAME2)  # 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.  # Don't know how to test this yet in pytest...
    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,
        'orientation': 'landscape',
        'azimuth': 30
    }
    demo.makeModule(name='simple_panel', x=0.95, y=1.59)
    scene = demo.makeScene(
        'simple_panel', sceneDict, nMods=10, nRows=3
    )  #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 = AnalysisObj(
        octfile, demo.name
    )  # return an analysis object including the scan dimensions for back irradiance
    analysis.analysis(octfile, demo.name, scene.frontscan,
                      scene.backscan)  # compare the back vs front irradiance
    #assert np.round(np.mean(analysis.backRatio),2) == 0.20  # bifi ratio was == 0.22 in v0.2.2
    assert np.mean(analysis.Wm2Front) == pytest.approx(912, rel=0.005)
    assert np.mean(analysis.Wm2Back) == pytest.approx(182, rel=0.01)
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
    demo = RadianceObj()  # 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,
        'orientation': 'landscape'
    }
    demo.makeModule(name='simple_panel', x=0.95, y=1.59)
    scene = demo.makeScene(
        'simple_panel', sceneDict, nMods=10, nRows=3
    )  #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 = AnalysisObj(
        octfile, demo.name
    )  # return an analysis object including the scan dimensions for back irradiance
    analysis.analysis(octfile, demo.name, scene.frontscan,
                      scene.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)
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 = 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(214.0, 0.01))
    assert (np.mean(demo.Wm2Back) == pytest.approx(40.0, 0.1))
    
from bifacial_radiance import RadianceObj, AnalysisObj    


# <a id='step1a'></a>

# ### A. Generating the first scene object
# 
# This is a standard fixed-tilt setup for one hour. Gencumsky could be used too for the whole year.
# 
# The key here is that we are setting in sceneDict the variable **appendRadfile** to true.

# In[2]:


demo = RadianceObj("tutorial_7", path = testfolder) 
demo.setGround(0.62)
epwfile = demo.getEPW(lat = 37.5, lon = -77.6)    
metdata = demo.readWeatherFile(epwfile, coerce_year=2001) 
fullYear = True
timestamp = metdata.datetime.index(pd.to_datetime('2001-06-17 13:0:0 -5'))  # Noon, June 17th  
demo.gendaylit(timestamp)  
module_type = 'test-moduleA' 
mymodule = demo.makeModule(name=module_type,y=1,x=1.7)
sceneDict = {'tilt':10,'pitch':1.5,'clearance_height':0.2,'azimuth':180, 'nMods': 5, 'nRows': 2, 'appendRadfile':True} 
sceneObj1 = demo.makeScene(mymodule, sceneDict)  


# Checking values after Scene for the scene Object created

# In[3]: